adcloud 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/RELEASE_NOTES.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Release Notes
2
2
  =============
3
3
 
4
+ ### 0.7.2
5
+
6
+ * Add campaign and advertisement attributes
7
+ * Allow campaign state changes
8
+ * Allow advertisement deletion (including media files)
9
+
4
10
  ### 0.7.1
5
11
 
6
12
  * Remove Gemfile.lock from gem
@@ -2,6 +2,7 @@ module Adcloud
2
2
  class Advertisement < Adcloud::Entity
3
3
  attribute :id, Integer
4
4
  attribute :product_id, Integer
5
+ attribute :campaign_id, Integer
5
6
  attribute :type, String
6
7
  attribute :advertisement_design_id, Integer
7
8
  attribute :target_url, String
@@ -37,18 +37,21 @@ module Adcloud
37
37
  attribute :keyword_lifetime, Integer
38
38
  attribute :comment, String
39
39
  attribute :budget_limit, Float
40
+ attribute :budget_limit_today, Float
40
41
  attribute :budget_limit_allowed, Boolean
41
42
  attribute :unit_price_maximum, Float
42
43
  attribute :locations, Array
43
44
  attribute :type, Integer
45
+ attribute :topic_ids, Array
44
46
  attribute :delivery_external, Boolean
45
47
  attribute :delivery_internal, Boolean
46
48
  attribute :delivery_type, Integer
47
49
  attribute :deactivated_on, DateTime
50
+ attribute :options, Hash
51
+ attribute :has_end_date, Boolean
48
52
  attribute :modified, DateTime
49
53
  attribute :created, DateTime
50
54
  # attribute :fixed_price, # missing
51
- # attribute :mobile_targeting, # missing
52
55
 
53
56
  # @return [void] Validate the campaign against the api
54
57
  def validate
@@ -60,6 +63,16 @@ module Adcloud
60
63
  end
61
64
  end
62
65
 
66
+ def request_approval!
67
+ result = connection.put("campaigns/#{self.id}/request_approval")
68
+ result && result["_meta"] && result["_meta"]["status"] == 200 || false
69
+ end
70
+
71
+ def end!
72
+ result = connection.put("campaigns/#{self.id}/end")
73
+ result && result["_meta"] && result["_meta"]["status"] == 200 || false
74
+ end
75
+
63
76
  # @return [Boolean] True when campaign is valid - otherwise false
64
77
  def valid?
65
78
  self.validate
@@ -0,0 +1,25 @@
1
+ class CampaignState
2
+ STATES = {
3
+ :inactive => 0,
4
+ :online => 1,
5
+ :offer => 2,
6
+ :rejected => 3,
7
+ :accepted => 4,
8
+ :awaiting_approval => 5,
9
+ :paused => 6,
10
+ :ended => 7,
11
+ :billed => 9,
12
+ :paid => 10,
13
+ :approved => 11,
14
+ :canceled => 12,
15
+ :approval_rejected => 13,
16
+ }
17
+
18
+ def id_to_string(id)
19
+ STATES.find { |_, value| value.to_s == id.to_s }
20
+ end
21
+
22
+ def string_to_id(string)
23
+ STATES[string.to_sym]
24
+ end
25
+ end
@@ -42,5 +42,15 @@ module Adcloud
42
42
  response.body
43
43
  end
44
44
 
45
+ def put(path, params = {})
46
+ response = connection.put path, params
47
+ response.body
48
+ end
49
+
50
+ def delete(path, params = {})
51
+ response = connection.delete path, params
52
+ response.body
53
+ end
54
+
45
55
  end
46
56
  end
@@ -3,6 +3,8 @@ module Adcloud
3
3
  class Entity
4
4
  include Virtus
5
5
 
6
+ MAX_PER_PAGE = 200
7
+
6
8
  attr_accessor :errors
7
9
 
8
10
  attribute :_meta, Hash
@@ -27,6 +29,11 @@ module Adcloud
27
29
  false
28
30
  end
29
31
 
32
+ def destroy
33
+ result = connection.delete("#{self.class.api_endpoint}/#{id}")
34
+ self
35
+ end
36
+
30
37
  class << self
31
38
  attr_accessor :api_endpoint, :connection
32
39
 
@@ -45,9 +52,22 @@ module Adcloud
45
52
  # @return [Array] Entities matching the criteria or all
