fb-core 1.0.0.alpha11 → 1.0.0.alpha12

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: d5d54f1aee3c5728c61bdbc457d9ffa9446d2d87
4
- data.tar.gz: 5c11e39c01d565d582baf9b156a6ca6632a6049e
3
+ metadata.gz: cd59a79b809b6f4ecd3306cb4513115e5e4f25df
4
+ data.tar.gz: c167e50a5222e725f62b675734e7ffe3aa02424d
5
5
  SHA512:
6
- metadata.gz: 0cca2085532fb3539ff29e5592de956ee83467b3d85608eb5c339264ae04a4fc0519e2c6c25372fd3d61cac168b3abdd6c096977b6e5b42d9929ba2514453c81
7
- data.tar.gz: 5eb69fecae088ac81fa285963ee82b00e8ed2ea10de24b7585e2eb00be6a81853301d87303a18c9dbb09c3fd97439ceda71a3350b3b3e0382bbb873a276c88b7
6
+ metadata.gz: '0194add029d28a6a4c452370f6fce79b45ad81fb16f0b10ed52af5c211cc7a4865171f700c944b8a6b90287eb5a30d26ebd51e9603ebebf94ae42663fd1cdcb6'
7
+ data.tar.gz: 792587046f24310265871bbad3e5d6714b358361ed2a9668f8cd85a88974c1fdd8afbb1fa1a6be0de88ebbb310da18b1407631bc4318dd9c0d9c3987630e13ad
data/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ 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.alpha12 - 2017/12/08
10
+
11
+ * [FEATURE] Add `Fb::Video` and `Fb::Page#videos`
12
+ * [FEATURE] Add fields of "/videos" endpoint such as `comment_count`, `length` etc to `Fb::Video`
13
+ * [FEATURE] Add metrics from "/video_insights" endpoint such as `total_views` to `Fb::Video`
14
+
9
15
  ## 1.0.0.alpha11 - 2017/12/01
10
16
 
11
17
  * [FEATURE] Add `share_count` to `Fb::Post` for number of shares of a post.
data/lib/fb/core.rb CHANGED
@@ -4,6 +4,7 @@ require 'fb/resource'
4
4
  require 'fb/page'
5
5
  require 'fb/user'
6
6
  require 'fb/post'
7
+ require 'fb/video'
7
8
  # An object-oriented Ruby client for the Facebook Graph API.
8
9
  # @see http://www.rubydoc.info/gems/fb-core/
9
10
  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.alpha11'
6
+ VERSION = '1.0.0.alpha12'
7
7
  end
8
8
  end
data/lib/fb/page.rb CHANGED
@@ -77,6 +77,15 @@ module Fb
77
77
  end
78
78
  end
79
79
 
80
+ # @return [Array<Fb::Video>] the uploaded videos for the page.
81
+ def videos
82
+ @videos ||= begin
83
+ request = PaginatedRequest.new path: "/v2.9/#{@id}/videos", params: video_params
84
+ data = request.run.body['data']
85
+ videos_with_metrics_from(data)
86
+ end
87
+ end
88
+
80
89
  # @return [String] the representation of the page.
81
90
  def to_s
