Class: Admincredible::Resources::Oauth

Inherits:
Admincredible::Resource show all
Defined in:
lib/admincredible/resources/Oauth.rb

Instance Attribute Summary

Attributes inherited from Admincredible::Resource

#client

Instance Method Summary collapse

Methods inherited from Admincredible::Resource

#config, #connection, #initialize

Constructor Details

This class inherits a constructor from Admincredible::Resource

Instance Method Details

#access_token(oauth_verifier) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/admincredible/resources/Oauth.rb', line 34

def access_token(oauth_verifier)       
  params = {
    :resource       => 'oauth',
    :task           => 'access_token',
    :oauth_token    => config.token,
    :oauth_verifier => oauth_verifier
  }
  oauth_header = ROAuth.header(config.oauth_options, config.url, params)
  response     = JSON.parse(Nestful.get(config.url, :params => params, :headers => {'Accept' => 'application/json', 'Authorization' => oauth_header}))
  return response unless response['status'] == 200
  
  config.token        = response['data']['access_token']['oauth_token']
  config.token_secret = response['data']['access_token']['oauth_token_secret']

  client.rebuild_connection
  return response['data']['access_token']
end

#authorization_urlObject



26
27
28
29
30
31
32
# File 'lib/admincredible/resources/Oauth.rb', line 26

def authorization_url
  url    = config.url.gsub(config.direct_endpoint, config.main_endpoint)
  url    = URI.parse(url)
  params = CGI.parse(url.query)

  return ROAuth.sign_url(config.oauth_options, url.scheme + '://' + url.host + url.path, params.merge({:oauth_callback => config.oauth_callback}))
end

#registerObject



4
5
6
7
8
9
10
11
12
13
# File 'lib/admincredible/resources/Oauth.rb', line 4

def register
  response = client.jget('oauth', 'register')
  return response unless response['status'] == 200

  config.consumer_key    = response['data']['osr_consumer_key']
  config.consumer_secret = response['data']['osr_consumer_secret']

  client.rebuild_connection
  return response['data']
end

#request_tokenObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/admincredible/resources/Oauth.rb', line 15

def request_token
  response = client.jget('oauth', 'request_token')
  return response unless response['status'] == 200
  
  config.token        = response['data']['request_token']['oauth_token']
  config.token_secret = response['data']['request_token']['oauth_token_secret']

  client.rebuild_connection
  return response['data']['request_token']
end