fb-core 1.0.0.alpha6 → 1.0.0.alpha7

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: eba1fc16c8b7532b533f2f9de7dab75ce28207e3
4
- data.tar.gz: b1a2873d94e44bc65d4f8f1da60924c9df6a43ee
3
+ metadata.gz: fb91cd80d655f7e81bf36f22a491bff96f8b2e27
4
+ data.tar.gz: e6b0a8a0dfa8f2142103b57f8f5f6fd9cce4a904
5
5
  SHA512:
6
- metadata.gz: 817e444187eb6b6487c78386bc10c34e087ccac19762821d8eb7274331096138e7ab1bfdc8f2889f56a61dc40027883658e0ae08e72cb0fe44435d3ddf4d0a9f
7
- data.tar.gz: c2373650288e74af845087a8d28d51caa515844465f452a58accbd6ac1b9d23d58f2bfda297bdcccf310f46607a4139d0ba9105f530c2b3d4355faaed34f58c7
6
+ metadata.gz: 4cd41e9397e2c3798ed31fcb3b870ff953e66fb55c7176077acedd0291dcdcdd2db34b6a55bb128b1c1d5f877007d2295ba8fd4a172f25f6145088ed5d819675
7
+ data.tar.gz: 7960deaf0f1d145bd5772d292a2033ec2071d027b9f09b044463d8f0a315110591785c206415d758138126e9ff73ff707a20e9b2344aa2fdf071d7d493b70551
data/README.md CHANGED
@@ -52,6 +52,14 @@ page.posts
52
52
  # => [#<Fb::Post: id="1234", type="video">, #<Fb::Post: id="5678", type="video">]
53
53
  ```
54
54
 
55
+ Pass `since` (`Time`) and `until` (`Time`) options to get posts in between the two times.
56
+
57
+ ```ruby
58
+ options = { since: Time.new(2015, 05, 15), until: Time.now }
59
+ page.posts(options)
60
+ # => [#<Fb::Post: id="5678", type="video">,..]
61
+ ```
62
+
55
63
  Fb::Page#like_count
56
64
  --------------
57
65
 
@@ -120,7 +128,7 @@ Fb::Page#metric_insights
120
128
  You can get an individual metric through using `metric_insights` which takes a
121
129
  metric, period, and options (since & until). Refer to
122
130
  [metrics](https://developers.facebook.com/docs/graph-api/reference/v2.9/insights#availmetrics)
123
- for a list of available weekly metrics and periods.
131
+ for a list of available metrics and periods.
124
132
 
125
133
  **Ensure that the period that you are using is supported by the metric**.
126
134
  For example, `page_views_total` (page views) is available for `week`, `week`, and `days_28`
@@ -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.alpha6'
6
+ VERSION = '1.0.0.alpha7'
7
7
  end
8
8
  end
data/lib/fb/page.rb CHANGED
@@ -36,7 +36,6 @@ module Fb
36
36
  end.to_h
37
37
  end
38
38
 
39
- #values.map {|v| [Date.strptime(v['end_time'], '%Y-%m-%dT%H:%M:%S+0000'), v.fetch('value', 0)]}.to_h
40
39
  # @return [Hash] a hash of metrics mapped to their values.
41
40
  # @param [Array<String, Symbol>] :metrics the metrics to fetch.
42
41
  # @option [Date] :until only sum seven days before this date.
@@ -66,10 +65,11 @@ module Fb
66
65
  end
67
66
 
68
67
  # @return [Array<Fb::Post>] the posts published on the page.
69
- def posts
68
+ # @option [Time] :since only return posts ahead of this time.
69
+ # @option [Time] :until only return posts previous to this time.
70
+ def posts(options = {})
70
71
  @posts ||= begin
71
- fields = %i(type created_time).join ','
72
- params = {access_token: @access_token, limit: 100, fields: fields}
72
+ params = posts_params.merge options
73
73
  request = PaginatedRequest.new path: "/v2.9/#{@id}/posts", params: params
74
74
  request.run.body['data'].map do |post_data|
75
75
  Post.new symbolize_keys post_data
@@ -89,5 +89,13 @@ module Fb
89
89
  request = HTTPRequest.new path: "/v2.9/#{@id}/insights", params: params
90
90
  request.run.body['data']
91
91
  end
92
+
93
+ def posts_params
94
+ {}.tap do |params|
95
+ params[:access_token] = @access_token
96
+ params[:limit] = 100
97
+ params[:fields]= %i(id message permalink_url created_time type properties).join ','
98
+ end
99
+ end
92
100
  end
93
101
  end
@@ -9,7 +9,8 @@ module Fb
9
9
  # @raise [Fb::HTTPError] if the request fails.
10
10
  def run
11
11
  response = super
12
- while after = response.body.dig('paging', 'cursors', 'after')
12
+ while response.body.dig 'paging', 'next'
13
+ after = response.body.dig 'paging', 'cursors', 'after'
13
14
  next_params = @params.merge after: after, limit: 100
14
15
  next_request = HTTPRequest.new path: @path, params: next_params
15
16
  next_body = next_request.run.body
data/lib/fb/post.rb CHANGED
@@ -2,25 +2,43 @@
2
2
  # @see http://www.rubydoc.info/gems/Fb/
3
3
  module Fb
4
4
  # Fb::Post reprensents a Facebook post. Post provides getters for:
5
- # :id, :title, :url, :created_time, and :type.
5
+ # :id, :url, :created_at, :type, :message, and :length.
6
6
  class Post
7
+
7
8
  # @option [String] the post’s unique ID.
8
9
  attr_reader :id
9
10
 
10
- # @option [String] the post’s type.
11
- attr_reader :type
11
+ # @option [String] the post’s permanent url.
12
+ attr_reader :url
12
13
 
13
14
  # @option [Time] the post’s creation time.
14
15
  attr_reader :created_at
15
16
 
17
+ # @option [String] the post’s type.
18
+ attr_reader :type
19
+
20
+ # @option [String] the post’s message.
21
+ attr_reader :message
22
+
23
+ # @option [String] the attached video's length or n/a.
24
+ attr_reader :length
25
+
16
26
  # @param [Hash] options the options to initialize an instance of Fb::Post.
17
- # @option [String] :id the post id.
18
- # @option [String] :type the post’s type.
19
- # @option [String] :created_time the post’s creation time in iso8601 format.
27
+ # @option [String] :id The post id.
28
+ # @option [String] :message The status message in the post or post story.
29
+ # @option [String] :url URL to the permalink page of the post.
30
+ # @option [String] :created_time The time the post was initially published.
31
+ # @option [String] :type A string indicating the object type of this post.
32
+ # @option [String] :properties of the post (e.g. length).
20
33
  def initialize(options = {})
21
34
  @id = options[:id]
35
+ @url = options[:permalink_url]
36
+ @created_at = Time.strptime(options[:created_time], '%Y-%m-%dT%H:%M:%S+0000')
22
37
  @type = options[:type]
23
- @created_at = Time.parse(options[:created_time]) if options[:created_time]
38
+ @message = options[:message]
39
+ @length = options.fetch(:properties, []).find(-> { {'text' => 'n/a'} }) do |property|
40
+ property['name'] == 'Length'
41
+ end['text']
24
42
  end
25
43
 
26
44
  # @return [String] the representation of the post.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha6
4
+ version: 1.0.0.alpha7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-08 00:00:00.000000000 Z
11
+ date: 2017-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fb-support