Class: Instagramrb::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
  if options[:access_token]
    @access_token = options[:access_token]
  else
    @client_id = options[:client_id]
    @client_secret = options[:client_secret]
    @callback_url = options[:callback_url]
  end
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

#callback_urlObject

Returns the value of attribute callback_url.



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

def callback_url
  @callback_url
end

#client_idObject

Returns the value of attribute client_id.



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

def client_id
  @client_id
end

#client_secretObject

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_urlObject



19
20
21
# File 'lib/instagramrb/client.rb', line 19

def authorize_url
  "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