Class: CombineHashtags::Query

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

Overview

Queries the instagram API with basic permissions AKA only self“s profile

Instance Method Summary collapse

Constructor Details

#initializeQuery

Returns a new instance of Query.



8
9
10
# File 'lib/combine_hashtags/query.rb', line 8

def initialize
  @request = build_query
end

Instance Method Details

#build_queryObject

put together the query URL with access token set in .env



13
14
15
16
17
18
19
# File 'lib/combine_hashtags/query.rb', line 13

def build_query
  base = "https://graph.instagram.com/me/media"
  access_token = ENV["ACCESS_TOKEN"]
  field = "id,timestamp,caption,media_url,permalink,media_type"

  "#{base}?fields=#{field}&access_token=#{access_token}"
end

#call_apiObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/combine_hashtags/query.rb', line 21

def call_api
  begin
    response = RestClient.get @request
  # prompt the user in case of missing or invalid access_token  
  rescue RestClient::BadRequest
    bad_request_msg
  else
    parse(response)
  end
end