Class: OAuthClient::Client
- Inherits:
-
Object
- Object
- OAuthClient::Client
- Defined in:
- lib/oauth_client/client.rb
Class Method Summary collapse
-
.http_method(http_method = nil) ⇒ Object
class method for setting/getting the http method for API.
- .request_scheme(scheme = nil) ⇒ Object
-
.scheme(scheme = nil) ⇒ Object
class method for setting/getting the http method for API.
-
.site(site = nil) ⇒ Object
class method for setting/getting the base uri for API.
Instance Method Summary collapse
-
#authorize(token, secret, options = {}) ⇒ 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(options = {}) ⇒ Object
get the request token.
-
#xml ⇒ Object
xml adapter, allowing xml.get and xml.post methods.
Constructor Details
#initialize(options = {}) ⇒ Client
constructor
28 29 30 31 32 33 34 |
# File 'lib/oauth_client/client.rb', line 28 def initialize( = {}) @consumer_key = [:consumer_key] @consumer_secret = [:consumer_secret] @token = [:token] || "" @secret = [:secret] @adapters = {} end |
Class Method Details
.http_method(http_method = nil) ⇒ Object
class method for setting/getting the http method for API
11 12 13 14 |
# File 'lib/oauth_client/client.rb', line 11 def self.http_method(http_method = nil) @@http_method = http_method if http_method @@http_method end |
.request_scheme(scheme = nil) ⇒ Object
22 23 24 25 |
# File 'lib/oauth_client/client.rb', line 22 def self.request_scheme(scheme = nil) @@request_scheme = scheme if scheme @@request_scheme end |
.scheme(scheme = nil) ⇒ Object
class method for setting/getting the http method for API
17 18 19 20 |
# File 'lib/oauth_client/client.rb', line 17 def self.scheme(scheme = nil) @@scheme = scheme if scheme @@scheme end |
.site(site = nil) ⇒ Object
class method for setting/getting the base uri for API
5 6 7 8 |
# File 'lib/oauth_client/client.rb', line 5 def self.site(site = nil) @@site = site if site @@site end |
Instance Method Details
#authorize(token, secret, options = {}) ⇒ Object
authorization
37 38 39 40 41 42 43 44 45 |
# File 'lib/oauth_client/client.rb', line 37 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
53 54 55 56 |
# File 'lib/oauth_client/client.rb', line 53 def get(url) raise OAuthUnauthorized if !access_token access_token.get(url) end |
#json ⇒ Object
json adapter, allowing json.get and json.post methods
65 66 67 68 69 |
# File 'lib/oauth_client/client.rb', line 65 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
59 60 61 62 |
# File 'lib/oauth_client/client.rb', line 59 def post(url, params = {}) raise OAuthUnauthorized if !access_token access_token.post(url, params) end |
#request_token(options = {}) ⇒ Object
get the request token
48 49 50 |
# File 'lib/oauth_client/client.rb', line 48 def request_token( = {}) consumer(:scheme => (@@request_scheme || :header)).get_request_token() end |
#xml ⇒ Object
xml adapter, allowing xml.get and xml.post methods
72 73 74 75 76 |
# File 'lib/oauth_client/client.rb', line 72 def xml return @adapters[:xml] if @adapters[:xml] require 'oauth_client/adapters/xml' @adapters[:xml] = OAuthClient::Adapters::Xml.new(self) end |