2Performant 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ lib/test.rb
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{2Performant}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["2Performant"]
12
+ s.date = %q{2010-04-29}
13
+ s.description = %q{Library for the 2Performant API}
14
+ s.email = %q{andrei@2performant.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "2Performant.gemspec",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/two_performant.rb",
28
+ "lib/two_performant/oauth.rb",
29
+ "test/helper.rb",
30
+ "test/test_2performant.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/2performant/2Performant}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.6}
36
+ s.summary = %q{Library for the 2Performant API}
37
+ s.test_files = [
38
+ "test/helper.rb",
39
+ "test/test_2performant.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
48
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<httparty>, [">= 0"])
51
+ s.add_dependency(%q<shoulda>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<httparty>, [">= 0"])
55
+ s.add_dependency(%q<shoulda>, [">= 0"])
56
+ end
57
+ end
58
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Andrei Bocan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = 2performant
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 2Performant. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "2Performant"
8
+ gem.summary = %Q{Library for the 2Performant API}
9
+ gem.description = %Q{Library for the 2Performant API}
10
+ gem.email = "andrei@2performant.com"
11
+ gem.homepage = "http://github.com/2performant/2Performant"
12
+ gem.authors = ["2Performant"]
13
+ gem.add_dependency "httparty"
14
+ gem.add_development_dependency "shoulda", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "2performant #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,578 @@
1
+ require 'httparty'
2
+ require 'two_performant/oauth'
3
+
4
+ class TwoPerformant
5
+ include HTTParty
6
+ attr_accessor :user, :pass, :host, :version, :auth_type, :oauth, :oauth_request
7
+
8
+ def initialize(auth_type, auth_obj, host)
9
+ if auth_type == :simple
10
+ self.class.basic_auth auth_obj[:user], auth_obj[:pass]
11
+ elsif auth_type == :oauth
12
+ self.oauth = TwoPerformant::OAuth.new(auth_obj, host)
13
+ else
14
+ return false
15
+ end
16
+
17
+ self.auth_type = auth_type
18
+ self.host = host
19
+ self.class.base_uri host
20
+ end
21
+
22
+ # =======
23
+ # Users
24
+ # =======
25
+ def user_show(user_id)
26
+ self.hook("/users/#{user_id}.xml", "user");
27
+ end
28
+
29
+
30
+ # Display public information about the logged in user
31
+ def user_loggedin
32
+ self.hook("/users/loggedin.xml", "user");
33
+ end
34
+
35
+ # ===========
36
+ # Campaigns
37
+ # ===========
38
+
39
+ # List campaigns. Displays the first 6 entries by default.
40
+ def campaigns_list(category_id=nil, page=1, perpage=6)
41
+ request = {
42
+ 'category_id' => category_id,
43
+ 'page' => page,
44
+ 'perpage' => perpage
45
+ }
46
+
47
+ self.hook("/campaigns.xml", "campaign", request, 'GET')
48
+ end
49
+
50
+ # Search for campaigns
51
+ def campaigns_search(search, page = 1, perpage = 6)
52
+ request = {
53
+ 'page' => page,
54
+ 'perpage' => perpage,
55
+ 'search' => search
56
+ }
57
+
58
+ self.hook("/campaigns/search.xml", "campaign", request, 'GET')
59
+ end
60
+
61
+ # Display public information about a campaign
62
+ def campaign_show(campaign_id)
63
+ self.hook("/campaigns/#{campaign_id}.xml", "campaign")
64
+ end
65
+
66
+ # Affiliates: List campaigns which have the logged in user accepted
67
+ def campaigns_listforaffiliate
68
+ self.hook("/campaigns/listforaffiliate.xml", "campaign")
69
+ end
70
+
71
+ # Merchants: List all campaigns created by the logged in user
72
+ def campaigns_listforowner
73
+ self.hook("/campaigns/listforowner.xml", "campaign")
74
+ end
75
+
76
+ # Merchants: Display complete information about a campaign (only available to owner)
77
+ def campaign_showforowner(campaign_id)
78
+ self.hook("/campaigns/#{campaign_id}/showforowner.xml", "campaign")
79
+ end
80
+
81
+ # Merchants: Update a campaign
82
+ def campaign_update(campaign_id, campaign)
83
+ request = {
84
+ 'campaign' => campaign
85
+ }
86
+ self.hook("/campaigns/#{campaign_id}.xml", "campaign", request, 'PUT')
87
+ end
88
+
89
+ # Create a Deep Link. This method was created so it wouldn't make a request for every Quick Link.
90
+ # You may need to get some data before using it.
91
+ def campaign_quicklink(campaign_id, aff_code, redirect)
92
+ url = "#{self.host}/events/click?ad_type=quicklink&aff_code=#{aff_code}&unique=#{campaign_id}&redirect_to=#{redirect}"
93
+
94
+ if (self.auth_type == :oauth)
95
+ url << "&app=#{self.oauth}"
96
+ end
97
+
98
+ url
99
+ end
100
+
101
+ # ============
102
+ # Affiliates
103
+ # ============
104
+
105
+ # Search for affiliates
106
+ def affiliates_search(search, page=1, perpage=6)
107
+ request = {
108
+ 'page' => page,
109
+ 'perpage' => perpage,
110
+ 'search' => search
111
+ }
112
+
113
+ self.hook("/affiliates/search", "user", request, 'GET')
114
+ end
115
+
116
+ # Merchants: List affiliates approved in campaigns
117
+ def affiliates_listformerchant(campaign_id=nil)
118
+ request = {
119
+ 'campaign_id' => campaign_id
120
+ }
121
+ self.hook("/affiliates/listformerchant", "user", request, 'GET')
122
+ end
123
+
124
+ # =============
125
+ # Commissions
126
+ # =============
127
+
128
+ # Search for commissions. Month: 01 to 12; Year: 20xx. Status: accepted, pending or rejected. nil if empty search.
129
+ def commissions_search(options, campaign_id=nil, month=nil, year=nil, page=1, perpage=6)
130
+ request = {
131
+ 'campaign_id' => campaign_id,
132
+ 'month' => month,
133
+ 'year' => year,
134
+ 'page' => page,
135
+ 'perpage' => perpage
136
+ }
137
+
138
+ request.merge(options)
139
+
140
+ self.hook("/commissions/search.xml", "commission", request, 'GET')
141
+ end
142
+
143
+ # Merchants: List commissions on campaigns. Month: 01 to 12; Year: 20xx.
144
+ def commissions_listformerchant(campaign_id, month, year)
145
+ request = {
146
+ 'campaign_id' => campaign_id,
147
+ 'month' => month,
148
+ 'year' => year
149
+ }
150
+
151
+ self.hook("/commissions/listformerchant.xml", "campaign", request, 'GET')
152
+ end
153
+
154
+ # Affiliates: List commissions on campaigns. Month: 01 to 12; Year: 20xx.
155
+ def commissions_listforaffiliate(campaign_id, month, year)
156
+ request = {
157
+ 'campaign_id' => campaign_id,
158
+ 'month' => month,
159
+ 'year' => year
160
+ }
161
+
162
+ self.hook("/commissions/listforaffiliate.xml", "commission", request, 'GET')
163
+ end
164
+
165
+ # Merchant Campaign Owner or Affiliate Commission Owner: Show information about a commission
166
+ def commission_show(commission_id)
167
+ self.hook("/commissions/#{commission_id}.xml", "commission")
168
+ end
169
+
170
+ # Merchant: Update a commission
171
+ def commission_update(commission_id, commission)
172
+ request = {
173
+ 'commission' => commission
174
+ }
175
+ self.hook("/commissions/#{commission_id}.xml", "commission", request, 'PUT')
176
+ end
177
+
178
+ # =======
179
+ # Sites
180
+ # =======
181
+
182
+ # List sites. Displays the first 6 entries by default.
183
+ def sites_list(category_id=nil, page=1, perpage=6)
184
+ request = {
185
+ 'category_id' => category_id,
186
+ 'page' => page,
187
+ 'perpage' => perpage
188
+ }
189
+
190
+ self.hook("/sites.xml", "site", request)
191
+ end
192
+
193
+ # Display information about a site
194
+ def site_show(site_id)
195
+ self.hook("/sites/#{site_id}.xml", "site")
196
+ end
197
+
198
+ # Search for sites
199
+ def sites_search(search, page=1, perpage=6)
200
+ request = {
201
+ 'page' => page,
202
+ 'perpage' => perpage,
203
+ 'search' => search
204
+ }
205
+
206
+ self.hook("/sites/search.xml", "site", request, 'GET')
207
+ end
208
+
209
+ # Affiliates: List all sites created by the logged in user
210
+ def sites_listforowner
211
+ self.hook("/sites/listforowner.xml", "site")
212
+ end
213
+
214
+ # Affiliates: Update a site
215
+ def site_update(site_id, site)
216
+ request = {
217
+ 'site' => site
218
+ }
219
+ self.hook("/sites/#{site_id}.xml", "site", request, 'PUT')
220
+ end
221
+
222
+
223
+ # Affiliates: Destroy a site
224
+ def site_destroy(site_id)
225
+ self.hook("/sites/#{site_id}.xml", "site", request, 'DELETE')
226
+ end
227
+
228
+ # ============
229
+ # Text Links
230
+ # ============
231
+
232
+ # List text links from a campaign. Displays the first 6 entries by default.
233
+ def txtlinks_list(campaign_id, page=1, perpage=6)
234
+ request = {
235
+ 'page' => page,
236
+ 'perpage' => perpage
237
+ }
238
+
239
+ self.hook("/campaigns/#{campaign_id}/txtlinks.xml", "txtlink", request, 'GET')
240
+ end
241
+
242
+ # Display information about a text link
243
+ def txtlink_show(campaign_id, txtlink_id)
244
+ self.hook("/campaigns/#{campaign_id}/txtlinks/#{txtlink_id}.xml", "txtlink")
245
+ end
246
+
247
+ # Search for text links in a campaign
248
+ def txtlinks_search(campaign_id, search, page=1, perpage=6, sort='date')
249
+ request = {
250
+ 'page' => page,
251
+ 'perpage' => perpage,
252
+ 'search' => search,
253
+ 'sort' => sort,
254
+ }
255
+
256
+ self.hook("/campaigns/#{campaign_id}/txtlinks/search.xml", "txtlink", request, 'GET')
257
+ end
258
+
259
+ #
260
+ # Merchants: Create Text Link.
261
+ # Txtlink must look like: array("title" => "title", "url" => "url", "help" => "help"); where "help" is optional
262
+
263
+ def txtlink_create(campaign_id, txtlink)
264
+ request = {
265
+ 'txtlink' => txtlink
266
+ }
267
+
268
+ self.hook("/campaigns/#{campaign_id}/txtlinks.xml", "txtlink", request, 'POST')
269
+ end
270
+
271
+ # Merchants: Update a text link
272
+ def txtlink_update(campaign_id, txtlink_id, txtlink)
273
+ request = {
274
+ 'txtlink' => txtlink
275
+ }
276
+ self.hook("/campaigns/#{campaign_id}/txtlinks/#{txtlink_id}.xml", "txtlink", request, 'PUT')
277
+ end
278
+
279
+ # Merchants: Destroy a text link
280
+ def txtlink_destroy(campaign_id, txtlink_id)
281
+ self.hook("/campaigns/#{campaign_id}/txtlinks/#{txtlink_id}.xml", "txtlink", nil, 'DELETE')
282
+ end
283
+
284
+ # ============
285
+ # Text Ads
286
+ # ============
287
+
288
+ # List text ads from a campaign. Displays the first 6 entries by default.
289
+ def txtads_list(campaign_id, page=1, perpage=6)
290
+ request = {
291
+ 'page' => page,
292
+ 'perpage' => perpage
293
+ }
294
+
295
+ self.hook("/campaigns/#{campaign_id}/txtads.xml", "txtad", request, 'GET')
296
+ end
297
+
298
+ # Display information about a text ad
299
+ def txtad_show(campaign_id, txtad_id)
300
+ self.hook("/campaigns/#{campaign_id}/txtads/#{txtad_id}.xml", "txtad")
301
+ end
302
+
303
+ # Search for text ads in a campaign
304
+ def txtads_search(campaign_id, search, page=1, perpage=6, sort='date')
305
+ request = {
306
+ 'page' => page,
307
+ 'perpage' => perpage,
308
+ 'search' => search,
309
+ 'sort' => sort
310
+ }
311
+
312
+ self.hook("/campaigns/#{campaign_id}/txtads/search.xml", "txtad", request, 'GET')
313
+ end
314
+
315
+ #
316
+ # Merchants: Create Text Ad.
317
+ # Txtad must look like: array("title" => "title", "content" => "content", "url" => "url", "help" => "help"); where "help" is optional
318
+
319
+ def txtad_create(campaign_id, txtad)
320
+ request = {
321
+ 'txtad' => txtad
322
+ }
323
+
324
+ self.hook("/campaigns/#{campaign_id}/txtads.xml", "txtad", request, 'POST')
325
+ end
326
+
327
+
328
+ # Merchants: Update a text ad
329
+ def txtad_update(campaign_id, txtad_id, txtad)
330
+ request = {
331
+ 'txtad' => txtad
332
+ }
333
+
334
+ self.hook("/campaigns/#{campaign_id}/txtads/#{txtad_id}.xml", "txtad", request, 'PUT')
335
+ end
336
+
337
+ # Merchants: Destroy a text ad
338
+ def txtad_destroy(campaign_id, txtad_id)
339
+ self.hook("/campaigns/#{campaign_id}/txtads/#{txtad_id}.xml", "txtad", nil, 'DELETE')
340
+ end
341
+
342
+ # =========
343
+ # Banners
344
+ # =========
345
+
346
+ # List banners from a campaign. Displays the first 6 entries by default.
347
+ def banners_list(campaign_id, page=1, perpage=6)
348
+ request = {
349
+ 'page' => page,
350
+ 'perpage' => perpage
351
+ }
352
+
353
+ self.hook("/campaigns/#{campaign_id}/banners.xml", "banner", request, 'GET')
354
+ end
355
+
356
+ # Display information about a banner
357
+ def banner_show(campaign_id, banner_id)
358
+ self.hook("/campaigns/#{campaign_id}/banners/#{banner_id}.xml", "banner")
359
+ end
360
+
361
+ # Search for banners in a campaign
362
+ def banners_search(campaign_id, search, page=1, perpage=6, sort='date')
363
+ request = {
364
+ 'page' => page,
365
+ 'perpage' => perpage,
366
+ 'search' => search,
367
+ 'sort' => sort
368
+ }
369
+
370
+ self.hook("/campaigns/#{campaign_id}/banners/search.xml", "banner", request, 'GET')
371
+ end
372
+
373
+ # Merchants: Update a banner
374
+ def banner_update(campaign_id, banner_id, banner)
375
+ request = {
376
+ 'banner' => banner
377
+ }
378
+
379
+ self.hook("/campaigns/#{campaign_id}/banners/#{banner_id}.xml", "banner", request, 'PUT')
380
+ end
381
+
382
+ # Merchants: Destroy a banner
383
+ def banner_destroy(campaign_id, banner_id)
384
+ self.hook("/campaigns/#{campaign_id}/banners/#{banner_id}.xml", "banner", nil, 'DELETE')
385
+ end
386
+
387
+ # ===============
388
+ # Widget Stores
389
+ # ===============
390
+
391
+ # List Widget Stores from a Campaign
392
+ def product_stores_list(campaign_id)
393
+ request = {
394
+ 'campaign_id' => campaign_id
395
+ }
396
+
397
+ self.hook("/product_stores.xml", "product-store", request)
398
+ end
399
+
400
+ # Show a WidgetStore
401
+ def product_store_show(product_store_id)
402
+ self.hook("/product_stores/#{product_store_id}.xml", "product-store")
403
+ end
404
+
405
+ # Show Products from a WidgetStore
406
+ def product_store_showitems(product_store_id, category=nil, page=1, perpage=6, uniq_products=nil)
407
+ request = {
408
+ 'category' => category,
409
+ 'page' => page,
410
+ 'perpage' => perpage
411
+ }
412
+
413
+ request['uniq_products'] = uniq_products if (uniq_products)
414
+
415
+ self.hook("/product_stores/#{product_store_id}/showitems.xml", "product-store-data", request)
416
+ end
417
+
418
+ # Show a Product from a WidgetStore
419
+ def product_store_showitem(product_store_id, product_id)
420
+ request = {
421
+ 'product_id' => product_id
422
+ }
423
+
424
+ self.hook("/product_stores/#{product_store_id}/showitem.xml", "product-store-data", request)
425
+ end
426
+
427
+
428
+ # Search for Products in a WidgetStore
429
+ def product_store_products_search(campaign_id, search, product_store_id='all', category=nil, page=1, perpage=6, sort='date', uniq_products=false)
430
+ request = {
431
+ 'page' => page,
432
+ 'perpage' => perpage,
433
+ 'search' => search,
434
+ 'category' => category,
435
+ 'campaign_id' => campaign_id,
436
+ 'sort' => sort
437
+ }
438
+
439
+ request['uniq_products'] = uniq_products if uniq_products
440
+
441
+ product_store_id = 'all' if !product_store_id
442
+
443
+ self.hook("/product_stores/#{product_store_id}/searchpr.xml", "product-store-data", request, 'GET')
444
+ end
445
+
446
+ # Merchants: Update a WidgetStore
447
+ def product_store_update(product_store_id, product_store)
448
+ request = {
449
+ 'product_store' => product_store
450
+ }
451
+
452
+ self.hook("/product_stores/#{product_store_id}.xml", "product-store", request, 'PUT')
453
+ end
454
+
455
+ # Merchants: Destroy a WidgetStore
456
+ def product_store_destroy(product_store_id)
457
+ self.hook("/product_stores/#{product_store_id}.xml", "product-store", nil, 'DELETE')
458
+ end
459
+
460
+ #
461
+ # Merchants: Create a WidgetStoreProduct.
462
+ # WidgetStoreProduct must look like:
463
+ # array("title" => "title", "description" => "desc", "caption" => "caption", "price" => "price(integer in RON)",
464
+ # "promoted" => "promoted (0 or 1)", "category" => "category", "subcategory" => "subcategory", "url" => "url",
465
+ # "image_url" => "url to image location", "prid" => "product id")
466
+
467
+ def product_store_createitem(product_store_id, product)
468
+ request = {
469
+ 'product' => product
470
+ }
471
+
472
+ self.hook("/product_stores/#{product_store_id}/createitem.xml", "product-store-data", request, 'POST')
473
+ end
474
+
475
+ # Merchants: Update a product
476
+ def product_store_updateitem(product_store_id, product_id, product)
477
+ request = {
478
+ 'product' => product,
479
+ 'product_id' => product_id
480
+ }
481
+
482
+ self.hook("/product_stores/#{product_store_id}/updateitem.xml", "product-store-data", request, 'PUT')
483
+ end
484
+
485
+ # Merchants: Destroy a product
486
+ def product_store_destroyitem(product_store_id, product_id)
487
+ request = {
488
+ 'pr_id' => product_id
489
+ }
490
+
491
+ self.hook("/product_stores/#{product_store_id}/destroyitem.xml", "product-store-data", request, 'DELETE')
492
+ end
493
+
494
+ # =====================
495
+ # Affiliate Ad Groups
496
+ # =====================
497
+
498
+ # Affiliates: List Ad Groups
499
+ def ad_groups_list
500
+ self.hook("/ad_groups.xml", "ad_group", nil, "GET")
501
+ end
502
+
503
+ # Affiliates: Display information about an Ad Group
504
+ def ad_group_show(ad_group_id)
505
+ self.hook("/ad_groups/#{ad_group_id}.xml", "ad_group", nil, "GET")
506
+ end
507
+
508
+ # Affiliates: Destroy an Ad Group
509
+ def ad_group_destroy(ad_group_id)
510
+ self.hook("/ad_groups/#{ad_group_id}.xml", "ad_group", nil, "DELETE")
511
+ end
512
+
513
+ # Affiliates: Delete an Tool from a Group. tooltype is one of 'txtlink', 'txtad' or 'banner'.
514
+ def ad_group_destroyitem(ad_group_id, tool_type, tool_id)
515
+ request = {
516
+ 'tool_type' => tool_type,
517
+ 'tool_id' => tool_id
518
+ }
519
+
520
+ self.hook("/ad_groups/#{ad_group_id}/destroyitem.xml", "ad_group", request, "DELETE")
521
+ end
522
+
523
+ # ==========
524
+ # Messages
525
+ # ==========
526
+
527
+ # List received messages. Displays the first 6 entries by default.
528
+ def received_messages_list(page=1, perpage=6)
529
+ request = {
530
+ 'page' => page,
531
+ 'perpage' => perpage
532
+ }
533
+
534
+ self.hook("/messages.xml", "message", nil, "GET")
535
+ end
536
+
537
+ # List sent messages. Displays the first 6 entries by default.
538
+ def sent_messages_list(page=1, perpage=6)
539
+ request = {
540
+ 'page' => page,
541
+ 'perpage' => perpage
542
+ }
543
+
544
+ self.hook("/messages/sent.xml", "message", nil, "GET")
545
+ end
546
+
547
+ # Display information about a message
548
+ def message_show(message_id)
549
+ self.hook("/messages/#{message_id}.xml", "message")
550
+ end
551
+
552
+ # Destroy a message
553
+ def message_destroy(message_id)
554
+ self.hook("/messages/#{message_id}.xml", "message", nil, 'DELETE')
555
+ end
556
+
557
+
558
+ # ===========================
559
+ # Actually process the data
560
+ # ===========================
561
+
562
+ def hook(path, expected, send = nil, method = 'GET')
563
+ if self.oauth
564
+ result = self.oauth.send(method.downcase, path, send)
565
+ else
566
+ result = self.class.send(method.downcase, path, :query => send)
567
+ end
568
+
569
+ # scrap the container
570
+ result.values.first
571
+ end
572
+
573
+ def simpleHttpRequest(url, params, method)
574
+ end
575
+
576
+ def oauthHttpRequest(url, params, method)
577
+ end
578
+ end
@@ -0,0 +1,36 @@
1
+ require 'oauth'
2
+
3
+ class TwoPerformant
4
+ class OAuth
5
+ attr_accessor :access_token, :consumer
6
+
7
+ def initialize(options, host)
8
+ consumer = ::OAuth::Consumer.new(options[:consumer_token], options[:consumer_secret], {:site => host})
9
+ @access_token = ::OAuth::AccessToken.new(consumer, options[:access_token], options[:access_secret])
10
+ end
11
+
12
+ def get(path, params)
13
+ params ||= {}
14
+ response = access_token.get("#{path}?#{params.to_params}")
15
+ Crack::XML.parse(response.body)
16
+ end
17
+
18
+ def post(path, params)
19
+ params ||= {}
20
+ response = access_token.post(path, params)
21
+ Crack::XML.parse(response.body)
22
+ end
23
+
24
+ def put(path, params)
25
+ params ||= {}
26
+ response = access_token.put(path, params)
27
+ Crack::XML.parse(response.body)
28
+ end
29
+
30
+ def delete(path, params)
31
+ params ||= {}
32
+ response = access_token.delete("#{path}?#{params.to_params}")
33
+ Crack::XML.parse(response.body)
34
+ end
35
+ end
36
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require '2performant'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class Test2performant < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: 2Performant
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - 2Performant
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-29 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: httparty
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: shoulda
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :development
43
+ version_requirements: *id002
44
+ description: Library for the 2Performant API
45
+ email: andrei@2performant.com
46
+ executables: []
47
+
48
+ extensions: []
49
+
50
+ extra_rdoc_files:
51
+ - LICENSE
52
+ - README.rdoc
53
+ files:
54
+ - .document
55
+ - .gitignore
56
+ - 2Performant.gemspec
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - lib/two_performant.rb
62
+ - lib/two_performant/oauth.rb
63
+ - test/helper.rb
64
+ - test/test_2performant.rb
65
+ has_rdoc: true
66
+ homepage: http://github.com/2performant/2Performant
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.6
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Library for the 2Performant API
95
+ test_files:
96
+ - test/helper.rb
97
+ - test/test_2performant.rb