sklik-api 0.0.2 → 0.0.3
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 +53 -2
- data/lib/sklik-api/sklik_object.rb +20 -1
- data/sklik-api.gemspec +2 -2
- data/test/unit/campaign.rb +32 -6
- metadata +33 -33
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/sklik-api/campaign.rb
CHANGED
@@ -64,6 +64,7 @@ Example of input hash
|
|
64
64
|
if args[:campaign_id].nil? || (args[:campaign_id] && args[:campaign_id].to_i == campaign[:id].to_i)
|
65
65
|
out << Campaign.new(
|
66
66
|
:campaign_id => campaign[:id],
|
67
|
+
:customer_id => args[:customer_id],
|
67
68
|
:budget => campaign[:dayBudget].to_f/100.0,
|
68
69
|
:name => campaign[:name],
|
69
70
|
:status => fix_status(campaign)
|
@@ -84,6 +85,16 @@ Example of input hash
|
|
84
85
|
return :unknown
|
85
86
|
end
|
86
87
|
end
|
88
|
+
|
89
|
+
def status_for_update
|
90
|
+
if @args[:status] == :running
|
91
|
+
return "active"
|
92
|
+
elsif @args[:status] == :paused
|
93
|
+
return "suspend"
|
94
|
+
else
|
95
|
+
return nil
|
96
|
+
end
|
97
|
+
end
|
87
98
|
|
88
99
|
def to_hash
|
89
100
|
if @campaign_data
|
@@ -95,6 +106,23 @@ Example of input hash
|
|
95
106
|
end
|
96
107
|
end
|
97
108
|
|
109
|
+
def update_args
|
110
|
+
out = []
|
111
|
+
|
112
|
+
#add campaign id on which will be performed update
|
113
|
+
out << @args[:campaign_id]
|
114
|
+
|
115
|
+
#prepare campaign struct
|
116
|
+
args = {}
|
117
|
+
args[:name] = @args[:name] if @args[:name]
|
118
|
+
args[:status] = status_for_update if status_for_update
|
119
|
+
args[:dayBudget] = (@args[:budget] * 100).to_i if @args[:budget]
|
120
|
+
args[:context] = @args[:network_setting][:context] ||= true if @args[:network_setting]
|
121
|
+
out << args
|
122
|
+
|
123
|
+
out
|
124
|
+
end
|
125
|
+
|
98
126
|
def create_args
|
99
127
|
out = []
|
100
128
|
|
@@ -107,14 +135,37 @@ Example of input hash
|
|
107
135
|
|
108
136
|
#add customer id on which account campaign should be created
|
109
137
|
out << @customer_id if @customer_id
|
110
|
-
pp @customer_id
|
111
|
-
pp out
|
112
138
|
out
|
113
139
|
end
|
140
|
+
|
141
|
+
def self.get_current_status args = {}
|
142
|
+
raise ArgumentError, "Campaign_id is required" unless args[:campaign_id]
|
143
|
+
campaigns = self.find(args)
|
144
|
+
pp campaigns
|
145
|
+
if campaigns.size == 1
|
146
|
+
campaigns.first.args[:status]
|
147
|
+
else
|
148
|
+
raise ArgumentError, "Campaign by #{args.inspect} couldn't be found!"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def get_current_status
|
153
|
+
self.class.get_current_status :campaign_id => @args[:campaign_id], :customer_id => @customer_id
|
154
|
+
end
|
114
155
|
|
115
156
|
def save
|
116
157
|
if @args[:campaign_id] #do update
|
158
|
+
#get current status of campaign
|
159
|
+
before_status = get_current_status
|
160
|
+
|
161
|
+
#restore campaign before update
|
162
|
+
restore if before_status == :stopped
|
163
|
+
|
164
|
+
#update campaign
|
165
|
+
update
|
117
166
|
|
167
|
+
#remove it if new status is stopped or status doesn't changed and before it was stopped
|
168
|
+
remove if (@args[:status] == :stopped) || (@args[:status].nil? && before_status == :stopped)
|
118
169
|
else #do save
|
119
170
|
#create campaign
|
120
171
|
create
|
@@ -39,7 +39,16 @@ class SklikApi
|
|
39
39
|
def args
|
40
40
|
@args
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
|
+
def restore
|
44
|
+
connection.call("#{self.class::NAME}.restore", @args[:campaign_id] ) { |param| true }
|
45
|
+
end
|
46
|
+
|
47
|
+
def remove
|
48
|
+
pp "REMOVING!: #{@args[:campaign_id]}"
|
49
|
+
connection.call("#{self.class::NAME}.remove", @args[:campaign_id] ) { |param| true }
|
50
|
+
end
|
51
|
+
|
43
52
|
def create
|
44
53
|
out = connection.call("#{self.class::NAME}.create", *create_args ) { |param|
|
45
54
|
param["#{self.class::NAME}Id".to_sym]
|
@@ -48,10 +57,20 @@ class SklikApi
|
|
48
57
|
@args
|
49
58
|
end
|
50
59
|
|
60
|
+
def update
|
61
|
+
pp "updating!!!"
|
62
|
+
pp update_args
|
63
|
+
out = connection.call("#{self.class::NAME}.setAttributes", *update_args ) { |param| true }
|
64
|
+
end
|
65
|
+
|
51
66
|
def create_args
|
52
67
|
raise(NoMethodError, "Please implement 'create_args' method in class: #{self.class} - should return array which will be placed into create method")
|
53
68
|
end
|
54
69
|
|
70
|
+
def update_args
|
71
|
+
raise(NoMethodError, "Please implement 'update_args' method in class: #{self.class} - should return array which will be placed into update method")
|
72
|
+
end
|
73
|
+
|
55
74
|
def to_hash
|
56
75
|
raise(NoMethodError, "Please implement 'to_hash' method in class: #{self.class} - should return hash which contains all data")
|
57
76
|
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.3"
|
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 = "2012-03-
|
12
|
+
s.date = "2012-03-26"
|
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/unit/campaign.rb
CHANGED
@@ -84,11 +84,10 @@ class CampaignTest < Test::Unit::TestCase
|
|
84
84
|
@campaign.save
|
85
85
|
end
|
86
86
|
|
87
|
-
should "
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
should "be created with right parameters" do
|
87
|
+
should "be created with right parameters and updated" do
|
88
|
+
|
89
|
+
assert_equal @campaign.args[:status], :running, "Must be running"
|
90
|
+
|
92
91
|
campaigns = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id])
|
93
92
|
campaign_hash = campaigns.first.to_hash
|
94
93
|
assert_equal campaign_hash[:campaign_id], @campaign.args[:campaign_id], "campaign id should be same"
|
@@ -96,8 +95,35 @@ class CampaignTest < Test::Unit::TestCase
|
|
96
95
|
assert_equal campaign_hash[:budget].to_f, @test_campaign_hash[:budget].to_f, "budgets should be same"
|
97
96
|
assert_equal campaign_hash[:name], @test_campaign_hash[:name], "campaign name should be same"
|
98
97
|
assert_equal campaign_hash[:ad_groups].size, @test_campaign_hash[:ad_groups].size, "campaign ad_groups should have same count"
|
98
|
+
|
99
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
100
|
+
new_name = "Test of updated campaign name- #{Time.now.strftime("%Y.%m.%d %H:%M:%S")}"
|
101
|
+
campaign.args[:name] = new_name
|
102
|
+
campaign.save
|
103
|
+
campaign_hash = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first.to_hash
|
104
|
+
assert_equal campaign_hash[:name], new_name, "campaign name should be same"
|
105
|
+
|
106
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
107
|
+
campaign.args[:status] = :paused
|
108
|
+
campaign.save
|
109
|
+
campaign_hash = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first.to_hash
|
110
|
+
assert_equal campaign_hash[:status], :paused, "campaign should be paused"
|
111
|
+
|
112
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
113
|
+
campaign.args[:status] = :stopped
|
114
|
+
puts "STOPPINGGGGGG"
|
115
|
+
campaign.save
|
116
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
117
|
+
assert_equal campaign.args[:status], :stopped, "campaign should be stopped"
|
118
|
+
|
119
|
+
campaign = SklikApi::Campaign.find(:customer_id => @campaign.args[:customer_id], :campaign_id => @campaign.args[:campaign_id]).first
|
120
|
+
campaign.args[:status] = :paused
|
121
|
+
puts "PAUSINGGGGGGG"
|
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], :paused, "campaign should be paused"
|
125
|
+
|
99
126
|
end
|
100
127
|
end
|
101
|
-
|
102
128
|
end
|
103
129
|
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.0.3
|
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: 2012-03-
|
12
|
+
date: 2012-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70320103849080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70320103849080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: unicode
|
27
|
-
requirement: &
|
27
|
+
requirement: &70320103848400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.4.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70320103848400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: text
|
38
|
-
requirement: &
|
38
|
+
requirement: &70320103882000 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.2.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70320103882000
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: i18n
|
49
|
-
requirement: &
|
49
|
+
requirement: &70320103881400 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.6.0
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70320103881400
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: activesupport
|
60
|
-
requirement: &
|
60
|
+
requirement: &70320103880680 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 3.1.0
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70320103880680
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rack-test
|
71
|
-
requirement: &
|
71
|
+
requirement: &70320103880000 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70320103880000
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: shoulda-context
|
82
|
-
requirement: &
|
82
|
+
requirement: &70320103879440 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70320103879440
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: turn
|
93
|
-
requirement: &
|
93
|
+
requirement: &70320103878840 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 0.8.2
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70320103878840
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: minitest
|
104
|
-
requirement: &
|
104
|
+
requirement: &70320103878300 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70320103878300
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: ansi
|
115
|
-
requirement: &
|
115
|
+
requirement: &70320103877640 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ~>
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: 1.2.5
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70320103877640
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: jeweler
|
126
|
-
requirement: &
|
126
|
+
requirement: &70320103876920 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ~>
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: 1.8.3
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70320103876920
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: fakeweb
|
137
|
-
requirement: &
|
137
|
+
requirement: &70320103876320 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70320103876320
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: thin
|
148
|
-
requirement: &
|
148
|
+
requirement: &70320103875700 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ! '>='
|
@@ -153,10 +153,10 @@ dependencies:
|
|
153
153
|
version: '0'
|
154
154
|
type: :development
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *70320103875700
|
157
157
|
- !ruby/object:Gem::Dependency
|
158
158
|
name: shotgun
|
159
|
-
requirement: &
|
159
|
+
requirement: &70320103875120 !ruby/object:Gem::Requirement
|
160
160
|
none: false
|
161
161
|
requirements:
|
162
162
|
- - ! '>='
|
@@ -164,10 +164,10 @@ dependencies:
|
|
164
164
|
version: '0'
|
165
165
|
type: :development
|
166
166
|
prerelease: false
|
167
|
-
version_requirements: *
|
167
|
+
version_requirements: *70320103875120
|
168
168
|
- !ruby/object:Gem::Dependency
|
169
169
|
name: rcov
|
170
|
-
requirement: &
|
170
|
+
requirement: &70320103895060 !ruby/object:Gem::Requirement
|
171
171
|
none: false
|
172
172
|
requirements:
|
173
173
|
- - =
|
@@ -175,7 +175,7 @@ dependencies:
|
|
175
175
|
version: 0.9.10
|
176
176
|
type: :development
|
177
177
|
prerelease: false
|
178
|
-
version_requirements: *
|
178
|
+
version_requirements: *70320103895060
|
179
179
|
description: Sklik advertising PPC api for creating campaigns and updating them when
|
180
180
|
they runs
|
181
181
|
email: ondrej@bartas.cz
|
@@ -222,7 +222,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
222
222
|
version: '0'
|
223
223
|
segments:
|
224
224
|
- 0
|
225
|
-
hash:
|
225
|
+
hash: 291056950167711620
|
226
226
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
227
227
|
none: false
|
228
228
|
requirements:
|