Class: OAuth::AccessToken

Inherits:
ConsumerToken show all
Defined in:
lib/oauth/tokens/access_token.rb

Overview

The Access Token is used for the actual “real” web service calls that you perform against the server

Instance Attribute Summary

Attributes inherited from ConsumerToken

#consumer, #params, #response

Attributes inherited from Token

#secret, #token

Instance Method Summary collapse

Methods inherited from ConsumerToken

from_hash, #initialize, #sign!

Methods inherited from Token

#initialize, #to_query

Methods included from Helper

_escape, escape, generate_key, generate_timestamp, normalize, normalize_nested_query, parse_header, stringify_keys, unescape

Constructor Details

This class inherits a constructor from OAuth::ConsumerToken

Instance Method Details

#delete(path, headers = {}) ⇒ Object

Make a regular DELETE request using AccessToken

@response = @token.delete('/people/123')
@response = @token.delete('/people/123', { 'Accept' => 'application/xml' })


81
82
83
# File 'lib/oauth/tokens/access_token.rb', line 81

def delete(path, headers = {})
  request(:delete, path, headers)
end

#get(path, headers = {}) ⇒ Object

Make a regular GET request using AccessToken

@response = @token.get('/people')
@response = @token.get('/people', { 'Accept'=>'application/xml' })


28
29
30
# File 'lib/oauth/tokens/access_token.rb', line 28

def get(path, headers = {})
  request(:get, path, headers)
end

#head(path, headers = {}) ⇒ Object

Make a regular HEAD request using AccessToken

@response = @token.head('/people')


36
37
38
# File 'lib/oauth/tokens/access_token.rb', line 36

def head(path, headers = {})
  request(:head, path, headers)
end

#patch(path, body = "", headers = {}) ⇒ Object

Make a regular PATCH request using AccessToken

@response = @token.patch('/people/123')
@response = @token.patch('/people/123', { :name => 'Bob', :email => '[email protected]' })
@response = @token.patch('/people/123', { :name => 'Bob', :email => '[email protected]' }, { 'Accept' => 'application/xml' })
@response = @token.patch('/people/123', nil, { 'Accept' => 'application/xml' })
@response = @token.patch('/people/123', @person.to_xml, { 'Accept' => 'application/xml', 'Content-Type' => 'application/xml' })


72
73
74
# File 'lib/oauth/tokens/access_token.rb', line 72

def patch(path, body = "", headers = {})
  request(:patch, path, body, headers)
end

#post(path, 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' })


48
49
50
# File 'lib/oauth/tokens/access_token.rb', line 48

def post(path, body = "", headers = {})
  request(:post, path, body, headers)
end

#put(path, 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' })


60
61
62
# File 'lib/oauth/tokens/access_token.rb', line 60

def put(path, body = "", headers = {})
  request(:put, path, body, headers)
end

#request(http_method, path, *arguments) ⇒ Object

The less intrusive way. Otherwise, if we are to do it correctly inside consumer, we need to restructure and touch more methods: request(), sign!(), etc.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/oauth/tokens/access_token.rb', line 8

def request(http_method, path, *arguments)
  request_uri = URI.parse(path)
  site_uri = consumer.uri
  is_service_uri_different = (request_uri.absolute? && request_uri != site_uri)
  begin
    consumer.uri(request_uri) if is_service_uri_different
    @response = super(http_method, path, *arguments)
  ensure
    # NOTE: reset for wholesomeness? meaning that we admit only AccessToken service calls may use different URIs?
    # so reset in case consumer is still used for other token-management tasks subsequently?
    consumer.uri(site_uri) if is_service_uri_different
  end
  @response
end