Class HeyWatch::Browser
In: lib/heywatch/browser.rb
Parent: Object

This class is used to request the Hey!Watch service.

  Browser::get '/video', session
  Browser::post '/download', {:url => 'http://host.com/video.avi'}, session
  Browser::put '/encoded_video/54000', {:title => 'new title'}, session
  Browser::delete '/encoded_video/54000', session

Methods

delete   get   post   put   raise_if_response_error  

Public Class methods

DELETE on path

[Source]

    # File lib/heywatch/browser.rb, line 65
65:       def delete(path, session=nil)
66:         res = Net::HTTP.start(Host) {|http| http.delete(path+"."+OutFormat, header(session))}
67:         raise_if_response_error(res)
68:         true
69:       end

GET on path

[Source]

    # File lib/heywatch/browser.rb, line 41
41:       def get(path, session=nil)
42:         path += ".#{OutFormat}" unless path.include? "."
43:         res = Net::HTTP.start(Host) {|http| http.get(path, header(session))}
44:         raise_if_response_error(res)
45:         res
46:       end

POST on path and pass the query(Hash)

[Source]

    # File lib/heywatch/browser.rb, line 49
49:       def post(path, query={}, session=nil)
50:         res = Net::HTTP.start(Host) {|http| http.post(path, query.merge(:format => OutFormat).to_a.map{|x| x.join("=")}.join("&"), self.header(session))}
51:         raise_if_response_error(res)
52:         res
53:       end

PUT on path and pass the query(Hash)

[Source]

    # File lib/heywatch/browser.rb, line 56
56:       def put(path, query={}, session=nil)
57:         req = Net::HTTP::Put.new(path, header(session))
58:         req.form_data = query.merge(:format => OutFormat)
59:         res = Net::HTTP.new(Host).start {|http| http.request(req) }
60:         raise_if_response_error(res)
61:         true
62:       end

Raise when code response != 2xx

[Source]

    # File lib/heywatch/browser.rb, line 13
13:       def raise_if_response_error(res)
14:         code = res.response.code.to_i
15:         message = res.response.message
16:         return if code.to_s =~ /^2/
17:         
18:         raise RequestError, HeyWatch::response(res.body).content if code == 400
19:         raise NotAuthorized, message if code == 401
20:         raise ResourceNotFound, message if code == 404
21:         raise ServerError, message if code == 500
22:       end

[Validate]