fb-auth 0.1.0 → 0.1.1

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: 106ab81033317409467304dd112b0824da4ecc06
4
- data.tar.gz: bc4a79e1ea273dd2ab3e19480c49933653a7957c
3
+ metadata.gz: a4091f0bb97d9c056731edce37fbd6e62c36fe29
4
+ data.tar.gz: 52896b096eb97caa7a4b7b6cf032a4295bd65fca
5
5
  SHA512:
6
- metadata.gz: 2ea2bcffa704f4a249aa558586c6fe139d1eb539bca3e34b4057e366b5d5c7b8012714aa9138c408a6ba1aeb6b28c899dacd2419299d25253a5864b8fb32eacc
7
- data.tar.gz: 9578d4e367eee8bf8125f11346df95daf274b1fec3618d13f25a6e7430ca98cbef72fbfceac59a3c99b622315b73677760bd53bb4760291685d1a4031dfd958c
6
+ metadata.gz: e87ad08d25287b42cd3614cf13459a47afe203ca70998efbbec7e912e7ed7bd91cefa736fb928377d41c2f099349851938694a896a030b6d56949d9bb81f98c4
7
+ data.tar.gz: 1a1a4f22a83d45152865844bdf84342eb4674c72bb8a841505bab192c3e18d18c6a7417661c326eac99f44613bc5dd31904f0a8c8fc8b424c8fa3930c39a90c0
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  .DS_Store
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+ *.gem
data/CHANGELOG.md CHANGED
@@ -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
+ ## 0.1.1 - 2017/06/29
10
+
11
+ * [FEATURE] Add `Fb::Page#insights`
12
+
9
13
  ## 0.1.0 - 2017/06/29
10
14
 
11
15
  * [FEATURE] Add `Fb::Auth#url`
