adcloud 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -12,10 +12,13 @@ doc
12
12
  # bundler
13
13
  .bundle
14
14
 
15
+ # not wanted in gems
16
+ Gemfile.lock
17
+
15
18
  # jeweler generated
16
19
  pkg
17
20
 
18
- # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
21
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
22
  #
20
23
  # * Create a file at ~/.gitignore
21
24
  # * Include files you want ignored
data/RELEASE_NOTES.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Release Notes
2
2
  =============
3
3
 
4
+ ### 0.7.3
5
+
6
+ * Allow campaig and advertisement updates
7
+ * Make performance data available
8
+ * Incorporate webhooks api changes
9
+
4
10
  ### 0.7.2
5
11
 
6
12
  * Add campaign and advertisement attributes
@@ -0,0 +1,14 @@
1
+ module Adcloud
2
+ class CampaignPerformanceData < Adcloud::Entity
3
+ include Virtus
4
+
5
+ attribute :_meta, Hash
6
+ attribute :items, Array[Adcloud::CampaignPerformanceDataEntry]
7
+
8
+ def self.find_by_campaign_ids(campaign_ids)
9
+ result = connection.get(self.api_endpoint, { :campaign_ids => campaign_ids.join(',') })
10
+ self.new(result)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module Adcloud
2
+ class CampaignPerformanceDataEntry
3
+ include Virtus
4
+
5
+ attribute :budget_delivered, Float
6
+ attribute :budget_delivered_today, Float
7
+ attribute :budget_limit_today, Float
8
+ attribute :campaign_id, Integer
9
+ attribute :clicks_delivered, Integer
10
+ attribute :clicks_delivered_today, Integer
11
+ attribute :impressions_delivered, Integer
12
+ attribute :impressions_delivered_today, Integer
13
+ attribute :leads_delivered, Integer
14
+ attribute :leads_delivered_today, Integer
15
+ attribute :performance, Float
16
+
17
+ end
18
+ end
@@ -29,6 +29,14 @@ module Adcloud
29
29
  false
30
30
  end
31
31
 
32
+ def update
33
+ result = connection.put("#{self.class.api_endpoint}/#{id}", { self.class.api_name => attributes_for_update })
34
+ true
35
+ rescue Adcloud::BadRequestError => ex
36
+ derive_errors_from_error(ex)
37
+ false
38
+ end
39
+
32
40
  def destroy
33
41
  result = connection.delete("#{self.class.api_endpoint}/#{id}")
34
42
  self
@@ -99,6 +107,10 @@ module Adcloud
99
107
  self.attributes.reject { |i| [:id, :_meta].include?(i) }
100
108
  end
101
109
 
110
+ def attributes_for_update
111
+ self.attributes.reject { |i| [:_meta].include?(i) }
112
+ end
113
+
102
114
  end
103
115
 
104
116
  end
@@ -1,3 +1,3 @@
1
1
  module Adcloud
2
- VERSION = '0.7.2'
2
+ VERSION = '0.7.3'
3
3
  end
@@ -21,7 +21,7 @@ module Adcloud
21
21
  def process!
22
22
  self.events.each do |event|
23
23
  proc = case event.type
24
- when 'TopicPrice.update'
24
+ when 'TopicDiscount.update'
25
25
  :on_topic_price_update
26
26
  when 'Booking.update'
27
27
  :on_campaign_update
data/lib/adcloud.rb CHANGED
@@ -15,6 +15,8 @@ module Adcloud
15
15
  autoload :ApiError, "adcloud/api_error"
16
16
  autoload :Authentication, "adcloud/authentication"
17
17
  autoload :Campaign, "adcloud/campaign"
18
+ autoload :CampaignPerformanceData, "adcloud/campaign_performance_data"
19
+ autoload :CampaignPerformanceDataEntry, "adcloud/campaign_performance_data_entry"
18
20
  autoload :Connection, "adcloud/connection"
19
21
  autoload :Customer, "adcloud/customer"
20
22
  autoload :Entity, "adcloud/entity"
@@ -0,0 +1,34 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ describe Adcloud::CampaignPerformanceData do
5
+ subject { Adcloud::CampaignPerformanceData }
6
+
7
+ let(:connection) { stub }
8
+
9
+ describe ".find_by_campaign_ids" do
10
+ let(:response_data) { { "_meta" => {"page" => 1, "per_page" => 2, "size" => 2, "sort" => {}, "total_count" => 2, "total_pages" => 1, "type" => "Array<CampaignPerformanceData>", "uuid" => "542fe08151374ceaf8e97dfbc22d480d"}, "items" => [{"budget_delivered" => 0.0, "budget_delivered_today" => 0.0, "budget_limit_today" => 100.0, "campaign_id" => 101, "clicks_delivered" => 0, "clicks_delivered_today" => 0, "impressions_delivered" => 0, "impressions_delivered_today" => 0, "leads_delivered" => 0, "leads_delivered_today" => 0, "performance" => 0.0 }, {"budget_delivered" => 0.0, "budget_delivered_today" => 0.0, "budget_limit_today" => 100.0, "campaign_id" => 102, "clicks_delivered" => 0, "clicks_delivered_today" => 0, "impressions_delivered" => 0, "impressions_delivered_today" => 0, "leads_delivered" => 0, "leads_delivered_today" => 0, "performance" => 0.0 } ] } }
11
+
12
+ before do
13
+ subject.stubs(:connection => connection)
14
+ connection.stubs(:get).returns(response_data)
15
+ end
16
+
17
+ it 'access the api at the correct path' do
18
+ subject.connection.expects(:get).with('campaign_performance_data', { campaign_ids: '101,102' })
19
+ subject.find_by_campaign_ids([101, 102])
20
+ end
21
+
22
+ it 'returns a campaign performance data set' do
23
+ subject.find_by_campaign_ids([101, 102]).must_be_instance_of(Adcloud::CampaignPerformanceData)
24
+ end
25
+
26
+ it 'creates report entries for all items' do
27
+ subject.find_by_campaign_ids([101, 102]).items.first.must_be_instance_of(Adcloud::CampaignPerformanceDataEntry)
28
+ end
29
+
30
+ it 'parses the entry data correctly' do
31
+ subject.find_by_campaign_ids([101, 102]).items.first[:budget_limit_today].must_equal 100.0
32
+ end
33
+ end
34
+ end
@@ -134,6 +134,27 @@ describe Adcloud::Entity do
134
134
  end
135
135
  end
136
136
 
137
+ describe '#update' do
138
+ before { subject.stubs(:connection => connection) }
139
+
140
+ describe 'when submitting a valid object' do
141
+ let(:response) { { '_meta' => { 'status' => 200 }, 'id' => 1 } }
142
+
143
+ it 'sends a request to the api' do
144
+ car = subject.new(:id => 1, :name => 'Audi')
145
+ attributes = car.attributes
146
+ attributes.delete(:_meta)
147
+ connection.expects(:put).with('cars/1', { 'car' => attributes }).returns(response)
148
+ car.update
149
+ end
150
+
151
+ it 'returns true' do
152
+ connection.stubs(:put).returns(response)
153
+ subject.new.update.must_equal true
154
+ end
155
+ end
156
+ end
157
+
137
158
  describe '.create' do
138
159
  it 'creates a new car' do
139
160
  car = subject.new
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe Adcloud::Webhook do
4
- let(:event_payload) { '{"id":"2","country_id":"1","guidance_price_cpc":"1.49","guidance_price_cpm":"0.6","variance":"20.00","modified":"2012-09-04 14:21:20","created":"2012-04-10 20:40:24","_meta":{"is_test_data":true,"model":"TopicPrice","event":"TopicPrice.update","updated_fields":["guidance_price_cpc","guidance_price_cpm"],"id":"2"}}' }
4
+ let(:event_payload) { '{"id":"2","country_id":"1","guidance_price_cpc":"1.49","guidance_price_cpm":"0.6","variance":"20.00","modified":"2012-09-04 14:21:20","created":"2012-04-10 20:40:24","_meta":{"is_test_data":true,"model":"TopicPrice","event":"TopicDiscount.update","updated_fields":["guidance_price_cpc","guidance_price_cpm"],"id":"2"}}' }
5
5
  let(:payload) { "[#{event_payload}]" }
6
6
 
7
7
  subject { Adcloud::Webhook.new(payload) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-08 00:00:00.000000000 Z
13
+ date: 2012-10-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest
@@ -179,6 +179,8 @@ files:
179
179
  - lib/adcloud/api_error.rb
180
180
  - lib/adcloud/authentication.rb
181
181
  - lib/adcloud/campaign.rb
182
+ - lib/adcloud/campaign_performance_data.rb
183
+ - lib/adcloud/campaign_performance_data_entry.rb
182
184
  - lib/adcloud/campaign_state.rb
183
185
  - lib/adcloud/connection.rb
184
186
  - lib/adcloud/customer.rb
@@ -197,6 +199,7 @@ files:
197
199
  - lib/adcloud/webhook_event.rb
198
200
  - test/adcloud/advertisement_test.rb
199
201
  - test/adcloud/authentication_test.rb
202
+ - test/adcloud/campaign_performance_data_test.rb
200
203
  - test/adcloud/campaign_test.rb
201
204
  - test/adcloud/connection_test.rb
202
205
  - test/adcloud/customer_test.rb
@@ -236,6 +239,7 @@ summary: Wrapper for adcloud API
236
239
  test_files:
237
240
  - test/adcloud/advertisement_test.rb
238
241
  - test/adcloud/authentication_test.rb
242
+ - test/adcloud/campaign_performance_data_test.rb
239
243
  - test/adcloud/campaign_test.rb
240
244
  - test/adcloud/connection_test.rb
241
245
  - test/adcloud/customer_test.rb