Class: Insta::API
- Inherits:
-
Object
- Object
- Insta::API
- Defined in:
- lib/insta.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#next_url ⇒ Object
Returns the value of attribute next_url.
Instance Method Summary collapse
-
#initialize(access_token) ⇒ API
constructor
A new instance of API.
- #me ⇒ Object
- #media(limit = 100) ⇒ Object
- #next_page ⇒ Object
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_token ⇒ Object
Returns the value of attribute access_token.
60 61 62 |
# File 'lib/insta.rb', line 60 def access_token @access_token end |
#next_url ⇒ Object
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
#me ⇒ Object
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_page ⇒ Object
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 |