46
53
  def all(filter = {}, page = 1, per_page = 50)
47
54
  result = connection.get(self.api_endpoint, :filter => filter, :page => page, :per_page => per_page)
55
+ yield result['_meta'] if block_given?
48
56
  result["items"].map { |raw_campaign| self.new(raw_campaign) }
49
57
  end
50
58
 
59
+ # fetches all objects via pagination. Be careful, this could be a lot!
60
+ def all!(filter = {})
61
+ result = []
62
+ page = 0
63
+ total_pages = 1
64
+ begin
65
+ page += 1
66
+ result += self.all(filter, page, MAX_PER_PAGE) { |meta_data| total_pages = meta_data['total_pages'] }
67
+ end while page < total_pages
68
+ result
69
+ end
70
+
51
71
  # @return [Object] The entity with the unique identifier
52
72
  def find(id)
53
73
  result = connection.get("#{self.api_endpoint}/#{id}")
@@ -1,3 +1,3 @@
1
1
  module Adcloud
2
- VERSION = '0.7.1'
2
+ VERSION = '0.7.2'
3
3
  end
@@ -51,4 +51,36 @@ describe Adcloud::Campaign do
51
51
  end
52
52
  end
53
53
 
54
+ describe '#request_approval!' do
55
+ before { campaign.id = 123 }
56
+
57
+ it 'is true when the state has changed' do
58
+ response_data = {'_meta' => { 'status' => 200, 'message' => 'status changed' } }
59
+ connection.expects(:put).with('campaigns/123/request_approval').returns(response_data)
60
+ campaign.request_approval!.must_equal true
61
+ end
62
+
63
+ it 'is false when the state could not be changed' do
64
+ response_data = {'_meta' => { 'status' => 400, 'message' => 'bad request' } }
65
+ connection.expects(:put).with('campaigns/123/request_approval').returns(response_data)
66
+ campaign.request_approval!.must_equal false
67
+ end
68
+ end
69
+
70
+ describe '#end!' do
71
+ before { campaign.id = 123 }
72
+
73
+ it 'is true when the state has changed' do
74
+ response_data = {'_meta' => { 'status' => 200, 'message' => 'status changed' } }
75
+ connection.expects(:put).with('campaigns/123/end').returns(response_data)
76
+ campaign.end!.must_equal true
77
+ end
78
+
79
+ it 'is false when the state could not be changed' do
80
+ response_data = {'_meta' => { 'status' => 400, 'message' => 'bad request' } }
81
+ connection.expects(:put).with('campaigns/123/end').returns(response_data)
82
+ campaign.end!.must_equal false
83
+ end
84
+ end
85
+
54
86
  end
@@ -7,20 +7,16 @@ describe Adcloud::Connection do
7
7
  let(:authentication) { stub(:authenticate! => true, :token => "0987654321") }
8
8
 
9
9
  describe "url" do
10
-
11
10
  it "should be https://api.adcloud.com:443/" do
12
11
  subject.url.must_equal "https://api.adcloud.com:443/v2/"
13
12
  end
14
-
15
13
  end
16
14
 
17
15
  describe "authentication token" do
18
-
19
16
  it "should be 0987654321" do
20
17
  subject.expects(:authentication).returns(authentication)
21
18
  subject.authentication_token.must_equal "0987654321"
22
19
  end
23
-
24
20
  end
25
21
 
26
22
  describe "authentication" do
@@ -36,43 +32,33 @@ describe Adcloud::Connection do
36
32
  before do
37
33
  subject.stubs(:authentication_token).returns("0987654321")
38
34
  end
39
-
40
- describe "post" do
41
35
 
36
+ describe "post" do
42
37
  it "should fire a post request" do
43
38
  stub_request(:post, url).to_return(:status => 200, :body => {"_meta" => {}, "hello" => "world"}, :headers => {})
44
39
  subject.post('whatever').must_equal({"_meta" => {}, "hello" => "world" })
45
40
  end
41
+ end
46
42
 
47
- # it "should raise an InvalidRequest Exception" do
48
- # stub_request(:post, url).to_return(:status => 500, :body => "{}", :headers => {})
49
- # -> { subject.post('whatever') }.must_raise(Adcloud::InvalidRequest)
50
- # end
43
+ describe "put" do
44
+ it "should fire a put request" do
45
+ stub_request(:put, url).to_return(:status => 200, :body => { "_meta" => {}, "hello" => "world" }, :headers => {})
46
+ subject.put('whatever').must_equal({ "_meta" => {}, "hello" => "world" })
47
+ end
48
+ end
51
49
 
