2Performant 0.0.1 → 0.0.2
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/2Performant.gemspec +4 -4
- data/README.md +55 -0
- data/VERSION +1 -1
- data/lib/two_performant.rb +53 -19
- data/lib/two_performant/oauth.rb +8 -10
- metadata +5 -5
- data/README.rdoc +0 -17
data/2Performant.gemspec
CHANGED
@@ -5,23 +5,23 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{2Performant}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["2Performant"]
|
12
|
-
s.date = %q{2010-04
|
12
|
+
s.date = %q{2010-05-04}
|
13
13
|
s.description = %q{Library for the 2Performant API}
|
14
14
|
s.email = %q{andrei@2performant.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
"README.
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
22
|
"2Performant.gemspec",
|
23
23
|
"LICENSE",
|
24
|
-
"README.
|
24
|
+
"README.md",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"lib/two_performant.rb",
|
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/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/two_performant.rb
CHANGED
@@ -3,6 +3,9 @@ require 'two_performant/oauth'
|
|
3
3
|
|
4
4
|
class TwoPerformant
|
5
5
|
include HTTParty
|
6
|
+
format :xml
|
7
|
+
headers 'Content-Type' => 'text/xml'
|
8
|
+
|
6
9
|
attr_accessor :user, :pass, :host, :version, :auth_type, :oauth, :oauth_request
|
7
10
|
|
8
11
|
def initialize(auth_type, auth_obj, host)
|
@@ -14,6 +17,7 @@ class TwoPerformant
|
|
14
17
|
return false
|
15
18
|
end
|
16
19
|
|
20
|
+
self.version = "v1.0"
|
17
21
|
self.auth_type = auth_type
|
18
22
|
self.host = host
|
19
23
|
self.class.base_uri host
|
@@ -258,7 +262,12 @@ class TwoPerformant
|
|
258
262
|
|
259
263
|
#
|
260
264
|
# Merchants: Create Text Link.
|
261
|
-
#
|
265
|
+
#
|
266
|
+
# Txtlink must be a hash of:
|
267
|
+
# { "title" => "title",
|
268
|
+
# "url" => "url",
|
269
|
+
# "help" => "help"
|
270
|
+
# }, where "help" is optional
|
262
271
|
|
263
272
|
def txtlink_create(campaign_id, txtlink)
|
264
273
|
request = {
|
@@ -314,8 +323,12 @@ class TwoPerformant
|
|
314
323
|
|
315
324
|
#
|
316
325
|
# Merchants: Create Text Ad.
|
317
|
-
# Txtad must
|
318
|
-
|
326
|
+
# Txtad must be a hash of:
|
327
|
+
# { "title" => "title",
|
328
|
+
# "content" => "content",
|
329
|
+
# "url" => "url",
|
330
|
+
# "help" => "help"
|
331
|
+
# }, where "help" is optional
|
319
332
|
def txtad_create(campaign_id, txtad)
|
320
333
|
request = {
|
321
334
|
'txtad' => txtad
|
@@ -459,11 +472,18 @@ class TwoPerformant
|
|
459
472
|
|
460
473
|
#
|
461
474
|
# Merchants: Create a WidgetStoreProduct.
|
462
|
-
# WidgetStoreProduct must
|
463
|
-
#
|
464
|
-
#
|
465
|
-
#
|
466
|
-
|
475
|
+
# WidgetStoreProduct must be a hash of:
|
476
|
+
# { "title" => "title",
|
477
|
+
# "description" => "desc",
|
478
|
+
# "caption" => "caption",
|
479
|
+
# "price" => "price(integer in RON)",
|
480
|
+
# "promoted" => "promoted (0 or 1)",
|
481
|
+
# "category" => "category",
|
482
|
+
# "subcategory" => "subcategory",
|
483
|
+
# "url" => "url",
|
484
|
+
# "image_url" => "url to image location",
|
485
|
+
# "prid" => "product id"
|
486
|
+
# }
|
467
487
|
def product_store_createitem(product_store_id, product)
|
468
488
|
request = {
|
469
489
|
'product' => product
|
@@ -555,24 +575,38 @@ class TwoPerformant
|
|
555
575
|
end
|
556
576
|
|
557
577
|
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
def hook(path, expected, send = nil, method = 'GET')
|
578
|
+
def hook(path, expected, send = nil, method = 'GET') #:nodoc:
|
579
|
+
params = normalize_params(send, method)
|
580
|
+
|
563
581
|
if self.oauth
|
564
|
-
result = self.oauth.send(method.downcase, path, send)
|
582
|
+
result = self.oauth.send(method.downcase, "/#{version}#{path}", send, params)
|
565
583
|
else
|
566
|
-
result = self.class.send(method.downcase, path, :
|
584
|
+
result = self.class.send(method.downcase, "/#{version}#{path}", :body => params)
|
567
585
|
end
|
568
586
|
|
569
587
|
# scrap the container
|
570
|
-
result.values
|
588
|
+
if result.respond_to? :values
|
589
|
+
result.values.first
|
590
|
+
else
|
591
|
+
result
|
592
|
+
end
|
571
593
|
end
|
572
|
-
|
573
|
-
def
|
594
|
+
|
595
|
+
def normalize_params(params, method)
|
596
|
+
hash_to_xml(:request => params).to_s
|
574
597
|
end
|
575
598
|
|
576
|
-
def
|
599
|
+
def hash_to_xml(var, document = nil)
|
600
|
+
document = REXML::Document.new if document.nil?
|
601
|
+
|
602
|
+
if var.respond_to? :keys
|
603
|
+
var.keys.each do |key|
|
604
|
+
hash_to_xml(var[key], document.add_element(key.to_s))
|
605
|
+
end
|
606
|
+
else
|
607
|
+
document.add_text(var.to_s)
|
608
|
+
end
|
609
|
+
|
610
|
+
document
|
577
611
|
end
|
578
612
|
end
|
data/lib/two_performant/oauth.rb
CHANGED
@@ -7,28 +7,26 @@ class TwoPerformant
|
|
7
7
|
def initialize(options, host)
|
8
8
|
consumer = ::OAuth::Consumer.new(options[:consumer_token], options[:consumer_secret], {:site => host})
|
9
9
|
@access_token = ::OAuth::AccessToken.new(consumer, options[:access_token], options[:access_secret])
|
10
|
+
@headers = { 'Accept' => 'application/xml', 'Content-Type' => 'application/xml' }
|
10
11
|
end
|
11
12
|
|
12
|
-
def get(path,
|
13
|
-
|
14
|
-
response = access_token.get("#{path}?#{
|
13
|
+
def get(path, params_hash, params_xml)
|
14
|
+
params_hash ||= {}
|
15
|
+
response = access_token.get("#{path}?#{params_hash.to_params}")
|
15
16
|
Crack::XML.parse(response.body)
|
16
17
|
end
|
17
18
|
|
18
|
-
def post(path,
|
19
|
-
|
20
|
-
response = access_token.post(path, params)
|
19
|
+
def post(path, params_hash, params_xml)
|
20
|
+
response = access_token.post(path, params_xml, @headers)
|
21
21
|
Crack::XML.parse(response.body)
|
22
22
|
end
|
23
23
|
|
24
|
-
def put(path,
|
25
|
-
|
26
|
-
response = access_token.put(path, params)
|
24
|
+
def put(path, params_hash, params_xml)
|
25
|
+
response = access_token.put(path, params_xml, @headers)
|
27
26
|
Crack::XML.parse(response.body)
|
28
27
|
end
|
29
28
|
|
30
29
|
def delete(path, params)
|
31
|
-
params ||= {}
|
32
30
|
response = access_token.delete("#{path}?#{params.to_params}")
|
33
31
|
Crack::XML.parse(response.body)
|
34
32
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- 2Performant
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04
|
17
|
+
date: 2010-05-04 00:00:00 +03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -49,13 +49,13 @@ extensions: []
|
|
49
49
|
|
50
50
|
extra_rdoc_files:
|
51
51
|
- LICENSE
|
52
|
-
- README.
|
52
|
+
- README.md
|
53
53
|
files:
|
54
54
|
- .document
|
55
55
|
- .gitignore
|
56
56
|
- 2Performant.gemspec
|
57
57
|
- LICENSE
|
58
|
-
- README.
|
58
|
+
- README.md
|
59
59
|
- Rakefile
|
60
60
|
- VERSION
|
61
61
|
- lib/two_performant.rb
|
data/README.rdoc
DELETED
@@ -1,17 +0,0 @@
|
|
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.
|