|
AccessToken
How the AccessToken api works
IntroductionThe AccessToken is used for accessing Web Services using the OAuth protocol. This is only used from the ConsumerService side. AccessToken lifecycle
Contains
CreationYou ask the RequestToken to exchange it self for an AccessToken from the ServiceProvider: @access_token=@request_token.get_access_token Accessing REST webservicesIt wraps the ruby http/s object with simple methods for each http method: # GET /people.xml
@response=@access_token.get('/people.xml')
# GET /people/1.xml
@response=@access_token.get('/people/1.xml')
# POST /people
@response=@access_token.post('/people',"person[name]=Bob")
# POST /people with xml
@response=@access_token.post('/people',@person.to_xml,{'Content-Type'=>'application/xml')
# PUT /people/1
@response=@access_token.post('/people/1',"person[name]=Bob%20Smith")
# PUT /people/1 with xml
@response=@access_token.put('/people/1',@person.to_xml,{'Content-Type'=>'application/xml')
# DELETE /people/1
@response=@access_token.delete('/people/1')
|
Sign in to add a comment
there's some errata. {'Content-Type'=>'application/xml' => {'Content-Type'=>'application/xml'}
thanks for great document.
Using a long living AccessToken
If the provider does not invalidate the access token until explicitly requested to do so, then one can keep the string values to use at a later time:
# Initialisation based on string values: consumer_key = 'AVff2raXvhMUxFnif06g' consumer_secret = 'u0zg77R1bQqbzutAusJYmTxqeUpWVt7U2TjWlzbVZkA' access_token = 'R1bQqbzYm0zg77tAusJzbVZkAVt7U2T' access_token_secret = 'sVbVZkAt7U2TjWlJYmTxqR1bQqbzutAuWzeUpu0zg77' @consumer = OAuth::Consumer.new(consumer_key, consumer_secret, {:site=>'http://my.site'}) @accesstoken = OAuth::AccessToken.new(@consumer, access_token, access_token_secret)Sending specific HTTP headers
To send specific HTTP headers such as User-Agent or Accept:
@response = @access_token.get('/people.xml', {'User-Agent'=>'my user agent'})