sklik-api 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.15
1
+ 0.0.16
@@ -130,7 +130,11 @@ Example of input hash
130
130
  @campaign_data
131
131
  else
132
132
  @campaign_data = @args
133
- @campaign_data[:ad_groups] = Adgroup.find(self).collect{|a| a.to_hash}
133
+ if @args[:status] != :stopped
134
+ @campaign_data[:ad_groups] = Adgroup.find(self).collect{|a| a.to_hash}
135
+ else
136
+ @campaign_data[:ad_groups] = []
137
+ end
134
138
  @campaign_data
135
139
  end
136
140
  end
@@ -259,6 +263,8 @@ Example of input hash
259
263
  #remove it if new status is stopped or status doesn't changed and before it was stopped
260
264
  remove if (@args[:status] == :stopped) || (@args[:status].nil? && before_status == :stopped)
261
265
 
266
+ raise ArgumentError, "Problem with updating campaign datas #{@errors}" unless @errors.size == 0
267
+
262
268
  return true
263
269
  else #do save
264
270
  #create campaign
@@ -100,8 +100,13 @@ Example of input hash
100
100
  @adgroup_data
101
101
  else
102
102
  @adgroup_data = @args
103
- @adgroup_data[:ads] = Adtext.find(self).collect{|a| a.to_hash}
104
- @adgroup_data[:keywords] = Keyword.find(self).collect{|k| k.to_hash}
103
+ if @args[:status] != :stopped
104
+ @adgroup_data[:ads] = Adtext.find(self).collect{|a| a.to_hash}
105
+ @adgroup_data[:keywords] = Keyword.find(self).collect{|k| k.to_hash}
106
+ else
107
+ @adgroup_data[:ads] = []
108
+ @adgroup_data[:keywords] = []
109
+ end
105
110
  @adgroup_data
106
111
  end
107
112
  end
@@ -169,24 +174,21 @@ Example of input hash
169
174
  ############
170
175
  ## KEYWORDS
171
176
  ############
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
177
 
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
178
+ #update keywords
179
+ keywords_error = []
180
+ @new_keywords = @keywords.clone
181
+ delete_first = true
182
+ while @new_keywords && @new_keywords.size > 0 do
183
+ begin
184
+ connection.call('keywords.set', @args[:adgroup_id], @new_keywords[0..199].collect{|k| k.create_args.last }, delete_first) do |params|
185
+ @campaign.errors << params[:statusMessage] if params[:statusMessage] != "OK"
186
+ end
187
+ rescue Exception => e
188
+ @campaign.errors << e.message
189
+ end
190
+ @new_keywords = @new_keywords[200..-1]
191
+ delete_first = false
190
192
  end
191
193
 
192
194
  ############
@@ -199,13 +201,24 @@ Example of input hash
199
201
 
200
202
  #adtexts to be deleted
201
203
  (@saved_adtexts.keys - @new_adtexts.keys).each do |k|
204
+ puts "deleting adtext #{@saved_adtexts[k]} in #{@args[:name]}"
202
205
  #don't try to remove already removed adtext
203
206
  @saved_adtexts[k].remove unless @saved_adtexts[k].args[:status] == :stopped
204
207
  end
205
208
 
206
209
  #adtexts to be created
207
210
  (@new_adtexts.keys - @saved_adtexts.keys).each do |k|
208
- @new_adtexts[k].save
211
+ puts "creating new adtext #{k} in #{@args[:name]}"
212
+ begin
213
+ @new_adtexts[k].save
214
+ rescue Exception => e
215
+ #take care about error message -> do it nicer
216
+ if /There is error from sklik ad.create: Invalid parameters/ =~ e.message
217
+ @campaign.errors << "Problem with creating #{@new_adtexts[k].args} in adgroup #{@args[:name]}"
218
+ else
219
+ @campaign.errors << e.message
220
+ end
221
+ end
209
222
  end
210
223
 
211
224
  #check status to be running
@@ -235,18 +248,20 @@ Example of input hash
235
248
 
236
249
  #create keywords
237
250
  keywords_error = []
238
- @keywords.each do |keyword|
251
+ @new_keywords = @keywords.clone
252
+ delete_first = true
253
+ while @new_keywords && @new_keywords.size > 0 do
239
254
  begin
240
- keyword.save
241
- rescue Exception => e
242
- #take care about error message -> do it nicer
243
- if /Sklik returned: keyword.create: Invalid data in request/ =~ e.message
244
- keywords_error << e.message.split("{:name=>\"").last.split("\", :matchType").first
245
- else
246
- @campaign.errors << e.message
255
+ connection.call('keywords.set', @args[:adgroup_id], @new_keywords[0..199].collect{|k| k.create_args.last }, delete_first) do |params|
256
+ @campaign.errors << params[:statusMessage] if params[:statusMessage] != "OK"
247
257
  end
258
+ rescue Exception => e
259
+ @campaign.errors << e.message
248
260
  end
261
+ @new_keywords = @new_keywords[200..-1]
262
+ delete_first = false
249
263
  end
264
+
250
265
  if keywords_error.size > 0
251
266
  @campaign.errors << "Problem with creating keywords: #{keywords_error.join(", ")} in adgroup #{@args[:name]}"
252
267
  end
data/sklik-api.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "sklik-api"
8
- s.version = "0.0.15"
8
+ s.version = "0.0.16"
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"]
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.15
4
+ version: 0.0.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -296,7 +296,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
296
296
  version: '0'
297
297
  segments:
298
298
  - 0
299
- hash: -2058175083174565127
299
+ hash: -3350698988788175861
300
300
  required_rubygems_version: !ruby/object:Gem::Requirement
301
301
  none: false
302
302
  requirements: