Module: Orkut::Request
- Included in:
- API
- Defined in:
- lib/orkut/request.rb
Overview
Defines HTTP request methods
Instance Method Summary collapse
-
#delete_v1(path = nil, headers = {}) ⇒ Object
Make a regular DELETE request using AccessToken.
- #execute(entity, action, params = {}, body = '', headers = {}) ⇒ Object
- #get_refresh_access_token ⇒ Object
-
#get_v1(path = nil, headers = {}) ⇒ Object
Make a regular GET request using AccessToken.
-
#head_v1(path = nil, headers = {}) ⇒ Object
Make a regular HEAD request using AccessToken.
-
#post_v1(path = nil, body = '', headers = {}) ⇒ Object
Make a regular POST request using AccessToken.
-
#put_v1(path = nil, body = '', headers = {}) ⇒ Object
Make a regular PUT request using AccessToken.
- #verify_path(path) ⇒ Object
Instance Method Details
#delete_v1(path = nil, headers = {}) ⇒ Object
Make a regular DELETE request using AccessToken
@response = @token.delete('/people/123')
@response = @token.delete('/people/123', { 'Accept' => 'application/xml' })
58 59 60 |
# File 'lib/orkut/request.rb', line 58 def delete_v1(path = nil, headers = {}) connection_v1.delete(verify_path(path), headers) end |
#execute(entity, action, params = {}, body = '', headers = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/orkut/request.rb', line 62 def execute(entity, action, params = {}, body = '', headers = {}) raise(Orkut::Error, 'Parameters entity and action cannot be nil') if entity.blank? or action.blank? raise(Orkut::Error, 'Parameter body cannot be nil or empty') if params.blank? or params.empty? extra = params.delete(Orkut::Constants::Fields::EXTRA_PARAMS) orkut = connection.discovered_api('orkut', 'v2') response = connection(extra).execute(orkut.try(entity.to_sym).try(action.to_sym), params, body, headers) response = response.response if !response.kind_of?(Array) status, headers, body = response if status == 200 return body.first else return '{"error" : "erro"}' end end |
#get_refresh_access_token ⇒ Object
6 7 8 9 10 |
# File 'lib/orkut/request.rb', line 6 def get_refresh_access_token res = credentials res = connection..fetch_access_token! if connection..expired? res end |
#get_v1(path = nil, headers = {}) ⇒ Object
Make a regular GET request using AccessToken
@response = @token.get('/people')
@response = @token.get('/people', { 'Accept'=>'application/xml' })
17 18 19 |
# File 'lib/orkut/request.rb', line 17 def get_v1(path = nil, headers = {}) connection_v1.get(verify_path(path), headers) end |
#head_v1(path = nil, headers = {}) ⇒ Object
Make a regular HEAD request using AccessToken
@response = @token.head('/people')
25 26 27 |
# File 'lib/orkut/request.rb', line 25 def head_v1(path = nil, headers = {}) connection_v1.head(verify_path(path), headers) end |
#post_v1(path = nil, body = '', headers = {}) ⇒ Object
Make a regular POST request using AccessToken
@response = @token.post('/people')
@response = @token.post('/people', { :name => 'Bob', :email => '[email protected]' })
@response = @token.post('/people', { :name => 'Bob', :email => '[email protected]' }, { 'Accept' => 'application/xml' })
@response = @token.post('/people', nil, {'Accept' => 'application/xml' })
@response = @token.post('/people', @person.to_xml, { 'Accept'=>'application/xml', 'Content-Type' => 'application/xml' })
37 38 39 |
# File 'lib/orkut/request.rb', line 37 def post_v1(path = nil, body = '', headers = {}) connection_v1.post(verify_path(path), body, headers) end |
#put_v1(path = nil, body = '', headers = {}) ⇒ Object
Make a regular PUT request using AccessToken
@response = @token.put('/people/123')
@response = @token.put('/people/123', { :name => 'Bob', :email => '[email protected]' })
@response = @token.put('/people/123', { :name => 'Bob', :email => '[email protected]' }, { 'Accept' => 'application/xml' })
@response = @token.put('/people/123', nil, { 'Accept' => 'application/xml' })
@response = @token.put('/people/123', @person.to_xml, { 'Accept' => 'application/xml', 'Content-Type' => 'application/xml' })
49 50 51 |
# File 'lib/orkut/request.rb', line 49 def put_v1(path = nil, body = '', headers = {}) connection_v1.put(verify_path(path), body, headers) end |
#verify_path(path) ⇒ Object
79 80 81 82 |
# File 'lib/orkut/request.rb', line 79 def verify_path(path) path ||= endpoint path end |