sklik-api 0.1.0 → 0.1.1

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/LICENSE.txt CHANGED
@@ -1,4 +1,5 @@
1
- Copyright (c) 2012 Ondrej Bartas
1
+ Copyright (c) 2012-2013 Ondrej Bartas
2
+ Copyright (c) 2012-2013 Ataxo Interactive s.r.o.
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining
4
5
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -9,32 +9,268 @@ Gemfile.rb
9
9
  gem "sklik-api", :require => "sklik-api"
10
10
  ```
11
11
 
12
+ initializers/sklik-api.rb
13
+ ```ruby
12
14
 
15
+ # Set logger for SklikApi - default is to STDOUT
16
+ SklikApi.logger = Logger.new("log/sklik-api.log")
13
17
 
14
- # Usage
18
+ # when something goes wrong in creation of campaing/adgroup
19
+ # return errors and automatically rename (campaign/adgroup) with name to:
20
+ # name + FAILED CREATION + Timestamp
21
+ # and then remove it
22
+ SklikApi.use_rollback = true
23
+ #this setting can be changed on the fly!
15
24
 
16
- Campaign creation
17
25
 
26
+ # you can set it before every action to sklik api, if you have multiple accounts :-)
27
+ SklikApi::Access.set(
28
+ :email => "your_email@seznam.cz",
29
+ :password => "password",
30
+ # :customer_id => 1112 # (optional) - this will switch you into connected account and all creation will be performed there
31
+ )
32
+ #this setting can be changed on the fly!
33
+ ```
34
+
35
+ # Usage
36
+
37
+ Look at documentation on [Sklik Api](http://api.sklik.cz).
38
+
39
+ In SklikApi you have this hierarchy
40
+ * account
41
+ * campaign
42
+ * adgroup
43
+ * adtext
44
+ * keyword
45
+
46
+ # Basic usage
47
+
48
+ ## Find
49
+
50
+ Find methods (on Campaign, Adgroup, Adtext, Keyword)
51
+ ``` ruby
52
+ # get by campaign id
53
+ SklikApi::Campaign.get(123456)
54
+ #=> <SklikApi::Campaign:..>
55
+
56
+ # same as
57
+ SklikApi::Campaign.find(123456)
58
+ #=> <SklikApi::Campaign:..>
59
+
60
+ # with ID by hash - but it will return array!!! All finds by hash params will return array!
61
+ SklikApi::Campaign.find( campaign_id: 123456 )
62
+ #=> [<SklikApi::Campaign:..>]
63
+
64
+ # without ID and no specification - get all campaigns on logged account
65
+ SklikApi::Campaign.find()
66
+ #=> [<SklikApi::Campaign:..>,<SklikApi::Campaign:..>]
67
+
68
+ # without ID and with customer_id - get all campaigns on specified account
69
+ SklikApi::Campaign.find( customer_id: 222333 )
70
+ #=> [<SklikApi::Campaign:..>,<SklikApi::Campaign:..>]
71
+ ```
72
+
73
+ You can filter response array directly in find method by status and name (if object has it)
74
+
75
+ * Find for campaigns needs to be privided with customer_id = nil || account id
76
+ * Find for adgroups needs to be privided with campaign_id
77
+ * Find for adtexts and keywords needs to be privided with adgroup_id
78
+
79
+ # Basic usage
80
+
81
+ ## Save
82
+
83
+ Thera are tow ways how to save thing in Sklik Api:
84
+ * hierarchical - complete structure of for example adgroup with adtexts and keywords
85
+ * per item - one item in time creating adgroup, then keyword etc.
86
+
87
+ ### Hierarchical
88
+
89
+ You will provide all data in one hash:
18
90
  ``` ruby
