Class: Foursquared::OAuth::Client

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

Overview

OAuth Client class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret, callback_url, opts = {}, &block) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/foursquared/oauth/client.rb', line 8

def initialize(client_id, client_secret, callback_url, opts={}, &block)
  @client_id = client_id
  @client_secret = client_secret
  @callback_url = callback_url
  ssl = opts.delete(:ssl)

  @options = {
              :site => 'https://foursquare.com/',
              :authorize_url => '/oauth2/authenticate?response_type=code',
              :token_url => '/oauth2/access_token',
              :parse_json => true}.merge(opts)
  @options[:connection_opts][:ssl] = ssl if ssl
  @oauth_client = OAuth2::Client.new(client_id, client_secret, @options)
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



7
8
9
# File 'lib/foursquared/oauth/client.rb', line 7

def access_token
  @access_token
end

#callback_urlObject

Returns the value of attribute callback_url.



7
8
9
# File 'lib/foursquared/oauth/client.rb', line 7

def callback_url
  @callback_url
end

#client_idObject

Returns the value of attribute client_id.



7
8
9
# File 'lib/foursquared/oauth/client.rb', line 7

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



7
8
9
# File 'lib/foursquared/oauth/client.rb', line 7

def client_secret
  @client_secret
end

#oauth_clientObject

Returns the value of attribute oauth_client.



7
8
9
# File 'lib/foursquared/oauth/client.rb', line 7

def oauth_client
  @oauth_client
end

Instance Method Details

#authorize_urlString

Step 1: URL for OAuth2 oauthorizetion of Foursquare

Returns:

  • (String)


25
26
27
# File 'lib/foursquared/oauth/client.rb', line 25

def authorize_url
  oauth_client.auth_code.authorize_url(:redirect_uri => callback_url)
end

#get_access_token(code) ⇒ String

Step 2: Get access token after authorizing user

Parameters:

  • code (String)

    The value extracted from the callback url param ‘code’

Returns:

  • (String)

    the access token



32
33
34
35
# File 'lib/foursquared/oauth/client.rb', line 32

def get_access_token code
  token = oauth_client.auth_code.get_token(code, :redirect_uri => callback_url)
  @access_token = token.token
end