fb-core 1.0.0.alpha12 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd59a79b809b6f4ecd3306cb4513115e5e4f25df
4
- data.tar.gz: c167e50a5222e725f62b675734e7ffe3aa02424d
3
+ metadata.gz: 2d1ed4eed672a395c27801bc02db07900070337f
4
+ data.tar.gz: 4fef2f273973e16f75a6a7e79e016356df83a31e
5
5
  SHA512:
6
- metadata.gz: '0194add029d28a6a4c452370f6fce79b45ad81fb16f0b10ed52af5c211cc7a4865171f700c944b8a6b90287eb5a30d26ebd51e9603ebebf94ae42663fd1cdcb6'
7
- data.tar.gz: 792587046f24310265871bbad3e5d6714b358361ed2a9668f8cd85a88974c1fdd8afbb1fa1a6be0de88ebbb310da18b1407631bc4318dd9c0d9c3987630e13ad
6
+ metadata.gz: 67ee600baecd0b2a1d8e821edaeb0b52a40098284cc4148979ee5d71f0aa0fe6ccbd25cbdb576b13bf7bff5e93fba46da7707c8e4834def977e41738f1bf8360
7
+ data.tar.gz: b5ee2d255afaeaeafcd7bc3b77c17981921e9ead4c4ea3ec71627c7419b43f9d752fa9ed9df709f8811a25bc71117dc4f2929e7c878b927324b279edc3d154de
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+
10
+ ## 1.0.0.beta1 - 2018/02/14
11
+
12
+ * [ENHANCEMENT] Fix and use Page Access Token when request page insights.
13
+
9
14
  ## 1.0.0.alpha12 - 2017/12/08
10
15
 
11
16
  * [FEATURE] Add `Fb::Video` and `Fb::Page#videos`
@@ -3,6 +3,6 @@ module Fb
3
3
  class Core
4
4
  # @return [String] the SemVer-compatible gem version.
5
5
  # @see http://semver.org
6
- VERSION = '1.0.0.alpha12'
6
+ VERSION = '1.0.0.beta1'
7
7
  end
8
8
  end
data/lib/fb/page.rb CHANGED
@@ -94,7 +94,15 @@ module Fb
94
94
  private
95
95
 
96
96
  def page_insights(metrics, options = {})
97
- insights(metrics, options.merge(ids: id))[id]['data']
97
+ insights(metrics, options.merge(ids: id, access_token: page_access_token))[id]['data']
98
+ end
99
+
100
+ def page_access_token
101
+ @page_access_token ||= begin
102
+ params = {fields: 'access_token', access_token: @access_token}
103
+ request = HTTPRequest.new path: "/v2.9/#{@id}", params: params
104
+ request.run.body["access_token"]
105
+ end
98
106
  end
99
107
 
100
108
  def posts_from(data)
@@ -117,7 +125,7 @@ module Fb
117
125
  end
118
126
 
119
127
  def insights(metrics, options = {})
120
- params = options.merge metric: metrics.join(','), access_token: @access_token
128
+ params = {metric: metrics.join(','), access_token: @access_token}.merge options
121
129
  request = HTTPRequest.new path: "/v2.9/insights", params: params
122
130
  request.run.body
123
131
  end
@@ -138,7 +146,7 @@ module Fb
138
146
  def videos_with_metrics_from(data)
139
147
  data.each_slice(25).flat_map do |video_slice|
140
148
  video_ids = video_slice.map {|video| video['id']}.join(',')
141
- metrics = video_insights(ids: video_ids)
149
+ metrics = video_insights(video_metrics, ids: video_ids)
142
150
  video_slice.map do |video_data|
143
151
  insights_data = metrics[video_data['id']]['data'].map do |metric|
144
152
  [metric['name'], metric['values'].last.fetch('value', 0)]
@@ -148,8 +156,8 @@ module Fb
148
156
  end
149
157
  end
150
158
 
151
- def video_insights(options = {})
152
- params = options.merge access_token: @access_token
159
+ def video_insights(metrics, options = {})
160
+ params = options.merge metric: metrics.join(','), access_token: @access_token
153
161
  request = HTTPRequest.new path: "/v2.9/video_insights", params: params
154
162
  request.run.body
155
163
  end
@@ -164,5 +172,11 @@ module Fb
164
172
  ].join(',')
165
173
  end
166
174
  end
175
+
176
+ def video_metrics
177
+ %i(total_video_views total_video_views_unique total_video_avg_time_watched
178
+ total_video_views_autoplayed total_video_views_clicked_to_play total_video_complete_views_auto_played
179
+ total_video_complete_views_clicked_to_play total_video_views_sound_on total_video_10s_views_sound_on)
180
+ end
167
181
  end
168
182
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha12
4
+ version: 1.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-12-09 00:00:00.000000000 Z
12
+ date: 2018-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fb-support