50
+ describe "delete" do
51
+ it "should fire a delete request" do
52
+ stub_request(:delete, url).to_return(:status => 200, :body => { "_meta" => {}, "hello" => "world" }, :headers => {})
53
+ subject.delete('whatever').must_equal({ "_meta" => {}, "hello" => "world" })
54
+ end
52
55
  end
53
56
 
54
57
  describe "get" do
55
-
56
58
  it "should fire a get request" do
57
59
  stub_request(:get, url).to_return(:status => 200, :body => {"_meta" => {}, "hello" => "world"}, :headers => {})
58
60
  subject.get('whatever').must_equal({"_meta" => {}, "hello" => "world" })
59
61
  end
60
-
61
- # it "should raise an InvalidFilter Exception" do
62
- # stub_request(:get, url).to_return(:status => 400, :body => "{}", :headers => {})
63
- # -> { subject.get('whatever') }.must_raise(Adcloud::InvalidFilter)
64
- # end
65
-
66
- # it "should raise a NotFound Exception" do
67
- # stub_request(:get, url).to_return(:status => 404, :body => "{}", :headers => {})
68
- # -> { subject.get('whatever') }.must_raise(Adcloud::NotFound)
69
- # end
70
-
71
- # it "should raise an InvalidRequest Exception" do
72
- # stub_request(:get, url).to_return(:status => 500, :body => "{}", :headers => {})
73
- # -> { subject.get('whatever') }.must_raise(Adcloud::InvalidRequest)
74
- # end
75
-
76
62
  end
77
63
  end
78
64
  end
@@ -73,6 +73,20 @@ describe Adcloud::Entity do
73
73
  end
74
74
  end
75
75
 
76
+ describe '.all!' do
77
+ let(:items) { (1..200).to_a.map{ |i| { "id" => i, "name" => "Test Car #{i}", "_meta" => { "type" => "Car" } } } }
78
+ let(:first_page) { { "_meta" => { "type" => "Array<Car>", "page" => 1, "size" => 200, "per_page" => 200, "total_count" => 201, "total_pages" => 2, "sort" => {}, "uuid" => "aabe4f5f31691f049ea1942e6a6d1793" }, "items" => items} }
79
+ let(:second_page) { { "_meta" => { "type" => "Array<Car>", "page" => 2, "size" => 1, "per_page" => 200, "total_count" => 201, "total_pages" => 2, "sort" => {}, "uuid" => "aabe4f5f31691f049ea1942e6a6d1794" }, "items" => [{ "id" => 201, "name" => "Test Car 201", "_meta" => { "type" => "Car" } }]} }
80
+
81
+ before { subject.stubs(:connection => connection) }
82
+
83
+ it 'fetches all entity objects' do
84
+ connection.expects(:get).with('cars', :filter => {}, :page => 1, :per_page => 200).returns(first_page)
85
+ connection.expects(:get).with('cars', :filter => {}, :page => 2, :per_page => 200).returns(second_page)
86
+ subject.all!.size.must_equal 201
87
+ end
88
+ end
89
+
76
90
  describe '#create' do
77
91
  before { subject.stubs(:connection => connection) }
78
92
 
@@ -129,6 +143,14 @@ describe Adcloud::Entity do
129
143
  end
130
144
  end
131
145
 
146
+ describe '.delete' do
147
+ it 'deletes an existing car' do
148
+ car = subject.new(:id => 42)
149
+ car.connection.expects(:delete).returns('response')
150
+ car.destroy.must_equal car
151
+ end
152
+ end
153
+
132
154
  describe "errors" do
133
155
  it "should be empty" do
134
156
  subject.new.errors.must_be_empty
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.1
4
+ version: 0.7.2
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-09-14 00:00:00.000000000 Z
13
+ date: 2012-10-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest
@@ -179,6 +179,7 @@ files:
179
179
  - lib/adcloud/api_error.rb
180
180
  - lib/adcloud/authentication.rb
181
181
  - lib/adcloud/campaign.rb
182
+ - lib/adcloud/campaign_state.rb
182
183
  - lib/adcloud/connection.rb
183
184
  - lib/adcloud/customer.rb
184
185
  - lib/adcloud/entity.rb