sklik-api 0.0.16 → 0.1.0
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/Rakefile +28 -4
- data/VERSION +1 -1
- data/lib/sklik-api/campaign.rb +112 -67
- data/lib/sklik-api/campaign_parts/adgroup.rb +272 -95
- data/lib/sklik-api/campaign_parts/adtext.rb +165 -31
- data/lib/sklik-api/campaign_parts/keyword.rb +192 -38
- data/lib/sklik-api/client.rb +4 -4
- data/lib/sklik-api/connection.rb +36 -13
- data/lib/sklik-api/exceptions.rb +6 -0
- data/lib/sklik-api/sklik_object.rb +29 -1
- data/lib/sklik-api.rb +20 -3
- data/sklik-api.gemspec +11 -3
- data/test/integration/adgroup_test.rb +126 -0
- data/test/integration/adtext_test.rb +106 -0
- data/test/integration/campaign_test.rb +87 -0
- data/test/integration/errors_test.rb +164 -0
- data/test/integration/keyword_test.rb +131 -0
- data/test/unit/adgroup_test.rb +147 -0
- data/test/unit/campaign_test.rb +318 -0
- data/test/unit/client_test.rb +27 -0
- metadata +12 -4
- data/test/unit/campaign.rb +0 -180
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
class SklikApi
|
3
|
-
module
|
3
|
+
module SklikObject
|
4
4
|
def self.included(base)
|
5
5
|
base.send :extend, ClassMethods
|
6
6
|
base.send :include, InstanceMethods
|
@@ -12,6 +12,16 @@ class SklikApi
|
|
12
12
|
SklikApi::Connection.connection
|
13
13
|
end
|
14
14
|
|
15
|
+
def get name, id
|
16
|
+
args = ["#{name}.getAttributes", id]
|
17
|
+
return connection.call(*args) { |param|
|
18
|
+
param[name.to_sym].symbolize_keys
|
19
|
+
}
|
20
|
+
rescue SklikApi::NotFound => e
|
21
|
+
puts "#{e.class} - #{e.message}"
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
|
15
25
|
def find name, id = nil
|
16
26
|
if id
|
17
27
|
args = ["list#{name.pluralize.camelize}", id]
|
@@ -77,6 +87,16 @@ class SklikApi
|
|
77
87
|
}
|
78
88
|
end
|
79
89
|
|
90
|
+
def status_for_update
|
91
|
+
if @args[:status] == :running
|
92
|
+
return "active"
|
93
|
+
elsif @args[:status] == :paused
|
94
|
+
return "suspend"
|
95
|
+
else
|
96
|
+
return nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
80
100
|
def update_object
|
81
101
|
out = connection.call("#{self.class::NAME}.setAttributes", *update_args ) { |param| true }
|
82
102
|
end
|
@@ -96,6 +116,14 @@ class SklikApi
|
|
96
116
|
def underscore_hash_keys hash
|
97
117
|
hash.inject({ }) { |x, (k,v)| x[k.underscore.to_sym] = v; x }
|
98
118
|
end
|
119
|
+
|
120
|
+
def clear_errors
|
121
|
+
@errors = []
|
122
|
+
end
|
123
|
+
|
124
|
+
def errors
|
125
|
+
@errors ||= []
|
126
|
+
end
|
99
127
|
end
|
100
128
|
end
|
101
129
|
end
|
data/lib/sklik-api.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'rubygems'
|
3
3
|
require 'rack'
|
4
|
-
require 'pp'
|
5
4
|
require 'json'
|
6
5
|
require 'unicode'
|
7
6
|
require 'uri'
|
@@ -25,11 +24,29 @@ ENV['RACK_ENV'] ||= "development"
|
|
25
24
|
|
26
25
|
#initialzie SklikApi class
|
27
26
|
class SklikApi
|
28
|
-
|
27
|
+
|
28
|
+
def self.use_rollback= how
|
29
|
+
@use_rollback = how
|
30
|
+
end
|
31
|
+
|
32
|
+
#default setting for rollback is true!
|
33
|
+
def self.use_rollback?
|
34
|
+
@use_rollback.nil? || @use_rollback
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.logger
|
38
|
+
@logger ||= Logger.new(STDOUT)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.log type, message
|
42
|
+
logger.send(type, "SklikApi: #{message}")
|
43
|
+
rescue Exception => e
|
44
|
+
puts "SklikApi.logger Exception: #{e.message}"
|
45
|
+
end
|
29
46
|
end
|
30
47
|
|
31
48
|
#including sklik-api
|
32
|
-
["xmlrpc_setup", "access", "connection", "sklik_object", "client", "campaign"].each do |file|
|
49
|
+
["exceptions", "xmlrpc_setup", "access", "connection", "sklik_object", "client", "campaign"].each do |file|
|
33
50
|
require File.join(File.dirname(__FILE__),"/sklik-api/#{file}.rb")
|
34
51
|
end
|
35
52
|
|
data/sklik-api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "sklik-api"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ondrej Bartas"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-06-21"
|
13
13
|
s.description = "Sklik advertising PPC api for creating campaigns and updating them when they runs"
|
14
14
|
s.email = "ondrej@bartas.cz"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,12 +32,20 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/sklik-api/campaign_parts/keyword.rb",
|
33
33
|
"lib/sklik-api/client.rb",
|
34
34
|
"lib/sklik-api/connection.rb",
|
35
|
+
"lib/sklik-api/exceptions.rb",
|
35
36
|
"lib/sklik-api/sklik_object.rb",
|
36
37
|
"lib/sklik-api/xmlrpc_setup.rb",
|
37
38
|
"sklik-api.gemspec",
|
38
39
|
"test/fake_web.rb",
|
39
40
|
"test/helper.rb",
|
40
|
-
"test/
|
41
|
+
"test/integration/adgroup_test.rb",
|
42
|
+
"test/integration/adtext_test.rb",
|
43
|
+
"test/integration/campaign_test.rb",
|
44
|
+
"test/integration/errors_test.rb",
|
45
|
+
"test/integration/keyword_test.rb",
|
46
|
+
"test/unit/adgroup_test.rb",
|
47
|
+
"test/unit/campaign_test.rb",
|
48
|
+
"test/unit/client_test.rb"
|
41
49
|
]
|
42
50
|
s.homepage = "http://github.com/ondrejbartas/sklik-api"
|
43
51
|
s.licenses = ["MIT"]
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
class AdgroupIntegrationTest < Test::Unit::TestCase
|
4
|
+
context "Integration:Adgroup" do
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@campaign_hash = {
|
8
|
+
:name => "integration adgroup - #{Time.now.strftime("%Y.%m.%d %H:%M:%S.%L")}",
|
9
|
+
:status => :running,
|
10
|
+
:budget => 15.0,
|
11
|
+
:customer_id => 192495,
|
12
|
+
:excluded_search_services => [2,3,4,5,6,7,8], #choose only seznam.cz
|
13
|
+
:network_setting => {
|
14
|
+
:content => true,
|
15
|
+
:search => true
|
16
|
+
},
|
17
|
+
:ad_groups => []
|
18
|
+
}
|
19
|
+
@campaign = SklikApi::Campaign.new(@campaign_hash)
|
20
|
+
unless @campaign.save
|
21
|
+
raise "Unable to continue - Campaign: #{@campaign.errors}"
|
22
|
+
end
|
23
|
+
|
24
|
+
@adgroup_hash = {
|
25
|
+
:name => "my adgroup name - #{Time.now.strftime("%Y.%m.%d %H:%M:%S.%L")}",
|
26
|
+
:cpc => 6.0,
|
27
|
+
:campaign_id => @campaign.args[:campaign_id],
|
28
|
+
:keywords => [],
|
29
|
+
:ads => [],
|
30
|
+
:status => :running,
|
31
|
+
}
|
32
|
+
|
33
|
+
@adgroup = SklikApi::Adgroup.new(@adgroup_hash)
|
34
|
+
unless @adgroup.save
|
35
|
+
raise "Unable to continue - Adgroup: #{@adgroup.errors}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def teardown
|
40
|
+
@campaign.remove if SklikApi::Campaign.get(@campaign.args[:campaign_id]).args[:status] != :stopped
|
41
|
+
end
|
42
|
+
|
43
|
+
should "create paused adgroup" do
|
44
|
+
@adgroup_hash[:name] += "Paused"
|
45
|
+
@adgroup_hash[:status] = :paused
|
46
|
+
adgroup = SklikApi::Adgroup.new(@adgroup_hash)
|
47
|
+
assert adgroup.save, "Problem with creating adgroup: #{adgroup.errors}"
|
48
|
+
|
49
|
+
assert_equal SklikApi::Adgroup.get(adgroup.args[:adgroup_id]).args[:status], :paused
|
50
|
+
end
|
51
|
+
|
52
|
+
should "create stopped adgroup" do
|
53
|
+
@adgroup_hash[:name] += "Stopped"
|
54
|
+
@adgroup_hash[:status] = :stopped
|
55
|
+
adgroup = SklikApi::Adgroup.new(@adgroup_hash)
|
56
|
+
assert adgroup.save, "Problem with creating adgroup: #{@adgroup.errors}"
|
57
|
+
|
58
|
+
assert_equal SklikApi::Adgroup.get(adgroup.args[:adgroup_id]).args[:status], :stopped
|
59
|
+
end
|
60
|
+
|
61
|
+
should "find" do
|
62
|
+
assert_equal SklikApi::Adgroup.find(@adgroup.args[:adgroup_id]).to_hash.to_a.sort, @adgroup_hash.to_a.sort
|
63
|
+
assert_equal SklikApi::Adgroup.find(adgroup_id: @adgroup.args[:adgroup_id]).first.to_hash.to_a.sort, @adgroup_hash.to_a.sort
|
64
|
+
end
|
65
|
+
|
66
|
+
should "get" do
|
67
|
+
assert_equal SklikApi::Adgroup.get(@adgroup.args[:adgroup_id]).to_hash.to_a.sort, @adgroup_hash.to_a.sort
|
68
|
+
end
|
69
|
+
|
70
|
+
should "update" do
|
71
|
+
adgroup = SklikApi::Adgroup.get(@adgroup.args[:adgroup_id])
|
72
|
+
|
73
|
+
new_attributes = {
|
74
|
+
name: adgroup.args[:name] + " T1",
|
75
|
+
status: :stopped,
|
76
|
+
cpc: 5.0,
|
77
|
+
}
|
78
|
+
adgroup.update new_attributes
|
79
|
+
|
80
|
+
adgroup = SklikApi::Adgroup.get(@adgroup.args[:adgroup_id])
|
81
|
+
assert_equal adgroup.to_hash.to_a.sort, @adgroup_hash.merge(new_attributes).to_a.sort, "First update"
|
82
|
+
|
83
|
+
new_attributes = {
|
84
|
+
name: adgroup.args[:name] + " T2",
|
85
|
+
status: :paused,
|
86
|
+
cpc: 8.0,
|
87
|
+
}
|
88
|
+
adgroup.update new_attributes
|
89
|
+
adgroup = SklikApi::Adgroup.get(@adgroup.args[:adgroup_id])
|
90
|
+
assert_equal adgroup.to_hash.to_a.sort, @adgroup_hash.merge(new_attributes).to_a.sort, "Second update"
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
should "create adgroup with specified KW" do
|
95
|
+
adgroup_hash = {
|
96
|
+
:name => "my adgroup name - #{Time.now.strftime("%Y.%m.%d %H:%M:%S.%L")} - Testing KW",
|
97
|
+
:cpc => 6.0,
|
98
|
+
:campaign_id => @campaign.args[:campaign_id],
|
99
|
+
:keywords => [
|
100
|
+
{ :keyword => "[super kw]", :url => 'http://super.bartas.cz/', :cpc => 3.0},
|
101
|
+
{ :keyword => "\"other kw\"", :url => 'http://mega.bartas.cz/', :cpc => 9.1}
|
102
|
+
],
|
103
|
+
:ads => [],
|
104
|
+
:status => :running,
|
105
|
+
}
|
106
|
+
|
107
|
+
adgroup = SklikApi::Adgroup.new(adgroup_hash)
|
108
|
+
assert adgroup.save, "Should be saved but got: #{adgroup.errors}"
|
109
|
+
|
110
|
+
|
111
|
+
adgroup = SklikApi::Adgroup.get(adgroup.args[:adgroup_id])
|
112
|
+
returned_hash = adgroup.to_hash
|
113
|
+
|
114
|
+
returned_hash[:keywords].each do |kw|
|
115
|
+
kw.delete(:keyword_id)
|
116
|
+
kw.delete(:adgroup_id)
|
117
|
+
kw.delete(:status)
|
118
|
+
end
|
119
|
+
|
120
|
+
returned_hash[:keywords] = returned_hash[:keywords].to_a.collect{|h|h.to_a.sort}.sort
|
121
|
+
adgroup_hash[:keywords] = adgroup_hash[:keywords].to_a.collect{|h|h.to_a.sort}.sort
|
122
|
+
assert_equal returned_hash.to_a.sort, adgroup_hash.to_a.sort
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
class AdtextIntegrationTest < Test::Unit::TestCase
|
4
|
+
context "Integration:Adtext" do
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@campaign_hash = {
|
8
|
+
:name => "integration adtext - #{Time.now.strftime("%Y.%m.%d %H:%M:%S.%L")}",
|
9
|
+
:status => :running,
|
10
|
+
:budget => 15.0,
|
11
|
+
:customer_id => 192495,
|
12
|
+
:excluded_search_services => [2,3,4,5,6,7,8], #choose only seznam.cz
|
13
|
+
:network_setting => {
|
14
|
+
:content => true,
|
15
|
+
:search => true
|
16
|
+
},
|
17
|
+
:ad_groups => []
|
18
|
+
}
|
19
|
+
@campaign = SklikApi::Campaign.new(@campaign_hash)
|
20
|
+
unless @campaign.save
|
21
|
+
raise "Unable to continue - Campaign: #{@campaign.errors}"
|
22
|
+
end
|
23
|
+
|
24
|
+
@adgroup_hash = {
|
25
|
+
:name => "my adgroup name - #{Time.now.strftime("%Y.%m.%d %H:%M:%S.%L")}",
|
26
|
+
:cpc => 6.0,
|
27
|
+
:campaign_id => @campaign.args[:campaign_id],
|
28
|
+
:keywords => [],
|
29
|
+
:ads => [],
|
30
|
+
:status => :running,
|
31
|
+
}
|
32
|
+
|
33
|
+
@adgroup = SklikApi::Adgroup.new(@adgroup_hash)
|
34
|
+
unless @adgroup.save
|
35
|
+
raise "Unable to continue - Adgroup: #{@adgroup.errors}"
|
36
|
+
end
|
37
|
+
|
38
|
+
@adtext_hash = {
|
39
|
+
:adgroup_id => @adgroup.args[:adgroup_id],
|
40
|
+
:headline => "Super headline",
|
41
|
+
:description1 => "Trying to do ",
|
42
|
+
:description2 => "best description ever",
|
43
|
+
:display_url => "bartas.cz",
|
44
|
+
:url => "http://www.bartas.cz/",
|
45
|
+
:status => :running,
|
46
|
+
}
|
47
|
+
@adtext = SklikApi::Adtext.new(@adtext_hash)
|
48
|
+
unless @adtext.save
|
49
|
+
raise "Unable to continue - Adtext: #{@adtext.errors}"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def teardown
|
55
|
+
@campaign.remove if SklikApi::Campaign.get(@campaign.args[:campaign_id]).args[:status] != :stopped
|
56
|
+
end
|
57
|
+
|
58
|
+
should "create paused adtext" do
|
59
|
+
@adtext_hash[:headline] += "Paused"
|
60
|
+
@adtext_hash[:status] = :paused
|
61
|
+
adtext = SklikApi::Adtext.new(@adtext_hash)
|
62
|
+
assert adtext.save, "Problem with creating adgroup: #{adtext.errors}"
|
63
|
+
|
64
|
+
assert_equal SklikApi::Adtext.get(adtext.args[:adtext_id]).args[:status], :paused
|
65
|
+
end
|
66
|
+
|
67
|
+
should "create stopped adtext" do
|
68
|
+
@adtext_hash[:headline] += "Stopped"
|
69
|
+
@adtext_hash[:status] = :stopped
|
70
|
+
adtext = SklikApi::Adtext.new(@adtext_hash)
|
71
|
+
assert adtext.save, "Problem with creating adgroup: #{adtext.errors}"
|
72
|
+
|
73
|
+
assert_equal SklikApi::Adtext.get(adtext.args[:adtext_id]).args[:status], :stopped
|
74
|
+
end
|
75
|
+
|
76
|
+
should "find" do
|
77
|
+
assert_equal SklikApi::Adtext.find(@adtext.args[:adtext_id]).to_hash.to_a.sort, @adtext_hash.to_a.sort, "By ID"
|
78
|
+
assert_equal SklikApi::Adtext.find(adtext_id: @adtext.args[:adtext_id]).first.to_hash.to_a.sort, @adtext_hash.to_a.sort, "By Hash with ID"
|
79
|
+
end
|
80
|
+
|
81
|
+
should "get" do
|
82
|
+
assert_equal SklikApi::Adtext.get(@adtext.args[:adtext_id]).to_hash.to_a.sort, @adtext_hash.to_a.sort
|
83
|
+
end
|
84
|
+
|
85
|
+
should "update" do
|
86
|
+
adtext = SklikApi::Adtext.get(@adtext.args[:adtext_id])
|
87
|
+
|
88
|
+
new_attributes = {
|
89
|
+
status: :stopped,
|
90
|
+
}
|
91
|
+
adtext.update new_attributes
|
92
|
+
|
93
|
+
adtext = SklikApi::Adtext.get(@adtext.args[:adtext_id])
|
94
|
+
assert_equal adtext.to_hash.to_a.sort, @adtext_hash.merge(new_attributes).to_a.sort, "First update"
|
95
|
+
|
96
|
+
new_attributes = {
|
97
|
+
status: :paused,
|
98
|
+
}
|
99
|
+
adtext.update new_attributes
|
100
|
+
adtext = SklikApi::Adtext.get(@adtext.args[:adtext_id])
|
101
|
+
assert_equal adtext.to_hash.to_a.sort, @adtext_hash.merge(new_attributes).to_a.sort, "Second update"
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
class CampaignIntegrationTest < Test::Unit::TestCase
|
4
|
+
context "Integration:Campaign" do
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@only_campaign_hash = {
|
8
|
+
:name => "integration campaign - #{Time.now.strftime("%Y.%m.%d %H:%M:%S.%L")}",
|
9
|
+
:status => :running,
|
10
|
+
:budget => 15.0,
|
11
|
+
:customer_id => 192495,
|
12
|
+
:excluded_search_services => [2,3,4,5,6,7,8], #choose only seznam.cz
|
13
|
+
:network_setting => {
|
14
|
+
:content => true,
|
15
|
+
:search => true
|
16
|
+
},
|
17
|
+
:ad_groups => []
|
18
|
+
}
|
19
|
+
@campaign = SklikApi::Campaign.new(@only_campaign_hash)
|
20
|
+
unless @campaign.save
|
21
|
+
raise "Unable to continue: #{@campaign.errors}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
@campaign.remove if @campaign.args[:campaign_id] && SklikApi::Campaign.get(@campaign.args[:campaign_id]).args[:status] != :stopped
|
27
|
+
end
|
28
|
+
|
29
|
+
should "create paused campaign" do
|
30
|
+
@only_campaign_hash[:name] += "Paused"
|
31
|
+
@only_campaign_hash[:status] = :paused
|
32
|
+
campaign = SklikApi::Campaign.new(@only_campaign_hash)
|
33
|
+
assert campaign.save, "Problem with creating campaing: #{@campaign.errors}"
|
34
|
+
|
35
|
+
assert_equal SklikApi::Campaign.get(campaign.args[:campaign_id]).args[:status], :paused
|
36
|
+
end
|
37
|
+
|
38
|
+
should "create stopped campaign" do
|
39
|
+
@only_campaign_hash[:name] += "Stopped"
|
40
|
+
@only_campaign_hash[:status] = :stopped
|
41
|
+
campaign = SklikApi::Campaign.new(@only_campaign_hash)
|
42
|
+
assert campaign.save, "Problem with creating campaing: #{campaign.errors}"
|
43
|
+
|
44
|
+
assert_equal SklikApi::Campaign.get(campaign.args[:campaign_id]).args[:status], :stopped
|
45
|
+
end
|
46
|
+
|
47
|
+
should "find" do
|
48
|
+
assert_equal SklikApi::Campaign.find(@campaign.args[:campaign_id]).to_hash.to_a.sort, @only_campaign_hash.to_a.sort
|
49
|
+
assert_equal SklikApi::Campaign.find(campaign_id: @campaign.args[:campaign_id]).first.to_hash.to_a.sort, @only_campaign_hash.to_a.sort
|
50
|
+
end
|
51
|
+
|
52
|
+
should "get" do
|
53
|
+
assert_equal SklikApi::Campaign.get(@campaign.args[:campaign_id]).to_hash.to_a.sort, @only_campaign_hash.to_a.sort
|
54
|
+
end
|
55
|
+
|
56
|
+
should "update" do
|
57
|
+
campaign = SklikApi::Campaign.get(@campaign.args[:campaign_id])
|
58
|
+
|
59
|
+
new_attributes = {
|
60
|
+
status: :stopped,
|
61
|
+
budget: 12.0,
|
62
|
+
:network_setting => {
|
63
|
+
:content => false,
|
64
|
+
:search => true
|
65
|
+
}
|
66
|
+
}
|
67
|
+
campaign.update new_attributes
|
68
|
+
|
69
|
+
campaign = SklikApi::Campaign.get(@campaign.args[:campaign_id])
|
70
|
+
assert_equal campaign.to_hash.to_a.sort, @only_campaign_hash.merge(new_attributes).to_a.sort, "First update"
|
71
|
+
|
72
|
+
new_attributes = {
|
73
|
+
status: :paused,
|
74
|
+
budget: 17.0,
|
75
|
+
:network_setting => {
|
76
|
+
:content => true,
|
77
|
+
:search => true
|
78
|
+
}
|
79
|
+
}
|
80
|
+
campaign.update new_attributes
|
81
|
+
campaign = SklikApi::Campaign.get(@campaign.args[:campaign_id])
|
82
|
+
assert_equal campaign.to_hash.to_a.sort, @only_campaign_hash.merge(new_attributes).to_a.sort, "Second update"
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
class ErrorsIntegrationTest < Test::Unit::TestCase
|
4
|
+
context "Integration:Error - Campaign" do
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@campaign_hash = {
|
8
|
+
:name => "integration error - #{Time.now.strftime("%Y.%m.%d %H:%M:%S.%L")}",
|
9
|
+
:status => :running,
|
10
|
+
:budget => 15.0,
|
11
|
+
:customer_id => 192495,
|
12
|
+
:excluded_search_services => [2,3,4,5,6,7,8], #choose only seznam.cz
|
13
|
+
:network_setting => {
|
14
|
+
:content => true,
|
15
|
+
:search => true
|
16
|
+
},
|
17
|
+
:ad_groups => []
|
18
|
+
}
|
19
|
+
@campaign = SklikApi::Campaign.new(@campaign_hash)
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
@campaign.remove if @campaign.args[:campaign_id] && SklikApi::Campaign.get(@campaign.args[:campaign_id]).args[:status] != :stopped
|
24
|
+
end
|
25
|
+
|
26
|
+
should "return errors for invalid campaign" do
|
27
|
+
@campaign.args[:budget] = 0
|
28
|
+
refute @campaign.valid?
|
29
|
+
assert @campaign.errors.any?, "Campaign validation should have errors #{@campaign.errors}"
|
30
|
+
|
31
|
+
@campaign.args[:budget] = 2
|
32
|
+
assert @campaign.valid?, "Should be valid but got error on save"
|
33
|
+
refute @campaign.save
|
34
|
+
|
35
|
+
assert @campaign.errors.any?, "Campaign should have errors #{@campaign.errors}"
|
36
|
+
assert_equal @campaign.errors, ["Campaign daybudget is too low (field = dayBudget, minimum = 1000)"]
|
37
|
+
end
|
38
|
+
|
39
|
+
context "-> Adgroup" do
|
40
|
+
|
41
|
+
setup do
|
42
|
+
#save campaign before testing!
|
43
|
+
@campaign.save
|
44
|
+
|
45
|
+
@adgroup_hash = {
|
46
|
+
:name => "my adgroup name - #{Time.now.strftime("%Y.%m.%d %H:%M:%S.%L")}",
|
47
|
+
:cpc => 6.0,
|
48
|
+
:campaign_id => @campaign.args[:campaign_id],
|
49
|
+
:keywords => [],
|
50
|
+
:ads => [],
|
51
|
+
:status => :running,
|
52
|
+
}
|
53
|
+
@adgroup = SklikApi::Adgroup.new(@adgroup_hash)
|
54
|
+
end
|
55
|
+
|
56
|
+
should "return errors to invalid adgroup" do
|
57
|
+
@adgroup.args[:cpc] = 0
|
58
|
+
refute @adgroup.valid?
|
59
|
+
assert @adgroup.errors.any?, "Adgroup validation should have errors #{@adgroup.errors}"
|
60
|
+
|
61
|
+
@adgroup.args[:cpc] = 0.01
|
62
|
+
assert @adgroup.valid?, "Should be valid but got error on save"
|
63
|
+
refute @adgroup.save
|
64
|
+
|
65
|
+
assert @adgroup.errors.any?, "Adgroup should have errors #{@adgroup.errors}"
|
66
|
+
assert_equal @adgroup.errors, ["Group cpc is too low (field = cpc, minimum = 20)"]
|
67
|
+
end
|
68
|
+
|
69
|
+
should "return adgroups error into campaign errors" do
|
70
|
+
@adgroup_hash[:cpc] = 0.01
|
71
|
+
@campaign_hash[:ad_groups] = [@adgroup_hash]
|
72
|
+
@campaign_hash.delete(:campaign_id)
|
73
|
+
@campaign_hash[:name] += " Second level"
|
74
|
+
@campaign = SklikApi::Campaign.new(@campaign_hash)
|
75
|
+
refute @campaign.save, "Shouldn't be saved"
|
76
|
+
assert @campaign.errors.any?, "Campaign should have errors #{@campaign.errors}"
|
77
|
+
assert @campaign.errors.first =~ /Group cpc is too low/, "#{@campaign.errors} should have error from adgroup /Group cpc si too low/"
|
78
|
+
end
|
79
|
+
|
80
|
+
should "return adgroups error into campaign errors && rollback!" do
|
81
|
+
|
82
|
+
SklikApi.use_rollback = true
|
83
|
+
|
84
|
+
@adgroup_hash[:cpc] = 0.01
|
85
|
+
@campaign_hash[:ad_groups] = [@adgroup_hash]
|
86
|
+
@campaign_hash.delete(:campaign_id)
|
87
|
+
@campaign_hash[:name] += " Second level"
|
88
|
+
old_name = "#{@campaign_hash[:name]}"
|
89
|
+
@campaign = SklikApi::Campaign.new(@campaign_hash)
|
90
|
+
refute @campaign.save, "Shouldn't be saved"
|
91
|
+
assert @campaign.errors.any?, "Campaign should have errors #{@campaign.errors}"
|
92
|
+
assert @campaign.errors.first =~ /Group cpc is too low/, "#{@campaign.errors} should have error from adgroup /Group cpc si too low/"
|
93
|
+
|
94
|
+
campaign = SklikApi::Campaign.get(@campaign.args[:campaign_id])
|
95
|
+
assert_not_equal old_name, campaign.args[:name], "Names should be diferent: #{@campaign_hash[:name]} != #{campaign.args[:name]}"
|
96
|
+
assert_equal campaign.args[:status], :stopped, "Campaign should be stopped after rollback"
|
97
|
+
end
|
98
|
+
|
99
|
+
should "return adgroups error into campaign errors && dont rollback!" do
|
100
|
+
|
101
|
+
SklikApi.use_rollback = false
|
102
|
+
|
103
|
+
@adgroup_hash[:cpc] = 0.01
|
104
|
+
@campaign_hash[:ad_groups] = [@adgroup_hash]
|
105
|
+
@campaign_hash.delete(:campaign_id)
|
106
|
+
@campaign_hash[:name] += " Second level"
|
107
|
+
@campaign = SklikApi::Campaign.new(@campaign_hash)
|
108
|
+
refute @campaign.save, "Shouldn't be saved"
|
109
|
+
assert @campaign.errors.any?, "Campaign should have errors #{@campaign.errors}"
|
110
|
+
assert @campaign.errors.first =~ /Group cpc is too low/, "#{@campaign.errors} should have error from adgroup /Group cpc si too low/"
|
111
|
+
|
112
|
+
campaign = SklikApi::Campaign.get(@campaign.args[:campaign_id])
|
113
|
+
assert_equal @campaign_hash[:name], campaign.args[:name], "Names should be same: #{@campaign_hash[:name]} == #{campaign.args[:name]}"
|
114
|
+
assert_equal campaign.args[:status], :running, "Campaign should be running and without rollback"
|
115
|
+
end
|
116
|
+
|
117
|
+
context "-> Adtext" do
|
118
|
+
|
119
|
+
setup do
|
120
|
+
@adgroup.save
|
121
|
+
@adtext_hash = {
|
122
|
+
:adgroup_id => @adgroup.args[:adgroup_id],
|
123
|
+
:headline => "Super headline",
|
124
|
+
:description1 => "Trying to do ",
|
125
|
+
:description2 => "best description ever",
|
126
|
+
:display_url => "bartas.cz",
|
127
|
+
:url => "http://www.bartas.cz/",
|
128
|
+
:status => :running,
|
129
|
+
}
|
130
|
+
@adtext = SklikApi::Adtext.new(@adtext_hash)
|
131
|
+
end
|
132
|
+
|
133
|
+
should "return errors to invalid adtext" do
|
134
|
+
@adtext.args[:headline] = ""
|
135
|
+
refute @adtext.valid?
|
136
|
+
assert @adtext.errors.any?, "Adtext validation should have errors #{@adtext.errors}"
|
137
|
+
|
138
|
+
@adtext.args[:headline] = "Long head valid not by sklik"
|
139
|
+
assert @adtext.valid?, "Should be valid - got: #{@adtext.errors}"
|
140
|
+
refute @adtext.save
|
141
|
+
|
142
|
+
assert @adtext.errors.any?, "Adtext should have errors #{@adtext.errors}"
|
143
|
+
assert_equal @adtext.errors, ["Creative1 is too long (field = creative1)"]
|
144
|
+
end
|
145
|
+
|
146
|
+
should "return adgroups error into campaign errors" do
|
147
|
+
@adgroup_hash.delete(:adgroup_id)
|
148
|
+
@campaign_hash.delete(:campaign_id)
|
149
|
+
|
150
|
+
@adtext_hash[:headline] = "Long head valid not by sklik"
|
151
|
+
@adgroup_hash[:ads] = [@adtext_hash]
|
152
|
+
@adgroup_hash[:name] += " Third level"
|
153
|
+
@campaign_hash[:ad_groups] = [@adgroup_hash]
|
154
|
+
@campaign_hash[:name] += " Third level"
|
155
|
+
@campaign = SklikApi::Campaign.new(@campaign_hash)
|
156
|
+
refute @campaign.save, "Shouldn't be saved"
|
157
|
+
assert @campaign.errors.any?, "Campaign should have errors #{@campaign.errors}"
|
158
|
+
assert @campaign.errors.first =~ /Creative1 is too long/, "#{@campaign.errors} should have error from adgroup /Creative1 is too long/"
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|