Class: Instagramrb::Client
- Inherits:
-
Object
- Object
- Instagramrb::Client
- Defined in:
- lib/instagramrb/client.rb
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 ⇒ Object
- #fetch(url) ⇒ Object
- #get_access_token(code = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 |
# File 'lib/instagramrb/client.rb', line 9 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.
7 8 9 |
# File 'lib/instagramrb/client.rb', line 7 def access_token @access_token end |
#callback_url ⇒ Object
Returns the value of attribute callback_url.
7 8 9 |
# File 'lib/instagramrb/client.rb', line 7 def callback_url @callback_url end |
#client_id ⇒ Object
Returns the value of attribute client_id.
7 8 9 |
# File 'lib/instagramrb/client.rb', line 7 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
7 8 9 |
# File 'lib/instagramrb/client.rb', line 7 def client_secret @client_secret end |
Instance Method Details
#authorize_url ⇒ Object
19 20 21 |
# File 'lib/instagramrb/client.rb', line 19 def "https://api.instagram.com/oauth/authorize/?client_id=#{@client_id}&redirect_uri=#{@callback_url}&response_type=code" end |
#fetch(url) ⇒ Object
40 41 42 43 |
# File 'lib/instagramrb/client.rb', line 40 def fetch(url) fullUrl = "https://api.instagram.com/"+ url + "/?access_token=" + @access_token get(fullUrl) end |
#get_access_token(code = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/instagramrb/client.rb', line 23 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 |