class Instagramrb::Client

Attributes

access_token[RW]
callback_url[RW]
client_id[RW]
client_secret[RW]

Public Class Methods

new(options={}) click to toggle source
# 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

Public Instance Methods

authorize_url() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

auth_params() click to toggle source
# File lib/instagramrb/client.rb, line 56
def auth_params
  @access_token ? { :access_token => @access_token } : { :client_id => @client_id }
end
get(url) click to toggle source
# File lib/instagramrb/client.rb, line 46
def get(url)
  response = HTTP.get url
  JSON.parse(response)
end
post(url, params={}, body={}, headers={}) click to toggle source
# File lib/instagramrb/client.rb, line 51
def post(url, params={}, body={}, headers={})
  response = HTTP.post(url, :form => body)
  JSON.parse(response)
end