Class: Foursquare::OAuth

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

Instance Method Summary collapse

Constructor Details

#initialize(ctoken, csecret, options = {}) ⇒ OAuth

Returns a new instance of OAuth.



12
13
14
# File 'lib/foursquare.rb', line 12

def initialize(ctoken, csecret, options={})
  @consumer_token, @consumer_secret = ctoken, csecret
end

Instance Method Details

#access_tokenObject



44
45
46
# File 'lib/foursquare.rb', line 44

def access_token
  @access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
end

#authorize_from_access(atoken, asecret) ⇒ Object



48
49
50
# File 'lib/foursquare.rb', line 48

def authorize_from_access(atoken, asecret)
  @atoken, @asecret = atoken, asecret
end

#authorize_from_request(request_token, request_secret, verifier) ⇒ Object



38
39
40
41
42
# File 'lib/foursquare.rb', line 38

def authorize_from_request(request_token, request_secret, verifier)
  request_token = ::OAuth::RequestToken.new(consumer, request_token, request_secret)
  access_token = request_token.get_access_token(:oauth_verifier => verifier)
  @atoken, @asecret = access_token.token, access_token.secret
end

#consumerObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/foursquare.rb', line 16

def consumer
  return @consumer if @consumer
  @consumer = ::OAuth::Consumer.new(@consumer_token, @consumer_secret, {
    :site               => "http://foursquare.com",
    :scheme             => :header,
    :http_method        => :post,
    :request_token_path => "/oauth/request_token",
    :access_token_path  => "/oauth/access_token",
    :authorize_path     => "/oauth/authorize",
    :proxy              => (ENV['HTTP_PROXY'] || ENV['http_proxy'])
  })
end

#request_token(options = {}) ⇒ Object



34
35
36
# File 'lib/foursquare.rb', line 34

def request_token(options={})
  @request_token ||= consumer.get_request_token(options)
end

#set_callback_url(url) ⇒ Object



29
30
31
32
# File 'lib/foursquare.rb', line 29

def set_callback_url(url)
  clear_request_token
  request_token(:oauth_callback => url)
end