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
@@ -0,0 +1,131 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
class KeywordIntegrationTest < Test::Unit::TestCase
|
4
|
+
context "Integration:Keyword" do
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@campaign_hash = {
|
8
|
+
:name => "integration keyword - #{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
|
+
@keyword_hash = {
|
39
|
+
:adgroup_id => @adgroup.args[:adgroup_id],
|
40
|
+
:keyword => 'testing keyword',
|
41
|
+
:status => :running,
|
42
|
+
}
|
43
|
+
@keyword = SklikApi::Keyword.new(@keyword_hash)
|
44
|
+
unless @keyword.save
|
45
|
+
raise "Unable to continue - Keyword: #{@keyword.errors}"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def teardown
|
51
|
+
@campaign.remove if SklikApi::Campaign.get(@campaign.args[:campaign_id]).args[:status] != :stopped
|
52
|
+
end
|
53
|
+
|
54
|
+
should "create keyword with match type!" do
|
55
|
+
keyword_hash = {
|
56
|
+
:adgroup_id => @adgroup.args[:adgroup_id],
|
57
|
+
:keyword => "[phrase]",
|
58
|
+
:status => :running
|
59
|
+
}
|
60
|
+
keyword = SklikApi::Keyword.new(keyword_hash)
|
61
|
+
assert keyword.save, "Problem with creating phrase keyword: #{keyword.errors}"
|
62
|
+
assert_equal SklikApi::Keyword.get(keyword.args[:keyword_id]).args[:keyword], keyword_hash[:keyword]
|
63
|
+
|
64
|
+
keyword_hash = {
|
65
|
+
:adgroup_id => @adgroup.args[:adgroup_id],
|
66
|
+
:keyword => "broad",
|
67
|
+
:status => :running
|
68
|
+
}
|
69
|
+
keyword = SklikApi::Keyword.new(keyword_hash)
|
70
|
+
assert keyword.save, "Problem with creating broad keyword: #{keyword.errors}"
|
71
|
+
assert_equal SklikApi::Keyword.get(keyword.args[:keyword_id]).args[:keyword], keyword_hash[:keyword]
|
72
|
+
|
73
|
+
keyword_hash = {
|
74
|
+
:adgroup_id => @adgroup.args[:adgroup_id],
|
75
|
+
:keyword => "\"exact\"",
|
76
|
+
:status => :running
|
77
|
+
}
|
78
|
+
keyword = SklikApi::Keyword.new(keyword_hash)
|
79
|
+
assert keyword.save, "Problem with creating exact keyword: #{keyword.errors}"
|
80
|
+
assert_equal SklikApi::Keyword.get(keyword.args[:keyword_id]).args[:keyword], keyword_hash[:keyword]
|
81
|
+
|
82
|
+
end
|
83
|
+
should "create paused keyword" do
|
84
|
+
@keyword_hash[:keyword] += "Paused"
|
85
|
+
@keyword_hash[:status] = :paused
|
86
|
+
keyword = SklikApi::Keyword.new(@keyword_hash)
|
87
|
+
assert keyword.save, "Problem with creating keyword: #{keyword.errors}"
|
88
|
+
|
89
|
+
assert_equal SklikApi::Keyword.get(keyword.args[:keyword_id]).args[:status], :paused
|
90
|
+
end
|
91
|
+
|
92
|
+
should "create stopped keyword" do
|
93
|
+
@keyword_hash[:keyword] += " stopped"
|
94
|
+
@keyword_hash[:status] = :stopped
|
95
|
+
keyword = SklikApi::Keyword.new(@keyword_hash)
|
96
|
+
assert keyword.save, "Problem with creating keyword: #{keyword.errors}"
|
97
|
+
|
98
|
+
assert_equal SklikApi::Keyword.get(keyword.args[:keyword_id]).args[:status], :stopped
|
99
|
+
end
|
100
|
+
|
101
|
+
should "find" do
|
102
|
+
assert_equal SklikApi::Keyword.find(@keyword.args[:keyword_id]).to_hash.to_a.sort, @keyword_hash.to_a.sort, "By ID"
|
103
|
+
assert_equal SklikApi::Keyword.find(keyword_id: @keyword.args[:keyword_id]).first.to_hash.to_a.sort, @keyword_hash.to_a.sort, "By Hash with ID"
|
104
|
+
end
|
105
|
+
|
106
|
+
should "get" do
|
107
|
+
assert_equal SklikApi::Keyword.get(@keyword.args[:keyword_id]).to_hash.to_a.sort, @keyword_hash.to_a.sort
|
108
|
+
end
|
109
|
+
|
110
|
+
should "update" do
|
111
|
+
keyword = SklikApi::Keyword.get(@keyword.args[:keyword_id])
|
112
|
+
|
113
|
+
new_attributes = {
|
114
|
+
status: :stopped,
|
115
|
+
}
|
116
|
+
keyword.update new_attributes
|
117
|
+
|
118
|
+
keyword = SklikApi::Keyword.get(@keyword.args[:keyword_id])
|
119
|
+
assert_equal keyword.to_hash.to_a.sort, @keyword_hash.merge(new_attributes).to_a.sort, "First update"
|
120
|
+
|
121
|
+
new_attributes = {
|
122
|
+
status: :paused,
|
123
|
+
}
|
124
|
+
keyword.update new_attributes
|
125
|
+
keyword = SklikApi::Keyword.get(@keyword.args[:keyword_id])
|
126
|
+
assert_equal keyword.to_hash.to_a.sort, @keyword_hash.merge(new_attributes).to_a.sort, "Second update"
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
class AdgroupTest < Test::Unit::TestCase
|
4
|
+
context "Adgroup" do
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@campaign_hash = {
|
8
|
+
:name => "Campaign adgroup test - #{Time.now.strftime("%Y.%m.%d %H:%M:%S.%L")}",
|
9
|
+
:status => :running,
|
10
|
+
:budget => 15.0,
|
11
|
+
:cpc => 3.5,
|
12
|
+
:customer_id => 192495,
|
13
|
+
:excluded_search_services => [2,3,4,5,6,7,8], #choose only seznam.cz
|
14
|
+
:network_setting => {
|
15
|
+
:content => true,
|
16
|
+
:search => true
|
17
|
+
},
|
18
|
+
:ad_groups => [
|
19
|
+
{
|
20
|
+
:name => "my adgroup name",
|
21
|
+
:ads => [
|
22
|
+
{
|
23
|
+
:headline => "Super headline",
|
24
|
+
:description1 => "Trying to do ",
|
25
|
+
:description2 => "best description ever",
|
26
|
+
:display_url => "bartas.cz",
|
27
|
+
:url => "http://www.bartas.cz"
|
28
|
+
}
|
29
|
+
],
|
30
|
+
:keywords => [
|
31
|
+
"\"some funny keyword\"",
|
32
|
+
"[myphrase keyword]",
|
33
|
+
"mybroad keyword for me",
|
34
|
+
"test of diarcritics âô"
|
35
|
+
]
|
36
|
+
}
|
37
|
+
]
|
38
|
+
}
|
39
|
+
|
40
|
+
if @campaign = SklikApi::Campaign.find(@campaign_hash).first
|
41
|
+
unless @campaign.update @campaign_hash
|
42
|
+
pp @campaign.errors
|
43
|
+
raise 'Unable to update campaign!!! Fix this before tesing more'
|
44
|
+
end
|
45
|
+
else
|
46
|
+
@campaign = SklikApi::Campaign.new(@campaign_hash)
|
47
|
+
unless @campaign.save
|
48
|
+
pp @campaign.errors
|
49
|
+
raise 'Unable to Create campaign!!! Fix this before tesing more'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
should "be found in campaign" do
|
55
|
+
assert SklikApi::Adgroup.find(campaign_id: @campaign.args[:campaign_id]).size > 0, "In sklik should be some adgroups"
|
56
|
+
end
|
57
|
+
|
58
|
+
should "be found/get by id" do
|
59
|
+
adgroup = SklikApi::Adgroup.get(7053769)
|
60
|
+
assert_not_nil adgroup
|
61
|
+
assert adgroup.is_a?(SklikApi::Adgroup), "return SklikApi::Adgroup"
|
62
|
+
|
63
|
+
adgroup = SklikApi::Adgroup.find(adgroup_id: 7053769).first
|
64
|
+
assert_not_nil adgroup
|
65
|
+
assert adgroup.is_a?(SklikApi::Adgroup), "return SklikApi::Adgroup"
|
66
|
+
|
67
|
+
adgroup = SklikApi::Adgroup.find(campaign_id: 'doesnt matter', adgroup_id: 7053769).first
|
68
|
+
assert_not_nil adgroup
|
69
|
+
assert adgroup.is_a?(SklikApi::Adgroup), "return SklikApi::Adgroup"
|
70
|
+
end
|
71
|
+
|
72
|
+
should "return empty array when asking for not known adgroup" do
|
73
|
+
assert_equal SklikApi::Adgroup.find(:campaign_id => @campaign.args[:campaign_id], :name => 'unknown').size , 0
|
74
|
+
end
|
75
|
+
|
76
|
+
context "only adgroup" do
|
77
|
+
setup do
|
78
|
+
|
79
|
+
@adgroup_hash = {
|
80
|
+
:name => "my adgroup name - #{Time.now}",
|
81
|
+
:campaign_id => @campaign.args[:campaign_id],
|
82
|
+
:cpc => 2.0,
|
83
|
+
:ads => [
|
84
|
+
{
|
85
|
+
:headline => "Super headline",
|
86
|
+
:description1 => "Trying to do ",
|
87
|
+
:description2 => "best description ever",
|
88
|
+
:display_url => "bartas.cz",
|
89
|
+
:url => "http://www.bartas.cz"
|
90
|
+
}
|
91
|
+
],
|
92
|
+
:keywords => [
|
93
|
+
"\"some funny keyword\"",
|
94
|
+
"[myphrase keyword]",
|
95
|
+
"mybroad keyword for me",
|
96
|
+
"test of diarcritics âô"
|
97
|
+
]
|
98
|
+
}
|
99
|
+
@adgroup = SklikApi::Adgroup.new(@adgroup_hash)
|
100
|
+
end
|
101
|
+
|
102
|
+
should "be initialized" do
|
103
|
+
assert_nothing_raised do
|
104
|
+
SklikApi::Adgroup.new(@adgroup_hash)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
should "be invalid without given campaign_id or campaign" do
|
109
|
+
@adgroup_hash.delete(:campaign_id)
|
110
|
+
refute SklikApi::Adgroup.new(@adgroup_hash).valid?
|
111
|
+
end
|
112
|
+
|
113
|
+
should "be valid with given campaign_id" do
|
114
|
+
assert SklikApi::Adgroup.new(@adgroup_hash).valid?
|
115
|
+
end
|
116
|
+
|
117
|
+
should "be valid with given campaign" do
|
118
|
+
@adgroup_hash.delete(:campaign_id)
|
119
|
+
@adgroup_hash[:campaign] = @campaign
|
120
|
+
adgroup = SklikApi::Adgroup.new(@adgroup_hash)
|
121
|
+
assert adgroup.valid?, "Problem with: #{adgroup.errors}"
|
122
|
+
end
|
123
|
+
|
124
|
+
should "use campaign cpc (if no cpc given)" do
|
125
|
+
@adgroup_hash.delete(:campaign_id)
|
126
|
+
@adgroup_hash.delete(:cpc)
|
127
|
+
@adgroup_hash[:campaign] = @campaign
|
128
|
+
@campaign.args[:cpc] = @campaign_hash[:cpc]
|
129
|
+
adgroup = SklikApi::Adgroup.new(@adgroup_hash)
|
130
|
+
assert adgroup.valid?
|
131
|
+
assert_equal adgroup.args[:cpc], @campaign_hash[:cpc]
|
132
|
+
end
|
133
|
+
|
134
|
+
should "use cpc of adgroup if campaign was given" do
|
135
|
+
@adgroup_hash.delete(:campaign_id)
|
136
|
+
@adgroup_hash[:campaign] = @campaign
|
137
|
+
adgroup = SklikApi::Adgroup.new(@adgroup_hash)
|
138
|
+
assert adgroup.valid?
|
139
|
+
assert_equal adgroup.args[:cpc], @adgroup_hash[:cpc]
|
140
|
+
end
|
141
|
+
|
142
|
+
should "have hash stored inside" do
|
143
|
+
assert_equal @adgroup.args, @adgroup_hash
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,318 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
class CampaignTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Campaign" do
|
6
|
+
|
7
|
+
should "be found" do
|
8
|
+
assert SklikApi::Campaign.find(:customer_id => 192495).size > 0, "In sklik sandbox should be some campaigns"
|
9
|
+
end
|
10
|
+
|
11
|
+
should "be found without specifying customer_id" do
|
12
|
+
assert SklikApi::Campaign.find().size > 0, "In sklik sandbox should be some campaigns"
|
13
|
+
end
|
14
|
+
|
15
|
+
should "return empty array when asking for not known campaign" do
|
16
|
+
assert_equal SklikApi::Campaign.find(:campaign_id => 123456789).size , 0
|
17
|
+
end
|
18
|
+
|
19
|
+
should "return array of search services" do
|
20
|
+
assert_equal SklikApi::Campaign.list_search_services, [{:id=>1, :name=>"Vyhledávání na Seznam.cz"},
|
21
|
+
{:id=>2, :name=>"Firmy.cz"},
|
22
|
+
{:id=>3, :name=>"Sbazar.cz"},
|
23
|
+
{:id=>4, :name=>"Encyklopedie.Seznam.cz"},
|
24
|
+
{:id=>5, :name=>"Seznam na mobil (Smobil.cz)"},
|
25
|
+
{:id=>6, :name=>"Seznam Obrázky (Obrazky.cz)"},
|
26
|
+
{:id=>7, :name=>"Seznam Zboží (Zbozi.cz)"},
|
27
|
+
{:id=>8, :name=>"Partnerské vyhledávače"}]
|
28
|
+
end
|
29
|
+
|
30
|
+
context "only campaign" do
|
31
|
+
setup do
|
32
|
+
#preserve uniq names of campaigns!
|
33
|
+
@only_campaign_hash = {
|
34
|
+
:name => "hustokrutě megapřísně - #{Time.now.strftime("%Y.%m.%d %H:%M:%S.%L")} - only",
|
35
|
+
:status => :running,
|
36
|
+
:budget => 15.0,
|
37
|
+
:customer_id => 192495,
|
38
|
+
:excluded_search_services => [2,3,4,5,6,7,8], #choose only seznam.cz
|
39
|
+
:network_setting => {
|
40
|
+
:content => true,
|
41
|
+
:search => true
|
42
|
+
}
|
43
|
+
}
|
44
|
+
@campaign = SklikApi::Campaign.new(@only_campaign_hash)
|
45
|
+
end
|
46
|
+
|
47
|
+
def teardown
|
48
|
+
@campaign.remove if @campaign && @campaign.args[:campaign_id] && SklikApi::Campaign.get(@campaign.args[:campaign_id]) && SklikApi::Campaign.get(@campaign.args[:campaign_id]).args[:status] != :stopped
|
49
|
+
end
|
50
|
+
|
51
|
+
should "be initialized" do
|
52
|
+
assert_nothing_raised do
|
53
|
+
SklikApi::Campaign.new(@only_campaign_hash)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
should "have hash stored inside" do
|
58
|
+
assert_equal @campaign.args, @only_campaign_hash
|
59
|
+
end
|
60
|
+
|
61
|
+
context "create" do
|
62
|
+
setup do
|
63
|
+
@campaign = SklikApi::Campaign.new(@only_campaign_hash)
|
64
|
+
unless @campaign.save
|
65
|
+
puts "ERROR: \n #{@campaign.errors.join("\n")}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
should "return campaign by get method" do
|
70
|
+
campaign = SklikApi::Campaign.get(@campaign.args[:campaign_id])
|
71
|
+
campaign_hash = campaign.to_hash
|
72
|
+
assert_equal campaign_hash[:ad_groups].size, 0, "Campaign should have 0 adgroups"
|
73
|
+
end
|
74
|
+
|
75
|
+
should "be found/get by id" do
|
76
|
+
campaign = SklikApi::Campaign.get(@campaign.args[:campaign_id])
|
77
|
+
assert_not_nil campaign
|
78
|
+
assert campaign.is_a?(SklikApi::Campaign), "return SklikApi::Campaign"
|
79
|
+
|
80
|
+
campaign = SklikApi::Campaign.find(campaign_id: @campaign.args[:campaign_id]).first
|
81
|
+
assert_not_nil campaign
|
82
|
+
assert campaign.is_a?(SklikApi::Campaign), "return SklikApi::Campaign"
|
83
|
+
end
|
84
|
+
|
85
|
+
should "return valid to_hash" do
|
86
|
+
campaigns = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id])
|
87
|
+
assert_equal campaigns.size, 1, "Find should return array containing one campaign"
|
88
|
+
campaign = campaigns.first
|
89
|
+
campaign_hash = campaign.to_hash
|
90
|
+
assert_equal campaign_hash[:ad_groups].size, 0, "Campaign should have 0 adgroups"
|
91
|
+
end
|
92
|
+
|
93
|
+
should "be created with right parameters" do
|
94
|
+
assert_equal @campaign.args[:status], :running, "Must be running"
|
95
|
+
|
96
|
+
campaigns = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id])
|
97
|
+
campaign_hash = campaigns.first.to_hash
|
98
|
+
|
99
|
+
assert_equal campaign_hash[:campaign_id], @campaign.args[:campaign_id], "campaign id should be same"
|
100
|
+
assert_equal campaign_hash[:status], :running , "campaign should be running"
|
101
|
+
assert_equal campaign_hash[:budget].to_f, @only_campaign_hash[:budget].to_f, "budgets should be same"
|
102
|
+
assert_equal campaign_hash[:name], @only_campaign_hash[:name], "campaign name should be same"
|
103
|
+
assert_equal campaign_hash[:ad_groups].size, 0, "campaign ad_groups should have 0 adgroups"
|
104
|
+
end
|
105
|
+
|
106
|
+
should "be created and updated by changing arguments" do
|
107
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
108
|
+
new_name = "Test of updated campaign name- #{Time.now.strftime("%Y.%m.%d %H:%M:%S")} - only"
|
109
|
+
campaign.args[:name] = new_name
|
110
|
+
campaign.save
|
111
|
+
campaign_hash = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first.to_hash
|
112
|
+
assert_equal campaign_hash[:name], new_name, "campaign name should be same"
|
113
|
+
|
114
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
115
|
+
campaign.args[:status] = :paused
|
116
|
+
campaign.save
|
117
|
+
campaign_hash = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first.to_hash
|
118
|
+
assert_equal campaign_hash[:status], :paused, "campaign should be paused"
|
119
|
+
|
120
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
121
|
+
campaign.args[:status] = :stopped
|
122
|
+
campaign.save
|
123
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
124
|
+
assert_equal campaign.args[:status], :stopped, "campaign should be stopped"
|
125
|
+
|
126
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
127
|
+
campaign.args[:status] = :paused
|
128
|
+
campaign.save
|
129
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
130
|
+
assert_equal campaign.args[:status], :paused, "campaign should be paused"
|
131
|
+
end
|
132
|
+
|
133
|
+
should "be created and updated by update method" do
|
134
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
135
|
+
new_name = "Test of updated campaign name- #{Time.now.strftime("%Y.%m.%d %H:%M:%S")}"
|
136
|
+
assert campaign.update(name: new_name), "Should update name"
|
137
|
+
campaign_hash = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first.to_hash
|
138
|
+
assert_equal campaign_hash[:name], new_name, "campaign name should be same"
|
139
|
+
|
140
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
141
|
+
assert campaign.update(status: :paused), "should update status to paused"
|
142
|
+
campaign_hash = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first.to_hash
|
143
|
+
assert_equal campaign_hash[:status], :paused, "campaign should be paused"
|
144
|
+
|
145
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
146
|
+
assert campaign.update(status: :stopped), "should update status to stopped"
|
147
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
148
|
+
assert_equal campaign.args[:status], :stopped, "campaign should be stopped"
|
149
|
+
|
150
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
151
|
+
assert campaign.update(status: :paused), "should update status to paused"
|
152
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
153
|
+
assert_equal campaign.args[:status], :paused, "campaign should be paused"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
context "full creation" do
|
160
|
+
|
161
|
+
setup do
|
162
|
+
@test_campaign_hash = {
|
163
|
+
:name => "hustokrutě megapřísně - #{Time.now.strftime("%Y.%m.%d %H:%M:%S.%L")}",
|
164
|
+
:status => :running,
|
165
|
+
:cpc => 3.5,
|
166
|
+
:budget => 15.0,
|
167
|
+
:customer_id => 192495,
|
168
|
+
:excluded_search_services => [2,3,4,5,6,7,8], #choose only seznam.cz
|
169
|
+
:network_setting => {
|
170
|
+
:content => true,
|
171
|
+
:search => true
|
172
|
+
},
|
173
|
+
|
174
|
+
:ad_groups => [
|
175
|
+
{
|
176
|
+
:name => "my adgroup name",
|
177
|
+
:ads => [
|
178
|
+
{
|
179
|
+
:headline => "Super headline",
|
180
|
+
:description1 => "Trying to do ",
|
181
|
+
:description2 => "best description ever",
|
182
|
+
:display_url => "bartas.cz",
|
183
|
+
:url => "http://www.bartas.cz"
|
184
|
+
}
|
185
|
+
],
|
186
|
+
:keywords => [
|
187
|
+
"\"some funny keyword\"",
|
188
|
+
"[myphrase keyword]",
|
189
|
+
"mybroad keyword for me",
|
190
|
+
"test of diarcritics âô"
|
191
|
+
]
|
192
|
+
},
|
193
|
+
{
|
194
|
+
:name => "hustokrutě mazácká adgroupa",
|
195
|
+
:ads => [
|
196
|
+
{
|
197
|
+
:headline => "Super bombasitcký",
|
198
|
+
:description1 => "Trying to do ",
|
199
|
+
:description2 => "best description ever",
|
200
|
+
:display_url => "bartas.cz",
|
201
|
+
:url => "http://www.bartas.cz?utm_adgroup=4"
|
202
|
+
}
|
203
|
+
],
|
204
|
+
:keywords => [
|
205
|
+
"\"some funny keyword\"",
|
206
|
+
"[myphrase keyword]",
|
207
|
+
"-negative broad keyword",
|
208
|
+
"test of diarcritics âô",
|
209
|
+
"dokonalý kw"
|
210
|
+
]
|
211
|
+
}
|
212
|
+
]
|
213
|
+
}
|
214
|
+
@campaign = SklikApi::Campaign.new(@test_campaign_hash)
|
215
|
+
end
|
216
|
+
|
217
|
+
should "be initialized" do
|
218
|
+
assert_nothing_raised do
|
219
|
+
SklikApi::Campaign.new(@test_campaign_hash)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
should "have hash stored inside" do
|
224
|
+
assert_equal @campaign.args, @test_campaign_hash
|
225
|
+
end
|
226
|
+
|
227
|
+
context "create" do
|
228
|
+
setup do
|
229
|
+
@campaign = SklikApi::Campaign.new(@test_campaign_hash)
|
230
|
+
unless @campaign.save
|
231
|
+
puts "ERROR: \n #{@campaign.errors.join("\n")}"
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
should "return stats" do
|
236
|
+
assert_nothing_raised do
|
237
|
+
SklikApi::Campaign.find(@campaign.args[:campaign_id]).get_stats Date.today, Date.today
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
should "return valid to_hash" do
|
243
|
+
campaigns = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id])
|
244
|
+
assert_equal campaigns.size, 1, "Find should return array containing one campaign"
|
245
|
+
campaign = campaigns.first
|
246
|
+
campaign_hash = campaign.to_hash
|
247
|
+
assert_equal campaign_hash[:ad_groups].size, @test_campaign_hash[:ad_groups].size, "Campaign should have right adgroup count"
|
248
|
+
assert_equal campaign_hash[:ad_groups].inject(0){|i,o| i + o[:keywords].size}, @test_campaign_hash[:ad_groups].inject(0){|i,o| i + o[:keywords].size}, "Campaign should have right keywords count"
|
249
|
+
assert_equal campaign_hash[:ad_groups].inject(0){|i,o| i + o[:ads].size}, @test_campaign_hash[:ad_groups].inject(0){|i,o| i + o[:ads].size}, "Campaign should have right ads count"
|
250
|
+
end
|
251
|
+
|
252
|
+
should "be created with right parameters" do
|
253
|
+
|
254
|
+
assert_equal @campaign.args[:status], :running, "Must be running"
|
255
|
+
|
256
|
+
campaigns = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id])
|
257
|
+
campaign_hash = campaigns.first.to_hash
|
258
|
+
|
259
|
+
assert_equal campaign_hash[:campaign_id], @campaign.args[:campaign_id], "campaign id should be same"
|
260
|
+
assert_equal campaign_hash[:status], :running , "campaign should be running"
|
261
|
+
assert_equal campaign_hash[:budget].to_f, @test_campaign_hash[:budget].to_f, "budgets should be same"
|
262
|
+
assert_equal campaign_hash[:name], @test_campaign_hash[:name], "campaign name should be same"
|
263
|
+
assert_equal campaign_hash[:ad_groups].size, @test_campaign_hash[:ad_groups].size, "campaign ad_groups should have same count"
|
264
|
+
end
|
265
|
+
|
266
|
+
should "be created and updated by changing arguments" do
|
267
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
268
|
+
new_name = "Test of updated campaign name- #{Time.now.strftime("%Y.%m.%d %H:%M:%S")}"
|
269
|
+
campaign.args[:name] = new_name
|
270
|
+
campaign.save
|
271
|
+
campaign_hash = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first.to_hash
|
272
|
+
assert_equal campaign_hash[:name], new_name, "campaign name should be same"
|
273
|
+
|
274
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
275
|
+
campaign.args[:status] = :paused
|
276
|
+
campaign.save
|
277
|
+
campaign_hash = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first.to_hash
|
278
|
+
assert_equal campaign_hash[:status], :paused, "campaign should be paused"
|
279
|
+
|
280
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
281
|
+
campaign.args[:status] = :stopped
|
282
|
+
campaign.save
|
283
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
284
|
+
assert_equal campaign.args[:status], :stopped, "campaign should be stopped"
|
285
|
+
|
286
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
287
|
+
campaign.args[:status] = :paused
|
288
|
+
campaign.save
|
289
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
290
|
+
assert_equal campaign.args[:status], :paused, "campaign should be paused"
|
291
|
+
end
|
292
|
+
|
293
|
+
should "be created and updated by update method" do
|
294
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
295
|
+
new_name = "Test of updated campaign name- #{Time.now.strftime("%Y.%m.%d %H:%M:%S")}"
|
296
|
+
assert campaign.update(name: new_name), "Should update name"
|
297
|
+
campaign_hash = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first.to_hash
|
298
|
+
assert_equal campaign_hash[:name], new_name, "campaign name should be same"
|
299
|
+
|
300
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
301
|
+
assert campaign.update(status: :paused), "should update status to paused"
|
302
|
+
campaign_hash = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first.to_hash
|
303
|
+
assert_equal campaign_hash[:status], :paused, "campaign should be paused"
|
304
|
+
|
305
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
306
|
+
assert campaign.update(status: :stopped), "should update status to stopped"
|
307
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
308
|
+
assert_equal campaign.args[:status], :stopped, "campaign should be stopped"
|
309
|
+
|
310
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
311
|
+
assert campaign.update(status: :paused), "should update status to paused"
|
312
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
313
|
+
assert_equal campaign.args[:status], :paused, "campaign should be paused"
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
class ClientTest < Test::Unit::TestCase
|
4
|
+
context "Client" do
|
5
|
+
|
6
|
+
should "be initialized" do
|
7
|
+
assert_nothing_raised do
|
8
|
+
SklikApi::Client.new()
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
should "found all Clients" do
|
13
|
+
assert_equal SklikApi::Client.find().size, 2
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be found by id" do
|
17
|
+
assert_equal SklikApi::Client.find(:customer_id => 192107).first.args[:email], "test-ataxo@seznam.cz"
|
18
|
+
assert_equal SklikApi::Client.find(:customer_id => 192495).first.args[:email], "test3-ataxo@seznam.cz"
|
19
|
+
end
|
20
|
+
|
21
|
+
should "be found by email" do
|
22
|
+
assert_equal SklikApi::Client.find(:email => "test-ataxo@seznam.cz").first.args[:customer_id], 192107
|
23
|
+
assert_equal SklikApi::Client.find(:email => "test3-ataxo@seznam.cz").first.args[:customer_id], 192495
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sklik-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.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: 2013-
|
12
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -275,12 +275,20 @@ files:
|
|
275
275
|
- lib/sklik-api/campaign_parts/keyword.rb
|
276
276
|
- lib/sklik-api/client.rb
|
277
277
|
- lib/sklik-api/connection.rb
|
278
|
+
- lib/sklik-api/exceptions.rb
|
278
279
|
- lib/sklik-api/sklik_object.rb
|
279
280
|
- lib/sklik-api/xmlrpc_setup.rb
|
280
281
|
- sklik-api.gemspec
|
281
282
|
- test/fake_web.rb
|
282
283
|
- test/helper.rb
|
283
|
-
- test/
|
284
|
+
- test/integration/adgroup_test.rb
|
285
|
+
- test/integration/adtext_test.rb
|
286
|
+
- test/integration/campaign_test.rb
|
287
|
+
- test/integration/errors_test.rb
|
288
|
+
- test/integration/keyword_test.rb
|
289
|
+
- test/unit/adgroup_test.rb
|
290
|
+
- test/unit/campaign_test.rb
|
291
|
+
- test/unit/client_test.rb
|
284
292
|
homepage: http://github.com/ondrejbartas/sklik-api
|
285
293
|
licenses:
|
286
294
|
- MIT
|
@@ -296,7 +304,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
296
304
|
version: '0'
|
297
305
|
segments:
|
298
306
|
- 0
|
299
|
-
hash:
|
307
|
+
hash: 3135873328890994326
|
300
308
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
301
309
|
none: false
|
302
310
|
requirements:
|