Module: InstagramGraphApi::Client::Media

Included in:
InstagramGraphApi::Client
Defined in:
lib/instagram_graph_api/client/media.rb

Constant Summary collapse

METRIC_HASH =
{
  image: 'impressions,reach',
  video: 'impressions,reach,video_views',
  story: 'impressions,replies,reach,taps_forward,taps_back,exits'
}
MEDIA_INFO_HASH =
{
  image: "comments_count,like_count,media_type,"\
              "media_url,permalink,timestamp,thumbnail_url",
  video: "comments_count,like_count,media_type,"\
              "media_url,permalink,timestamp,thumbnail_url",
  story: "media_type,media_url,permalink,"\
                "timestamp,thumbnail_url"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#media_infoObject

Returns the value of attribute media_info.



4
5
6
# File 'lib/instagram_graph_api/client/media.rb', line 4

def media_info
  @media_info
end

#raw_insightsObject

Returns the value of attribute raw_insights.



4
5
6
# File 'lib/instagram_graph_api/client/media.rb', line 4

def raw_insights
  @raw_insights
end

Instance Method Details

#get_media_details(media_id, type: "image") ⇒ Object



29
30
31
32
# File 'lib/instagram_graph_api/client/media.rb', line 29

def get_media_details(media_id, type: "image")
  fields ||= MEDIA_INFO_HASH[type.to_sym]
  get_connections(media_id , "?fields=#{fields}")
end

#get_user_recent_media(id, type: "image", options: {}) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/instagram_graph_api/client/media.rb', line 21

def get_user_recent_media(id, type: "image", options: {})
  entity = type.eql?("story") ? "stories" : "media"
  query = "#{entity}?fields=#{MEDIA_INFO_HASH[type.to_sym]}"
  query += "&after=#{options[:after]}" if options[:after]
  query += "&before=#{options[:before]}" if options[:before]
  get_connections(id, query)
end

#insights(media_id, type: "image", metrics: nil) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/instagram_graph_api/client/media.rb', line 34

def insights(media_id, type: "image", metrics: nil)
  metrics ||= METRIC_HASH[type.to_sym]
  @raw_insights = get_connections(media_id , "insights?metric=#{metrics}")
  @raw_insights.reduce({}) do |result, insight_data|
    result[insight_data["name"]] = insight_data["values"].first["value"]
    result
  end
end