Class: OAuthClient::Client

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

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

constructor



16
17
18
19
20
21
22
# File 'lib/oauth_client/client.rb', line 16

def initialize(options = {})
  @consumer_key = options[:consumer_key]
  @consumer_secret = options[:consumer_secret]
  @token = options[:token]
  @secret = options[: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 authorize(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

Raises:

  • (OAuthUnauthorized)


41
42
43
44
# File 'lib/oauth_client/client.rb', line 41

def get(url)
  raise OAuthUnauthorized if !access_token
  access_token.get(url)
end

#jsonObject

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

Raises:

  • (OAuthUnauthorized)


47
48
49
50
# File 'lib/oauth_client/client.rb', line 47

def post(url, params = {})
  raise OAuthUnauthorized if !access_token
  access_token.post(url, params)
end

#request_tokenObject

get the request token



36
37
38
# File 'lib/oauth_client/client.rb', line 36

def request_token
  consumer.get_request_token
end