Class: OAuthClient::Client
- Inherits:
-
Object
- Object
- OAuthClient::Client
- Defined in:
- lib/oauth_client/client.rb
Class Attribute Summary collapse
-
.site(site = nil) ⇒ Object
class method for setting/getting the base uri for API.
Instance Method Summary collapse
-
#authorize(token, secret) ⇒ Object
authorization.
-
#get(url) ⇒ Object
make a GET request and return raw response.
-
#initialize(options = {}) ⇒ Client
constructor
constructor.
-
#json ⇒ Object
json adapter, allowing json.get and json.post methods.
-
#post(url, params = {}) ⇒ Object
make a POST request and return raw response.
-
#request_token ⇒ Object
get the request token.
Constructor Details
#initialize(options = {}) ⇒ Client
constructor
16 17 18 19 20 21 22 |
# File 'lib/oauth_client/client.rb', line 16 def initialize( = {}) @consumer_key = [:consumer_key] @consumer_secret = [:consumer_secret] @token = [:token] @secret = [:secret] @adapters = {} end |
Class Attribute Details
.site(site = nil) ⇒ Object
class method for setting/getting the base uri for API
10 11 12 |
# File 'lib/oauth_client/client.rb', line 10 def site @site end |
Instance Method Details
#authorize(token, secret) ⇒ Object
authorization
25 26 27 28 29 30 31 32 33 |
# File 'lib/oauth_client/client.rb', line 25 def (token, secret) request_token = OAuth::RequestToken.new( consumer, token, secret ) @access_token = request_token.get_access_token @token = @access_token.token @secret = @access_token.secret @access_token end |
#get(url) ⇒ Object
make a GET request and return raw response
41 42 43 44 |
# File 'lib/oauth_client/client.rb', line 41 def get(url) raise if !access_token access_token.get(url) end |
#json ⇒ Object
json adapter, allowing json.get and json.post methods
53 54 55 56 57 |
# File 'lib/oauth_client/client.rb', line 53 def json return @adapters[:json] if @adapters[:json] require 'oauth_client/adapters/json' @adapters[:json] = OAuthClient::Adapters::Json.new(self) end |
#post(url, params = {}) ⇒ Object
make a POST request and return raw response
47 48 49 50 |
# File 'lib/oauth_client/client.rb', line 47 def post(url, params = {}) raise if !access_token access_token.post(url, params) end |
#request_token ⇒ Object
get the request token
36 37 38 |
# File 'lib/oauth_client/client.rb', line 36 def request_token consumer.get_request_token end |