fb-auth 0.1.1 → 0.1.2

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: a4091f0bb97d9c056731edce37fbd6e62c36fe29
4
- data.tar.gz: 52896b096eb97caa7a4b7b6cf032a4295bd65fca
3
+ metadata.gz: e1c65df145f6718c64b0a56c90644ad84e9b7680
4
+ data.tar.gz: c74b56bfa92064a6104cfb0313a66bf4bb8ba8de
5
5
  SHA512:
6
- metadata.gz: e87ad08d25287b42cd3614cf13459a47afe203ca70998efbbec7e912e7ed7bd91cefa736fb928377d41c2f099349851938694a896a030b6d56949d9bb81f98c4
7
- data.tar.gz: 1a1a4f22a83d45152865844bdf84342eb4674c72bb8a841505bab192c3e18d18c6a7417661c326eac99f44613bc5dd31904f0a8c8fc8b424c8fa3930c39a90c0
6
+ metadata.gz: e7582dccb5248c30929e76314c3a0dd0331ab1ade55cf5245fbb6a2f4f5d610d54d3931db8d0a2f1d4e8435228e097cdfd0a3fb373ec25f90ab9695c5e93c5ee
7
+ data.tar.gz: '09e4778d8511b2f12ae52343fcb9d0c26f261979764f6c007d6040b3b1e3f9e55dd74be47cc559b6e8157eee8cf7826c165f8ca1548d32655346a93fa6732bb1'
data/CHANGELOG.md CHANGED
@@ -6,7 +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
- ## 0.1.1 - 2017/06/29
9
+ ## 0.1.2 - 2017/07/11
10
+
11
+ * [ENHANCEMENT] `Fb::Page#insights` now takes a hash of options on method call.
12
+
13
+ ## 0.1.1 - 2017/07/06
10
14
 
11
15
  * [FEATURE] Add `Fb::Page#insights`
12
16
 
data/README.md CHANGED
@@ -83,18 +83,29 @@ Fb::User.new(access_token).email
83
83
  Fb::Page#insights
84
84
  ---------------------
85
85
 
86
- For each page object created, you can get these pre-defined metrics: page_views_total, page_fan_adds_unique, page_engaged_users, page_video_views. The insights method will fetch the cumulative value of these metrics 7 days prior to two weeks ago (e.g. if today is July 6, 2017, the value of the metric will be for the 7 days prior to and ending on June 22, 2017). The selection of metrics and aggregate period will be options in a future patch.
86
+ For each page object, you can fetch page insights for these [available metrics](https://developers.facebook.com/docs/graph-api/reference/v2.9/insights#availmetrics). The insights method takes a hash of three options:
87
+
88
+ [String] :since The lower bound of the time range to consider.
89
+ [String] :period The aggregation period (must be available to all
90
+ given metrics).
91
+ [Array] :metric A list of metrics.
92
+
93
+ Insights will return a hash with the name of each metric as the key and the metric object as the value.
87
94
 
88
95
  ```ruby
89
- Fb::User.new('token').pages.insights
96
+ options = {
97
+ metric: %i(page_fan_adds_unique page_engaged_users page_views_total),
98
+ period: :week,
99
+ since: '2017-06-09' # sample date format
100
+ }
101
+ page = Fb::User.new('token').pages.first
102
+ page.insights(options)
90
103
  # => {"page_fan_adds_unique"=>#<Fb::Metric:0x123abc
91
- @name="page_fans", @description="Weekly: The
92
- number of new people who have liked your Page (Unique Users)",
93
- @value=123>,..}
104
+ # @name="page_fan_adds_unique", @description="Weekly: The
105
+ # number of new people who have liked your Page (Unique Users)",
106
+ # @value=123>,..}
94
107
  ```
95
108
 
96
- A full list of page/insights metrics are available at [metrics](https://developers.facebook.com/docs/graph-api/reference/v2.9/insights#availmetrics).
97
-
98
109
  Fb::Error
99
110
  -------------
100
111
 
@@ -2,6 +2,6 @@ module Fb
2
2
  class Auth
3
3
  # @return [String] the SemVer-compatible gem version.
4
4
  # @see http://semver.org
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
data/lib/fb/page.rb CHANGED
@@ -22,23 +22,24 @@ module Fb
22
22
  @user = options["user"]
23
23
  end
24
24
 
25
+ # @param [Hash] options to customize the insights returned from the API.
26
+ # @option [String] :since The lower bound of the time range to consider.
27
+ # @option [String] :period The aggregation period (must be available to all
28
+ # given metrics).
29
+ # @option [Array<String, Symbol>] :metric A list of metrics.
25
30
  # @return [Hash] a collection of metrics with metric name as key
26
31
  # and metric object as value.
27
32
  # @example
28
- # Fb::User.new('token').pages.insights
33
+ # page = Fb::User.new('token').pages.first
34
+ # page.insights(options)
29
35
  # => {"page_fan_adds_unique"=>#<Fb::Metric:0x123abc
30
36
  # @name="page_fans", @description="Weekly: The
31
37
  # number of new people who have liked your Page (Unique Users)",
32
38
  # @value=123>,..}
33
- def insights
34
- @insights ||= begin
35
- response_body = Fb::Request.new(
36
- path: "/v2.9/#{@id}/insights",
37
- params: insights_params).run
38
- response_body["data"].map do |metric_data|
39
- [metric_data["name"], Fb::Metric.new(metric_data)]
40
- end.to_h
41
- end
39
+ def insights(options = {})
40
+ fetch_insights(options)["data"].map do |metric_data|
41
+ [metric_data["name"], Fb::Metric.new(metric_data)]
42
+ end.to_h
42
43
  end
43
44
 
44
45
  # @return [String] the representation of the page.
@@ -48,15 +49,16 @@ module Fb
48
49
 
49
50
  private
50
51
 
51
- def insights_params
52
- {}.tap do |params|
53
- params[:since] = (Time.now - 14 * 86400).strftime("%Y-%m-%d")
54
- params[:until] = Date.parse(params[:since]) + 1
55
- params[:period] = :week
56
- params[:metric] = 'page_views_total,page_fan_adds_unique,
57
- page_engaged_users,page_video_views'
58
- params[:access_token] = @user.send(:access_token)
52
+ def fetch_insights(options)
53
+ unless options[:metric]
54
+ raise Fb::Error, 'Missing required parameter: metric'
59
55
  end
56
+ insights_params = options.merge(metric: options[:metric].join(","),
57
+ access_token: @user.send(:access_token))
58
+ Fb::Request.new(
59
+ path: "/v2.9/#{@id}/insights",
60
+ params: insights_params
61
+ ).run
60
62
  end
61
63
  end
62
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Dao
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-07-11 00:00:00.000000000 Z
12
+ date: 2017-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler