douaparale 0.0.8
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.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.md +55 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/douaparale.gemspec +61 -0
- data/lib/douaparale.rb +715 -0
- data/lib/douaparale/oauth.rb +34 -0
- data/test/helper.rb +10 -0
- data/test/test_2performant.rb +7 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3afcd5bb83630e8ab3f342b09591ff531b9f6fa3
|
4
|
+
data.tar.gz: 54a7ca4290dd988f2ba6412c4e2f4a9c05f469bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 171ec04d36bd6c6efdd3a181486770e9b1c66d1452b792d1d298fdaf8a1d10447f2516ae0443d367f741c432da0c4029162d2400c70a85280716f751fc4a9b95
|
7
|
+
data.tar.gz: 36d057aaa6f131df6d454573efc76ebb737ba277754f57888709d186d7908ddb22cacf0cb12a26e22424572f69600180a611a21835934e480636390ec07b6c10
|
data/.document
ADDED
data/.gitignore
ADDED
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.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# 2Performant Ruby API
|
2
|
+
|
3
|
+
The API allows you to integrate any 2Performant network in your application.
|
4
|
+
|
5
|
+
Its goal is to make sure developers can implement anything that can be done via the web interface using API functions.
|
6
|
+
|
7
|
+
The API is RESTful XML over HTTP using all four verbs (GET/POST/PUT/DELETE).
|
8
|
+
|
9
|
+
The current implementation is a straight port of the PHP library, so the documentation applies, for the most part, to both libraries.
|
10
|
+
|
11
|
+
API documentation can be found at:
|
12
|
+
http://help.2performant.com/API
|
13
|
+
|
14
|
+
|
15
|
+
## Some Examples
|
16
|
+
|
17
|
+
Interacting with 2Performant networks is very easy.
|
18
|
+
|
19
|
+
|
20
|
+
To initialize the object using simple authentication
|
21
|
+
|
22
|
+
session = TwoPerformant.new(:simple, {
|
23
|
+
:user => 'user',
|
24
|
+
:pass => 'password',
|
25
|
+
}, 'http://api.yournetwork.com')
|
26
|
+
|
27
|
+
To use oauth
|
28
|
+
|
29
|
+
tp = TwoPerformant.new(:oauth, {
|
30
|
+
:consumer_token => 'consumer_token',
|
31
|
+
:consumer_secret => 'consumer_secret',
|
32
|
+
:access_token => 'access_token',
|
33
|
+
:access_secret => 'access_secret'
|
34
|
+
}, 'http://api.yournetwork.com')
|
35
|
+
|
36
|
+
|
37
|
+
Afterwards you can call any function from the TPerformant class:
|
38
|
+
|
39
|
+
# display the last 6 received messages
|
40
|
+
p session.received_messages_list
|
41
|
+
|
42
|
+
For details about each API function the documentation can be found at:
|
43
|
+
http://help.2performant.com/API
|
44
|
+
|
45
|
+
|
46
|
+
## Advanced Applications
|
47
|
+
|
48
|
+
You can build advanced applications using the 2Performant API and have them distributed over 2Performant App Store.
|
49
|
+
|
50
|
+
Get Started at: http://apps.2performant.com and http://help.2performant.com/Developers-Area
|
51
|
+
|
52
|
+
## Reporting Problems
|
53
|
+
|
54
|
+
If you encounters any problems don't hesitate to contact us at:
|
55
|
+
support (at) 2performant.com
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "douaparale"
|
8
|
+
gem.summary = %Q{Library for the 2Parale API}
|
9
|
+
gem.description = %Q{Library for the 2Parale API}
|
10
|
+
gem.email = "gems@2parale.ro"
|
11
|
+
gem.homepage = "http://github.com/2performant/2Performant"
|
12
|
+
gem.authors = ["2Parale"]
|
13
|
+
gem.add_dependency "httparty"
|
14
|
+
gem.add_dependency "oauth"
|
15
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "2Parale #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.8
|
data/douaparale.gemspec
ADDED
@@ -0,0 +1,61 @@
|
|
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{douaparale}
|
8
|
+
s.version = "0.0.8"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["2Parale"]
|
12
|
+
s.date = %q{2010-07-26}
|
13
|
+
s.description = %q{Library for the 2Performant API}
|
14
|
+
s.email = %q{gems@2parale.ro}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"douaparale.gemspec",
|
23
|
+
"LICENSE",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/douaparale.rb",
|
28
|
+
"lib/douaparale/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.7}
|
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::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
48
|
+
s.add_runtime_dependency(%q<oauth>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
52
|
+
s.add_dependency(%q<oauth>, [">= 0"])
|
53
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
57
|
+
s.add_dependency(%q<oauth>, [">= 0"])
|
58
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/lib/douaparale.rb
ADDED
@@ -0,0 +1,715 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'douaparale/oauth'
|
3
|
+
|
4
|
+
class DouaParale
|
5
|
+
include HTTParty
|
6
|
+
format :xml
|
7
|
+
headers 'Content-Type' => 'text/xml'
|
8
|
+
|
9
|
+
attr_accessor :user, :pass, :host, :version, :auth_type, :oauth, :oauth_request
|
10
|
+
|
11
|
+
def initialize(auth_type, auth_obj, host)
|
12
|
+
if auth_type == :simple
|
13
|
+
self.class.basic_auth auth_obj[:user], auth_obj[:pass]
|
14
|
+
elsif auth_type == :oauth
|
15
|
+
self.oauth = TwoPerformant::OAuth.new(auth_obj, host)
|
16
|
+
else
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
|
20
|
+
self.version = "v1.0"
|
21
|
+
self.auth_type = auth_type
|
22
|
+
self.host = host
|
23
|
+
self.class.base_uri host
|
24
|
+
end
|
25
|
+
|
26
|
+
# =======
|
27
|
+
# Users
|
28
|
+
# =======
|
29
|
+
def user_show(user_id)
|
30
|
+
self.hook("/users/#{user_id}.xml", "user");
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
# Display public information about the logged in user
|
35
|
+
def user_loggedin
|
36
|
+
self.hook("/users/loggedin.xml", "user");
|
37
|
+
end
|
38
|
+
|
39
|
+
# ===========
|
40
|
+
# Campaigns
|
41
|
+
# ===========
|
42
|
+
|
43
|
+
# List campaigns. Displays the first 6 entries by default.
|
44
|
+
def campaigns_list(category_id=nil, page=1, perpage=6)
|
45
|
+
request = {
|
46
|
+
'category_id' => category_id,
|
47
|
+
'page' => page,
|
48
|
+
'perpage' => perpage
|
49
|
+
}
|
50
|
+
|
51
|
+
self.hook("/campaigns.xml", "campaign", request, 'GET')
|
52
|
+
end
|
53
|
+
|
54
|
+
# Search for campaigns
|
55
|
+
def campaigns_search(search, page = 1, perpage = 6)
|
56
|
+
request = {
|
57
|
+
'page' => page,
|
58
|
+
'perpage' => perpage,
|
59
|
+
'search' => search
|
60
|
+
}
|
61
|
+
|
62
|
+
self.hook("/campaigns/search.xml", "campaign", request, 'GET')
|
63
|
+
end
|
64
|
+
|
65
|
+
# Display public information about a campaign
|
66
|
+
def campaign_show(campaign_id)
|
67
|
+
self.hook("/campaigns/#{campaign_id}.xml", "campaign")
|
68
|
+
end
|
69
|
+
|
70
|
+
# Affiliates: List campaigns which have the logged in user accepted
|
71
|
+
def campaigns_listforaffiliate
|
72
|
+
self.hook("/campaigns/listforaffiliate.xml", "campaign")
|
73
|
+
end
|
74
|
+
|
75
|
+
# Merchants: List all campaigns created by the logged in user
|
76
|
+
def campaigns_listforowner
|
77
|
+
self.hook("/campaigns/listforowner.xml", "campaign")
|
78
|
+
end
|
79
|
+
|
80
|
+
# Merchants: Display complete information about a campaign (only available to owner)
|
81
|
+
def campaign_showforowner(campaign_id)
|
82
|
+
self.hook("/campaigns/#{campaign_id}/showforowner.xml", "campaign")
|
83
|
+
end
|
84
|
+
|
85
|
+
# Merchants: Update a campaign
|
86
|
+
def campaign_update(campaign_id, campaign)
|
87
|
+
request = {
|
88
|
+
'campaign' => campaign
|
89
|
+
}
|
90
|
+
self.hook("/campaigns/#{campaign_id}.xml", "campaign", request, 'PUT')
|
91
|
+
end
|
92
|
+
|
93
|
+
# Create a Deep Link. This method was created so it wouldn't make a request for every Quick Link.
|
94
|
+
# You may need to get some data before using it.
|
95
|
+
def campaign_quicklink(campaign_id, aff_code, redirect)
|
96
|
+
url = "#{self.host}/events/click?ad_type=quicklink&aff_code=#{aff_code}&unique=#{campaign_id}&redirect_to=#{redirect}"
|
97
|
+
|
98
|
+
if (self.auth_type == :oauth)
|
99
|
+
url << "&app=#{self.oauth}"
|
100
|
+
end
|
101
|
+
|
102
|
+
url
|
103
|
+
end
|
104
|
+
|
105
|
+
# ============
|
106
|
+
# Sales
|
107
|
+
# ============
|
108
|
+
|
109
|
+
def sale_create(campaign_id, sale)
|
110
|
+
request = {
|
111
|
+
'sale' => sale
|
112
|
+
}
|
113
|
+
|
114
|
+
self.hook("/campaigns/#{campaign_id}/sales.xml", "sale", request, "POST")
|
115
|
+
end
|
116
|
+
|
117
|
+
# ============
|
118
|
+
# Leads
|
119
|
+
# ============
|
120
|
+
|
121
|
+
def lead_create(campaign_id, lead)
|
122
|
+
request = {
|
123
|
+
'lead' => lead
|
124
|
+
}
|
125
|
+
|
126
|
+
self.hook("/campaigns/#{campaign_id}/leads.xml", "lead", request, "POST")
|
127
|
+
end
|
128
|
+
|
129
|
+
# ============
|
130
|
+
# Affiliates
|
131
|
+
# ============
|
132
|
+
|
133
|
+
# Search for affiliates
|
134
|
+
def affiliates_search(search, page=1, perpage=6)
|
135
|
+
request = {
|
136
|
+
'page' => page,
|
137
|
+
'perpage' => perpage,
|
138
|
+
'search' => search
|
139
|
+
}
|
140
|
+
|
141
|
+
self.hook("/affiliates/search.xml", "user", request, 'GET')
|
142
|
+
end
|
143
|
+
|
144
|
+
# Merchants: List affiliates approved in campaigns
|
145
|
+
def affiliates_listformerchant(campaign_id=nil)
|
146
|
+
request = {
|
147
|
+
'campaign_id' => campaign_id
|
148
|
+
}
|
149
|
+
self.hook("/affiliates/listformerchant.xml", "user", request, 'GET')
|
150
|
+
end
|
151
|
+
|
152
|
+
# =============
|
153
|
+
# Commissions
|
154
|
+
# =============
|
155
|
+
|
156
|
+
# Search for commissions. Month: 01 to 12; Year: 20xx. Status: accepted, pending or rejected. nil if empty search.
|
157
|
+
def commissions_search(options, campaign_id=nil, month=nil, year=nil, page=1, perpage=6)
|
158
|
+
request = {
|
159
|
+
'campaign_id' => campaign_id,
|
160
|
+
'month' => month,
|
161
|
+
'year' => year,
|
162
|
+
'page' => page,
|
163
|
+
'perpage' => perpage
|
164
|
+
}
|
165
|
+
|
166
|
+
request = request.merge(options)
|
167
|
+
|
168
|
+
self.hook("/commissions/search.xml", "commission", request, 'GET')
|
169
|
+
end
|
170
|
+
|
171
|
+
# Merchants: List commissions on campaigns. Month: 01 to 12; Year: 20xx.
|
172
|
+
def commissions_listformerchant(campaign_id, month, year)
|
173
|
+
request = {
|
174
|
+
'campaign_id' => campaign_id,
|
175
|
+
'month' => month,
|
176
|
+
'year' => year
|
177
|
+
}
|
178
|
+
|
179
|
+
self.hook("/commissions/listformerchant.xml", "campaign", request, 'GET')
|
180
|
+
end
|
181
|
+
|
182
|
+
# Affiliates: List commissions on campaigns. Month: 01 to 12; Year: 20xx.
|
183
|
+
def commissions_listforaffiliate(campaign_id, month, year)
|
184
|
+
request = {
|
185
|
+
'campaign_id' => campaign_id,
|
186
|
+
'month' => month,
|
187
|
+
'year' => year
|
188
|
+
}
|
189
|
+
|
190
|
+
self.hook("/commissions/listforaffiliate.xml", "commission", request, 'GET')
|
191
|
+
end
|
192
|
+
|
193
|
+
# Merchant Campaign Owner or Affiliate Commission Owner: Show information about a commission
|
194
|
+
def commission_show(commission_id)
|
195
|
+
self.hook("/commissions/#{commission_id}.xml", "commission")
|
196
|
+
end
|
197
|
+
|
198
|
+
# Merchant: Update a commission
|
199
|
+
def commission_update(commission_id, commission)
|
200
|
+
request = {
|
201
|
+
'commission' => commission
|
202
|
+
}
|
203
|
+
self.hook("/commissions/#{commission_id}.xml", "commission", request, 'PUT')
|
204
|
+
end
|
205
|
+
|
206
|
+
# =======
|
207
|
+
# Sites
|
208
|
+
# =======
|
209
|
+
|
210
|
+
# List sites. Displays the first 6 entries by default.
|
211
|
+
def sites_list(category_id=nil, page=1, perpage=6)
|
212
|
+
request = {
|
213
|
+
'category_id' => category_id,
|
214
|
+
'page' => page,
|
215
|
+
'perpage' => perpage
|
216
|
+
}
|
217
|
+
|
218
|
+
self.hook("/sites.xml", "site", request)
|
219
|
+
end
|
220
|
+
|
221
|
+
# Display information about a site
|
222
|
+
def site_show(site_id)
|
223
|
+
self.hook("/sites/#{site_id}.xml", "site")
|
224
|
+
end
|
225
|
+
|
226
|
+
# Search for sites
|
227
|
+
def sites_search(search, page=1, perpage=6)
|
228
|
+
request = {
|
229
|
+
'page' => page,
|
230
|
+
'perpage' => perpage,
|
231
|
+
'search' => search
|
232
|
+
}
|
233
|
+
|
234
|
+
self.hook("/sites/search.xml", "site", request, 'GET')
|
235
|
+
end
|
236
|
+
|
237
|
+
# Affiliates: List all sites created by the logged in user
|
238
|
+
def sites_listforowner
|
239
|
+
self.hook("/sites/listforowner.xml", "site")
|
240
|
+
end
|
241
|
+
|
242
|
+
# Affiliates: Update a site
|
243
|
+
def site_update(site_id, site)
|
244
|
+
request = {
|
245
|
+
'site' => site
|
246
|
+
}
|
247
|
+
self.hook("/sites/#{site_id}.xml", "site", request, 'PUT')
|
248
|
+
end
|
249
|
+
|
250
|
+
|
251
|
+
# Affiliates: Destroy a site
|
252
|
+
def site_destroy(site_id)
|
253
|
+
self.hook("/sites/#{site_id}.xml", "site", request, 'DELETE')
|
254
|
+
end
|
255
|
+
|
256
|
+
# ============
|
257
|
+
# Text Links
|
258
|
+
# ============
|
259
|
+
|
260
|
+
# List text links from a campaign. Displays the first 6 entries by default.
|
261
|
+
def txtlinks_list(campaign_id, page=1, perpage=6)
|
262
|
+
request = {
|
263
|
+
'page' => page,
|
264
|
+
'perpage' => perpage
|
265
|
+
}
|
266
|
+
|
267
|
+
self.hook("/campaigns/#{campaign_id}/txtlinks.xml", "txtlink", request, 'GET')
|
268
|
+
end
|
269
|
+
|
270
|
+
# Display information about a text link
|
271
|
+
def txtlink_show(campaign_id, txtlink_id)
|
272
|
+
self.hook("/campaigns/#{campaign_id}/txtlinks/#{txtlink_id}.xml", "txtlink")
|
273
|
+
end
|
274
|
+
|
275
|
+
# Search for text links in a campaign
|
276
|
+
def txtlinks_search(campaign_id, search, page=1, perpage=6, sort='date')
|
277
|
+
request = {
|
278
|
+
'page' => page,
|
279
|
+
'perpage' => perpage,
|
280
|
+
'search' => search,
|
281
|
+
'sort' => sort,
|
282
|
+
}
|
283
|
+
|
284
|
+
self.hook("/campaigns/#{campaign_id}/txtlinks/search.xml", "txtlink", request, 'GET')
|
285
|
+
end
|
286
|
+
|
287
|
+
#
|
288
|
+
# Merchants: Create Text Link.
|
289
|
+
#
|
290
|
+
# Txtlink must be a hash of:
|
291
|
+
# { "title" => "title",
|
292
|
+
# "url" => "url",
|
293
|
+
# "help" => "help"
|
294
|
+
# }, where "help" is optional
|
295
|
+
|
296
|
+
def txtlink_create(campaign_id, txtlink)
|
297
|
+
request = {
|
298
|
+
'txtlink' => txtlink
|
299
|
+
}
|
300
|
+
|
301
|
+
self.hook("/campaigns/#{campaign_id}/txtlinks.xml", "txtlink", request, 'POST')
|
302
|
+
end
|
303
|
+
|
304
|
+
# Merchants: Update a text link
|
305
|
+
def txtlink_update(campaign_id, txtlink_id, txtlink)
|
306
|
+
request = {
|
307
|
+
'txtlink' => txtlink
|
308
|
+
}
|
309
|
+
self.hook("/campaigns/#{campaign_id}/txtlinks/#{txtlink_id}.xml", "txtlink", request, 'PUT')
|
310
|
+
end
|
311
|
+
|
312
|
+
# Merchants: Destroy a text link
|
313
|
+
def txtlink_destroy(campaign_id, txtlink_id)
|
314
|
+
self.hook("/campaigns/#{campaign_id}/txtlinks/#{txtlink_id}.xml", "txtlink", nil, 'DELETE')
|
315
|
+
end
|
316
|
+
|
317
|
+
# ============
|
318
|
+
# Text Ads
|
319
|
+
# ============
|
320
|
+
|
321
|
+
# List text ads from a campaign. Displays the first 6 entries by default.
|
322
|
+
def txtads_list(campaign_id, page=1, perpage=6)
|
323
|
+
request = {
|
324
|
+
'page' => page,
|
325
|
+
'perpage' => perpage
|
326
|
+
}
|
327
|
+
|
328
|
+
self.hook("/campaigns/#{campaign_id}/txtads.xml", "txtad", request, 'GET')
|
329
|
+
end
|
330
|
+
|
331
|
+
# Display information about a text ad
|
332
|
+
def txtad_show(campaign_id, txtad_id)
|
333
|
+
self.hook("/campaigns/#{campaign_id}/txtads/#{txtad_id}.xml", "txtad")
|
334
|
+
end
|
335
|
+
|
336
|
+
# Search for text ads in a campaign
|
337
|
+
def txtads_search(campaign_id, search, page=1, perpage=6, sort='date')
|
338
|
+
request = {
|
339
|
+
'page' => page,
|
340
|
+
'perpage' => perpage,
|
341
|
+
'search' => search,
|
342
|
+
'sort' => sort
|
343
|
+
}
|
344
|
+
|
345
|
+
self.hook("/campaigns/#{campaign_id}/txtads/search.xml", "txtad", request, 'GET')
|
346
|
+
end
|
347
|
+
|
348
|
+
#
|
349
|
+
# Merchants: Create Text Ad.
|
350
|
+
# Txtad must be a hash of:
|
351
|
+
# { "title" => "title",
|
352
|
+
# "content" => "content",
|
353
|
+
# "url" => "url",
|
354
|
+
# "help" => "help"
|
355
|
+
# }, where "help" is optional
|
356
|
+
def txtad_create(campaign_id, txtad)
|
357
|
+
request = {
|
358
|
+
'txtad' => txtad
|
359
|
+
}
|
360
|
+
|
361
|
+
self.hook("/campaigns/#{campaign_id}/txtads.xml", "txtad", request, 'POST')
|
362
|
+
end
|
363
|
+
|
364
|
+
|
365
|
+
# Merchants: Update a text ad
|
366
|
+
def txtad_update(campaign_id, txtad_id, txtad)
|
367
|
+
request = {
|
368
|
+
'txtad' => txtad
|
369
|
+
}
|
370
|
+
|
371
|
+
self.hook("/campaigns/#{campaign_id}/txtads/#{txtad_id}.xml", "txtad", request, 'PUT')
|
372
|
+
end
|
373
|
+
|
374
|
+
# Merchants: Destroy a text ad
|
375
|
+
def txtad_destroy(campaign_id, txtad_id)
|
376
|
+
self.hook("/campaigns/#{campaign_id}/txtads/#{txtad_id}.xml", "txtad", nil, 'DELETE')
|
377
|
+
end
|
378
|
+
|
379
|
+
# =========
|
380
|
+
# Banners
|
381
|
+
# =========
|
382
|
+
|
383
|
+
# List banners from a campaign. Displays the first 6 entries by default.
|
384
|
+
def banners_list(campaign_id, page=1, perpage=6)
|
385
|
+
request = {
|
386
|
+
'page' => page,
|
387
|
+
'perpage' => perpage
|
388
|
+
}
|
389
|
+
|
390
|
+
self.hook("/campaigns/#{campaign_id}/banners.xml", "banner", request, 'GET')
|
391
|
+
end
|
392
|
+
|
393
|
+
# Display information about a banner
|
394
|
+
def banner_show(campaign_id, banner_id)
|
395
|
+
self.hook("/campaigns/#{campaign_id}/banners/#{banner_id}.xml", "banner")
|
396
|
+
end
|
397
|
+
|
398
|
+
# Search for banners in a campaign
|
399
|
+
def banners_search(campaign_id, search, page=1, perpage=6, sort='date')
|
400
|
+
request = {
|
401
|
+
'page' => page,
|
402
|
+
'perpage' => perpage,
|
403
|
+
'search' => search,
|
404
|
+
'sort' => sort
|
405
|
+
}
|
406
|
+
|
407
|
+
self.hook("/campaigns/#{campaign_id}/banners/search.xml", "banner", request, 'GET')
|
408
|
+
end
|
409
|
+
|
410
|
+
# Merchants: Create a banner
|
411
|
+
def banner_create(campaign_id, banner, banner_picture)
|
412
|
+
request = {
|
413
|
+
'banner' => banner,
|
414
|
+
'banner_picture' => banner_picture
|
415
|
+
}
|
416
|
+
|
417
|
+
self.hook("/campaigns/#{campaign_id}/banners.xml", "banner", request, 'POST')
|
418
|
+
end
|
419
|
+
|
420
|
+
# Merchants: Update a banner
|
421
|
+
def banner_update(campaign_id, banner_id, banner)
|
422
|
+
request = {
|
423
|
+
'banner' => banner
|
424
|
+
}
|
425
|
+
|
426
|
+
self.hook("/campaigns/#{campaign_id}/banners/#{banner_id}.xml", "banner", request, 'PUT')
|
427
|
+
end
|
428
|
+
|
429
|
+
# Merchants: Destroy a banner
|
430
|
+
def banner_destroy(campaign_id, banner_id)
|
431
|
+
self.hook("/campaigns/#{campaign_id}/banners/#{banner_id}.xml", "banner", nil, 'DELETE')
|
432
|
+
end
|
433
|
+
|
434
|
+
# ===============
|
435
|
+
# Product Stores
|
436
|
+
# ===============
|
437
|
+
|
438
|
+
# List Product Stores from a Campaign
|
439
|
+
def product_stores_list(campaign_id)
|
440
|
+
request = {
|
441
|
+
'campaign_id' => campaign_id
|
442
|
+
}
|
443
|
+
|
444
|
+
self.hook("/product_stores.xml", "product-store", request)
|
445
|
+
end
|
446
|
+
|
447
|
+
# Show a Product Store
|
448
|
+
def product_store_show(product_store_id)
|
449
|
+
self.hook("/product_stores/#{product_store_id}.xml", "product-store")
|
450
|
+
end
|
451
|
+
|
452
|
+
# Show Products from a Product Store
|
453
|
+
def product_store_showitems(product_store_id, category=nil, page=1, perpage=6, uniq_products=nil)
|
454
|
+
request = {
|
455
|
+
'category' => category,
|
456
|
+
'page' => page,
|
457
|
+
'perpage' => perpage
|
458
|
+
}
|
459
|
+
|
460
|
+
request['uniq_products'] = uniq_products if (uniq_products)
|
461
|
+
|
462
|
+
self.hook("/product_stores/#{product_store_id}/showitems.xml", "product-store-data", request)
|
463
|
+
end
|
464
|
+
|
465
|
+
# Show a Product from a Product Store
|
466
|
+
def product_store_showitem(product_store_id, product_id)
|
467
|
+
request = {
|
468
|
+
'product_id' => product_id
|
469
|
+
}
|
470
|
+
|
471
|
+
self.hook("/product_stores/#{product_store_id}/showitem.xml", "product-store-data", request)
|
472
|
+
end
|
473
|
+
|
474
|
+
|
475
|
+
# Search for Products in a Product Store
|
476
|
+
def product_store_products_search(campaign_id, search, product_store_id='all', category=nil, page=1, perpage=6, sort='date', uniq_products=false)
|
477
|
+
request = {
|
478
|
+
'page' => page,
|
479
|
+
'perpage' => perpage,
|
480
|
+
'search' => search,
|
481
|
+
'category' => category,
|
482
|
+
'campaign_id' => campaign_id,
|
483
|
+
'sort' => sort
|
484
|
+
}
|
485
|
+
|
486
|
+
request['uniq_products'] = uniq_products if uniq_products
|
487
|
+
|
488
|
+
product_store_id = 'all' if !product_store_id
|
489
|
+
|
490
|
+
self.hook("/product_stores/#{product_store_id}/searchpr.xml", "product-store-data", request, 'GET')
|
491
|
+
end
|
492
|
+
|
493
|
+
# Merchants: Update a Product Store
|
494
|
+
def product_store_update(product_store_id, product_store)
|
495
|
+
request = {
|
496
|
+
'product_store' => product_store
|
497
|
+
}
|
498
|
+
|
499
|
+
self.hook("/product_stores/#{product_store_id}.xml", "product-store", request, 'PUT')
|
500
|
+
end
|
501
|
+
|
502
|
+
# Merchants: Destroy a Product Store
|
503
|
+
def product_store_destroy(product_store_id)
|
504
|
+
self.hook("/product_stores/#{product_store_id}.xml", "product-store", nil, 'DELETE')
|
505
|
+
end
|
506
|
+
|
507
|
+
#
|
508
|
+
# Merchants: Create a Product Store Product.
|
509
|
+
# Product Store Product must be a hash of:
|
510
|
+
# { "title" => "title",
|
511
|
+
# "description" => "desc",
|
512
|
+
# "caption" => "caption",
|
513
|
+
# "price" => "price(integer in RON)",
|
514
|
+
# "promoted" => "promoted (0 or 1)",
|
515
|
+
# "category" => "category",
|
516
|
+
# "subcategory" => "subcategory",
|
517
|
+
# "url" => "url",
|
518
|
+
# "image_url" => "url to image location",
|
519
|
+
# "prid" => "product id"
|
520
|
+
# }
|
521
|
+
def product_store_createitem(product_store_id, product)
|
522
|
+
request = {
|
523
|
+
'product' => product
|
524
|
+
}
|
525
|
+
|
526
|
+
self.hook("/product_stores/#{product_store_id}/createitem.xml", "product-store-data", request, 'POST')
|
527
|
+
end
|
528
|
+
|
529
|
+
# Merchants: Update a product
|
530
|
+
def product_store_updateitem(product_store_id, product_id, product)
|
531
|
+
request = {
|
532
|
+
'product' => product,
|
533
|
+
'product_id' => product_id
|
534
|
+
}
|
535
|
+
|
536
|
+
self.hook("/product_stores/#{product_store_id}/updateitem.xml", "product-store-data", request, 'PUT')
|
537
|
+
end
|
538
|
+
|
539
|
+
# Merchants: Destroy a product
|
540
|
+
def product_store_destroyitem(product_store_id, product_id)
|
541
|
+
request = {
|
542
|
+
'pr_id' => product_id
|
543
|
+
}
|
544
|
+
|
545
|
+
self.hook("/product_stores/#{product_store_id}/destroyitem.xml", "product-store-data", request, 'DELETE')
|
546
|
+
end
|
547
|
+
|
548
|
+
# =====================
|
549
|
+
# Affiliate Ad Groups
|
550
|
+
# =====================
|
551
|
+
|
552
|
+
# Affiliates: List Ad Groups
|
553
|
+
def ad_groups_list
|
554
|
+
self.hook("/ad_groups.xml", "ad_group", nil, "GET")
|
555
|
+
end
|
556
|
+
|
557
|
+
# Affiliates: Display information about an Ad Group
|
558
|
+
def ad_group_show(ad_group_id)
|
559
|
+
self.hook("/ad_groups/#{ad_group_id}.xml", "ad_group", nil, "GET")
|
560
|
+
end
|
561
|
+
|
562
|
+
# Affiliates: Add item to an Ad Group / Crate new Ad Group
|
563
|
+
def ad_group_createitem(group_id, tool_type, tool_id, new_group = nil)
|
564
|
+
request = {
|
565
|
+
'group_id' => group_id,
|
566
|
+
'new_group' => new_group,
|
567
|
+
'tool_type' => tool_type,
|
568
|
+
'tool_id' => tool_id
|
569
|
+
}
|
570
|
+
|
571
|
+
self.hook("/ad_groups/createitem.xml", "ad_group", request, 'POST')
|
572
|
+
end
|
573
|
+
|
574
|
+
# Affiliates: Destroy an Ad Group
|
575
|
+
def ad_group_destroy(ad_group_id)
|
576
|
+
self.hook("/ad_groups/#{ad_group_id}.xml", "ad_group", nil, "DELETE")
|
577
|
+
end
|
578
|
+
|
579
|
+
# Affiliates: Delete an Tool from a Group. tooltype is one of 'txtlink', 'txtad' or 'banner'.
|
580
|
+
def ad_group_destroyitem(ad_group_id, tool_type, tool_id)
|
581
|
+
request = {
|
582
|
+
'tool_type' => tool_type,
|
583
|
+
'tool_id' => tool_id
|
584
|
+
}
|
585
|
+
|
586
|
+
self.hook("/ad_groups/#{ad_group_id}/destroyitem.xml", "ad_group", request, "DELETE")
|
587
|
+
end
|
588
|
+
|
589
|
+
#=================
|
590
|
+
# Affiliate Feeds
|
591
|
+
#=================
|
592
|
+
|
593
|
+
# Affiliates: List Feeds
|
594
|
+
def feeds_list()
|
595
|
+
self.hook("/feeds.xml", "feed", nil, "GET")
|
596
|
+
end
|
597
|
+
|
598
|
+
# Affiliates: Create a Feed
|
599
|
+
def feed_create(feed)
|
600
|
+
request = {
|
601
|
+
'feed' => feed
|
602
|
+
}
|
603
|
+
|
604
|
+
self.hook("/feeds.xml", "feed", request, 'POST')
|
605
|
+
end
|
606
|
+
|
607
|
+
# Affiliates: Update a Feed
|
608
|
+
def feed_update(feed_id, feed)
|
609
|
+
request = {
|
610
|
+
'feed' => feed
|
611
|
+
}
|
612
|
+
|
613
|
+
self.hook("/feeds/#{feed_id}.xml", "feed", request, 'PUT')
|
614
|
+
end
|
615
|
+
|
616
|
+
|
617
|
+
# Affiliates: Destroy a Feed
|
618
|
+
def feed_destroy(feed_id)
|
619
|
+
self.hook("/feeds/#{feed_id}.xml", "feed", nil, "DELETE")
|
620
|
+
end
|
621
|
+
|
622
|
+
# ==========
|
623
|
+
# Messages
|
624
|
+
# ==========
|
625
|
+
|
626
|
+
# List received messages. Displays the first 6 entries by default.
|
627
|
+
def received_messages_list(page=1, perpage=6)
|
628
|
+
request = {
|
629
|
+
'page' => page,
|
630
|
+
'perpage' => perpage
|
631
|
+
}
|
632
|
+
|
633
|
+
self.hook("/messages.xml", "message", nil, "GET")
|
634
|
+
end
|
635
|
+
|
636
|
+
# List sent messages. Displays the first 6 entries by default.
|
637
|
+
def sent_messages_list(page=1, perpage=6)
|
638
|
+
request = {
|
639
|
+
'page' => page,
|
640
|
+
'perpage' => perpage
|
641
|
+
}
|
642
|
+
|
643
|
+
self.hook("/messages/sent.xml", "message", nil, "GET")
|
644
|
+
end
|
645
|
+
|
646
|
+
# Display information about a message
|
647
|
+
def message_show(message_id)
|
648
|
+
self.hook("/messages/#{message_id}.xml", "message")
|
649
|
+
end
|
650
|
+
|
651
|
+
# Destroy a message
|
652
|
+
def message_destroy(message_id)
|
653
|
+
self.hook("/messages/#{message_id}.xml", "message", nil, 'DELETE')
|
654
|
+
end
|
655
|
+
|
656
|
+
|
657
|
+
#=======
|
658
|
+
# Hooks
|
659
|
+
#=======
|
660
|
+
|
661
|
+
# List Hooks
|
662
|
+
def hooks_list(oauth_token_key = 'current')
|
663
|
+
hook("/oauth_clients/#{oauth_token_key}/hooks.xml", "hook", nil, 'GET')
|
664
|
+
end
|
665
|
+
|
666
|
+
|
667
|
+
# Create a Hook
|
668
|
+
def hook_create(hook, oauth_token_key = 'current')
|
669
|
+
request = {
|
670
|
+
'hook' => hook
|
671
|
+
}
|
672
|
+
|
673
|
+
hook("/oauth_clients/#{oauth_token_key}/hooks.xml", "hook", request, 'POST')
|
674
|
+
end
|
675
|
+
|
676
|
+
# Destroy a Hook
|
677
|
+
def hook_destroy(hook_id, oauth_token_key = 'current')
|
678
|
+
hook("/oauth_clients/#{oauth_token_key}/hooks/#{hook_id}.xml", "hook", nil, 'DELETE')
|
679
|
+
end
|
680
|
+
|
681
|
+
def hook(path, expected, send = nil, method = 'GET') #:nodoc:
|
682
|
+
params = normalize_params(send, method)
|
683
|
+
|
684
|
+
if self.oauth
|
685
|
+
result = self.oauth.send(method.downcase, "/#{version}#{path}", send, params)
|
686
|
+
else
|
687
|
+
result = self.class.send(method.downcase, "/#{version}#{path}", :body => params)
|
688
|
+
end
|
689
|
+
|
690
|
+
# scrap the container
|
691
|
+
if result.respond_to? :values
|
692
|
+
result.values.first
|
693
|
+
else
|
694
|
+
result
|
695
|
+
end
|
696
|
+
end
|
697
|
+
|
698
|
+
def normalize_params(params, method)
|
699
|
+
hash_to_xml(:request => params).to_s
|
700
|
+
end
|
701
|
+
|
702
|
+
def hash_to_xml(var, document = nil)
|
703
|
+
document = REXML::Document.new if document.nil?
|
704
|
+
|
705
|
+
if var.respond_to? :keys
|
706
|
+
var.keys.each do |key|
|
707
|
+
hash_to_xml(var[key], document.add_element(key.to_s))
|
708
|
+
end
|
709
|
+
else
|
710
|
+
document.add_text(var.to_s)
|
711
|
+
end
|
712
|
+
|
713
|
+
document
|
714
|
+
end
|
715
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
|
3
|
+
class DouaParale
|
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
|
+
@headers = { 'Accept' => 'application/xml', 'Content-Type' => 'application/xml' }
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(path, params_hash, params_xml)
|
14
|
+
params_hash ||= {}
|
15
|
+
response = access_token.get("#{path}?#{params_hash.to_params}")
|
16
|
+
Crack::XML.parse(response.body)
|
17
|
+
end
|
18
|
+
|
19
|
+
def post(path, params_hash, params_xml)
|
20
|
+
response = access_token.post(path, params_xml, @headers)
|
21
|
+
Crack::XML.parse(response.body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def put(path, params_hash, params_xml)
|
25
|
+
response = access_token.put(path, params_xml, @headers)
|
26
|
+
Crack::XML.parse(response.body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete(path, params)
|
30
|
+
response = access_token.delete("#{path}?#{params.to_params}")
|
31
|
+
Crack::XML.parse(response.body)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: douaparale
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 2Parale
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2010-07-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oauth
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: shoulda
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Library for the 2Performant API
|
56
|
+
email: gems@2parale.ro
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files:
|
60
|
+
- LICENSE
|
61
|
+
- README.md
|
62
|
+
files:
|
63
|
+
- .document
|
64
|
+
- .gitignore
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- VERSION
|
69
|
+
- douaparale.gemspec
|
70
|
+
- lib/douaparale.rb
|
71
|
+
- lib/douaparale/oauth.rb
|
72
|
+
- test/helper.rb
|
73
|
+
- test/test_2performant.rb
|
74
|
+
homepage: http://github.com/2performant/2Performant
|
75
|
+
licenses: []
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- --charset=UTF-8
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Library for the 2Performant API
|
98
|
+
test_files:
|
99
|
+
- test/helper.rb
|
100
|
+
- test/test_2performant.rb
|