instagram_graph_api 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c146673cee7d9aa329292c2960179c110769dea3
4
- data.tar.gz: e32f237195aba30a370cef2f4325f8f71648ceda
2
+ SHA256:
3
+ metadata.gz: 28320da8d9ba8e5b0c16cf85f204d282b73766edf1f2c0614becaa87eee9394d
4
+ data.tar.gz: b24c8987eef0aeb5f97ca77001e450c9b9b110b26c7ea72df00488eb45a81532
5
5
  SHA512:
6
- metadata.gz: 9707fccfeffa43462d11236ea251f7de3491a21bdae65a8b4f40417b6d5f0d300446586f0f8ad4710b47be7cd207c78a25e71d8a4ce8bfbbc7803be8f60b3ead
7
- data.tar.gz: 0a6b45183ee0c6da248a264a656a93f76a577c30e4fe6417a625be99805f02baf3a06e0c305c3eb7a3b9a03809cd88e3181f24a9306f059bc10299a6b70c470b
6
+ metadata.gz: 93804d5de94409db1fe636bd58b7e0960bec82af3ca9b01872d85d06761d2a58d2e19864e762307d748cf790c38ff35a53e0d8c663c70ebc299e58d6550f071a
7
+ data.tar.gz: 0a5df44c8e045521b81069c6ac80cf9d2a2b1618b41d9fdc9c0dfce00616603227a3323c854204c804bab11d126dee3b5cb73868b25918067bbeb918d3871753
data/bin/console CHANGED
@@ -7,8 +7,5 @@ require "instagram_graph_api"
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
10
+ require "pry"
11
+ Pry.start
@@ -1,11 +1,29 @@
1
1
  module InstagramGraphApi
2
2
  class Client
3
3
  module Media
4
- def get_user_recent_media(ig_account_id, type: "media", options: {})
5
- query = "#{type}?fields=comments_count,like_count,media_type,media_url,permalink,timestamp,thumbnail_url"
4
+ attr_accessor :media_info, :insights
5
+
6
+ METRIC_HASH = {
7
+ image: 'impressions,reach',
8
+ video: 'impressions,reach,video_views',
9
+ story: 'impressions,replies,reach,taps_forward,taps_back,exits'
10
+ }
11
+
12
+ MEDIA_INFO_HASH = {
13
+ image: "comments_count,like_count,media_type,"\
14
+ "media_url,permalink,timestamp,thumbnail_url",
15
+ video: "comments_count,like_count,media_type,"\
16
+ "media_url,permalink,timestamp,thumbnail_url",
17
+ story: "media_type,media_url,permalink,"\
18
+ "timestamp,thumbnail_url"
19
+ }
20
+
21
+ def get_user_recent_media(id, type: "image", options: {})
22
+ entity = type.eql?("story") ? "stories" : "media"
23
+ query = "#{entity}?fields=#{MEDIA_INFO_HASH[type.to_sym]}"
6
24
  query += "&after=#{options[:after]}" if options[:after]
7
- query += "&after=#{options[:before]}" if options[:before]
8
- get_connections(ig_account_id, query)
25
+ query += "&before=#{options[:before]}" if options[:before]
26
+ get_connections(id, query)
9
27
  end
10
28
 
11
29
  def get_media_details(media_id, fields = nil)
@@ -13,6 +31,25 @@ module InstagramGraphApi
13
31
  media_url,permalink,timestamp,thumbnail_url,ig_id"
14
32
  get_connections(media_id , "?fields=#{fields}")
15
33
  end
34
+
35
+ def insight(media_id, type)
36
+ insights = get_insights(media_id)
37
+ if insights
38
+ insight = insights.select{|m| m["name"] == type}.first
39
+ data = if insight
40
+ insight
41
+ else
42
+ try(type).first
43
+ end
44
+
45
+ data["values"].first["value"]
46
+ end
47
+ end
48
+
49
+ private
50
+ def get_insights(media_id)
51
+ @insights = get_connections(media_id , "insights?metric=#{METRIC_HASH[type.to_sym]}")
52
+ end
16
53
  end
17
54
  end
18
55
  end
@@ -2,7 +2,7 @@ module InstagramGraphApi
2
2
  class Client
3
3
  module Users
4
4
  def ig_business_accounts(fields = nil)
5
- fields ||= 'id,name,biography, ig_id, followers_count, profile_picture_url,username'
5
+ fields ||= 'id,name,biography,ig_id,followers_count,profile_picture_url,username'
6
6
  accounts = get_pages("?fields=instagram_business_account{#{fields}}")
7
7
  accounts.map do |a|
8
8
  a["instagram_business_account"].merge(page_id: a["id"]) if a["instagram_business_account"]
@@ -1,3 +1,3 @@
1
1
  module InstagramGraphApi
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instagram_graph_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rakesh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-18 00:00:00.000000000 Z
11
+ date: 2018-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.6.11
98
+ rubygems_version: 2.7.7
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Instagram Graph API