fb-core 1.0.0.beta10 → 1.0.0.beta11

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
- SHA1:
3
- metadata.gz: 42466ce3b3855146af568ed94374c219e8409731
4
- data.tar.gz: 62a72bf0afd273c9fe122964ce92fed20649f799
2
+ SHA256:
3
+ metadata.gz: 3d5d9595ad06f96e9cd804a1795e01798482dbf95a6cad93731de6074bbdee36
4
+ data.tar.gz: c37aab3d7991f3eb33300871007a54751b31bd2c21ba38d69a354ca03a795a56
5
5
  SHA512:
6
- metadata.gz: ba53c107a9c8b3cf0089c58949c3dc84014212ae285aabd0d52df38eed4ec0123c096b025df9f01ff67a76ac6e91d8b47ebb6376c8b2451e4d966dd0879bfce9
7
- data.tar.gz: 33bdb5fcc8d469d2db6d37b7d3bc264386cccbb72c37029df766d79ab43b82c95a83d8c5b5315d2e213f58bcdb3ec7f0b30c58199c616a546bd178f1ce08c524
6
+ metadata.gz: b5e271e36f438510e4f3fef268fb5b1c2f57359763192980fa6c39412a5e1618d799eb75275e79d9aea7f41831dec619fe166b9ea2bed8ddcd186780a7de65d0
7
+ data.tar.gz: e4fd05041ec08593d03e03e3d1d6e05c11702f2218a1b02efc86d94ba99f6f334076fe14dc05f60de86e108419c2e3d681e473427abdb16dbfca3c7b7ed9a088
@@ -6,6 +6,27 @@ 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.beta11
11
+
12
+ * [IMPROVEMENT] Return UTC time for String value of `created_time`, `backdated_time`,
13
+ `end_time`, etc from Facebook to have exact time.
14
+ * [FEATURE] Add `Fb::Post#lifetime_insights` method to get metrics of each post.
15
+ * [BUGFIX] Return empty hash instead of nil when a metric returns empty array.
16
+
17
+ **How to upgrade**
18
+
19
+ If your code calls `.consumptions` then you must replace that code with `.clicks`
20
+ since those metrics will no longer be supported by Facebook API as of
21
+ [August 1, 2018](https://developers.facebook.com/docs/graph-api/reference/v2.9/insights#newnames).
22
+ If your code calls `fan_reach` from a Fb::Post then you must remove that code
23
+ because Facebook removed that metric from [version 3.0](https://developers.facebook.com/docs/graph-api/changelog/version3.0) and they already applied the change to v2.9 the version currently
24
+ fb-core uses.
25
+
26
+ * [REMOVAL] Remove `#consumptions` method for posts
27
+ * [REMOVAL] Remove `#fan_reach` method for posts
28
+ * [FEATURE] Add `#clicks` method for posts
29
+
9
30
  ## 1.0.0.beta10 - 2018/05/01
10
31
 
11
32
  * [FEATURE] Add `:since` and `:until` option to `Page#videos` method.
@@ -5,6 +5,7 @@ require 'fb/page'
5
5
  require 'fb/user'
6
6
  require 'fb/post'
7
7
  require 'fb/video'
8
+
8
9
  # An object-oriented Ruby client for the Facebook Graph API.
9
10
  # @see http://www.rubydoc.info/gems/fb-core/
10
11
  module Fb
@@ -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.beta10'
6
+ VERSION = '1.0.0.beta11'
7
7
  end
8
8
  end
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module Fb
2
4
  # Provides methods to interact with Facebook pages through the Graph API.
3
5
  # @see https://developers.facebook.com/docs/graph-api/reference/page/
@@ -11,6 +13,8 @@ module Fb
11
13
  # @option [String] the page’s category.
12
14
  attr_reader :category
13
15
 
16
+ attr_reader :access_token
17
+
14
18
  # @param [Hash] options to initialize a Page object.
15
19
  # @option [String] :id The page’s unique ID.
16
20
  # @option [String] :name The page’s name.
@@ -30,9 +34,10 @@ module Fb
30
34
  # @option [Date] :until only return dates previous to this day (upper bound).
31
35
  def metric_insights(metric, period, options = {})
32
36
  insights = page_insights Array(metric), options.merge(period: period)
33
- values = insights.find{|data| data['name'] == metric}['values']
37
+ return {} if insights.empty?
38
+ values = insights.find(->{{}}){|data| data['name'] == metric}['values']
34
39
  values.map do |v|
35
- [Date.strptime(v['end_time'], '%Y-%m-%dT%H:%M:%S+0000'), v.fetch('value', 0)]
40
+ [Date.parse(v['end_time']), v.fetch('value', 0)]
36
41
  end.to_h
37
42
  end
38
43
 
@@ -70,10 +75,11 @@ module Fb
70
75
  # @option [Boolean] :with_metrics whether to include insights for the posts.
71
76
  def posts(options = {})
72
77
  @posts ||= begin
78
+ with_metrics = options.delete :with_metrics
73
79
  params = posts_params.merge options
74
80
  request = PaginatedRequest.new path: "/v2.9/#{@id}/posts", params: params
75
81
  data = request.run.body['data']
76
- options[:with_metrics] ? posts_with_metrics_from(data) : posts_from(data)
82
+ with_metrics ? posts_with_metrics_from(data) : posts_from(data)
77
83
  end
78
84
  end
79
85
 
@@ -95,10 +101,11 @@ module Fb
95
101
  # @option [Boolean] :without_lifetime_metrics whether to include insights for the videos.
96
102
  def videos(options = {})
97
103
  @videos ||= begin
104
+ without_lifetime_metrics = options.delete :without_lifetime_metrics
98
105
  params = video_params.merge options
99
106
  request = PaginatedRequest.new path: "/v2.9/#{@id}/videos", params: params
100
107
  data = request.run.body['data']
101
- options[:without_lifetime_metrics] ? videos_from(data) : videos_with_metrics_from(data)
108
+ without_lifetime_metrics ? videos_from(data) : videos_with_metrics_from(data)
102
109
  end
103
110
  end
104
111
 
@@ -164,8 +171,8 @@ module Fb
164
171
  post_impressions_paid post_impressions_paid_unique post_impressions_fan
165
172
  post_impressions_fan_unique post_impressions_fan_paid post_impressions_fan_paid_unique
166
173
  post_impressions_organic post_impressions_organic_unique post_impressions_viral
167
- post_consumptions post_engaged_users post_negative_feedback post_engaged_fan
168
- post_fan_reach post_reactions_like_total post_reactions_love_total
174
+ post_clicks post_engaged_users post_negative_feedback post_engaged_fan
175
+ post_reactions_like_total post_reactions_love_total
169
176
  post_reactions_wow_total post_reactions_haha_total post_reactions_sorry_total
170
177
  post_reactions_anger_total post_video_avg_time_watched post_video_complete_views_organic
171
178
  post_video_complete_views_organic_unique post_video_complete_views_paid
@@ -1,11 +1,11 @@
1
- # Ruby client to authenticate a Facebook user.
2
- # @see http://www.rubydoc.info/gems/Fb/
1
+ require 'time'
2
+
3
3
  module Fb
4
4
  # Fb::Post reprensents a Facebook post. Post provides getters for:
5
5
  # :id, :url, :created_at, :type, :message, :length, engaged_users,
6
6
  # video_views, video_views_organic, video_views_paid, and so on.
7
7
  # @see https://developers.facebook.com/docs/graph-api/reference/v2.10/post
8
- class Post
8
+ class Post < Resource
9
9
  attr_accessor :custom_labels
10
10
 
11
11
  # @option [String] the post’s unique ID.
@@ -100,7 +100,7 @@ module Fb
100
100
 
101
101
  # @option [Integer] the number of times people clicked on anywhere
102
102
  # in your posts without generating a story.
103
- attr_reader :consumptions
103
+ attr_reader :clicks
104
104
 
105
105
  # @option [Integer] the number of people who clicked anywhere on the post.
106
106
  attr_reader :engaged_users
@@ -111,9 +111,6 @@ module Fb
111
111
  # @option [Integer] people who have liked your page and engaged with your post.
112
112
  attr_reader :engaged_fan
113
113
 
114
- # @option [Integer] post reach by people who like your page.
115
- attr_reader :fan_reach
116
-
117
114
  # @option [Integer] total "like" reactions of a post.
118
115
  attr_reader :reactions_like_total
119
116
 
@@ -236,7 +233,7 @@ module Fb
236
233
  def initialize(options = {})
237
234
  @id = options[:id]
238
235
  @url = options[:permalink_url]
239
- @created_at = Time.strptime(options[:created_time], '%Y-%m-%dT%H:%M:%S+0000')
236
+ @created_at = Time.parse(options[:created_time]) if options[:created_time]
240
237
  @type = options[:type]
241
238
  @message = options[:message]
242
239
  @length = options.fetch(:properties, []).find(-> { {'text' => 'n/a'} }) do |property|
@@ -263,11 +260,10 @@ module Fb
263
260
  @impressions_organic = options[:post_impressions_organic]
264
261
  @impressions_organic_unique = options[:post_impressions_organic_unique]
265
262
  @impressions_viral = options[:post_impressions_viral]
266
- @consumptions = options[:post_consumptions]
263
+ @clicks = options[:post_clicks]
267
264
  @engaged_users = options[:post_engaged_users]
268
265
  @negative_feedback = options[:post_negative_feedback]
269
266
  @engaged_fan = options[:post_engaged_fan]
270
- @fan_reach = options[:post_fan_reach]
271
267
  @reactions_like_total = options[:post_reactions_like_total]
272
268
  @reactions_love_total = options[:post_reactions_love_total]
273
269
  @reactions_wow_total = options[:post_reactions_wow_total]
@@ -300,6 +296,20 @@ module Fb
300
296
  @video_view_time_organic = options[:post_video_view_time_organic]
301
297
  end
302
298
 
299
+ # @return [Hash] a hash of metrics mapped to their values.
300
+ # @param [Array<String, Symbol>] :metrics the metrics to fetch.
301
+ # @param [String] :page_access_token page access token of its page.
302
+ def lifetime_insights(metrics, page_access_token)
303
+ params = { metric: Array(metrics).join(","), access_token: page_access_token, period: "lifetime", ids: id }
304
+ request = HTTPRequest.new path: "/v2.9/insights", params: params
305
+ insights = request.run.body
306
+
307
+ data = insights[id]['data'].map do |metric|
308
+ [metric['name'], metric['values'].last.fetch('value', 0)]
309
+ end.to_h
310
+ symbolize_keys data
311
+ end
312
+
303
313
  # @return [String] the representation of the post.
304
314
  def to_s
305
315
  %Q(#<#{self.class.name} #{@id} "#{@type}">)
@@ -1,3 +1,5 @@
1
+ require 'time'
2
+
1
3
  module Fb
2
4
  # Fb::Video represents a Facebook video. Fb::Video provides getter methods.
3
5
  # @see https://developers.facebook.com/docs/graph-api/reference/video/
@@ -97,8 +99,8 @@ module Fb
97
99
  @content_tags = options[:content_tags] ? Array(options[:content_tags]) : []
98
100
  @ad_breaks = options[:ad_breaks] ? Array(options[:ad_breaks]) : []
99
101
  @length = options[:length]
100
- @created_at = Time.strptime(options[:created_time], '%Y-%m-%dT%H:%M:%S+0000') if options[:created_time]
101
- @backdated_time = Time.strptime(options[:backdated_time], '%Y-%m-%dT%H:%M:%S+0000') if options[:backdated_time]
102
+ @created_at = Time.parse(options[:created_time]) if options[:created_time]
103
+ @backdated_time = Time.parse(options[:backdated_time]) if options[:backdated_time]
102
104
 
103
105
  @total_views = options[:total_video_views]
104
106
  @total_views_unique = options[:total_video_views_unique]
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.beta10
4
+ version: 1.0.0.beta11
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: 2018-05-01 00:00:00.000000000 Z
12
+ date: 2018-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fb-support
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  version: 1.3.1
146
146
  requirements: []
147
147
  rubyforge_project:
148
- rubygems_version: 2.6.13
148
+ rubygems_version: 2.7.6
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: Ruby client to interact with Facebook Graph API.