fb_graph 2.4.20 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fb_graph (2.4.19)
4
+ fb_graph (2.4.20)
5
5
  httpclient (>= 2.2.0.2)
6
+ json
6
7
  rack-oauth2 (>= 0.14.4)
7
8
  tzinfo
8
9
 
@@ -27,7 +28,7 @@ GEM
27
28
  multi_json (~> 1.0)
28
29
  addressable (2.3.2)
29
30
  attr_required (0.0.5)
30
- builder (3.0.0)
31
+ builder (3.0.3)
31
32
  configatron (2.9.1)
32
33
  yamler (>= 0.1.0)
33
34
  cover_me (1.2.0)
@@ -41,6 +42,7 @@ GEM
41
42
  httpclient (2.2.7)
42
43
  i18n (0.6.1)
43
44
  journey (1.0.4)
45
+ json (1.7.5)
44
46
  multi_json (1.3.6)
45
47
  rack (1.4.1)
46
48
  rack-cache (1.2)
@@ -60,7 +62,7 @@ GEM
60
62
  rspec-expectations (~> 2.11.0)
61
63
  rspec-mocks (~> 2.11.0)
62
64
  rspec-core (2.11.1)
63
- rspec-expectations (2.11.2)
65
+ rspec-expectations (2.11.3)
64
66
  diff-lcs (~> 1.1.3)
65
67
  rspec-mocks (2.11.2)
66
68
  sprockets (2.1.3)
@@ -69,7 +71,7 @@ GEM
69
71
  tilt (~> 1.1, != 1.3.0)
70
72
  tilt (1.3.3)
71
73
  tzinfo (0.3.33)
72
- webmock (1.8.9)
74
+ webmock (1.8.10)
73
75
  addressable (>= 2.2.7)
74
76
  crack (>= 0.1.7)
