fb_graph 2.1.4 → 2.1.5

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fb_graph (2.1.3)
4
+ fb_graph (2.1.4)
5
5
  httpclient (>= 2.2.0.2)
6
6
  rack-oauth2 (>= 0.9.4)
7
7
 
@@ -48,7 +48,7 @@ GEM
48
48
  rack (>= 0.4)
49
49
  rack-mount (0.8.3)
50
50
  rack (>= 1.0.0)
51
- rack-oauth2 (0.9.4)
51
+ rack-oauth2 (0.9.5)
52
52
  activesupport (>= 2.3)
53
53
  attr_required (>= 0.0.3)
54
54
  httpclient (>= 2.2.0.2)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.4
1
+ 2.1.5
@@ -2,6 +2,8 @@ module FbGraph
2
2
  class AdAccount < Node
3
3
  include Connections::AdCampaigns
4
4
  include Connections::AdGroups
5
+ include Connections::AdCampaignStats
6
+ include Connections::AdGroupStats
5
7
 
6
8
  attr_accessor :account_id, :name, :account_status, :daily_spend_limit, :users, :currency, :timezone_id, :timezone_name, :capabilities, :account_groups
7
9
 
@@ -0,0 +1,22 @@
1
+ module FbGraph
2
+ class AdCampaignStat < Node
3
+ attr_accessor :start_time, :end_time, :campaign_id, :impressions, :clicks, :spent, :social_impressions, :social_clicks, :social_spent,
4
+ :unique_impressions, :social_unique_impressions, :unique_clicks, :social_unique_clicks, :connections
5
+
6
+ def initialize(identifier, attributes = {})
7
+ super
8
+
9
+ %w(campaign_id impressions clicks spent social_impressions social_clicks social_spent unique_impressions social_unique_impressions unique_clicks social_unique_clicks connections).each do |field|
10
+ send("#{field}=", attributes[field.to_sym])
11
+ end
12
+
13
+ %w(start_time end_time).each do |field|
14
+ if val = attributes[field.to_sym]
15
+ # Handles integer timestamps and ISO8601 strings
16
+ time = Time.parse(val) rescue Time.at(val.to_i)
17
+ send("#{field}=", time)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module FbGraph
2
+ class AdGroupStat < Node
3
+ attr_accessor :start_time, :end_time, :adgroup_id, :impressions, :clicks, :spent, :social_impressions, :social_clicks, :social_spent,
4
+ :unique_impressions, :social_unique_impressions, :unique_clicks, :social_unique_clicks, :connections
5
+
6
+ def initialize(identifier, attributes = {})
7
+ super
8
+
9
+ %w(adgroup_id impressions clicks spent social_impressions social_clicks social_spent unique_impressions social_unique_impressions unique_clicks social_unique_clicks connections).each do |field|
10
+ send("#{field}=", attributes[field.to_sym])
11
+ end
12
+
13
+ %w(start_time end_time).each do |field|
14
+ if val = attributes[field.to_sym]
15
+ # Handles integer timestamps and ISO8601 strings
16
+ time = Time.parse(val) rescue Time.at(val.to_i)
17
+ send("#{field}=", time)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -13,7 +13,14 @@ module FbGraph
13
13
 
14
14
  def next(_options_ = {})
15
15
  if self.collection.next.present?
16
- self.owner.send(self.connection, self.options.merge(_options_).merge(self.collection.next))
16
+ connection_method = if self.owner.respond_to?(self.connection)
17
+ self.connection
18
+ else
19
+ self.owner.public_methods.detect do |method|
20
+ method.to_s.gsub('_', '') == self.connection.to_s
21
+ end
22
+ end
23
+ self.owner.send(connection_method, self.options.merge(_options_).merge(self.collection.next))
17
24
  else
18
25
  self.class.new(self.owner, self.connection)
19
26
  end