82
91
  %Q(#<#{self.class.name} #{@id} "#{@name}">)
@@ -125,5 +134,35 @@ module Fb
125
134
  def post_metrics
126
135
  %i(post_engaged_users post_video_views_organic post_video_views_paid post_video_views post_video_view_time)
127
136
  end
137
+
138
+ def videos_with_metrics_from(data)
139
+ data.each_slice(25).flat_map do |video_slice|
140
+ video_ids = video_slice.map {|video| video['id']}.join(',')
141
+ metrics = video_insights(ids: video_ids)
142
+ video_slice.map do |video_data|
143
+ insights_data = metrics[video_data['id']]['data'].map do |metric|
144
+ [metric['name'], metric['values'].last.fetch('value', 0)]
145
+ end.to_h
146
+ Video.new symbolize_keys video_data.merge(insights_data)
147
+ end
148
+ end
149
+ end
150
+
151
+ def video_insights(options = {})
152
+ params = options.merge access_token: @access_token
153
+ request = HTTPRequest.new path: "/v2.9/video_insights", params: params
154
+ request.run.body
155
+ end
156
+
157
+ def video_params
158
+ {}.tap do |params|
159
+ params[:access_token] = @access_token
160
+ params[:limit] = 25
161
+ params[:fields] = ['id', 'permalink_url', 'custom_labels', 'title',
162
+ 'length', 'content_tags', 'likes.limit(0).summary(true)', 'comments.limit(0).summary(true)',
163
+ 'created_time', 'ad_breaks', 'description', 'reactions.limit(0).summary(true)'
164
+ ].join(',')
165
+ end
166
+ end
128
167
  end
129
168
  end
@@ -11,7 +11,7 @@ module Fb
11
11
  response = super
12
12
  while response.body.dig 'paging', 'next'
13
13
  after = response.body.dig 'paging', 'cursors', 'after'
14
- next_params = @params.merge after: after, limit: 100
14
+ next_params = @params.merge after: after
15
15
  next_request = HTTPRequest.new path: @path, params: next_params
16
16
  next_body = next_request.run.body
17
17
  response.body['paging'] = next_body['paging']
data/lib/fb/video.rb ADDED
@@ -0,0 +1,103 @@
1
+ module Fb
2
+ # Fb::Video represents a Facebook video. Fb::Video provides getter methods.
3
+ # @see https://developers.facebook.com/docs/graph-api/reference/video/
4
+ class Video
5
+
6
+ # @option [String] the video’s unique ID.
7
+ attr_reader :id
8
+
9
+ # @option [String] the video’s permanent URL.
10
+ attr_reader :url
11
+
12
+ # @option [String] the video’s title or caption.
13
+ attr_reader :title
14
+
15
+ # @option [String] the video’s description or caption.
16
+ attr_reader :description
17
+
18
+ # @option [Array<String>] the video’s custom labels.
19
+ attr_reader :custom_labels
20
+
21
+ # @return [Integer] the number of comments on the video.
22
+ attr_reader :comment_count
23
+
24
+ # @return [Integer] the number of likes on the video.
25
+ attr_reader :like_count
26
+
27
+ # @return [Integer] the number of reactions on the video.
28
+ attr_reader :reaction_count
29
+
30
+ # @option [Array<String>] the video’s content tags.
31
+ attr_reader :content_tags
32
+
33
+ # @option [Array<Integer>] the video’s ad breaks in milliseconds.
34
+ attr_reader :ad_breaks
35
+
36
+ # @option [Float] the video’s length.
37
+ attr_reader :length
38
+
39
+ # @option [Time] The time the video was initially published.
40
+ attr_reader :created_at
41
+
42
+ # @option [Integer] Total number of times the video was viewed for 3 seconds
43
+ # or viewed to the end, whichever happened first. total_video_views.
44
+ # @see https://developers.facebook.com/docs/graph-api/reference/video/video_insights/
45
+ attr_reader :total_views
46
+
47
+ # @option [Integer] The total_video_views_unique of the video.
48
+ attr_reader :total_views_unique
49
+
50
+ # @option [Integer] The total_video_avg_time_watched of the video.
51
+ attr_reader :total_avg_time_watched
52
+
53
+ # @option [Integer] The total_video_views_autoplayed of the video.
54
+ attr_reader :total_views_autoplayed
55
+
56
+ # @option [Integer] The total_video_views_clicked_to_play of the video.
57
+ attr_reader :total_views_clicked_to_play
58
+
59
+ # @option [Integer] The total_video_complete_views_auto_played of the video.
60
+ attr_reader :total_complete_views_auto_played
61
+
62
+ # @option [Integer] The total_video_complete_views_clicked_to_play of the video.
63
+ attr_reader :total_complete_views_clicked_to_play
64
+
65
+ # @option [Integer] The total_video_views_sound_on of the video.
66
+ attr_reader :total_views_sound_on
67
+
68
+ # @option [Integer] The total_video_10s_views_auto_played of the video.
69
+ attr_reader :total_10s_views_sound_on
70
+
71
+ # @param [Hash] options the options to initialize an instance of Fb::Video.
72
+ def initialize(options = {})
73
+ @id = options[:id]
74
+ @url = options[:permalink_url]
75
+ @title = options[:title]
76
+ @description = options[:description]
77
+ @custom_labels = options[:custom_labels] ? Array(options[:custom_labels]) : Array.new
78
+
79
+ @comment_count = options[:comments]['summary']['total_count'] if options[:comments]
80
+ @like_count = options[:likes]['summary']['total_count'] if options[:likes]
81
+ @reaction_count = options[:reactions]['summary']['total_count'] if options[:reactions]
82
+ @content_tags = options[:content_tags] ? Array(options[:content_tags]) : Array.new
83
+ @ad_breaks = options[:ad_breaks] ? Array(options[:ad_breaks]) : Array.new
84
+ @length = options[:length]
85
+ @created_at = Time.strptime(options[:created_time], '%Y-%m-%dT%H:%M:%S+0000')
86
+
87
+ @total_views = options[:total_video_views] if options[:total_video_views]
88
+ @total_views_unique = options[:total_video_views_unique] if options[:total_video_views_unique]
89
+ @total_avg_time_watched = options[:total_video_avg_time_watched] if options[:total_video_avg_time_watched]
90
+ @total_views_autoplayed = options[:total_video_views_autoplayed] if options[:total_video_views_autoplayed]
91
+ @total_views_clicked_to_play = options[:total_video_views_clicked_to_play] if options[:total_video_views_clicked_to_play]
92
+ @total_complete_views_auto_played = options[:total_video_complete_views_auto_played] if options[:total_video_complete_views_auto_played]
93
+ @total_complete_views_clicked_to_play = options[:total_video_complete_views_clicked_to_play] if options[:total_video_complete_views_clicked_to_play]
94
+ @total_views_sound_on = options[:total_video_views_sound_on] if options[:total_video_views_sound_on]
95
+ @total_10s_views_sound_on = options[:total_video_10s_views_sound_on] if options[:total_video_10s_views_sound_on]
96
+ end
97
+
98
+ # @return [String] the representation of the post.
99
+ def to_s
100
+ %Q(#<#{self.class.name} #{@id} "#{@length}">)
101
+ end
102
+ end
103
+ 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.alpha11
4
+ version: 1.0.0.alpha12
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-02 00:00:00.000000000 Z
12
+ date: 2017-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fb-support
@@ -124,6 +124,7 @@ files:
124
124
  - lib/fb/post.rb
125
125
  - lib/fb/resource.rb
126
126
  - lib/fb/user.rb
127
+ - lib/fb/video.rb
127
128
  homepage: https://github.com/Fullscreen/fb-core
128
129
  licenses:
129
130
  - MIT