Class: Instagram::Client
- Inherits:
-
Object
- Object
- Instagram::Client
- Defined in:
- lib/instagram_api/client.rb,
lib/instagram_api/client/media.rb,
lib/instagram_api/client/users.rb
Overview
Client for the Instagram API.
Defined Under Namespace
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#callback_url ⇒ Object
Returns the value of attribute callback_url.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
Instance Method Summary collapse
-
#authorize_url ⇒ String
Return the authorize URL for a client.
-
#get_access_token(code = nil) ⇒ String
Get an access token for a user.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Methods included from Users
#feed, #liked, #recent, #search, #user
Methods included from Media
#media, #media_search, #popular_media
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 |
# File 'lib/instagram_api/client.rb', line 19 def initialize(={}) if [:access_token] @access_token = [:access_token] else @client_id = [:client_id] @client_secret = [:client_secret] @callback_url = [:callback_url] end end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
17 18 19 |
# File 'lib/instagram_api/client.rb', line 17 def access_token @access_token end |
#callback_url ⇒ Object
Returns the value of attribute callback_url.
17 18 19 |
# File 'lib/instagram_api/client.rb', line 17 def callback_url @callback_url end |
#client_id ⇒ Object
Returns the value of attribute client_id.
17 18 19 |
# File 'lib/instagram_api/client.rb', line 17 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
17 18 19 |
# File 'lib/instagram_api/client.rb', line 17 def client_secret @client_secret end |
Instance Method Details
#authorize_url ⇒ String
Return the authorize URL for a client.
33 34 35 |
# File 'lib/instagram_api/client.rb', line 33 def "#{Default::AUTH_URL}?client_id=#{@client_id}&redirect_uri=#{@callback_url}&response_type=code" end |
#get_access_token(code = nil) ⇒ String
Get an access token for a user.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/instagram_api/client.rb', line 45 def get_access_token(code=nil) unless @access_token params = { client_id: @client_id, client_secret: @client_secret, grant_type: 'authorization_code', redirect_uri: @callback_url, code: code } response = post "https://api.instagram.com/oauth/access_token", {}, params, { 'Content-type' => 'application/x-www-form-urlencoded' } @access_token = response['access_token'] @access_token else @access_token end end |