@@ -0,0 +1,22 @@
1
+ module FbGraph
2
+ module Connections
3
+ module AdCampaignStats
4
+ # When retrieving stats at the AdAccount level we use the 'adcampaignstats' connection
5
+ # This returns an Array of statistics
6
+ def ad_campaign_stats(options = {})
7
+ ad_campaign_stats = self.connection(:adcampaignstats, options)
8
+ ad_campaign_stats.map! do |ad_campaign_stat|
9
+ AdCampaignStat.new(ad_campaign_stat[:id], ad_campaign_stat.merge(
10
+ :access_token => options[:access_token] || self.access_token
11
+ ))
12
+ end
13
+ end
14
+
15
+ # Note: This could also be a connection on the AdCampaign model, but it has a different connection name
16
+ # 'stats' instead of 'adcampaignstats'
17
+ # In addition, it returns a single JSON response that does not conform to the standard connections
18
+ # array structure, making it difficult to parse with the underlying fb_graph Connection object.
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,22 @@
1
+ module FbGraph
2
+ module Connections
3
+ module AdGroupStats
4
+ # When retrieving stats at the AdAccount level we use the 'adgroupstats' connection
5
+ # This returns an Array of statistics
6
+ def ad_group_stats(options = {})
7
+ ad_group_stats = self.connection(:adgroupstats, options)
8
+ ad_group_stats.map! do |ad_group_stat|
9
+ AdGroupStat.new(ad_group_stat[:id], ad_group_stat.merge(
10
+ :access_token => options[:access_token] || self.access_token
11
+ ))
12
+ end
13
+ end
14
+
15
+ # Note: This could also be a connection on the AdGroup model, but it has a different connection name
16
+ # 'stats' instead of 'adgroupstats'
17
+ # In addition, it returns a single JSON response that does not conform to the standard connections
18
+ # array structure, making it difficult to parse with the underlying fb_graph Connection object.
19
+ end
20
+ end
21
+ end
22
+
data/lib/fb_graph.rb CHANGED
@@ -63,7 +63,9 @@ require 'fb_graph/work'
63
63
  require 'fb_graph/node'
64
64
  require 'fb_graph/ad_account'
65
65
  require 'fb_graph/ad_campaign'
66
+ require 'fb_graph/ad_campaign_stat'
66
67
  require 'fb_graph/ad_group'
68
+ require 'fb_graph/ad_group_stat'
67
69
  require 'fb_graph/album'
68
70
  require 'fb_graph/app_request'
