fb-core 1.0.0.beta3 → 1.0.0.beta4

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
2
  SHA1:
3
- metadata.gz: be4280ee1403156598600751f314cd45cc5db0ac
4
- data.tar.gz: f9a2b017df66583e09c77d50c8b976dcce8b34cc
3
+ metadata.gz: 2b9ebc24b6cab3ece4e96f94f96d71642650481b
4
+ data.tar.gz: '02519ca1e385d8e2ccffbfe362054403c19474ea'
5
5
  SHA512:
6
- metadata.gz: d8ae8810c7687e7e1ff82a80ac49d430872aa6fcea0bbeb317dd27c12668ebdad4ba19ee0b92d621e433a12d703ed8b900a88bf9b06e7f56a1f9aace40b0f12d
7
- data.tar.gz: 5b00b91a0c702fc6c3fd2d7fd391a13ccf2fa948740a655c2781b9ef7df857759c3749ebd3f00d6477e509b2002f844e45d6808d0b8a1c9d49bd875b9ce9e29a
6
+ metadata.gz: d0ebb9ad99986cc132c771a24372a398564765c5ea06c269ebf18780092ab31c7be2b815f7c9519325d74ce18f35d1fde87289d1decc3eef27a232bba6c9a1ba
7
+ data.tar.gz: fb888f906838ae8df5880442439d7bb48be88bd6de443632e4aff2cc445d9abee177711443a5a656a441b59f7f704cc0cb8bcf2fface332be59d6d71e27c7f7b
@@ -6,6 +6,10 @@ 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
+ ## 1.0.0.beta4 - 2018/03/27
10
+
11
+ * [FEATURE] Add `Fb::Page#insights_with_date_range` and `Fb::Page#posts_with_time_range`.
12
+
9
13
  ## 1.0.0.beta3 - 2018/03/14
10
14
 
11
15
  * [FEATURE] Add `video_avg_time_watched` to `Fb::Post` for length of average time watched.
data/README.md CHANGED
@@ -147,7 +147,7 @@ metric, period, and options (since & until). Refer to
147
147
  for a list of available metrics and periods.
148
148
 
149
149
  **Ensure that the period that you are using is supported by the metric**.
150
- For example, `page_views_total` (page views) is available for `week`, `week`, and `days_28`
150
+ For example, `page_views_total` (page views) is available for `day`, `week`, and `days_28`
151
151
  whereas `page_fans` (page likes) is only available as `lifetime`.
152
152
 
153
153
  `metric_insights` returns a hash of Dates mapped to values. Passing `since` only return dates ahead
@@ -24,10 +24,10 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ['lib']
26
26
 
27
- spec.add_dependency 'fb-support', '~> 1.0.0.alpha1'
27
+ spec.add_dependency 'fb-support', '~> 1.0.0.alpha4'
28
28
  spec.add_development_dependency 'bundler', '~> 1.15'
29
29
  spec.add_development_dependency 'rake', '~> 10.0'
30
30
  spec.add_development_dependency 'rspec', '~> 3.0'
31
- spec.add_development_dependency 'yard', '~> 0.9.9'
31
+ spec.add_development_dependency 'yard', '~> 0.9.12'
32
32
  spec.add_development_dependency 'coveralls'
33
33
  end
@@ -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.beta3'
6
+ VERSION = '1.0.0.beta4'
7
7
  end
8
8
  end
@@ -23,7 +23,7 @@ module Fb
23
23
  @access_token = options[:access_token]
24
24
  end
25
25
 
26
- # @return [Hash<Date, Integer>] a hash of Dates mapped to their values.
26
+ # @return [Hash<Date, Integer>] a hash of Dates mapped to their values.
27
27
  # @param [String] :metric the metric to fetch.
28
28
  # @param [<String, Symbol>] :period the aggregate period (day, week, days_28).
29
29
  # @option [Date] :since only return dates ahead to this date (lower bound).
@@ -42,8 +42,24 @@ module Fb
42
42
  def weekly_insights(metrics, options = {})
43
43
  since_date = options.fetch :until, Date.today - 1
44
44
  params = {period: :week, since: since_date, until: since_date + 2}
45
- metrics = page_insights Array(metrics), params
46
- metrics.map {|m| [m['name'].to_sym, m['values'].last.fetch('value', 0)]}.to_h
45
+ insights = page_insights Array(metrics), params
46
+ insights.map {|m| [m['name'].to_sym, m['values'].last.fetch('value', 0)]}.to_h
47
+ end
48
+
49
+ # @return [Hash] a hash of metrics mapped to their values.
50
+ # @param [Array<String, Symbol>] :metrics the metrics to fetch.
51
+ # @option [Time] :since sum the date period after this date.
52
+ # @option [Time] :until sum the period before this date.
53
+ def insights_with_date_range(metrics, options = {})
54
+ date_params = {since: options[:since].to_date - 1, until: options.fetch(:until, Date.today).to_date + 1}
55
+ params = {period: :day}.merge date_params
56
+ insights = page_insights Array(metrics), params
57
+ insights.map do |m|
58
+ [
59
+ m['name'].to_sym,
60
+ m['values'].sum {|value| value.fetch('value', 0)}
61
+ ]
62
+ end.to_h
47
63
  end
48
64
 
49
65
  # @return [Integer] the number of views of the page.
@@ -77,6 +93,17 @@ module Fb
77
93
  end
78
94
  end
79
95
 
96
+ # @return [Array<Fb::Post>] the posts published on the page.
97
+ # @option [Time] :since only return posts ahead of this time.
98
+ # @option [Time] :until only return posts previous to this time.
99
+ # @option [Boolean] :with_metrics whether to include insights for the posts.
100
+ def posts_with_time_range(options = {})
101
+ time_params = {since: options[:since], until: options[:until]}
102
+ request = PaginatedRequest.new path: "/v2.9/#{@id}/posts", params: posts_params.merge(time_params)
103
+ data = request.run.body['data']
104
+ options[:with_metrics] ? posts_with_metrics_from(data) : posts_from(data)
105
+ end
106
+
80
107
  # @return [Array<Fb::Video>] the uploaded videos for the page.
81
108
  def videos
82
109
  @videos ||= begin
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.beta3
4
+ version: 1.0.0.beta4
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-03-14 00:00:00.000000000 Z
12
+ date: 2018-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fb-support
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 1.0.0.alpha1
20
+ version: 1.0.0.alpha4
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 1.0.0.alpha1
27
+ version: 1.0.0.alpha4
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -73,14 +73,14 @@ dependencies:
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: 0.9.9
76
+ version: 0.9.12
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: 0.9.9
83
+ version: 0.9.12
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: coveralls
86
86
  requirement: !ruby/object:Gem::Requirement