Class: OAuthClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth_client/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

constructor



28
29
30
31
32
33
34
# File 'lib/oauth_client/client.rb', line 28

def initialize(options = {})
  @consumer_key = options[:consumer_key]
  @consumer_secret = options[:consumer_secret]
  @token = options[:token] || ""
  @secret = options[: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 authorize(token, secret, options = {})
  request_token = OAuth::RequestToken.new(
    consumer, token, secret
  )
  @access_token = request_token.get_access_token(options)
  @token = @access_token.token
  @secret = @access_token.secret
  @access_token
end

#get(url) ⇒ Object

make a GET request and return raw response

Raises:

  • (OAuthUnauthorized)


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

#jsonObject

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

Raises:

  • (OAuthUnauthorized)


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(options = {})
  consumer(:scheme => (@@request_scheme || :header)).get_request_token(options)
end

#xmlObject

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