69
71
  require 'fb_graph/application'
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Connections::AdCampaignStats, '#ad_campaign_stats' do
4
+ context 'when included by FbGraph::AdAccount' do
5
+ context 'when access_token is given' do
6
+ it 'should return ad_campaign_stats as FbGraph::AdCampaignStat' do
7
+ mock_graph :get, 'act_11223344/adcampaignstats', 'ad_accounts/ad_campaign_stats/test_ad_campaign_stats', :access_token => 'access_token' do
8
+ ad_campaign_stats = FbGraph::AdAccount.new('act_11223344', :access_token => 'access_token').ad_campaign_stats
9
+
10
+ ad_campaign_stats.size.should == 2
11
+ ad_campaign_stats.each { |ad_campaign_stat| ad_campaign_stat.should be_instance_of(FbGraph::AdCampaignStat) }
12
+ ad_campaign_stats.first.should == FbGraph::AdCampaignStat.new(
13
+ "6002647797777/stats/0/1315507793",
14
+ :campaign_id => 6002647797777,
15
+ :start_time => nil,
16
+ :end_time => Time.parse("2011-09-08T18:49:53+0000"),
17
+ :impressions => 232641,
18
+ :clicks => 534,
19
+ :spent => 18885,
20
+ :social_impressions => 22676,
21
+ :social_clicks => 81,
22
+ :social_spent => 1548,
23
+ :unique_impressions => 0,
24
+ :social_unique_impressions => 0,
25
+ :unique_clicks => 0,
26
+ :social_unique_clicks => 0,
27
+ :actions => 140,
28
+ :connections => 0,
29
+ :access_token => 'access_token'
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Connections::AdGroupStats, '#ad_group_stats' do
4
+ context 'when included by FbGraph::AdAccount' do
5
+ context 'when access_token is given' do
6
+ it 'should return ad_group_stats as FbGraph::AdGroupStat' do
7
+ mock_graph :get, 'act_11223344/adgroupstats', 'ad_accounts/ad_group_stats/test_ad_group_stats', :access_token => 'access_token' do
8
+ ad_group_stats = FbGraph::AdAccount.new('act_11223344', :access_token => 'access_token').ad_group_stats
9
+
10
+ ad_group_stats.size.should == 3
11
+ ad_group_stats.total_count.should == 3081
12
+ ad_group_stats.each { |ad_group_stat| ad_group_stat.should be_instance_of(FbGraph::AdGroupStat) }
13
+ ad_group_stats.first.should == FbGraph::AdGroupStat.new(
14
+ "6002647798444/stats/0/1315607403",
15
+ :impressions => 232641,
16
+ :clicks => 534,
17
+ :spent => 18885,
18
+ :social_impressions => 22676,
19
+ :social_clicks => 81,
20
+ :social_spent => 1548,
21
+ :unique_impressions => 0,
22
+ :social_unique_impressions => 0,
23
+ :unique_clicks => 0,
24
+ :social_unique_clicks => 0,
25
+ :actions => 140,
26
+ :connections => 0,
27
+ :adgroup_id => 6002647798444,
28
+ :start_time => nil,
29
+ :end_time => "2011-09-09T22:30:03+0000",
30
+ :access_token => "access_token"
31
+ )
32
+ end
33
+ end
34
+
35
+ context 'when paginating' do
36
+ it 'should use ad_group_stats as method name' do
37
+ mock_graph :get, 'act_11223344/adgroupstats', 'ad_accounts/ad_group_stats/test_ad_group_stats', :access_token => 'access_token' do
38
+ ad_group_stats = FbGraph::AdAccount.new('act_11223344', :access_token => 'access_token').ad_group_stats
39
+ ad_group_stats.owner.should_receive :ad_group_stats
40
+ ad_group_stats.next
41
+ end
42
+ end
43
+
44
+ it 'should use adcampaignstats as connection name' do
45
+ mock_graph :get, 'act_11223344/adgroupstats', 'ad_accounts/ad_group_stats/test_ad_group_stats', :access_token => 'access_token' do
46
+ ad_group_stats = FbGraph::AdAccount.new('act_11223344', :access_token => 'access_token').ad_group_stats
47
+ expect do
48
+ ad_group_stats.next
49
+ end.should request_to 'act_11223344/adgroupstats'
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
@@ -0,0 +1,42 @@
1
+ {
2
+ "start_time":null,
3
+ "end_time":"2011-09-08T18:49:53+0000",
4
+ "data": [{
5
+ "id":"6002647797777/stats/0/1315507793",
6
+ "campaign_id":6002647797777,
7
+ "start_time":null,
8
+ "end_time":"2011-09-08T18:49:53+0000",
9
+ "impressions":232641,
10
+ "clicks":534,
11
+ "spent":18885,
12
+ "social_impressions":22676,
13
+ "social_clicks":81,
14
+ "social_spent":1548,
15
+ "unique_impressions":0,
16
+ "social_unique_impressions":0,
17
+ "unique_clicks":0,
18
+ "social_unique_clicks":0,
19
+ "actions":140,
20
+ "connections":0
21
+ }, {
22
+ "id":"6002824447777/stats/0/1315507793",
23
+ "campaign_id":6002824447777,
24
+ "start_time":null,
25
+ "end_time":"2011-09-08T18:49:53+0000",
26
+ "impressions":0,
27
+ "clicks":0,
28
+ "spent":0,
29
+ "social_impressions":0,
30
+ "social_clicks":0,
31
+ "social_spent":0,
32
+ "unique_impressions":0,
33
+ "social_unique_impressions":0,
34
+ "unique_clicks":0,
35
+ "social_unique_clicks":0,
36
+ "actions":0,
37
+ "connections":0
38
+ }],
39
+ "count":2,
40
+ "limit":100,
41
+ "offset":0
42
+ }
@@ -0,0 +1,62 @@
1
+ {
2
+ "start_time":null,
3
+ "end_time":"2011-09-09T22:30:03+0000",
4
+ "data":[{
5
+ "id":"6002647798444/stats/0/1315607403",
6
+ "impressions":232641,
7
+ "clicks":534,
8
+ "spent":18885,
9
+ "social_impressions":22676,
10
+ "social_clicks":81,
11
+ "social_spent":1548,
12
+ "unique_impressions":0,
13
+ "social_unique_impressions":0,
14
+ "unique_clicks":0,
15
+ "social_unique_clicks":0,
16
+ "actions":140,
17
+ "connections":0,
18
+ "adgroup_id":6002647798444,
19
+ "start_time":null,
20
+ "end_time":"2011-09-09T22:30:03+0000"
21
+ }, {
22
+ "id":"6002867067888/stats/0/1315607403",
23
+ "impressions":0,
24
+ "clicks":0,
25
+ "spent":0,
26
+ "social_impressions":0,
27
+ "social_clicks":0,
28
+ "social_spent":0,
29
+ "unique_impressions":0,
30
+ "social_unique_impressions":0,
31
+ "unique_clicks":0,
32
+ "social_unique_clicks":0,
33
+ "actions":0,
34
+ "connections":0,
35
+ "adgroup_id":6002867067888,
36
+ "start_time":null,
37
+ "end_time":"2011-09-09T22:30:03+0000"
38
+ }, {
39
+ "id":"6002935967666/stats/0/1315607403",
40
+ "impressions":0,
41
+ "clicks":0,
42
+ "spent":0,
43
+ "social_impressions":0,
44
+ "social_clicks":0,
45
+ "social_spent":0,
46
+ "unique_impressions":0,
47
+ "social_unique_impressions":0,
48
+ "unique_clicks":0,
49
+ "social_unique_clicks":0,
50
+ "actions":0,
51
+ "connections":0,
52
+ "adgroup_id":6002935967666,
53
+ "start_time":null,
54
+ "end_time":"2011-09-09T22:30:03+0000"
55
+ }],
56
+ "count":3081,
57
+ "limit":3,
58
+ "offset":0,
59
+ "paging": {
60
+ "next":"https://graph.facebook.com/act_111222333/adgroupstats?access_token=aabbccdd&offset=100"
61
+ }
62
+ }
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fb_graph
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.1.4
5
+ version: 2.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - nov matake
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-10 00:00:00 Z
13
+ date: 2011-09-12 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httpclient
@@ -116,7 +116,9 @@ files:
116
116
  - lib/fb_graph/action.rb
117
117
  - lib/fb_graph/ad_account.rb
118
118
  - lib/fb_graph/ad_campaign.rb
119
+ - lib/fb_graph/ad_campaign_stat.rb
119
120
  - lib/fb_graph/ad_group.rb
121
+ - lib/fb_graph/ad_group_stat.rb
120
122
  - lib/fb_graph/album.rb
121
123
  - lib/fb_graph/app_request.rb
122
124
  - lib/fb_graph/application.rb
@@ -131,7 +133,9 @@ files:
131
133
  - lib/fb_graph/connections.rb
132
134
  - lib/fb_graph/connections/accounts.rb
133
135
  - lib/fb_graph/connections/activities.rb
136
+ - lib/fb_graph/connections/ad_campaign_stats.rb
134
137
  - lib/fb_graph/connections/ad_campaigns.rb
138
+ - lib/fb_graph/connections/ad_group_stats.rb
135
139
  - lib/fb_graph/connections/ad_groups.rb
136
140
  - lib/fb_graph/connections/admins.rb
137
141
  - lib/fb_graph/connections/albums.rb
@@ -243,6 +247,8 @@ files:
243
247
  - spec/fb_graph/connection_spec.rb
244
248
  - spec/fb_graph/connections/accounts_spec.rb
245
249
  - spec/fb_graph/connections/activities_spec.rb
250
+ - spec/fb_graph/connections/ad_campaign_stat_spec.rb
251
+ - spec/fb_graph/connections/ad_group_stat_spec.rb
246
252
  - spec/fb_graph/connections/ad_groups_spec.rb
247
253
  - spec/fb_graph/connections/admins_spec.rb
248
254
  - spec/fb_graph/connections/albums_spec.rb
@@ -338,6 +344,8 @@ files:
338
344
  - spec/fb_graph/work_spec.rb
339
345
  - spec/fb_graph_spec.rb
340
346
  - spec/helpers/webmock_helper.rb
347
+ - spec/mock_json/ad_accounts/ad_campaign_stats/test_ad_campaign_stats.json
348
+ - spec/mock_json/ad_accounts/ad_group_stats/test_ad_group_stats.json
341
349
  - spec/mock_json/ad_accounts/ad_groups/post_with_valid_access_token.json
342
350
  - spec/mock_json/ad_accounts/test_ad_account.json
343
351
  - spec/mock_json/ad_campaigns/ad_groups/22334455_ad_groups.json
@@ -530,6 +538,8 @@ test_files:
530
538
  - spec/fb_graph/connection_spec.rb
531
539
  - spec/fb_graph/connections/accounts_spec.rb
532
540
  - spec/fb_graph/connections/activities_spec.rb
541
+ - spec/fb_graph/connections/ad_campaign_stat_spec.rb
542
+ - spec/fb_graph/connections/ad_group_stat_spec.rb
533
543
  - spec/fb_graph/connections/ad_groups_spec.rb
534
544
  - spec/fb_graph/connections/admins_spec.rb
535
545
  - spec/fb_graph/connections/albums_spec.rb
@@ -625,6 +635,8 @@ test_files:
625
635
  - spec/fb_graph/work_spec.rb
626
636
  - spec/fb_graph_spec.rb
627
637
  - spec/helpers/webmock_helper.rb
638
+ - spec/mock_json/ad_accounts/ad_campaign_stats/test_ad_campaign_stats.json
639
+ - spec/mock_json/ad_accounts/ad_group_stats/test_ad_group_stats.json
628
640
  - spec/mock_json/ad_accounts/ad_groups/post_with_valid_access_token.json
629
641
  - spec/mock_json/ad_accounts/test_ad_account.json
630
642
  - spec/mock_json/ad_campaigns/ad_groups/22334455_ad_groups.json