data/README.md CHANGED
@@ -10,7 +10,6 @@ Fb::Auth can authenticate a Facebook user and return an access token with permis
10
10
  [![Gem Version](http://img.shields.io/gem/v/fb-auth.svg)](http://rubygems.org/gems/fb-auth)
11
11
 
12
12
  The **source code** is available on [GitHub](https://github.com/Fullscreen/fb-auth) and the **documentation** on [RubyDoc](http://www.rubydoc.info/gems/fb-auth/frames).
13
-
14
13
  ### Installing and Configuring Fb::Auth
15
14
 
16
15
  First, add fb-auth to your Gemfile:
@@ -67,7 +66,7 @@ array of type Fb::Page, each with an id and name.
67
66
  ```ruby
68
67
  access_token = Fb::Auth.new(redirect_uri: redirect_uri, code: code).access_token
69
68
  Fb::User.new(access_token).pages
70
- # => [#<Fb::Page: @name="sample1", @id="1234">, #<Fb::Page: @name="sample2", @id="5678">]
69
+ # => [#<Fb::Page: id="1234", name="sample1">, #<Fb::Page: id="5678", name="sample2">]
71
70
  ```
72
71
 
73
72
  Fb::User#email
@@ -81,6 +80,21 @@ Fb::User.new(access_token).email
81
80
  # => "john.smith@example.com"
82
81
  ```
83
82
 
83
+ Fb::Page#insights
84
+ ---------------------
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.
87
+
88
+ ```ruby
89
+ Fb::User.new('token').pages.insights
90
+ # => {"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>,..}
94
+ ```
95
+
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
+
84
98
  Fb::Error
85
99
  -------------
86
100
 
@@ -114,4 +128,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Fullsc
114
128
 
115
129
  ## License
116
130
 
117
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
131
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/fb-auth.gemspec CHANGED
@@ -6,8 +6,8 @@ require "fb/auth/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "fb-auth"
8
8
  spec.version = Fb::Auth::VERSION
9
- spec.authors = ["Aaron Dao"]
10
- spec.email = ["aaron.dao@fullscreen.com"]
9
+ spec.authors = ['Aaron Dao', 'Claudio Baccigalupo']
10
+ spec.email = ['aaron.dao@fullscreen.com', 'claudio@fullscreen.net']
11
11
 
12
12
  spec.summary = %q{Ruby client to authenticate a Facebook user.}
13
13
  spec.description = %q{Fb::Auth provides methods to obtain an access token to
@@ -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.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
@@ -15,7 +15,7 @@ module Fb
15
15
  # convention is to use [Fb.configure].
16
16
  #
17
17
  # @example
18
- # Fb.configuration.fb_client_id = 1234
18
+ # Fb.configuration.client_id = 1234
19
19
  def self.configuration
20
20
  @configuration ||= Configuration.new
21
21
  end
@@ -25,7 +25,7 @@ module Fb
25
25
  #
26
26
  # @example
27
27
  # Fb.configure do |config|
28
- # config.fb_client_id = 1234
28
+ # config.client_id = 1234
29
29
  # end
30
30
  def self.configure
31
31
  yield(configuration) if block_given?
data/lib/fb/metric.rb ADDED
@@ -0,0 +1,35 @@
1
+ # Ruby client to authenticate a Facebook user.
2
+ # @see http://www.rubydoc.info/gems/Fb/
3
+ module Fb
4
+ # Fb::Metric reprensents a Facebook page's metric.
5
+ # For a list of all available metrics, refer to:
6
+ # @see https://developers.facebook.com/docs/graph-api/reference/v2.9/insights
7
+ # Provides methods to read name, description, and value.
8
+ class Metric
9
+
10
+ # @return [String] the name of the metric (e.g. page_fans).
11
+ attr_reader :name
12
+
13
+ # @return [String] a description for the metric.
14
+ attr_reader :description
15
+
16
+ # @return [Integer] the value of the metric when last requested.
17
+ attr_reader :value
18
+
19
+ # @param [Hash] options the options to initialize an instance of Fb::Metric.
20
+ # @option [String] :name of the metric.
21
+ # @option [String] :title of the metric.
22
+ # @option [String] :description of the metric.
23
+ # @option [Integer] :value of this metric when last requested.
24
+ def initialize(options = {})
25
+ @name = options["name"]
26
+ @description = options["description"]
27
+ @value = options["values"].first["value"]
28
+ end
29
+
30
+ # @return [String] the representation of the metric.
31
+ def to_s
32
+ "#<#{self.class.name} name=#{@name}, description=#{@description}, value=#{@value}>"
33
+ end
34
+ end
35
+ end
data/lib/fb/page.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'date'
2
+ require 'fb/request'
3
+ require 'fb/metric'
2
4
  # Ruby client to authenticate a Facebook user.
3
5
  # @see http://www.rubydoc.info/gems/Fb/
4
6
  module Fb
@@ -17,12 +19,44 @@ module Fb
17
19
  def initialize(options = {})
18
20
  @name = options["name"]
19
21
  @id = options["id"]
22
+ @user = options["user"]
23
+ end
24
+
25
+ # @return [Hash] a collection of metrics with metric name as key
26
+ # and metric object as value.
27
+ # @example
28
+ # Fb::User.new('token').pages.insights
29
+ # => {"page_fan_adds_unique"=>#<Fb::Metric:0x123abc
30
+ # @name="page_fans", @description="Weekly: The
31
+ # number of new people who have liked your Page (Unique Users)",
32
+ # @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
20
42
  end
21
43
 
22
44
  # @return [String] the representation of the page.
23
45
  def to_s
24
46
  "#<#{self.class.name} id=#{@id}, name=#{@name}>"
25
47
  end
48
+
49
+ private
50
+
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)
59
+ end
60
+ end
26
61
  end
27
62
  end
28
-
data/lib/fb/user.rb CHANGED
@@ -25,9 +25,12 @@ module Fb
25
25
  response_body = Fb::Request.new(path: '/me/accounts',
26
26
  params: {access_token: @access_token}).run
27
27
  response_body["data"].map do |page_data|
28
- Fb::Page.new page_data
28
+ Fb::Page.new page_data.merge('user' => self)
29
29
  end
30
30
  end
31
31
  end
32
+
33
+ private
34
+ attr_reader :access_token
32
35
  end
33
36
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Dao
8
+ - Claudio Baccigalupo
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2017-06-30 00:00:00.000000000 Z
12
+ date: 2017-07-11 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -85,6 +86,7 @@ description: |-
85
86
  manage pages of a Facebook user.
86
87
  email:
87
88
  - aaron.dao@fullscreen.com
89
+ - claudio@fullscreen.net
88
90
  executables: []
89
91
  extensions: []
90
92
  extra_rdoc_files: []
@@ -105,6 +107,7 @@ files:
105
107
  - lib/fb/auth/version.rb
106
108
  - lib/fb/configuration.rb
107
109
  - lib/fb/error.rb
110
+ - lib/fb/metric.rb
108
111
  - lib/fb/page.rb
109
112
  - lib/fb/request.rb
110
113
  - lib/fb/user.rb