75
77
  yamler (0.1.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.4.20
1
+ 2.5.0
data/fb_graph.gemspec CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.add_runtime_dependency "httpclient", ">= 2.2.0.2"
16
16
  s.add_runtime_dependency "rack-oauth2", ">= 0.14.4"
17
17
  s.add_runtime_dependency "tzinfo"
18
+ s.add_runtime_dependency "json"
18
19
  s.add_development_dependency "rake", ">= 0.8"
19
20
  if RUBY_VERSION >= '1.9'
20
21
  s.add_development_dependency "cover_me", ">= 1.2.0"
@@ -0,0 +1,43 @@
1
+ module FbGraph
2
+ class AdCreative < Node
3
+
4
+ ATTRS = [
5
+ :id,
6
+ :view_tag,
7
+ :alt_view_tags,
8
+ :creative_id,
9
+ :type,
10
+ :title,
11
+ :body,
12
+ :image_hash,
13
+ :link_url,
14
+ :name,
15
+ :run_status,
16
+ :preview_url,
17
+ :count_current_adgroups,
18
+ :facebook_object_id, # can't use object_id since it's a core ruby method
19
+ :story_id,
20
+ :image_url,
21
+ :url_tags,
22
+ :related_fan_page,
23
+ :auto_update,
24
+ :action_spec
25
+ ]
26
+
27
+ attr_accessor *ATTRS
28
+ def initialize(identifier, attributes = {})
29
+ super
30
+ set_attrs(attributes)
31
+ end
32
+
33
+ protected
34
+
35
+ def set_attrs(attributes)
36
+ ATTRS.each do |field|
37
+ send("#{field}=", attributes[field.to_sym])
38
+ end
39
+ self.facebook_object_id = attributes[:object_id]
40
+ end
41
+ end
42
+ end
43
+
@@ -1,5 +1,7 @@
1
1
  module FbGraph
2
2
  class AdGroup < Node
3
+ include Connections::AdCreatives
4
+
3
5
  attr_accessor :ad_id, :campaign_id, :name, :adgroup_status, :bid_type, :max_bid, :targeting, :creative, :creative_ids, :adgroup_id,
4
6
  :end_time, :start_time, :updated_time, :bid_info, :disapprove_reason_descriptions
5
7
 
@@ -21,6 +23,10 @@ module FbGraph
21
23
  response
22
24
  end
23
25
 
26
+ def creatives(fetch = true)
27
+ creative_ids.map { |creative_id| fetch ? AdCreative.fetch(creative_id) : AdCreative.new(creative_id) }
28
+ end
29
+
24
30
  protected
25
31
 
26
32
  def set_attrs(attributes)
@@ -0,0 +1,14 @@
1
+ module FbGraph
2
+ module Connections
3
+ module AdCreatives
4
+ def ad_creatives(options = {})
5
+ ad_creatives = self.connection :adcreatives, options
6
+ ad_creatives.map! do |ad_creative|
7
+ AdCreative.new ad_creative[:id], ad_creative.merge(
8
+ :access_token => options[:access_token] || self.access_token
9
+ )
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/fb_graph.rb CHANGED
@@ -84,6 +84,7 @@ require 'fb_graph/ad_account'
84
84
  require 'fb_graph/ad_campaign'
85
85
  require 'fb_graph/ad_campaign_stat'
86
86
  require 'fb_graph/ad_connection_object'
87
+ require 'fb_graph/ad_creative'
87
88
  require 'fb_graph/ad_group'
88
89
  require 'fb_graph/ad_group_stat'
89
90
  require 'fb_graph/ad_keyword'
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::AdCreative, '.new' do
4
+
5
+ it 'should setup all supported attributes' do
6
+ attributes = {
7
+ :id => '6003590469668',
8
+ :view_tag => "",
9
+ :alt_view_tags => [],
10
+ :creative_id => "6003590469668",
11
+ :type => 1,
12
+ :title => "Some Creative",
13
+ :body => "The Body",
14
+ :image_hash => "4c34b48cdcbf5dd3055acb717343a9d6",
15
+ :link_url => "http://www.google.com/",
16
+ :name => "Creative Name",
17
+ :run_status => 1,
18
+ :preview_url => "http://www.facebook.com/ads/api/creative_preview.php?cid=6003590469668",
19
+ :count_current_adgroups => 1,
20
+ :object_id => 12345,
21
+ :story_id => 54321,
22
+ :image_url => "https://www.google.com/image.png",
23
+ :url_tags => "url=tags",
24
+ :related_fan_page => 5799040003,
25
+ :auto_update => 1,
26
+ :action_spec => '{"action.type":["flightsim:fly"], "application":[174829001234]}'
27
+ }
28
+ ad_creative = FbGraph::AdCreative.new(attributes.delete(:id), attributes)
29
+ ad_creative.identifier.should == "6003590469668"
30
+ ad_creative.view_tag.should == ""
31
+ ad_creative.alt_view_tags.should == []
32
+ ad_creative.creative_id.should == "6003590469668"
33
+ ad_creative.type.should == 1
34
+ ad_creative.title.should == "Some Creative"
35
+ ad_creative.body.should == "The Body"
36
+ ad_creative.image_hash.should == "4c34b48cdcbf5dd3055acb717343a9d6"
37
+ ad_creative.link_url.should == "http://www.google.com/"
38
+ ad_creative.name.should == "Creative Name"
39
+ ad_creative.run_status.should == 1
40
+ ad_creative.preview_url.should == "http://www.facebook.com/ads/api/creative_preview.php?cid=6003590469668"
41
+ ad_creative.count_current_adgroups.should == 1
42
+ ad_creative.facebook_object_id.should == 12345
43
+ ad_creative.image_url.should == "https://www.google.com/image.png"
44
+ ad_creative.url_tags.should == "url=tags"
45
+ ad_creative.related_fan_page.should == 5799040003
46
+ ad_creative.auto_update.should == 1
47
+ ad_creative.action_spec.should == '{"action.type":["flightsim:fly"], "application":[174829001234]}'
48
+ end
49
+ end
50
+
51
+
52
+ describe FbGraph::AdCreative, '.fetch' do
53
+ it 'should get the ad creative' do
54
+ mock_graph :get, '6003590469668', 'ad_creatives/test_ad_creative', :access_token => 'access_token' do
55
+ ad_creative = FbGraph::AdCreative.fetch('6003590469668', :access_token => 'access_token')
56
+ ad_creative.identifier.should == "6003590469668"
57
+ ad_creative.view_tag.should == ""
58
+ ad_creative.alt_view_tags.should == []
59
+ ad_creative.creative_id.should == "6003590469668"
60
+ ad_creative.type.should == 1
61
+ ad_creative.title.should == "Some Creative"
62
+ ad_creative.body.should == "The Body"
63
+ ad_creative.image_hash.should == "4c34b48cdcbf5dd3055acb717343a9d6"
64
+ ad_creative.link_url.should == "http://www.google.com/"
65
+ ad_creative.name.should == "Creative Name"
66
+ ad_creative.run_status.should == 1
67
+ ad_creative.preview_url.should == "http://www.facebook.com/ads/api/creative_preview.php?cid=6003590469668"
68
+ ad_creative.count_current_adgroups.should == 1
69
+ ad_creative.image_url.should == "https://www.google.com/image.png"
70
+ end
71
+ end
72
+ end
73
+
74
+ describe FbGraph::AdCreative, '.update' do
75
+ it "should return true from facebook" do
76
+ mock_graph :post, '6003590469668', 'true', :body => "New Body" do
77
+ attributes = {
78
+ :id => '6003590469668',
79
+ :body => "The Body"
80
+ }
81
+ ad_creative = FbGraph::AdCreative.new(attributes.delete(:id), attributes)
82
+ ad_creative.update(:body => "New Body").should be_true
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph::Connections::AdGroups, '#ad_creatives' do
4
+ context 'when included by FbGraph::AdGroup' do
5
+ context 'when access_token is given' do
6
+ it 'should return ad_creatives as FbGraph::AdCreative' do
7
+ mock_graph :get, '22334455/adcreatives', 'ad_groups/ad_creatives/22334455_ad_creatives', :access_token => 'access_token' do
8
+ ad_creatives = FbGraph::AdGroup.new('22334455', :access_token => 'access_token').ad_creatives
9
+ ad_creatives.size.should == 1
10
+ ad_creative = ad_creatives.first
11
+ ad_creative.identifier.should == "6003590469668"
12
+ ad_creative.view_tag.should == ""
13
+ ad_creative.alt_view_tags.should == []
14
+ ad_creative.creative_id.should == "6003590469668"
15
+ ad_creative.type.should == 1
16
+ ad_creative.title.should == "Some Creative"
17
+ ad_creative.body.should == "The Body"
18
+ ad_creative.image_hash.should == "4c34b48cdcbf5dd3055acb717343a9d6"
19
+ ad_creative.link_url.should == "http://www.google.com/"
20
+ ad_creative.name.should == "Creative Name"
21
+ ad_creative.run_status.should == 1
22
+ ad_creative.preview_url.should == "http://www.facebook.com/ads/api/creative_preview.php?cid=6003590469668"
23
+ ad_creative.count_current_adgroups.should == 1
24
+ ad_creative.image_url.should == "https://www.google.com/image.png"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ {
2
+ "id": "6003590469668",
3
+ "view_tag": "",
4
+ "alt_view_tags": [],
5
+ "creative_id": "6003590469668",
6
+ "type": 1,
7
+ "title": "Some Creative",
8
+ "body": "The Body",
9
+ "image_hash": "4c34b48cdcbf5dd3055acb717343a9d6",
10
+ "link_url": "http://www.google.com/",
11
+ "name": "Creative Name",
12
+ "run_status": 1,
13
+ "preview_url": "http://www.facebook.com/ads/api/creative_preview.php?cid=6003590469668",
14
+ "count_current_adgroups": 1,
15
+ "image_url": "https://www.google.com/image.png"
16
+ }
@@ -0,0 +1,18 @@
1
+ {"data": [
2
+ {
3
+ "id": "6003590469668",
4
+ "view_tag": "",
5
+ "alt_view_tags": [],
6
+ "creative_id": "6003590469668",
7
+ "type": 1,
8
+ "title": "Some Creative",
9
+ "body": "The Body",
10
+ "image_hash": "4c34b48cdcbf5dd3055acb717343a9d6",
11
+ "link_url": "http://www.google.com/",
12
+ "name": "Creative Name",
13
+ "run_status": 1,
14
+ "preview_url": "http://www.facebook.com/ads/api/creative_preview.php?cid=6003590469668",
15
+ "count_current_adgroups": 1,
16
+ "image_url": "https://www.google.com/image.png"
17
+ }]
18
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb_graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.20
4
+ version: 2.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-02 00:00:00.000000000 Z
12
+ date: 2012-09-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httpclient
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: json
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: rake
64
80
  requirement: !ruby/object:Gem::Requirement
@@ -167,6 +183,7 @@ files:
167
183
  - lib/fb_graph/ad_campaign.rb
168
184
  - lib/fb_graph/ad_campaign_stat.rb
169
185
  - lib/fb_graph/ad_connection_object.rb
186
+ - lib/fb_graph/ad_creative.rb
170
187
  - lib/fb_graph/ad_group.rb
171
188
  - lib/fb_graph/ad_group_stat.rb
172
189
  - lib/fb_graph/ad_keyword.rb
@@ -194,6 +211,7 @@ files:
194
211
  - lib/fb_graph/connections/ad_campaign_stats.rb
195
212
  - lib/fb_graph/connections/ad_campaigns.rb
196
213
  - lib/fb_graph/connections/ad_connection_objects.rb
214
+ - lib/fb_graph/connections/ad_creatives.rb
197
215
  - lib/fb_graph/connections/ad_group_stats.rb
198
216
  - lib/fb_graph/connections/ad_groups.rb
199
217
  - lib/fb_graph/connections/ad_previews.rb
@@ -330,6 +348,7 @@ files:
330
348
  - spec/fb_graph/ad_account_spec.rb
331
349
  - spec/fb_graph/ad_campaign_spec.rb
332
350
  - spec/fb_graph/ad_connection_object_spec.rb
351
+ - spec/fb_graph/ad_creative_spec.rb
333
352
  - spec/fb_graph/ad_group_spec.rb
334
353
  - spec/fb_graph/ad_keyword_spec.rb
335
354
  - spec/fb_graph/ad_keyword_suggestion_spec.rb
@@ -353,6 +372,7 @@ files:
353
372
  - spec/fb_graph/connections/ad_campaign_stat_spec.rb
354
373
  - spec/fb_graph/connections/ad_campaigns_spec.rb
355
374
  - spec/fb_graph/connections/ad_connection_objects_spec.rb
375
+ - spec/fb_graph/connections/ad_creatives_spec.rb
356
376
  - spec/fb_graph/connections/ad_group_stat_spec.rb
357
377
  - spec/fb_graph/connections/ad_groups_spec.rb
358
378
  - spec/fb_graph/connections/ad_previews_spec.rb
@@ -491,6 +511,8 @@ files:
491
511
  - spec/mock_json/ad_campaigns/ad_groups/22334455_ad_groups.json
492
512
  - spec/mock_json/ad_campaigns/test_ad_campaign.json
493
513
  - spec/mock_json/ad_campaigns/test_ad_campaign_update_with_redownload.json
514
+ - spec/mock_json/ad_creatives/test_ad_creative.json
515
+ - spec/mock_json/ad_groups/ad_creatives/22334455_ad_creatives.json
494
516
  - spec/mock_json/ad_groups/test_ad_group.json
495
517
  - spec/mock_json/ad_groups/test_ad_group_update_with_redownload.json
496
518
  - spec/mock_json/ad_keyword_suggestions/buffy_suggestions.json
@@ -712,6 +734,7 @@ test_files:
712
734
  - spec/fb_graph/ad_account_spec.rb
713
735
  - spec/fb_graph/ad_campaign_spec.rb
714
736
  - spec/fb_graph/ad_connection_object_spec.rb
737
+ - spec/fb_graph/ad_creative_spec.rb
715
738
  - spec/fb_graph/ad_group_spec.rb
716
739
  - spec/fb_graph/ad_keyword_spec.rb
717
740
  - spec/fb_graph/ad_keyword_suggestion_spec.rb
@@ -735,6 +758,7 @@ test_files:
735
758
  - spec/fb_graph/connections/ad_campaign_stat_spec.rb
736
759
  - spec/fb_graph/connections/ad_campaigns_spec.rb
737
760
  - spec/fb_graph/connections/ad_connection_objects_spec.rb
761
+ - spec/fb_graph/connections/ad_creatives_spec.rb
738
762
  - spec/fb_graph/connections/ad_group_stat_spec.rb
739
763
  - spec/fb_graph/connections/ad_groups_spec.rb
740
764
  - spec/fb_graph/connections/ad_previews_spec.rb
@@ -873,6 +897,8 @@ test_files:
873
897
  - spec/mock_json/ad_campaigns/ad_groups/22334455_ad_groups.json
874
898
  - spec/mock_json/ad_campaigns/test_ad_campaign.json
875
899
  - spec/mock_json/ad_campaigns/test_ad_campaign_update_with_redownload.json
900
+ - spec/mock_json/ad_creatives/test_ad_creative.json
901
+ - spec/mock_json/ad_groups/ad_creatives/22334455_ad_creatives.json
876
902
  - spec/mock_json/ad_groups/test_ad_group.json
877
903
  - spec/mock_json/ad_groups/test_ad_group_update_with_redownload.json
878
904
  - spec/mock_json/ad_keyword_suggestions/buffy_suggestions.json