Class: Insta::API

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ API

Returns a new instance of API.



61
62
63
64
# File 'lib/insta.rb', line 61

def initialize(access_token)
  @access_token  = access_token
  @next_url = nil
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



60
61
62
# File 'lib/insta.rb', line 60

def access_token
  @access_token
end

#next_urlObject

Returns the value of attribute next_url.



60
61
62
# File 'lib/insta.rb', line 60

def next_url
  @next_url
end

Instance Method Details

#meObject



66
67
68
69
# File 'lib/insta.rb', line 66

def me
  url = "https://graph.instagram.com/me?fields=account_type,media_count,username,id&access_token=#{access_token}"
  get(url)
end

#media(limit = 100) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/insta.rb', line 71

def media(limit = 100)
  url = "https://graph.instagram.com/me/media?fields=id,media_type,caption,permalink,thumbnail_url,media_url,username,timestamp&access_token=#{access_token}&limit=#{limit}"
  response  = get(url)
  puts response.dig('paging', 'next')
  @next_url = response.dig('paging', 'next') unless response.dig('paging', 'next').nil?
  response
end

#next_pageObject



79
80
81
82
83
84
85
86
87
88
# File 'lib/insta.rb', line 79

def next_page
  return {} if next_url.nil?
  response  = get(next_url)
  if response.dig('paging', 'next').nil?
    @next_url = nil
  else
    @next_url = response.dig('paging', 'next')
  end
  response
end