19
91
  campaign_hash = {
20
92
  :name => "name of your campaign",
93
+ :budget => 15.4, # budget is in CZK and in float
94
+ :customer_id => 123456, #optional without specifying it will be created on logged account
95
+
96
+ :status => :running, # [:paused, :stopped] - other options
97
+
98
+ :excluded_search_services = [ # (optional) specify search services you don't want to use for your campaign
99
+ 2,3
100
+ ],
101
+
102
+ :network_setting => {
103
+ :content => true
104
+ }
105
+
106
+ :ad_groups => [
107
+ {
108
+ :name => "my adgroup name",
109
+ :cpc => 3.5, # cpc is in CZK and in float and is set for adgroup
110
+ :ads => [
111
+ {
112
+ :headline => "Super headline",
113
+ :description1 => "Trying to do ",
114
+ :description2 => "best description ever",
115
+ :display_url => "bartas.cz",
116
+ :url => "http://www.bartas.cz",
117
+ :status => :paused,
118
+ }
119
+ ],
120
+ :keywords => [
121
+ "\"some funny keyword\"",
122
+ "[myphrase keyword]",
123
+ "my broad keyword for me",
124
+ "test of diarcritics âô"
125
+ ]
126
+ }
127
+ ]
128
+ }
129
+
130
+ campaign = SklikApi::Campaign.new(campaign_hash)
131
+ unless campaign.save
132
+ # print errors when something went wrong
133
+ puts campaign.errors
134
+ end
135
+ ```
136
+
137
+ It this way, when some error ocures in adtext creation then all errors
138
+ are posted from adtext to adgroup. and then from adgroup to campaign.
139
+
140
+ This will help you to fetch errors only on campaign (or on level where you hit save) level.
141
+
142
+ __Be aware of use_rollback setting.__
143
+ * for example adtext got error, then it will buble from adtext to campaign
144
+ and then will rollback this campaign (if you save campaing,
145
+ if you performed this save on adgroup level, then adgroup will be rollbacked).
146
+ _In errors you will have answer for what went wrong._
147
+
148
+ ### Per Item
149
+
150
+ You will create items by yourself:
151
+
152
+ ``` ruby
153
+ campaign_hash = {
154
+ :name => "name of your campaign",
155
+ :budget => 15.4, # budget is in CZK and in float
156
+ :customer_id => 123456, #optional without specifying it will be created on logged account
157
+
158
+ :status => :running, # [:paused, :stopped] - other options
159
+
160
+ :excluded_search_services = [ # (optional) specify search services you don't want to use for your campaign
161
+ 2,3
162
+ ],
163
+
164
+ :network_setting => {
165
+ :content => true
166
+ }
167
+ }
168
+ campaign = SklikApi::Campaign.new(campaign_hash)
169
+ #first save campaign
170
+ campaign.save
171
+
172
+ adgroup_hash = {
173
+ #you need to set parent, where adgroup should be created (campaing_id)
174
+ :campaign_id => campaign.args[:campaign_id],
175
+
176
+ :name => "my adgroup name",
21
177
  :cpc => 3.5, # cpc is in CZK and in float and is set for adgroup
22
- :budget => 15.4, # budget is in CZK and in float
178
+ }
179
+
180
+ adgroup = SklikApi::Adgroup.new(adgroup_hash)
181
+ #then save adgroup
182
+ adgroup.save
183
+
184
+ adtext_hash = {
185
+ #you need to set parent, where adtext should be created (adgroup_id)
186
+ :adgroup_id => adgroup.args[:adgroup_id],
187
+
188
+ :headline => "Super headline",
189
+ :description1 => "Trying to do ",
190
+ :description2 => "best description ever",
191
+ :display_url => "bartas.cz",
192
+ :url => "http://www.bartas.cz",
193
+ :status => :paused,
194
+ }
195
+
196
+ adtext = SklikApi::Adtext.new(adtext_hash)
197
+ #then save adgroup
198
+ adtext.save
199
+
200
+ keyword_hash = {
201
+ #you need to set parent, where adtext should be created (adgroup_id)
202
+ :adgroup_id => adgroup.args[:adgroup_id],
203
+
204
+ :keyword => "\"some funny keyword\""
205
+ }
206
+
207
+ keyword = SklikApi::Keyword.new(keyword_hash)
208
+ #then save adgroup
209
+ keyword.save
210
+
211
+ ```
212
+ This is little bit pain in the ass, but sometimes you need full controll of the way how it is done.
213
+
214
+ ## Find
215
+
216
+ Find methods (on Campaign, Adgroup, Adtext, Keyword)
217
+
218
+ ``` ruby
219
+ # get by campaign id
220
+ SklikApi::Campaign.get(123456)
221
+ #=> <SklikApi::Campaign:..>
222
+
223
+ # same as
224
+ SklikApi::Campaign.find(123456)
225
+ #=> <SklikApi::Campaign:..>
226
+
227
+ # with ID by hash - but it will return array!!! All finds by hash params will return array!
228
+ SklikApi::Campaign.find( campaign_id: 123456 )
229
+ #=> [<SklikApi::Campaign:..>]
230
+
231
+ # without ID and no specification - get all campaigns on logged account
232
+ SklikApi::Campaign.find()
233
+ #=> [<SklikApi::Campaign:..>,<SklikApi::Campaign:..>]
234
+
235
+ # without ID and with customer_id - get all campaigns on specified account
236
+ SklikApi::Campaign.find( customer_id: 222333 )
237
+ #=> [<SklikApi::Campaign:..>,<SklikApi::Campaign:..>]
238
+ ```
239
+
240
+ You can filter response array directly in find method by status and name (if object has it)
241
+
242
+ * Find for campaigns needs to be privided with customer_id = nil || account id
243
+ * Find for adgroups needs to be privided with campaign_id
244
+ * Find for adtexts and keywords needs to be privided with adgroup_id
245
+
246
+
247
+ ## Account
248
+
249
+ mostly used for getting remaining wallet information and global statistics for whole account.
250
+
251
+ ## Campaign
252
+
253
+ ``` ruby
254
+ campaign_hash = {
255
+ :name => "name of your campaign",
256
+ :cpc => 3.5, # cpc is in CZK and in float and is set for adgroup
257
+ :budget => 15.4, # budget is in CZK and in float
23
258
  :customer_id => 123456, #optional without specifying it will be created on logged account
24
-
259
+
260
+ :status => :running, # [:paused, :stopped] - other options
261
+
25
262
  :excluded_search_services = [ # (optional) specify search services you don't want to use for your campaign
26
263
  2,3
27
264
  ],
28
-
265
+
29
266
  :network_setting => {
30
- :content => true,
31
- :search => true
32
- },
33
-
267
+ :content => true
268
+ }
269
+
34
270
  :ad_groups => [
35
271
  {
36
272
  :name => "my adgroup name",
37
- :ads => [
273
+ :ads => [
38
274
  {
39
275
  :headline => "Super headline",
40
276
  :description1 => "Trying to do ",
@@ -53,21 +289,19 @@ campaign_hash = {
53
289
  ]
54
290
  }
55
291
 
56
- # This model also support additional params:
57
- # :excluded_search_services, :excluded_urls, :total_budget, :total_clicks,
58
- # :ad_selection, :start_date, :end_date, :status, :premise_id
292
+ # This model also support additional params:
293
+ # :excluded_search_services, :excluded_urls, :total_budget, :total_clicks,
294
+ # :ad_selection, :start_date, :end_date, :premise_id
59
295
  # Please look into documentation of api.sklik.cz
60
296
  # http://api.sklik.cz/campaign.create.html
61
297
 
62
- #you can set it before every action to sklik api, if you have multiple accounts :-)
63
- SklikApi::Access.set(
64
- :email => "your_email@seznam.cz",
65
- :password => "password"
66
- )
67
-
68
298
  # this will create campaign object and do save to sklik advertising system
69
299
  # if you have more than one account where to save your campaigns -> set customer_id where campaign will be created
70
- SklikApi::Campaign.new(campaign_hash).save
300
+ campaign = SklikApi::Campaign.new(campaign_hash)
301
+ unless campaign.save
302
+ # print errors when something went wrong
303
+ puts campaign.errors
304
+ end
71
305
  ```
72
306
 
73
307
  Update of Campaign
@@ -79,7 +313,17 @@ campaign.args[:name] = "Updated name of campaign"
79
313
  campaign.save
80
314
  #this will update status to paused and change campaign name
81
315
  ```
316
+ or by update method:
317
+ ``` ruby
318
+ campaign = SklikApi::Campaign.find(12345)
319
+ unless campaign.update(status: :paused, name: "Updated name of campaign", budget: 20)
320
+ # when something went wrong - check out errors!
321
+ puts campaign.errors
322
+ end
323
+ ```
82
324
 
325
+
326
+ # Other
83
327
  Get all search services (for settings your campaigns)
84
328
 
85
329
  ``` ruby
@@ -88,7 +332,7 @@ pp SklikApi::Campaign.list_search_services
88
332
  ```
89
333
 
90
334
  # Contributing to sklik-api
91
-
335
+
92
336
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
93
337
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
94
338
  * Fork the project.
@@ -99,6 +343,6 @@ pp SklikApi::Campaign.list_search_services
99
343
 
100
344
  # Copyright
101
345
 
102
- Copyright (c) 2012 Ondrej Bartas. See LICENSE.txt for
103
- further details.
346
+ Copyright (c) 2012-2013 Ondrej Bartas. Ataxo Interactive s.r.o.
347
+
104
348
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/sklik-api.rb CHANGED
@@ -25,6 +25,14 @@ ENV['RACK_ENV'] ||= "development"
25
25
  #initialzie SklikApi class
26
26
  class SklikApi
27
27
 
28
+ def self.use_sandbox_for_test= how
29
+ @use_sandbox_for_test = how
30
+ end
31
+
32
+ def self.use_sandbox_for_test?
33
+ @use_sandbox_for_test.nil? ? true : !!@use_sandbox_for_test
34
+ end
35
+
28
36
  def self.use_rollback= how
29
37
  @use_rollback = how
30
38
  end
@@ -16,8 +16,7 @@ Example of input hash
16
16
  :campaign_id => 12345, #(OPTIONAL) -> when setted it will on save do update of existing campaign
17
17
  :name => "my campaign name - #{Time.now.strftime("%Y.%m.%d %H:%M:%S")}",
18
18
  :status => :running,
19
- :cpc => 3,
20
- :budget => 50,
19
+ :budget => 50, #in CZK
21
20
 
22
21
  :network_setting => {
23
22
  :content => true,
@@ -10,6 +10,8 @@ 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
+ :cpc => 1.2, #in CZK
14
+ :stauts => :running,
13
15
  :ads => [
14
16
  {
15
17
  :headline => "Super headline",
@@ -12,11 +12,13 @@ class SklikApi
12
12
  =begin
13
13
  Example of input hash
14
14
  {
15
+ :adtext_id => 1234, #(OPTIONAL) -> when setted it will on save do update of existing adtext
15
16
  :headline => "Super headline",
16
17
  :description1 => "Trying to do ",
17
18
  :description2 => "best description ever",
18
19
  :display_url => "my_test_url.cz",
19
- :url => "http://my_test_url.cz"
20
+ :url => "http://my_test_url.cz",
21
+ :status => :running,
20
22
  }
21
23
 
22
24
 
@@ -15,6 +15,7 @@ class SklikApi
15
15
  =begin
16
16
  Example of input hash
17
17
  {
18
+ :keyword_id => 1234, #(OPTIONAL) -> when setted it will on save do update of existing keyword
18
19
  :keyword => "\"some funny keyword\""
19
20
  }
20
21
  =end
@@ -18,7 +18,7 @@ class SklikApi
18
18
 
19
19
  #prepare connection to sklik
20
20
  def connection
21
- path = (ENV['RACK_ENV'] || ENV['RAILS']) == "test" ? "/sandbox/RPC2" : "/RPC2"
21
+ path = (SklikApi.use_sandbox_for_test? && (ENV['RACK_ENV'] || ENV['RAILS'] == "test") ? "/sandbox/RPC2" : "/RPC2"
22
22
  server = XMLRPC::Client.new3(:host => "api.sklik.cz", :path => path, :port => 443, :use_ssl => true, :timeout => @args[:timeout])
23
23
  server.instance_variable_get(:@http).instance_variable_set(:@verify_mode, OpenSSL::SSL::VERIFY_NONE)
24
24
  #fix of UTF-8 encoding
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.0"
8
+ s.version = "0.1.1"
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-21"
12
+ s.date = "2013-06-23"
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 = [
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.0
4
+ version: 0.1.1
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-21 00:00:00.000000000 Z
12
+ date: 2013-06-23 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: 3135873328890994326
307
+ hash: 2426889930834557345
308
308
  required_rubygems_version: !ruby/object:Gem::Requirement
309
309
  none: false
310
310
  requirements: