sklik-api 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -59,7 +59,7 @@ Example of input hash
59
59
  #initialize adgroups
60
60
  @adtexts = []
61
61
  if args[:ads] && args[:ads].size > 0
62
- args[:ads].each do |adtext|
62
+ args[:ads].select{|a| !a.nil? }.each do |adtext|
63
63
  @adtexts << SklikApi::Adtext.new(adtext.merge(:adgroup => self))
64
64
  end
65
65
  end
@@ -67,9 +67,11 @@ Example of input hash
67
67
  #initialize adgroups
68
68
  @keywords = []
69
69
  if args[:keywords] && args[:keywords].size > 0
70
- args[:keywords].each do |keyword|
70
+ args[:keywords].select{|k| !k.nil? }.each do |keyword|
71
71
  if keyword.is_a?(Hash)
72
72
  @keywords << SklikApi::Keyword.new(keyword.merge(:adgroup => self))
73
+ elsif keyword.is_a?(SklikApi::Keyword)
74
+ @keywords << SklikApi::Keyword.new(:keyword => keyword.args[:keyword] || keyword.args[:name], :adgroup => self)
73
75
  else
74
76
  @keywords << SklikApi::Keyword.new(:keyword => keyword, :adgroup => self)
75
77
  end
@@ -324,57 +326,62 @@ Example of input hash
324
326
  ## KEYWORDS
325
327
  ############
326
328
 
327
- #update keywords
328
- keywords_error = []
329
- @new_keywords = @keywords.clone
330
- delete_first = true
331
- while @new_keywords && @new_keywords.size > 0 do
332
- begin
333
- connection.call('keywords.set', @args[:adgroup_id], @new_keywords[0..199].collect{|k| k.create_args.last }, delete_first) do |params|
334
- log_error params[:statusMessage] if params[:statusMessage] != "OK"
329
+ #update keywords only when setted
330
+ if @keywords.size > 0
331
+ #update keywords
332
+ keywords_error = []
333
+ @new_keywords = @keywords.clone
334
+ delete_first = true
335
+ while @new_keywords && @new_keywords.size > 0 do
336
+ begin
337
+ connection.call('keywords.set', @args[:adgroup_id], @new_keywords[0..199].collect{|k| k.create_args.last }, delete_first) do |params|
338
+ log_error params[:statusMessage] if params[:statusMessage] != "OK"
339
+ end
340
+ rescue Exception => e
341
+ log_error e.message
335
342
  end
336
- rescue Exception => e
337
- log_error e.message
343
+ @new_keywords = @new_keywords[200..-1]
344
+ delete_first = false
338
345
  end
339
- @new_keywords = @new_keywords[200..-1]
340
- delete_first = false
341
346
  end
342
347
 
343
348
  ############
344
349
  ## ADTEXTS
345
350
  ############
351
+
352
+ #update adtexts only when setted
353
+ if @adtexts.size > 0
354
+ #create new adtexts and delete old
355
+ @saved_adtexts = adtexts.inject({}){|o,a| o[a.uniq_identifier] = a ; o}
356
+ @new_adtexts = @adtexts.inject({}){|o,a| o[a.uniq_identifier] = a ; o}
357
+
358
+ #adtexts to be deleted
359
+ (@saved_adtexts.keys - @new_adtexts.keys).each do |k|
360
+ puts "deleting adtext #{@saved_adtexts[k]} in #{@args[:name]}"
361
+ #don't try to remove already removed adtext
362
+ @saved_adtexts[k].remove unless @saved_adtexts[k].args[:status] == :stopped
363
+ end
346
364
 
347
- #create new adtexts and delete old
348
- @saved_adtexts = adtexts.inject({}){|o,a| o[a.uniq_identifier] = a ; o}
349
- @new_adtexts = @adtexts.inject({}){|o,a| o[a.uniq_identifier] = a ; o}
350
-
351
- #adtexts to be deleted
352
- (@saved_adtexts.keys - @new_adtexts.keys).each do |k|
353
- puts "deleting adtext #{@saved_adtexts[k]} in #{@args[:name]}"
354
- #don't try to remove already removed adtext
355
- @saved_adtexts[k].remove unless @saved_adtexts[k].args[:status] == :stopped
356
- end
357
-
358
- #adtexts to be created
359
- (@new_adtexts.keys - @saved_adtexts.keys).each do |k|
360
- puts "creating new adtext #{k} in #{@args[:name]}"
361
- begin
362
- @new_adtexts[k].save
363
- rescue Exception => e
364
- #take care about error message -> do it nicer
365
- if /There is error from sklik ad.create: Invalid parameters/ =~ e.message
366
- log_error "Problem with creating #{@new_adtexts[k].args} in adgroup #{@args[:name]}"
367
- else
368
- log_error e.message
365
+ #adtexts to be created
366
+ (@new_adtexts.keys - @saved_adtexts.keys).each do |k|
367
+ puts "creating new adtext #{k} in #{@args[:name]}"
368
+ begin
369
+ @new_adtexts[k].save
370
+ rescue Exception => e
371
+ #take care about error message -> do it nicer
372
+ if /There is error from sklik ad.create: Invalid parameters/ =~ e.message
373
+ log_error "Problem with creating #{@new_adtexts[k].args} in adgroup #{@args[:name]}"
374
+ else
375
+ log_error e.message
376
+ end
369
377
  end
370
378
  end
371
- end
372
379
 
373
- #check status to be running
374
- (@new_adtexts.keys & @saved_adtexts.keys).each do |k|
375
- @saved_adtexts[k].restore if @saved_adtexts[k].args[:status] == :stopped
380
+ #check status to be running
381
+ (@new_adtexts.keys & @saved_adtexts.keys).each do |k|
382
+ @saved_adtexts[k].restore if @saved_adtexts[k].args[:status] == :stopped
383
+ end
376
384
  end
377
-
378
385
  rescue Exception => e
379
386
  log_error e.message
380
387
  end
@@ -95,7 +95,7 @@ Example of input hash
95
95
  end
96
96
 
97
97
  def strip_match_type keyword
98
- keyword.gsub(/(\[|\]|\")/, "").gsub(/^-/, "")
98
+ "#{keyword}".gsub(/(\[|\]|\")/, "").gsub(/^-/, "")
99
99
  end
100
100
 
101
101
  def get_math_type keyword
@@ -203,7 +203,8 @@ Example of input hash
203
203
  if @keyword_data
204
204
  @keyword_data
205
205
  else
206
- @keyword_data = @args end
206
+ @keyword_data = @args
207
+ end
207
208
  end
208
209
 
209
210
 
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.1.4"
8
+ s.version = "0.1.5"
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-06-26"
12
+ s.date = "2013-07-16"
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 = [
data/test/helper.rb CHANGED
@@ -18,5 +18,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
18
18
  require 'sklik-api'
19
19
  require './test/fake_web'
20
20
 
21
+ SklikApi.logger = Logger.new('log/sklik_api_test.log')
22
+
21
23
  class Test::Unit::TestCase
22
24
  end
@@ -56,15 +56,16 @@ class AdgroupTest < Test::Unit::TestCase
56
56
  end
57
57
 
58
58
  should "be found/get by id" do
59
- adgroup = SklikApi::Adgroup.get(7053769)
59
+ adgroup_id = SklikApi::Campaign.find(@campaign.args[:campaign_id]).adgroups.first.args[:adgroup_id]
60
+ adgroup = SklikApi::Adgroup.get(adgroup_id)
60
61
  assert_not_nil adgroup
61
62
  assert adgroup.is_a?(SklikApi::Adgroup), "return SklikApi::Adgroup"
62
63
 
63
- adgroup = SklikApi::Adgroup.find(adgroup_id: 7053769).first
64
+ adgroup = SklikApi::Adgroup.find(adgroup_id: adgroup_id).first
64
65
  assert_not_nil adgroup
65
66
  assert adgroup.is_a?(SklikApi::Adgroup), "return SklikApi::Adgroup"
66
67
 
67
- adgroup = SklikApi::Adgroup.find(campaign_id: 'doesnt matter', adgroup_id: 7053769).first
68
+ adgroup = SklikApi::Adgroup.find(campaign_id: 'doesnt matter', adgroup_id: adgroup_id).first
68
69
  assert_not_nil adgroup
69
70
  assert adgroup.is_a?(SklikApi::Adgroup), "return SklikApi::Adgroup"
70
71
  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.1.4
4
+ version: 0.1.5
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-06-26 00:00:00.000000000 Z
12
+ date: 2013-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -304,7 +304,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
304
304
  version: '0'
305
305
  segments:
306
306
  - 0
307
- hash: -67005859409429857
307
+ hash: 4110349452567973535
308
308
  required_rubygems_version: !ruby/object:Gem::Requirement
309
309
  none: false
310
310
  requirements: