ad_leads 0.1.6.1 → 0.1.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce9d2997804b510871ae6df0ce9352acfa0e9248
4
- data.tar.gz: 6e89fd30d81d604c877599b7d0125776e2e3fcb7
3
+ metadata.gz: 3d7000e942209e9c92354564fa68b260925f8c71
4
+ data.tar.gz: de28f9996e6ca7383f136852e9a8a5e36f706321
5
5
  SHA512:
6
- metadata.gz: 2311c0f3356752b816a3a62e18bd2289d82b54732a2849f088cf3abd842b4cc758819162fd382449204929dd1931fb38276b0cdb6a52aa35f80ffdc1d680cd5c
7
- data.tar.gz: 0950717a79e8af61fb04d980d03cd548f7a121cd5e492c4e7db9c1673cde4f55c8799f93a059476353b9fb6a1cc6737ca0ae497e100e98546d790fad2f47100a
6
+ metadata.gz: 77692bf8a3ded98d7d13ee154359d6dfaf7157738e988cc669de2f8912e99fa64eaa132c6f435219280c8afb235b8931f45f14cdf7523cdd18590095f1d4a7f8
7
+ data.tar.gz: 84af060967a19a460f53bfb5d2df70cfeb078cb28ee9132c1dc97a21073fa8e51a01a6bdaa36abe2fd51f4875e45d781207137ff782dfcd9d6ff5907ab7919d7
data/lib/ad_leads/ad.rb CHANGED
@@ -1,19 +1,9 @@
1
- class AdLeads::Ad < AdLeads::Base
2
- # params = {
3
- # 'type' => 'Mobile',
4
- # 'name' => 'test mobile ad',
5
- # 'headerText' => 'get your ad on this phone today',
6
- # 'bodyText' => 'this is mobile ad body copy'
7
- # }
8
-
9
- attr_accessor :creative_group_id
10
-
11
- def initialize(creative_group_id)
12
- @creative_group_id = creative_group_id
1
+ module AdLeads
2
+ class Client
3
+ module Ad
4
+ def create_ad(creative_group_id, options)
5
+ post "/creativegroups/#{creative_group_id}/creatives", options
6
+ end
7
+ end
13
8
  end
14
-
15
- def root_path
16
- "/creativegroups/#{creative_group_id}/creatives"
17
- end
18
-
19
9
  end
@@ -1,43 +1,58 @@
1
- class AdLeads::Campaign < AdLeads::Base
2
- include AdLeads::Etag
3
-
4
- # params = {
5
- # 'name' => 'test',
6
- # 'verticals' => 82,
7
- # 'offerIncentiveCategory' => 5,
8
- # 'collectedFields' => 'firstname,lastname,email,companyname',
9
- # 'budget' => 50,
10
- # 'creativeGroups' => creative_group.id
11
- # }
12
-
13
- def update!(params)
14
- client.post(campaign_path, params)
15
- end
16
-
17
- def verify!
18
- client.get(verify_campaign_path)
19
- end
20
-
21
- def launch!
22
- with_etag do
23
- client.post(launch_campaign_path, etag: etag)
1
+ module AdLeads
2
+ class Client
3
+ module Campaign
4
+ def create_campaign(creative_id, options)
5
+ post '/campaigns', options.merge(creativeGroups: creative_id)
6
+ end
7
+
8
+ def create_complete_campaign(options)
9
+ create_creative_group(options[:creative_group])
10
+ creative_id = self.last_response_id
11
+
12
+ create_ad(creative_id, options[:ad])
13
+ ad_id = self.last_response_id
14
+
15
+ create_image(creative_id, ad_id, options[:image])
16
+ image_id = self.last_response_id
17
+ upload_image(creative_id, ad_id, image_id, options[:file])
18
+
19
+ create_campaign(creative_id, options[:campaign])
20
+ end
21
+
22
+ def update_campaign(id, options)
23
+ post campaign_path(id), options
24
+ end
25
+
26
+ def verify_campaign(id)
27
+ get verify_campaign_path(id)
28
+ end
29
+
30
+ def launch_campaign(id)
31
+ remaining_tries ||= 3
32
+ post launch_campaign_path(id), etag: campaign_etag(id).headers['Etag']
33
+ rescue AdLeads::EtagMismatchError
34
+ remaining_tries -= 1
35
+ retry unless remaining_tries.zero?
36
+ end
37
+
38
+ private
39
+
40
+ def campaign_path(id)
41
+ "/campaigns/#{id}"
42
+ end
43
+ alias :campaign_etag_path :campaign_path
44
+
45
+ def launch_campaign_path(id)
46
+ campaign_path(id) + '/launch'
47
+ end
48
+
49
+ def verify_campaign_path(id)
50
+ campaign_path(id) + '/plan'
51
+ end
52
+
53
+ def campaign_etag(id)
54
+ get campaign_etag_path(id)
55
+ end
24
56
  end
25
57
  end
26
-
27
- def campaign_path
28
- root_path + "/#{id}"
29
- end
30
- alias :etag_path :campaign_path
31
-
32
- def launch_campaign_path
33
- campaign_path + '/launch'
34
- end
35
-
36
- def root_path
37
- '/campaigns'
38
- end
39
-
40
- def verify_campaign_path
41
- campaign_path + '/plan'
42
- end
43
58
  end
@@ -1,10 +1,12 @@
1
- require 'faraday'
2
- require 'json'
3
- require 'logger'
4
-
5
- module AdLeads
1
+ module AdLeads
6
2
  class Client
3
+ include AdLeads::Client::CreativeGroup
4
+ include AdLeads::Client::Ad
5
+ include AdLeads::Client::Image
6
+ include AdLeads::Client::Campaign
7
+
7
8
  attr_accessor *Configuration::VALID_CONFIG_KEYS
9
+ attr_reader :last_response
8
10
 
9
11
  def initialize(options={})
10
12
  merged_options = AdLeads.options.merge(options)
@@ -40,6 +42,10 @@ module AdLeads
40
42
  request(:post, path, params)
41
43
  end
42
44
 
45
+ def last_response_id
46
+ JSON.parse(last_response.body)['data'].first
47
+ end
48
+
43
49
  private
44
50
 
45
51
  def etag_opts(etag)
@@ -87,14 +93,14 @@ module AdLeads
87
93
  case response.status
88
94
  when 400 then raise ArgError.new response.body
89
95
  when 401 then raise AuthError.new "token: #{token}" + response.body.to_s
96
+ when 412 then raise EtagMismatchError.new response.body
90
97
  when 500 then raise ApiServerError.new response.body
91
98
  else
92
- response
99
+ @last_response = response
93
100
  end
94
101
  # rescue Faraday::Error::TimeoutError, Timeout::Error => error
95
102
  # rescue Faraday::Error::ClientError, JSON::ParserError => error
96
103
  end
97
-
98
104
  end
99
105
 
100
106
  class ApiError < StandardError
@@ -106,4 +112,5 @@ module AdLeads
106
112
  class AuthError < ApiError; end
107
113
  class ApiServerError < ApiError; end
108
114
  class ArgError < ApiError; end
115
+ class EtagMismatchError < ApiError; end
109
116
  end
@@ -1,13 +1,9 @@
1
- class AdLeads::CreativeGroup < AdLeads::Base
2
-
3
- # params = {
4
- # 'name' => 'test creative group',
5
- # 'productName' => 'test product',
6
- # 'privacyPolicyUrl' => 'http://privacy_url'
7
- # }
8
-
9
- def root_path
10
- '/creativegroups'
1
+ module AdLeads
2
+ class Client
3
+ module CreativeGroup
4
+ def create_creative_group(options)
5
+ post '/creativegroups', options
6
+ end
7
+ end
11
8
  end
12
-
13
9
  end
@@ -1,48 +1,38 @@
1
- class AdLeads::Image < AdLeads::Base
2
- include AdLeads::Etag
3
- attr_accessor :creative_group_id, :ad_id
1
+ module AdLeads
2
+ class Client
3
+ module Image
4
+ def create_image(creative_group_id, ad_id, options)
5
+ post image_root_path(creative_group_id, ad_id), options
6
+ end
4
7
 
5
- def initialize(opts)
6
- @creative_group_id = opts[:creative_group_id]
7
- @ad_id = opts[:ad_id]
8
- end
8
+ def upload_image(creative_group_id, ad_id, image_id, file)
9
+ remaining_tries ||= 3
10
+ post image_upload_path(creative_group_id, ad_id, image_id), image_upload_opts(creative_group_id, ad_id, image_id, file)
11
+ rescue AdLeads::EtagMismatchError
12
+ remaining_tries -= 1
13
+ retry unless remaining_tries.zero?
14
+ end
9
15
 
10
- def ids
11
- { group: creative_group_id, creative: ad_id }
12
- end
16
+ private
13
17
 
14
- def upload!(file)
15
- with_etag do
16
- client.post(image_upload_path, image_upload_params(file))
17
- end
18
- end
18
+ def image_root_path(creative_group_id, ad_id)
19
+ "/creativegroups/#{creative_group_id}/creatives/#{ad_id}/images"
20
+ end
19
21
 
20
- def image_upload_params(file)
21
- {
22
- file: Faraday::UploadIO.new(file, 'image/jpeg'),
23
- etag: etag
24
- }
25
- end
22
+ def image_upload_path(creative_group_id, ad_id, image_id)
23
+ "/creativegroups/#{creative_group_id}/creatives/#{ad_id}/images/#{image_id}/file"
24
+ end
26
25
 
27
- def image_upload_path
28
- [
29
- root_path,
30
- id,
31
- 'file'
32
- ].join('/')
33
- end
34
-
35
- def etag_path
36
- root_path + "/#{id}"
37
- end
26
+ def image_upload_opts(creative_group_id, ad_id, image_id, file)
27
+ {
28
+ file: Faraday::UploadIO.new(file, 'image/jpeg'),
29
+ etag: image_etag(creative_group_id, ad_id, image_id).headers['Etag']
30
+ }
31
+ end
38
32
 
39
- def root_path
40
- [
41
- '/creativegroups',
42
- creative_group_id,
43
- 'creatives',
44
- ad_id,
45
- 'images'
46
- ].join('/')
33
+ def image_etag(creative_group_id, ad_id, image_id)
34
+ get "/creativegroups/#{creative_group_id}/creatives/#{ad_id}/images/#{image_id}"
35
+ end
36
+ end
47
37
  end
48
38
  end
@@ -1,4 +1,4 @@
1
- module AdLeads
1
+ module AdLeads
2
2
  class Promotion
3
3
  def self.promotion_params(deal)
4
4
  {
@@ -1,5 +1,4 @@
1
- module AdLeads
2
-
1
+ module AdLeads
3
2
  class Token
4
3
  attr_accessor *Configuration::VALID_CONFIG_KEYS
5
4
 
@@ -1,3 +1,3 @@
1
1
  module AdLeads
2
- VERSION = "0.1.6.1"
2
+ VERSION = "0.1.7"
3
3
  end
data/lib/ad_leads.rb CHANGED
@@ -1,14 +1,16 @@
1
1
  require 'jwt'
2
+ require 'faraday'
3
+ require 'json'
4
+ require 'logger'
5
+
2
6
  require 'ad_leads/version'
3
7
  require 'ad_leads/configuration'
4
- require 'ad_leads/client'
5
8
  require 'ad_leads/token'
6
- require 'ad_leads/base'
7
- require 'ad_leads/etag'
9
+ require 'ad_leads/creative_group'
10
+ require 'ad_leads/ad'
8
11
  require 'ad_leads/image'
9
12
  require 'ad_leads/campaign'
10
- require 'ad_leads/ad'
11
- require 'ad_leads/creative_group'
13
+ require 'ad_leads/client'
12
14
 
13
15
  module AdLeads
14
16
  extend Configuration
@@ -1,24 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AdLeads::Ad do
4
- let(:ad) { AdLeads::Ad.new(1) }
5
- let(:client) { ad.client }
6
- let(:params) { {} }
7
-
8
- it 'inherits from AdLeads::Base' do
9
- expect(ad.class.ancestors).to include AdLeads::Base
10
- end
11
-
12
- describe '#create!' do
13
- it 'posts to Ad Leads ad endpoint for creatives' do
14
- expect(client).to receive(:post).with('/creativegroups/1/creatives', params)
15
- ad.create!(params)
16
- end
17
-
18
- it 'assigns #response' do
19
- client.stub(:post) { 'Foobar' }
20
- ad.create!(params)
21
- expect(ad.response).to eq 'Foobar'
3
+ describe AdLeads::Client::Ad do
4
+ let(:client) { AdLeads::Client.new }
5
+ let(:options) { {} }
6
+
7
+ describe '#create_ad' do
8
+ it 'creates an ad' do
9
+ expect(client).to receive(:post).with('/creativegroups/1/creatives', options)
10
+ client.create_ad(1, options)
22
11
  end
23
12
  end
24
13
 
@@ -1,69 +1,78 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AdLeads::Campaign do
4
- let(:campaign) { AdLeads::Campaign.new() }
5
- let(:client) { campaign.client }
6
- let(:params) { {} }
3
+ describe AdLeads::Client::Campaign do
4
+ let(:client) { AdLeads::Client.new }
5
+ let(:options) { {} }
7
6
  let(:http_success) { double(:http_success, status: 200) }
8
7
 
9
- it 'inherits from AdLeads::Base' do
10
- expect(campaign.class.ancestors).to include AdLeads::Base
11
- end
8
+ describe '#create_complete_campaign' do
9
+ let(:creative_opts) { {} }
10
+ let(:ad_opts) { {} }
11
+ let(:image_opts) { {} }
12
+ let(:file) { './spec/fixtures/test.jpg' }
13
+ let(:campaign_opts) { {} }
14
+ let(:complete_campaign_opts) {{
15
+ creative_group: creative_opts,
16
+ ad: ad_opts,
17
+ image: image_opts,
18
+ file: file,
19
+ campaign: campaign_opts
20
+ }}
12
21
 
13
- describe '#create!' do
14
- it 'posts to AdLeads::Campaign#root_path' do
15
- expect(client).to receive(:post).with('/campaigns', params)
16
- campaign.create!(params)
17
- end
22
+ it 'creates a creative group, ad, image, and campaign' do
23
+ client.stub(:last_response_id) { 1 }
18
24
 
19
- it 'assigns #response' do
20
- client.stub(:post) { 'Foobar' }
21
- campaign.create!(params)
22
- expect(campaign.response).to eq 'Foobar'
25
+ expect(client).to receive(:create_creative_group).with(creative_opts)
26
+ expect(client).to receive(:create_ad).with(1, ad_opts)
27
+ expect(client).to receive(:create_image).with(1, 1, image_opts)
28
+ expect(client).to receive(:upload_image).with(1, 1, 1, file)
29
+ expect(client).to receive(:create_campaign).with(1, campaign_opts)
30
+ client.create_complete_campaign(complete_campaign_opts)
23
31
  end
24
32
  end
25
33
 
26
- describe '#update!' do
27
- before { campaign.instance_variable_set(:@id, 1) }
28
-
29
- it 'posts to AdLeads::Campaign#campaign_path' do
30
- expect(client).to receive(:post).with('/campaigns/1', params)
31
- campaign.update!(params)
34
+ describe '#create_campaign' do
35
+ it 'creates a campaign' do
36
+ expect(client).to receive(:post).with('/campaigns', {creativeGroups: 1})
37
+ client.create_campaign(1, options)
32
38
  end
33
39
  end
34
40
 
35
- describe '#verify!' do
36
- before { campaign.instance_variable_set(:@id, 1) }
37
-
38
- it 'sends a GET request to AdLeads::Campaign#verify_campaign_path' do
39
- expect(client).to receive(:get).with('/campaigns/1/plan')
40
- campaign.verify!
41
+ describe '#update_campaign' do
42
+ it 'updates the respective campaign' do
43
+ expect(client).to receive(:post).with('/campaigns/1', options)
44
+ client.update_campaign(1, options)
41
45
  end
42
46
  end
43
47
 
44
- describe '#launch!' do
45
- before do
46
- campaign.stub(:id) { 1 }
47
- campaign.stub(:etag) { 'Fake etag' }
48
+ describe '#verify_campaign' do
49
+ it 'verifies the respective campaign' do
50
+ expect(client).to receive(:get).with('/campaigns/1/plan')
51
+ client.verify_campaign(1)
48
52
  end
53
+ end
49
54
 
50
- it 'posts to AdLeads::Campaign#launch_campaign_path' do
51
- expect(client).to receive(:post).with('/campaigns/1/launch', { etag: 'Fake etag'}).and_return(http_success)
52
- campaign.launch!
55
+ describe '#launch_campaign' do
56
+ it 'launches a campaign' do
57
+ etag_response = double :response, headers: { 'Etag' => 1 }
58
+ client.stub(:campaign_etag) { etag_response }
59
+ expect(client).to receive(:post).with('/campaigns/1/launch', {etag: 1} )
60
+ client.launch_campaign(1)
53
61
  end
54
62
 
55
- it 'uses #with_etag block' do
56
- client.stub(:post)
57
- expect(campaign).to receive(:with_etag)
58
- campaign.launch!
63
+ it 'gets etag' do
64
+ expect(client).to receive(:get).with('/campaigns/1')
65
+ client.send(:campaign_etag, 1)
59
66
  end
60
- end
61
-
62
- describe '#etag_path' do
63
- before { campaign.instance_variable_set(:@id, 1) }
64
67
 
65
- it 'is an alias for #campaign_path' do
66
- expect(campaign.etag_path).to eq campaign.campaign_path
68
+ context 'with EtagMismatchError' do
69
+ it 'retries launch a maximum of three times' do
70
+ etag_response = double :response, headers: { 'Etag' => 1 }
71
+ client.stub(:campaign_etag) { etag_response }
72
+ client.stub(:post) { raise AdLeads::EtagMismatchError.new 'Error' }
73
+ expect(client).to receive(:post).exactly(3).times
74
+ client.launch_campaign(1)
75
+ end
67
76
  end
68
77
  end
69
78
  end
@@ -10,6 +10,8 @@ describe AdLeads::Client do
10
10
 
11
11
  before { client.stub(:token) { token } }
12
12
 
13
+ it { should respond_to(:last_response) }
14
+
13
15
  describe '#connection' do
14
16
  let(:config_keys) { AdLeads::Configuration::VALID_CONFIG_KEYS }
15
17
 
@@ -29,6 +31,23 @@ describe AdLeads::Client do
29
31
  connection.stub(:post) { response }
30
32
  end
31
33
 
34
+ context 'status: 200' do
35
+ let(:status) { 200 }
36
+ it 'sets @last_response' do
37
+ client.post('foo')
38
+ expect(client.instance_variable_get(:@last_response)).to eq response
39
+ end
40
+ end
41
+
42
+ context 'status: 412' do
43
+ let(:status) { 412 }
44
+ it 'raises AdLeads::EtagMismatchError' do
45
+ expect {
46
+ client.post('foo')
47
+ }.to raise_error AdLeads::EtagMismatchError
48
+ end
49
+ end
50
+
32
51
  context 'status: 500' do
33
52
  let(:status) { 500 }
34
53
  it 'raises AdLeads::ApiError' do
@@ -46,4 +65,13 @@ describe AdLeads::Client do
46
65
  end
47
66
  end
48
67
  end
68
+
69
+ describe '#last_response_id' do
70
+ let(:last_response) { double :response, body: {'data' => [88]}.to_json }
71
+
72
+ it 'retrieves id from @last_response' do
73
+ client.stub(:last_response) { last_response }
74
+ expect(client.last_response_id).to eq 88
75
+ end
76
+ end
49
77
  end
@@ -1,24 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AdLeads::CreativeGroup do
4
- let(:creative_group) { AdLeads::CreativeGroup.new }
5
- let(:client) { creative_group.client }
6
- let(:params) {{}}
7
-
8
- it 'inherits from AdLeads::Base' do
9
- expect(creative_group.class.ancestors).to include AdLeads::Base
10
- end
11
-
12
- describe '#create!' do
13
- it 'posts to /creativegroups path' do
14
- expect(client).to receive(:post).with('/creativegroups', params)
15
- creative_group.create!(params)
16
- end
17
-
18
- it 'assigns #response' do
19
- client.stub(:post) { 'Foobar' }
20
- creative_group.create!(params)
21
- expect(creative_group.response).to eq 'Foobar'
3
+ describe AdLeads::Client::CreativeGroup do
4
+ let(:client) { AdLeads::Client.new }
5
+ let(:options) {{}}
6
+
7
+ describe '#create_creative_group' do
8
+ it 'creates a creative group' do
9
+ expect(client).to receive(:post).with('/creativegroups', options)
10
+ client.create_creative_group(options)
22
11
  end
23
12
  end
24
13
 
@@ -1,70 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
- # TODO: Extract Etag specs!
3
+ describe AdLeads::Client::Image do
4
+ let(:client) { AdLeads::Client.new }
5
+ let(:options) { {} }
6
+ let(:file) { './spec/fixtures/test.jpg' }
4
7
 
5
- describe AdLeads::Image do
6
- let(:image) { AdLeads::Image.new( {creative_group_id: 1, ad_id: 1} ) }
7
- let(:client) { image.client }
8
- let(:params) { {} }
9
- let(:success) { double(:http_response, status: 200) }
10
- let(:etag_mismatch) { double(:http_response, status: 412) }
11
- let(:new_etag) { double(:http_response, status: 200, headers: { 'Etag' => '123'} ) }
12
-
13
- it 'inherits from AdLeads::Base' do
14
- expect(image.class.ancestors).to include AdLeads::Base
15
- end
16
-
17
- describe '#create!' do
18
- it 'posts to AdLeads::Image endpoint' do
19
- expect(client).to receive(:post).with('/creativegroups/1/creatives/1/images', params)
20
- image.create!(params)
21
- end
22
-
23
- it 'assigns #response' do
24
- client.stub(:post) { 'Foobar' }
25
- image.create!(params)
26
- expect(image.response).to eq 'Foobar'
27
- end
28
- end
29
-
30
- describe '#refresh_etag' do
31
- before { image.stub(:etag_path) { '/foo' } }
32
- it 'sets @etag from response headers' do
33
- expect(client).to receive(:get).with('/foo').and_return(new_etag)
34
- image.refresh_etag!
35
- expect(image.etag).to eq '123'
8
+ describe '#create_image' do
9
+ it 'creates an image' do
10
+ expect(client).to receive(:post).
11
+ with('/creativegroups/1/creatives/1/images', options)
12
+ client.create_image(1, 1, options)
36
13
  end
37
14
  end
38
15
 
39
- describe '#upload!' do
40
- let(:file) { './spec/fixtures/test.jpg' }
41
- before do
42
- image.stub(:etag) { 'Fake etag' }
43
- image.stub(:id) { 1 }
44
- end
45
-
46
- it 'posts to AdLeads::Image#image_upload_path' do
47
- image.stub(:image_upload_params) {{}}
16
+ describe '#upload_image' do
17
+ it 'uploads an image' do
18
+ client.stub(:image_upload_opts) { {} }
48
19
  expect(client).to receive(:post).
49
- with('/creativegroups/1/creatives/1/images/1/file', params).
50
- and_return(success)
51
- image.upload!(file)
20
+ with('/creativegroups/1/creatives/1/images/1/file', options)
21
+ client.upload_image(1, 1, 1, file)
52
22
  end
53
23
 
54
- context 'with Etag mismatch' do
55
- it 'retries post' do
56
- expect(client).to receive(:post).once.and_return(etag_mismatch)
57
- expect(image).to receive(:refresh_etag!).and_return(1)
58
- expect(client).to receive(:post).once.and_return(success)
59
- image.upload!(file)
60
- end
24
+ it 'gets etag' do
25
+ etag_response = double :response, headers: { 'Etag' => 1 }
26
+ expect(client).to receive(:get).with('/creativegroups/1/creatives/1/images/1').
27
+ and_return(etag_response)
28
+ client.send(:image_upload_opts, 1, 1, 1, file)
29
+ end
61
30
 
62
- it 'raises EtagMismatchError' do
63
- client.stub(:post) { etag_mismatch }
64
- client.stub(:get) { new_etag }
65
- expect {
66
- image.upload!(file)
67
- }.to raise_error AdLeads::Etag::MismatchError
31
+ context 'with EtagMismatchError' do
32
+ it 'retries upload a maximum of three times' do
33
+ client.stub(:image_upload_opts) { {} }
34
+ client.stub(:post) { raise AdLeads::EtagMismatchError.new 'Error' }
35
+ expect(client).to receive(:post).exactly(3).times
36
+ client.upload_image(1, 1, 1, file)
68
37
  end
69
38
  end
70
39
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
+ require 'pry'
2
3
 
3
4
  describe AdLeads::Client do
4
5
  let!(:client) { AdLeads::Client.new }
5
6
  let(:connection) { client.connection }
6
- let(:creative_group_id) { 12858 }
7
- let(:token) { '99d3492c-f82e-40c1-ac12-95a3c3326edc' }
7
+ let(:token) { '55bd8390-9cd9-4b69-9966-1a10a9bc5591' }
8
8
  let(:file) { './spec/fixtures/test.jpg' }
9
9
 
10
10
  before do
@@ -16,47 +16,80 @@ describe AdLeads::Client do
16
16
  describe 'Ad Campaign' do
17
17
  xit 'uploads logo image, creates campaign using logo image, verifies and launches ad campaign' do
18
18
 
19
- params = {
19
+ options = {
20
20
  'name' => 'Creative Group Name',
21
21
  'productName' => 'amazing product',
22
22
  'privacyPolicyUrl' => 'http://privacy_url'
23
23
  }
24
24
 
25
- creative_group = AdLeads::CreativeGroup.new
26
- creative_group.create!(params)
25
+ client.create_creative_group(options)
26
+ creative_id = client.last_response_id
27
27
 
28
- params = {
28
+ options = {
29
29
  'type' => 'Mobile',
30
30
  'name' => 'Ad name',
31
31
  'headerText' => 'get your ad on this phone today',
32
32
  'bodyText' => 'this is mobile ad body copy'
33
33
  }
34
34
 
35
- ad = AdLeads::Ad.new(creative_group.id)
36
- ad.create!(params)
35
+ client.create_ad(creative_id, options)
36
+ ad_id = client.last_response_id
37
37
 
38
- params = { 'type' => 'LogoImage' }
38
+ options = { 'type' => 'LogoImage' }
39
39
 
40
- image = AdLeads::Image.new( { creative_group_id: creative_group.id, ad_id: ad.id } )
41
- image.create!(params)
42
- image.upload!(file)
40
+ client.create_image(creative_id, ad_id, options)
41
+ image_id = client.last_response_id
42
+ client.upload_image(creative_id, ad_id, image_id, file)
43
43
 
44
- params = {
44
+ options = {
45
45
  'name' => 'Campaign name',
46
46
  'verticals' => 82,
47
47
  'offerIncentiveCategory' => 5,
48
48
  'collectedFields' => 'firstname,lastname,email,companyname',
49
49
  'budget' => 50,
50
- 'creativeGroups' => creative_group.id
50
+ 'creativeGroups' => creative_id
51
51
  }
52
52
 
53
- campaign = AdLeads::Campaign.new
54
- campaign.create!(params)
55
- campaign.verify!
56
- campaign.launch!
53
+ client.create_campaign(options)
54
+ campaign_id = client.last_response_id
57
55
 
58
- expect(campaign.response.status).to eq(200)
59
- expect(JSON.parse(campaign.response.body)['result']).to eq true
56
+ client.verify_campaign(campaign_id)
57
+ response = client.launch_campaign(campaign_id)
58
+
59
+ expect(response.status).to eq(200)
60
+ expect(JSON.parse(response.body)['result']).to eq true
61
+ end
62
+
63
+ xit 'creates complete campaign in one step, verifies and launches ad campaign' do
64
+ options = {
65
+ creative_group: {
66
+ 'name' => 'Creative Group Name',
67
+ 'productName' => 'amazing product',
68
+ 'privacyPolicyUrl' => 'http://privacy_url'
69
+ },
70
+ ad: {
71
+ 'type' => 'Mobile',
72
+ 'name' => 'Ad name',
73
+ 'headerText' => 'get your ad on this phone today',
74
+ 'bodyText' => 'this is mobile ad body copy'
75
+ },
76
+ image: { 'type' => 'LogoImage' },
77
+ file: file,
78
+ campaign: {
79
+ 'name' => 'Campaign name',
80
+ 'verticals' => 82,
81
+ 'offerIncentiveCategory' => 5,
82
+ 'collectedFields' => 'firstname,lastname,email,companyname',
83
+ 'budget' => 50
84
+ }}
85
+
86
+ client.create_complete_campaign(options)
87
+ campaign_id = client.last_response_id
88
+ client.verify_campaign(campaign_id)
89
+ client.launch_campaign(campaign_id)
90
+
91
+ expect(client.last_response.status).to eq(200)
92
+ expect(JSON.parse(client.last_response.body)['result']).to eq true
60
93
  end
61
94
  end
62
95
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  require 'ad_leads'
2
2
  require 'rspec'
3
3
 
4
-
4
+ RSpec.configure do |config|
5
+ config.before :each do
6
+ Logger.stub(:new) { double(:logger, error: nil) }
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ad_leads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6.1
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dinshaw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-09 00:00:00.000000000 Z
11
+ date: 2014-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -123,19 +123,16 @@ files:
123
123
  - ad_leads.gemspec
124
124
  - lib/ad_leads.rb
125
125
  - lib/ad_leads/ad.rb
126
- - lib/ad_leads/base.rb
127
126
  - lib/ad_leads/campaign.rb
128
127
  - lib/ad_leads/campaign_helpers.rb
129
128
  - lib/ad_leads/client.rb
130
129
  - lib/ad_leads/configuration.rb
131
130
  - lib/ad_leads/creative_group.rb
132
- - lib/ad_leads/etag.rb
133
131
  - lib/ad_leads/image.rb
134
132
  - lib/ad_leads/promotion.rb
135
133
  - lib/ad_leads/token.rb
136
134
  - lib/ad_leads/version.rb
137
135
  - spec/ad_leads/ad_spec.rb
138
- - spec/ad_leads/base_spec.rb
139
136
  - spec/ad_leads/campaign_spec.rb
140
137
  - spec/ad_leads/client_spec.rb
141
138
  - spec/ad_leads/configuration_spec.rb
@@ -173,7 +170,6 @@ specification_version: 4
173
170
  summary: Ruby Wrapper for AdLeads API
174
171
  test_files:
175
172
  - spec/ad_leads/ad_spec.rb
176
- - spec/ad_leads/base_spec.rb
177
173
  - spec/ad_leads/campaign_spec.rb
178
174
  - spec/ad_leads/client_spec.rb
179
175
  - spec/ad_leads/configuration_spec.rb
data/lib/ad_leads/base.rb DELETED
@@ -1,19 +0,0 @@
1
- class AdLeads::Base
2
- attr_accessor :response
3
-
4
- def create!(params)
5
- self.response = client.post(root_path, params)
6
- end
7
-
8
- def client
9
- @client ||= AdLeads::Client.new
10
- end
11
-
12
- def id
13
- @id ||= JSON.parse(response.body)['data'].first
14
- end
15
-
16
- def status
17
- response.status
18
- end
19
- end
data/lib/ad_leads/etag.rb DELETED
@@ -1,30 +0,0 @@
1
- module AdLeads::Etag
2
- def etag_path
3
- # must be implemented in including class
4
- end
5
-
6
- def refresh_etag!
7
- @etag = client.get(etag_path).headers['Etag']
8
- end
9
-
10
- def etag
11
- @etag ||= refresh_etag!
12
- end
13
-
14
- def with_etag(count = 1, &block)
15
- raise MismatchError if count > 3
16
-
17
- response = yield
18
- count += 1
19
-
20
- if response.status == 412
21
- self.refresh_etag!
22
- with_etag(count) do
23
- yield
24
- end
25
- end
26
-
27
- end
28
-
29
- class MismatchError < StandardError; end
30
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AdLeads::Base do
4
- let(:base) { AdLeads::Base.new() }
5
-
6
- describe '#id' do
7
- let(:response) { double(:response, body: '{ "data": [1] }') }
8
- before { base.response = response }
9
-
10
- it 'parses ID from JSON response body' do
11
- expect(base.id).to eq 1
12
- end
13
- end
14
-
15
- describe 'client' do
16
- it 'returns an instance of AdLeads::Client' do
17
- expect(base.client).to be_a AdLeads::Client
18
- end
19
- end
20
- end