sklik-api 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/sklik-api/campaign.rb +87 -39
- data/lib/sklik-api/campaign_parts/adgroup.rb +113 -28
- data/lib/sklik-api/campaign_parts/adtext.rb +18 -15
- data/lib/sklik-api/sklik_object.rb +18 -18
- data/sklik-api.gemspec +3 -3
- metadata +110 -35
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.15
|
data/lib/sklik-api/campaign.rb
CHANGED
@@ -4,9 +4,9 @@ class SklikApi
|
|
4
4
|
|
5
5
|
NAME = "campaign"
|
6
6
|
|
7
|
-
ADDITIONAL_FIELDS = [
|
8
|
-
:excludedSearchServices, :excludedUrls, :totalBudget, :totalClicks,
|
9
|
-
:adSelection, :startDate, :endDate, :premiseId
|
7
|
+
ADDITIONAL_FIELDS = [
|
8
|
+
:excludedSearchServices, :excludedUrls, :totalBudget, :totalClicks,
|
9
|
+
:adSelection, :startDate, :endDate, :premiseId
|
10
10
|
]
|
11
11
|
|
12
12
|
include Object
|
@@ -23,11 +23,11 @@ Example of input hash
|
|
23
23
|
:content => true,
|
24
24
|
:search => true
|
25
25
|
},
|
26
|
-
|
26
|
+
|
27
27
|
:ad_groups => [
|
28
28
|
{
|
29
29
|
:name => "my adgroup name",
|
30
|
-
:ads => [
|
30
|
+
:ads => [
|
31
31
|
{
|
32
32
|
:headline => "Super headline",
|
33
33
|
:description1 => "Trying to do ",
|
@@ -46,20 +46,20 @@ Example of input hash
|
|
46
46
|
]
|
47
47
|
}
|
48
48
|
|
49
|
-
# This model also support additional params:
|
50
|
-
# :excluded_search_services, :excluded_urls, :total_budget, :total_clicks,
|
51
|
-
# :ad_selection, :start_date, :end_date, :status, :premise_id
|
49
|
+
# This model also support additional params:
|
50
|
+
# :excluded_search_services, :excluded_urls, :total_budget, :total_clicks,
|
51
|
+
# :ad_selection, :start_date, :end_date, :status, :premise_id
|
52
52
|
# Please look into documentation of api.sklik.cz
|
53
53
|
# http://api.sklik.cz/campaign.create.html
|
54
54
|
=end
|
55
|
-
|
55
|
+
|
56
56
|
def initialize args
|
57
57
|
#variable where are saved current data from system
|
58
58
|
@campaign_data = nil
|
59
|
-
|
59
|
+
|
60
60
|
#variable for storing errors
|
61
61
|
@errors = []
|
62
|
-
|
62
|
+
|
63
63
|
#initialize adgroups
|
64
64
|
@adgroups = []
|
65
65
|
if args[:ad_groups] && args[:ad_groups].size > 0
|
@@ -67,38 +67,38 @@ Example of input hash
|
|
67
67
|
@adgroups << SklikApi::Adgroup.new(self, adgroup)
|
68
68
|
end
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
@customer_id = args[:customer_id]
|
72
72
|
super args
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
def errors
|
76
|
-
@errors
|
76
|
+
@errors
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def self.find args = {}
|
80
80
|
out = []
|
81
81
|
super(NAME, args[:customer_id]).each do |campaign|
|
82
82
|
if (args[:campaign_id].nil? || (args[:campaign_id] && args[:campaign_id].to_i == campaign[:id].to_i)) && #find by campaign id
|
83
83
|
(args[:status].nil? || (args[:status] && args[:status] == fix_status(campaign))) # find by status
|
84
|
-
out << SklikApi::Campaign.new(
|
84
|
+
out << SklikApi::Campaign.new(
|
85
85
|
:campaign_id => campaign[:id],
|
86
|
-
:customer_id => args[:customer_id],
|
87
|
-
:budget => campaign[:dayBudget].to_f/100.0,
|
88
|
-
:name => campaign[:name],
|
86
|
+
:customer_id => args[:customer_id],
|
87
|
+
:budget => campaign[:dayBudget].to_f/100.0,
|
88
|
+
:name => campaign[:name],
|
89
89
|
:status => fix_status(campaign)
|
90
90
|
)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
out
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
def self.list_search_services
|
97
97
|
connection.call("listSearchServices") do |param|
|
98
98
|
return param[:searchServices].collect{|c| c.symbolize_keys}
|
99
|
-
end
|
99
|
+
end
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def self.fix_status campaign
|
103
103
|
if campaign[:removed] == true
|
104
104
|
return :stopped
|
@@ -120,7 +120,7 @@ Example of input hash
|
|
120
120
|
return nil
|
121
121
|
end
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
def adgroups
|
125
125
|
Adgroup.find(self)
|
126
126
|
end
|
@@ -134,13 +134,13 @@ Example of input hash
|
|
134
134
|
@campaign_data
|
135
135
|
end
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
def update_args
|
139
139
|
out = []
|
140
140
|
|
141
141
|
#add campaign id on which will be performed update
|
142
142
|
out << @args[:campaign_id]
|
143
|
-
|
143
|
+
|
144
144
|
#prepare campaign struct
|
145
145
|
args = {}
|
146
146
|
args[:name] = @args[:name] if @args[:name]
|
@@ -156,10 +156,10 @@ Example of input hash
|
|
156
156
|
|
157
157
|
out
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
def create_args
|
161
161
|
out = []
|
162
|
-
|
162
|
+
|
163
163
|
#prepare campaign struct
|
164
164
|
args = {}
|
165
165
|
args[:name] = @args[:name]
|
@@ -171,12 +171,12 @@ Example of input hash
|
|
171
171
|
end
|
172
172
|
|
173
173
|
out << args
|
174
|
-
|
174
|
+
|
175
175
|
#add customer id on which account campaign should be created
|
176
176
|
out << @customer_id if @customer_id
|
177
177
|
out
|
178
178
|
end
|
179
|
-
|
179
|
+
|
180
180
|
def self.get_current_status args = {}
|
181
181
|
raise ArgumentError, "Campaign_id is required" unless args[:campaign_id]
|
182
182
|
campaigns = self.find(args)
|
@@ -194,23 +194,71 @@ Example of input hash
|
|
194
194
|
|
195
195
|
def update args = {}
|
196
196
|
@args.merge!(args)
|
197
|
+
|
198
|
+
#initialize update of adgroups adgroups
|
199
|
+
@adgroups = []
|
200
|
+
if args[:ad_groups] && args[:ad_groups].size > 0
|
201
|
+
@adgroups_update = true
|
202
|
+
args[:ad_groups].each do |adgroup|
|
203
|
+
@adgroups << SklikApi::Adgroup.new(self, adgroup)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
197
207
|
save
|
198
208
|
end
|
199
209
|
|
200
|
-
def save
|
210
|
+
def save
|
201
211
|
if @args[:campaign_id] #do update
|
202
212
|
#get current status of campaign
|
203
213
|
before_status = get_current_status
|
204
|
-
|
205
|
-
#restore campaign before update
|
214
|
+
|
215
|
+
#restore campaign before update
|
206
216
|
restore if before_status == :stopped
|
207
|
-
|
208
|
-
#
|
209
|
-
|
210
|
-
|
217
|
+
|
218
|
+
#rescue from any error to ensure remove will be done when something went wrong
|
219
|
+
error = nil
|
220
|
+
begin
|
221
|
+
#update campaign
|
222
|
+
update_object
|
223
|
+
|
224
|
+
#update adgroups!
|
225
|
+
if @adgroups_update
|
226
|
+
@saved_adgroups = adgroups.inject({}){|o,a| o[a.args[:name]] = a; o}
|
227
|
+
@new_adgroups = @adgroups.inject({}){|o,a| o[a.args[:name]] = a; o}
|
228
|
+
#adgroups to be deleted
|
229
|
+
(@saved_adgroups.keys - @new_adgroups.keys).each do |k|
|
230
|
+
#don't try to remove already removed adgroup
|
231
|
+
unless @saved_adgroups[k].args[:status] == :stopped
|
232
|
+
puts "removing old adgroup: #{@saved_adgroups[k].args[:name]}"
|
233
|
+
@saved_adgroups[k].remove
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
#adgroups to be created
|
238
|
+
(@new_adgroups.keys - @saved_adgroups.keys).each do |k|
|
239
|
+
puts "creating new adgroup: #{@new_adgroups[k].args[:name]}"
|
240
|
+
@new_adgroups[k].save
|
241
|
+
end
|
242
|
+
|
243
|
+
#check status to be running
|
244
|
+
(@new_adgroups.keys & @saved_adgroups.keys).each do |k|
|
245
|
+
puts "checking status of adgroup: #{@saved_adgroups[k].args[:name]}"
|
246
|
+
if @saved_adgroups[k].args[:status] == :stopped
|
247
|
+
@saved_adgroups[k].restore
|
248
|
+
end
|
249
|
+
puts "updating adgroup: #{@saved_adgroups[k].args[:name]}"
|
250
|
+
@saved_adgroups[k].update @new_adgroups[k]
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
rescue Exception => e
|
256
|
+
@errors << e.message
|
257
|
+
end
|
258
|
+
|
211
259
|
#remove it if new status is stopped or status doesn't changed and before it was stopped
|
212
260
|
remove if (@args[:status] == :stopped) || (@args[:status].nil? && before_status == :stopped)
|
213
|
-
|
261
|
+
|
214
262
|
return true
|
215
263
|
else #do save
|
216
264
|
#create campaign
|
@@ -220,11 +268,11 @@ Example of input hash
|
|
220
268
|
@errors << e.message
|
221
269
|
return false
|
222
270
|
end
|
223
|
-
|
271
|
+
|
224
272
|
begin
|
225
273
|
#create adgroups
|
226
274
|
@adgroups.each{ |adgroup| adgroup.save }
|
227
|
-
|
275
|
+
|
228
276
|
@campaign_data = @args
|
229
277
|
raise ArgumentError, "Problem with creating campaign datas" unless @errors.size == 0
|
230
278
|
return true
|
@@ -10,7 +10,7 @@ Example of input hash
|
|
10
10
|
{
|
11
11
|
:adgroup_id => 1234, #(OPTIONAL) -> when setted it will on save do update of existing adgroup
|
12
12
|
:name => "my adgroup name",
|
13
|
-
:ads => [
|
13
|
+
:ads => [
|
14
14
|
{
|
15
15
|
:headline => "Super headline",
|
16
16
|
:description1 => "Trying to do ",
|
@@ -29,7 +29,7 @@ Example of input hash
|
|
29
29
|
|
30
30
|
|
31
31
|
=end
|
32
|
-
|
32
|
+
|
33
33
|
def initialize campaign, args
|
34
34
|
@adgroup_data = nil
|
35
35
|
#set adgroup owner campaign
|
@@ -49,25 +49,25 @@ Example of input hash
|
|
49
49
|
@keywords << SklikApi::Keyword.new(self, :keyword => keyword)
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
super args
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def self.find campaign, args = {}
|
57
57
|
out = []
|
58
58
|
super(NAME, campaign.args[:campaign_id]).each do |adgroup|
|
59
59
|
if args[:adgroup_id].nil? || (args[:adgroup_id] && args[:adgroup_id].to_i == adgroup[:id].to_i)
|
60
|
-
out << SklikApi::Adgroup.new( campaign,
|
60
|
+
out << SklikApi::Adgroup.new( campaign,
|
61
61
|
:adgroup_id => adgroup[:id],
|
62
|
-
:cpc => adgroup[:cpc].to_f/100.0,
|
63
|
-
:name => adgroup[:name],
|
62
|
+
:cpc => adgroup[:cpc].to_f/100.0,
|
63
|
+
:name => adgroup[:name],
|
64
64
|
:status => fix_status(adgroup)
|
65
65
|
)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
out
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
def self.fix_status adgroup
|
72
72
|
if adgroup[:removed] == true
|
73
73
|
return :stopped
|
@@ -75,7 +75,7 @@ Example of input hash
|
|
75
75
|
return :running
|
76
76
|
end
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def keywords_stats from, to
|
80
80
|
output = []
|
81
81
|
keywords = Keyword.find(self)
|
@@ -105,36 +105,122 @@ Example of input hash
|
|
105
105
|
@adgroup_data
|
106
106
|
end
|
107
107
|
end
|
108
|
-
|
109
|
-
|
108
|
+
|
109
|
+
|
110
110
|
def create_args
|
111
111
|
raise ArgumentError, "Adgroup need's to know campaign_id" unless @campaign.args[:campaign_id]
|
112
112
|
raise ArgumentError, "Adgroup need's to know campaigns CPC" unless @campaign.args[:cpc]
|
113
113
|
|
114
114
|
out = []
|
115
115
|
#add campaign id to know where to create adgroup
|
116
|
-
out << @campaign.args[:campaign_id]
|
117
|
-
|
116
|
+
out << @campaign.args[:campaign_id]
|
117
|
+
|
118
118
|
#add adgroup struct
|
119
119
|
args = {}
|
120
120
|
args[:name] = @args[:name]
|
121
121
|
args[:cpc] = (@campaign.args[:cpc] * 100).to_i if @campaign.args[:cpc]
|
122
122
|
out << args
|
123
|
-
|
123
|
+
|
124
124
|
#return output
|
125
125
|
out
|
126
126
|
end
|
127
|
-
|
128
|
-
def
|
127
|
+
|
128
|
+
def adtexts
|
129
|
+
Adtext.find(self)
|
130
|
+
end
|
131
|
+
|
132
|
+
def keywords
|
133
|
+
Keyword.find(self)
|
134
|
+
end
|
135
|
+
|
136
|
+
def update args = {}
|
137
|
+
if args.is_a?(SklikApi::Adgroup)
|
138
|
+
#get data from another adgroup
|
139
|
+
@adtexts = args.instance_variable_get("@adtexts")
|
140
|
+
@keywords = args.instance_variable_get("@keywords")
|
141
|
+
|
142
|
+
#set parent to this adgroup
|
143
|
+
@adtexts.each{|a| a.instance_variable_set("@adgroup", self)}
|
144
|
+
@keywords.each{|a| a.instance_variable_set("@adgroup", self)}
|
145
|
+
else
|
146
|
+
#initialize new adtexts
|
147
|
+
@adtexts = []
|
148
|
+
if args[:ads] && args[:ads].size > 0
|
149
|
+
args[:ads].each do |adtext|
|
150
|
+
@adtexts << SklikApi::Adtext.new(self, adtext)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
#initialize new keywords
|
155
|
+
@keywords = []
|
156
|
+
if args[:keywords] && args[:keywords].size > 0
|
157
|
+
args[:keywords].each do |keyword|
|
158
|
+
@keywords << SklikApi::Keyword.new(self, :keyword => keyword)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
save
|
164
|
+
end
|
165
|
+
|
166
|
+
def save
|
129
167
|
if @args[:adgroup_id] #do update
|
130
|
-
|
168
|
+
|
169
|
+
############
|
170
|
+
## KEYWORDS
|
171
|
+
############
|
172
|
+
#create new keyowrds and delete old
|
173
|
+
@saved_keywords = keywords.inject({}){|o,k| o[k.args[:keyword]] = k ; o}
|
174
|
+
@new_keywords = @keywords.inject({}){|o,k| o[k.args[:keyword]] = k ; o}
|
175
|
+
|
176
|
+
#keywords to be deleted
|
177
|
+
(@saved_keywords.keys - @new_keywords.keys).each do |k|
|
178
|
+
#don't try to remove already removed keyword
|
179
|
+
@saved_keywords[k].remove unless @saved_keywords[k].args[:status] == :stopped
|
180
|
+
end
|
181
|
+
|
182
|
+
#keywords to be created
|
183
|
+
(@new_keywords.keys - @saved_keywords.keys).each do |k|
|
184
|
+
@new_keywords[k].save
|
185
|
+
end
|
186
|
+
|
187
|
+
#check status to be running
|
188
|
+
(@new_keywords.keys & @saved_keywords.keys).each do |k|
|
189
|
+
@saved_keywords[k].restore if @saved_keywords[k].args[:status] == :stopped
|
190
|
+
end
|
191
|
+
|
192
|
+
############
|
193
|
+
## ADTEXTS
|
194
|
+
############
|
195
|
+
|
196
|
+
#create new adtexts and delete old
|
197
|
+
@saved_adtexts = adtexts.inject({}){|o,a| o[a.uniq_identifier] = a ; o}
|
198
|
+
@new_adtexts = @adtexts.inject({}){|o,a| o[a.uniq_identifier] = a ; o}
|
199
|
+
|
200
|
+
#adtexts to be deleted
|
201
|
+
(@saved_adtexts.keys - @new_adtexts.keys).each do |k|
|
202
|
+
#don't try to remove already removed adtext
|
203
|
+
@saved_adtexts[k].remove unless @saved_adtexts[k].args[:status] == :stopped
|
204
|
+
end
|
205
|
+
|
206
|
+
#adtexts to be created
|
207
|
+
(@new_adtexts.keys - @saved_adtexts.keys).each do |k|
|
208
|
+
@new_adtexts[k].save
|
209
|
+
end
|
210
|
+
|
211
|
+
#check status to be running
|
212
|
+
(@new_adtexts.keys & @saved_adtexts.keys).each do |k|
|
213
|
+
@saved_adtexts[k].restore if @saved_adtexts[k].args[:status] == :stopped
|
214
|
+
end
|
215
|
+
|
216
|
+
|
131
217
|
else #do save
|
132
218
|
#create adgroup
|
133
219
|
create
|
134
|
-
|
220
|
+
|
135
221
|
#create adtexts
|
136
|
-
@adtexts.each do |adtext|
|
137
|
-
begin
|
222
|
+
@adtexts.each do |adtext|
|
223
|
+
begin
|
138
224
|
adtext.save
|
139
225
|
rescue Exception => e
|
140
226
|
#take care about error message -> do it nicer
|
@@ -145,16 +231,16 @@ Example of input hash
|
|
145
231
|
end
|
146
232
|
end
|
147
233
|
end
|
148
|
-
|
149
|
-
|
234
|
+
|
235
|
+
|
150
236
|
#create keywords
|
151
237
|
keywords_error = []
|
152
|
-
@keywords.each do |keyword|
|
153
|
-
begin
|
238
|
+
@keywords.each do |keyword|
|
239
|
+
begin
|
154
240
|
keyword.save
|
155
241
|
rescue Exception => e
|
156
242
|
#take care about error message -> do it nicer
|
157
|
-
if /Sklik returned: keyword.create: Invalid data in request/ =~ e.message
|
243
|
+
if /Sklik returned: keyword.create: Invalid data in request/ =~ e.message
|
158
244
|
keywords_error << e.message.split("{:name=>\"").last.split("\", :matchType").first
|
159
245
|
else
|
160
246
|
@campaign.errors << e.message
|
@@ -164,11 +250,10 @@ Example of input hash
|
|
164
250
|
if keywords_error.size > 0
|
165
251
|
@campaign.errors << "Problem with creating keywords: #{keywords_error.join(", ")} in adgroup #{@args[:name]}"
|
166
252
|
end
|
167
|
-
|
253
|
+
|
168
254
|
end
|
169
255
|
end
|
170
256
|
|
171
257
|
end
|
172
258
|
end
|
173
|
-
|
174
|
-
|
259
|
+
|
@@ -4,7 +4,7 @@ class SklikApi
|
|
4
4
|
|
5
5
|
NAME = "ad"
|
6
6
|
|
7
|
-
ADDITIONAL_FIELDS = [
|
7
|
+
ADDITIONAL_FIELDS = [
|
8
8
|
:premiseMode, :premiseID
|
9
9
|
]
|
10
10
|
|
@@ -26,17 +26,20 @@ Example of input hash
|
|
26
26
|
@adtext_data = nil
|
27
27
|
#set adtext owner adgroup
|
28
28
|
@adgroup = adgroup
|
29
|
-
|
29
|
+
|
30
30
|
super args
|
31
31
|
end
|
32
|
-
|
33
|
-
|
32
|
+
|
33
|
+
def uniq_identifier
|
34
|
+
"#{@args[:headline]}#{@args[:description1]}#{@args[:description2]}#{@args[:display_url]}#{@args[:url]}"
|
35
|
+
end
|
36
|
+
|
34
37
|
def create_args
|
35
38
|
raise ArgumentError, "Adtexts need's to know adgroup_id" unless @adgroup.args[:adgroup_id]
|
36
39
|
out = []
|
37
40
|
#add campaign id to know where to create adgroup
|
38
|
-
out << @adgroup.args[:adgroup_id]
|
39
|
-
|
41
|
+
out << @adgroup.args[:adgroup_id]
|
42
|
+
|
40
43
|
#add adtext struct
|
41
44
|
args = {}
|
42
45
|
args[:creative1] = @args[:headline]
|
@@ -51,16 +54,16 @@ Example of input hash
|
|
51
54
|
end
|
52
55
|
|
53
56
|
out << args
|
54
|
-
|
57
|
+
|
55
58
|
#return output
|
56
59
|
out
|
57
60
|
end
|
58
|
-
|
61
|
+
|
59
62
|
def self.find adgroup, args = {}
|
60
63
|
out = []
|
61
64
|
super(NAME, adgroup.args[:adgroup_id]).each do |adtext|
|
62
65
|
if args[:adtext_id].nil? || (args[:adtext_id] && args[:adtext_id].to_i == adtext[:id].to_i)
|
63
|
-
out << SklikApi::Adtext.new(
|
66
|
+
out << SklikApi::Adtext.new(
|
64
67
|
adgroup,
|
65
68
|
:adtext_id => adtext[:id],
|
66
69
|
:headline => adtext[:creative1],
|
@@ -68,7 +71,7 @@ Example of input hash
|
|
68
71
|
:description2 => adtext[:creative3],
|
69
72
|
:display_url =>adtext[:clickthruText],
|
70
73
|
:url => adtext[:clickthruUrl],
|
71
|
-
:name => adtext[:name],
|
74
|
+
:name => adtext[:name],
|
72
75
|
:status => fix_status(adtext)
|
73
76
|
)
|
74
77
|
end
|
@@ -95,15 +98,15 @@ Example of input hash
|
|
95
98
|
@adtext_data = @args
|
96
99
|
end
|
97
100
|
end
|
98
|
-
|
99
|
-
def save
|
101
|
+
|
102
|
+
def save
|
100
103
|
if @args[:adtext_id] #do update
|
101
|
-
|
104
|
+
|
102
105
|
else #do save
|
103
106
|
#create adtext
|
104
|
-
create
|
107
|
+
create
|
105
108
|
end
|
106
109
|
end
|
107
110
|
end
|
108
111
|
end
|
109
|
-
|
112
|
+
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
class SklikApi
|
3
3
|
module Object
|
4
|
-
def self.included(base)
|
5
|
-
base.send :extend, ClassMethods
|
6
|
-
base.send :include, InstanceMethods
|
4
|
+
def self.included(base)
|
5
|
+
base.send :extend, ClassMethods
|
6
|
+
base.send :include, InstanceMethods
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
module ClassMethods
|
10
|
-
|
10
|
+
|
11
11
|
def connection
|
12
12
|
SklikApi::Connection.connection
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def find name, id = nil
|
16
16
|
if id
|
17
17
|
args = ["list#{name.pluralize.camelize}", id]
|
@@ -23,7 +23,7 @@ class SklikApi
|
|
23
23
|
param[name.pluralize.to_sym].collect{|c| c.symbolize_keys }
|
24
24
|
}
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
27
27
|
|
28
28
|
module InstanceMethods
|
29
29
|
#get connection for request
|
@@ -39,22 +39,22 @@ class SklikApi
|
|
39
39
|
def args
|
40
40
|
@args
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def restore
|
44
|
-
begin
|
45
|
-
connection.call("#{self.class::NAME}.restore", @args[:
|
44
|
+
begin
|
45
|
+
connection.call("#{self.class::NAME}.restore", @args["#{self.class.to_s.downcase.split(":").last}_id".to_sym] ) { |param| true }
|
46
46
|
rescue Exception => e
|
47
|
-
# if there is a problem but returned Not removed
|
47
|
+
# if there is a problem but returned Not removed
|
48
48
|
# return true, becasue it says it is restored
|
49
|
-
return true if e.message == "Rescuing from request by: ArgumentError - There is error from sklik
|
49
|
+
return true if e.message == "Rescuing from request by: ArgumentError - There is error from sklik #{self.class.to_s.downcase}.restore: Not removed"
|
50
50
|
raise e
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def remove
|
55
|
-
connection.call("#{self.class::NAME}.remove", @args[:
|
55
|
+
connection.call("#{self.class::NAME}.remove", @args["#{self.class.to_s.downcase.split(":").last}_id".to_sym] ) { |param| true }
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def create
|
59
59
|
out = connection.call("#{self.class::NAME}.create", *create_args ) { |param|
|
60
60
|
param["#{self.class::NAME}Id".to_sym]
|
@@ -70,17 +70,17 @@ class SklikApi
|
|
70
70
|
def stats
|
71
71
|
@stats ||= {}
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def get_stats from, to
|
75
75
|
@stats ||= connection.call("#{self.class::NAME}.stats", @args["#{self.class.name.to_s.split("::").last.underscore}_id".to_sym], from, to ) { |param|
|
76
76
|
{:fulltext => underscore_hash_keys(param[:fulltext]), :context => underscore_hash_keys(param[:context]) }
|
77
77
|
}
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
def update_object
|
81
81
|
out = connection.call("#{self.class::NAME}.setAttributes", *update_args ) { |param| true }
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def create_args
|
85
85
|
raise(NoMethodError, "Please implement 'create_args' method in class: #{self.class} - should return array which will be placed into create method")
|
86
86
|
end
|
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.0.15"
|
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 = "
|
12
|
+
s.date = "2013-03-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 = [
|
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
s.homepage = "http://github.com/ondrejbartas/sklik-api"
|
43
43
|
s.licenses = ["MIT"]
|
44
44
|
s.require_paths = ["lib"]
|
45
|
-
s.rubygems_version = "1.8.
|
45
|
+
s.rubygems_version = "1.8.24"
|
46
46
|
s.summary = "Sklik advertising PPC api for creating campaigns"
|
47
47
|
|
48
48
|
if s.respond_to? :specification_version then
|
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.0.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: unicode
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: text
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: i18n
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :runtime
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: activesupport
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :runtime
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: rack-test
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,10 +101,15 @@ dependencies:
|
|
76
101
|
version: '0'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
80
110
|
- !ruby/object:Gem::Dependency
|
81
111
|
name: shoulda-context
|
82
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
83
113
|
none: false
|
84
114
|
requirements:
|
85
115
|
- - ! '>='
|
@@ -87,10 +117,15 @@ dependencies:
|
|
87
117
|
version: '0'
|
88
118
|
type: :development
|
89
119
|
prerelease: false
|
90
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
91
126
|
- !ruby/object:Gem::Dependency
|
92
127
|
name: turn
|
93
|
-
requirement:
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
94
129
|
none: false
|
95
130
|
requirements:
|
96
131
|
- - ~>
|
@@ -98,10 +133,15 @@ dependencies:
|
|
98
133
|
version: 0.8.2
|
99
134
|
type: :development
|
100
135
|
prerelease: false
|
101
|
-
version_requirements:
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 0.8.2
|
102
142
|
- !ruby/object:Gem::Dependency
|
103
143
|
name: minitest
|
104
|
-
requirement:
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
105
145
|
none: false
|
106
146
|
requirements:
|
107
147
|
- - ! '>='
|
@@ -109,10 +149,15 @@ dependencies:
|
|
109
149
|
version: '0'
|
110
150
|
type: :development
|
111
151
|
prerelease: false
|
112
|
-
version_requirements:
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
113
158
|
- !ruby/object:Gem::Dependency
|
114
159
|
name: ansi
|
115
|
-
requirement:
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
116
161
|
none: false
|
117
162
|
requirements:
|
118
163
|
- - ~>
|
@@ -120,10 +165,15 @@ dependencies:
|
|
120
165
|
version: 1.2.5
|
121
166
|
type: :development
|
122
167
|
prerelease: false
|
123
|
-
version_requirements:
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.2.5
|
124
174
|
- !ruby/object:Gem::Dependency
|
125
175
|
name: jeweler
|
126
|
-
requirement:
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
127
177
|
none: false
|
128
178
|
requirements:
|
129
179
|
- - ~>
|
@@ -131,10 +181,15 @@ dependencies:
|
|
131
181
|
version: 1.8.3
|
132
182
|
type: :development
|
133
183
|
prerelease: false
|
134
|
-
version_requirements:
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ~>
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: 1.8.3
|
135
190
|
- !ruby/object:Gem::Dependency
|
136
191
|
name: fakeweb
|
137
|
-
requirement:
|
192
|
+
requirement: !ruby/object:Gem::Requirement
|
138
193
|
none: false
|
139
194
|
requirements:
|
140
195
|
- - ! '>='
|
@@ -142,10 +197,15 @@ dependencies:
|
|
142
197
|
version: '0'
|
143
198
|
type: :development
|
144
199
|
prerelease: false
|
145
|
-
version_requirements:
|
200
|
+
version_requirements: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
202
|
+
requirements:
|
203
|
+
- - ! '>='
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
146
206
|
- !ruby/object:Gem::Dependency
|
147
207
|
name: thin
|
148
|
-
requirement:
|
208
|
+
requirement: !ruby/object:Gem::Requirement
|
149
209
|
none: false
|
150
210
|
requirements:
|
151
211
|
- - ! '>='
|
@@ -153,10 +213,15 @@ dependencies:
|
|
153
213
|
version: '0'
|
154
214
|
type: :development
|
155
215
|
prerelease: false
|
156
|
-
version_requirements:
|
216
|
+
version_requirements: !ruby/object:Gem::Requirement
|
217
|
+
none: false
|
218
|
+
requirements:
|
219
|
+
- - ! '>='
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
157
222
|
- !ruby/object:Gem::Dependency
|
158
223
|
name: shotgun
|
159
|
-
requirement:
|
224
|
+
requirement: !ruby/object:Gem::Requirement
|
160
225
|
none: false
|
161
226
|
requirements:
|
162
227
|
- - ! '>='
|
@@ -164,18 +229,28 @@ dependencies:
|
|
164
229
|
version: '0'
|
165
230
|
type: :development
|
166
231
|
prerelease: false
|
167
|
-
version_requirements:
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
none: false
|
234
|
+
requirements:
|
235
|
+
- - ! '>='
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: '0'
|
168
238
|
- !ruby/object:Gem::Dependency
|
169
239
|
name: rcov
|
170
|
-
requirement:
|
240
|
+
requirement: !ruby/object:Gem::Requirement
|
171
241
|
none: false
|
172
242
|
requirements:
|
173
|
-
- - =
|
243
|
+
- - '='
|
174
244
|
- !ruby/object:Gem::Version
|
175
245
|
version: 0.9.10
|
176
246
|
type: :development
|
177
247
|
prerelease: false
|
178
|
-
version_requirements:
|
248
|
+
version_requirements: !ruby/object:Gem::Requirement
|
249
|
+
none: false
|
250
|
+
requirements:
|
251
|
+
- - '='
|
252
|
+
- !ruby/object:Gem::Version
|
253
|
+
version: 0.9.10
|
179
254
|
description: Sklik advertising PPC api for creating campaigns and updating them when
|
180
255
|
they runs
|
181
256
|
email: ondrej@bartas.cz
|
@@ -221,7 +296,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
221
296
|
version: '0'
|
222
297
|
segments:
|
223
298
|
- 0
|
224
|
-
hash:
|
299
|
+
hash: -2058175083174565127
|
225
300
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
226
301
|
none: false
|
227
302
|
requirements:
|
@@ -230,7 +305,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
305
|
version: '0'
|
231
306
|
requirements: []
|
232
307
|
rubyforge_project:
|
233
|
-
rubygems_version: 1.8.
|
308
|
+
rubygems_version: 1.8.24
|
234
309
|
signing_key:
|
235
310
|
specification_version: 3
|
236
311
|
summary: Sklik advertising PPC api for creating campaigns
|