pasrb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/LICENSE +19 -0
- data/Manifest +10 -0
- data/README +25 -0
- data/Rakefile +11 -0
- data/autotest/discover.rb +1 -0
- data/lib/pas.rb +213 -0
- data/pasrb.gemspec +36 -0
- data/spec/pas_spec.rb +380 -0
- data/spec/spec_helper.rb +7 -0
- metadata +112 -0
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v0.1. Initial release
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
(c) 2010 Mark Abramov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/Manifest
ADDED
data/README
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
PAS.rb -- the ruby window to PAS API
|
2
|
+
------------------------------------
|
3
|
+
|
4
|
+
This gem is a client library for querying PAS API.
|
5
|
+
API docs can be found here: http://www.pokeraffiliatesolutions.com/docs/
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
* `gem install pasrb`
|
11
|
+
* `require pasrb`
|
12
|
+
*
|
13
|
+
pas_api = PAS.new('YOUR_API_ACCESS_KEY', 'YOUR_API_ACCESS_TOKEN')
|
14
|
+
pas_api.list_all_members # { "SAMPLEUSER" => {:id => 28746, :login => "SAMPLEUSER", ...}, "WTFOMG" => {:id => 28123, :login => "WTFOMG", ...} }
|
15
|
+
|
16
|
+
|
17
|
+
Important notes
|
18
|
+
---------------
|
19
|
+
|
20
|
+
That is some minimal subset of PAS API functions (I, for one, don't need most of them), if you'd like to modify / add functionality, feel free to fork + pull request.
|
21
|
+
|
22
|
+
License & Authorship
|
23
|
+
--------------------
|
24
|
+
|
25
|
+
PASrb is written by Mark Markiz Abramov and distributed under terms of MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'echoe'
|
2
|
+
Echoe.new('pasrb', '0.0.1') do |g|
|
3
|
+
g.description = "PokerAffiliateSupport api querying via ruby"
|
4
|
+
g.url = "http://github.com/markiz/pasrb"
|
5
|
+
g.author = "Markiz"
|
6
|
+
g.email = "markizko@gmail.com"
|
7
|
+
g.ignore_pattern = ['spec/*/public/**/*']
|
8
|
+
g.runtime_dependencies = ["mechanize", "xml-simple"]
|
9
|
+
g.development_dependencies = []
|
10
|
+
g.use_sudo = false
|
11
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/lib/pas.rb
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'mechanize'
|
7
|
+
require 'xmlsimple'
|
8
|
+
|
9
|
+
class PAS
|
10
|
+
# Your api key
|
11
|
+
attr_accessor :api_key
|
12
|
+
|
13
|
+
# api token for querying, set it if you know it or let it be auto-requested
|
14
|
+
attr_accessor :api_token
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
def initialize(api_key, api_token, api_site = "publisher.pokeraffiliatesolutions.com")
|
20
|
+
self.api_site = api_site
|
21
|
+
self.api_key = api_key
|
22
|
+
self.api_token = api_token
|
23
|
+
end
|
24
|
+
|
25
|
+
# Site that is using the PAS api
|
26
|
+
def api_site
|
27
|
+
@api_site
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_site=(value)
|
31
|
+
@api_site = value =~ /^https:\/\// ? value : "https://#{value}"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def request_signature(uri, method = "GET", timestamp = Time.now.to_i)
|
36
|
+
payload = api_token.to_s + method + uri + timestamp.to_s
|
37
|
+
signature = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, api_key, payload)
|
38
|
+
CGI::escape(Base64.encode64(signature).chomp)
|
39
|
+
end
|
40
|
+
|
41
|
+
## MEMBER LEVEL
|
42
|
+
|
43
|
+
# List all members
|
44
|
+
# That is a very request-heavy method, be afraid, be very afraid
|
45
|
+
def list_all_members
|
46
|
+
@all_members ||= list_all_members!
|
47
|
+
end
|
48
|
+
alias_method :all_members, :list_all_members
|
49
|
+
|
50
|
+
def list_all_members!
|
51
|
+
members = (1..member_page_count).inject([]) {|result, page| result + member_page(page) }
|
52
|
+
members.inject({}) do |result, member|
|
53
|
+
result[member[:id]] = member
|
54
|
+
result[member[:login]] = member
|
55
|
+
result
|
56
|
+
end
|
57
|
+
rescue
|
58
|
+
{}
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns member page count
|
62
|
+
# @api private
|
63
|
+
def member_page_count
|
64
|
+
@member_page_count ||= member_page_count!
|
65
|
+
end
|
66
|
+
|
67
|
+
# @api private
|
68
|
+
def member_page_count!
|
69
|
+
result = xml_to_hash(make_request("/publisher_members.xml", "GET"))
|
70
|
+
result["members"]["total_pages"].to_i
|
71
|
+
rescue
|
72
|
+
0
|
73
|
+
end
|
74
|
+
|
75
|
+
# Gets a single members page
|
76
|
+
# @api private
|
77
|
+
def member_page(page)
|
78
|
+
result = xml_to_hash(make_request("/publisher_members.xml", "GET", {:page => page}))
|
79
|
+
members = [result["members"]["member"]].flatten
|
80
|
+
symbolize_keys(members).map {|m| m[:id] = m[:id].to_i; m}
|
81
|
+
rescue
|
82
|
+
[]
|
83
|
+
end
|
84
|
+
|
85
|
+
# Gets a list of all member trackers
|
86
|
+
def get_member_trackers(member_id)
|
87
|
+
result = xml_to_hash(make_request("/publisher_members/#{member_id}/stats.xml", "GET"))
|
88
|
+
[result["statistics"]["member_trackers"]["member_tracker"]].flatten.map {|t| symbolize_keys(t) }.map {|t| t[:id] = t[:id].to_i; t }
|
89
|
+
rescue
|
90
|
+
[]
|
91
|
+
end
|
92
|
+
|
93
|
+
def get_member_trackers_stats(member_id, start_date, end_date)
|
94
|
+
@member_tracker_stats ||= {}
|
95
|
+
@member_tracker_stats[member_id] ||= {}
|
96
|
+
@member_tracker_stats[member_id][start_date] ||= {}
|
97
|
+
@member_tracker_stats[member_id][start_date][end_date] ||= get_member_trackers_stats!(member_id, start_date, end_date)
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_member_trackers_stats!(member_id, start_date, end_date)
|
101
|
+
start_date = start_date.strftime("%Y-%m-%d")
|
102
|
+
end_date = end_date.strftime("%Y-%m-%d")
|
103
|
+
response = xml_to_hash(make_request("/publisher_members/#{member_id}/stats.xml", "GET", {:start_date => start_date, :end_date => end_date}))
|
104
|
+
trackers = [response["statistics"]["member_trackers"]["member_tracker"]].flatten
|
105
|
+
trackers.inject({}) do |result, tracker|
|
106
|
+
id = tracker["id"].to_i
|
107
|
+
result[id] = {
|
108
|
+
:identifier => tracker["identifier"],
|
109
|
+
:poker_room_id => tracker["poker_room_id"],
|
110
|
+
:poker_room => tracker["poker_room"],
|
111
|
+
:mgr => tracker["mgr"].to_f,
|
112
|
+
:rakeback => tracker["rakeback"].to_f
|
113
|
+
}
|
114
|
+
result[id.to_s] = result[id]
|
115
|
+
result[tracker["identifier"]] = result[id]
|
116
|
+
result
|
117
|
+
end
|
118
|
+
rescue
|
119
|
+
nil
|
120
|
+
end
|
121
|
+
|
122
|
+
def get_member_tracker_stats(member_id, tracker_id, start_date, end_date)
|
123
|
+
trackers = get_member_trackers_stats(member_id, start_date, end_date)
|
124
|
+
trackers ? trackers[tracker_id] : nil
|
125
|
+
rescue
|
126
|
+
nil
|
127
|
+
end
|
128
|
+
|
129
|
+
def create_member_tracker(member_id, identifier, website_offer_id)
|
130
|
+
new_member_tracker = {"member_tracker" => {"identifier" => identifier, "website_offer_id" => website_offer_id}}
|
131
|
+
response = make_request("/publisher_members/#{member_id}/publisher_member_trackers.xml", "POST", hash_to_xml(new_member_tracker))
|
132
|
+
response = xml_to_hash(response)["member_tracker"]
|
133
|
+
result = {}
|
134
|
+
result[:affiliate_id] = response["affiliate_id"]["content"].to_i
|
135
|
+
result[:id] = response["id"]["content"].to_i
|
136
|
+
result[:identifier] = response["identifier"]
|
137
|
+
result[:member_rakeback_rate] = response["member_rakeback_rate"]
|
138
|
+
result[:poker_room_id] = response["poker_room_id"]
|
139
|
+
result
|
140
|
+
rescue
|
141
|
+
nil
|
142
|
+
end
|
143
|
+
#protected
|
144
|
+
def xml_to_hash(xml)
|
145
|
+
XmlSimple.xml_in(xml,
|
146
|
+
'forcearray' => false,
|
147
|
+
'forcecontent' => false,
|
148
|
+
'keeproot' => true
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
def hash_to_xml(hash)
|
153
|
+
XmlSimple.xml_out(hash,
|
154
|
+
'keeproot' => true
|
155
|
+
)
|
156
|
+
end
|
157
|
+
|
158
|
+
def new_request
|
159
|
+
Mechanize.new
|
160
|
+
end
|
161
|
+
|
162
|
+
def make_request(uri, method, payload = {}, signed = true)
|
163
|
+
request = new_request
|
164
|
+
|
165
|
+
query_params = if signed
|
166
|
+
timestamp = Time.now.to_i
|
167
|
+
{
|
168
|
+
:timestamp, timestamp,
|
169
|
+
:api_token, api_token,
|
170
|
+
:signature, request_signature(uri, method, timestamp)
|
171
|
+
}
|
172
|
+
else
|
173
|
+
{}
|
174
|
+
end
|
175
|
+
|
176
|
+
case method
|
177
|
+
when "GET"
|
178
|
+
request.get(api_site + uri + "?" + build_query_string(query_params.merge(payload))).body
|
179
|
+
when "POST"
|
180
|
+
request.post(api_site + uri + "?" + build_query_string(query_params), payload, "Content-Type" => "application/xml").body
|
181
|
+
else
|
182
|
+
nil
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
#
|
188
|
+
# Basically the same as the Mechanize::Util.build_query_string but without urlencode
|
189
|
+
# (would have urlencoded it twice otherwise)
|
190
|
+
#
|
191
|
+
def build_query_string(params)
|
192
|
+
params.map { |k,v|
|
193
|
+
[k.to_s, v.to_s].join("=") if k
|
194
|
+
}.compact.join('&')
|
195
|
+
end
|
196
|
+
|
197
|
+
# recursive key symbolization
|
198
|
+
def symbolize_keys(arg)
|
199
|
+
case arg
|
200
|
+
when Array
|
201
|
+
arg.map { |elem| symbolize_keys elem }
|
202
|
+
when Hash
|
203
|
+
Hash[
|
204
|
+
arg.map { |key, value|
|
205
|
+
k = key.is_a?(String) ? key.to_sym : key
|
206
|
+
v = symbolize_keys value
|
207
|
+
[k,v]
|
208
|
+
}]
|
209
|
+
else
|
210
|
+
arg
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
data/pasrb.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{pasrb}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Markiz"]
|
9
|
+
s.date = %q{2010-10-19}
|
10
|
+
s.description = %q{PokerAffiliateSupport api querying via ruby}
|
11
|
+
s.email = %q{markizko@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/pas.rb"]
|
13
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "autotest/discover.rb", "lib/pas.rb", "spec/pas_spec.rb", "spec/spec_helper.rb", "pasrb.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/markiz/pasrb}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Pasrb", "--main", "README"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{pasrb}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{PokerAffiliateSupport api querying via ruby}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<mechanize>, [">= 0"])
|
27
|
+
s.add_runtime_dependency(%q<xml-simple>, [">= 0"])
|
28
|
+
else
|
29
|
+
s.add_dependency(%q<mechanize>, [">= 0"])
|
30
|
+
s.add_dependency(%q<xml-simple>, [">= 0"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<mechanize>, [">= 0"])
|
34
|
+
s.add_dependency(%q<xml-simple>, [">= 0"])
|
35
|
+
end
|
36
|
+
end
|
data/spec/pas_spec.rb
ADDED
@@ -0,0 +1,380 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PAS do
|
4
|
+
def stub_request(content)
|
5
|
+
subject.stub!(:new_request).and_return(mock("Request", :get => mock("Response", :body => content), :post => mock("Response", :body => content)))
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { PAS.new("API_MEGA_KEY", "API_ZETA_TOKEN", "exampletracker.com") }
|
9
|
+
|
10
|
+
describe "initialization" do
|
11
|
+
it "should set api key from arguments" do
|
12
|
+
PAS.new("FGSFDS", "").api_key.should == "FGSFDS"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should optionally accept api token" do
|
16
|
+
PAS.new("", "WTF").api_token.should == "WTF"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should optionally set api site from arguments" do
|
20
|
+
PAS.new("", "", "https://exampletracker.com").api_site.should == "https://exampletracker.com"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should prepend https:// to url" do
|
24
|
+
PAS.new("","","exampletracker.com").api_site.should == "https://exampletracker.com"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#request_signature" do
|
30
|
+
subject { PAS.new("BaEc8f13QlXgjQd4fBQ", "143aec8f13dfcc6cb364e6a9c9ff4bb0") }
|
31
|
+
let(:method) { "GET" }
|
32
|
+
let(:uri) { "/publisher_members/404043.xml" }
|
33
|
+
let(:timestamp) { 1276980199 }
|
34
|
+
let(:api_token) { "143aec8f13dfcc6cb364e6a9c9ff4bb0" }
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
Time.stub!(:now).and_return(Time.at(timestamp))
|
38
|
+
subject.api_token = api_token
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should generate valid signature for given params" do
|
42
|
+
subject.request_signature(uri, method).should == "3gc17tMRqcXHxFKxBEdheCYfb0Q%3D"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should accept timestamp as an optional argument" do
|
46
|
+
subject.request_signature(uri, method, timestamp).should == "3gc17tMRqcXHxFKxBEdheCYfb0Q%3D"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#member_page_count" do
|
51
|
+
subject { PAS.new("BaEc8f13QlXgjQd4fBQ", "143aec8f13dfcc6cb364e6a9c9ff4bb0") }
|
52
|
+
before(:each) {
|
53
|
+
stub_request("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<members current_page=\"1\" next_page=\"\" total_pages=\"98\" total_entries=\"0\">\n</members>\n")
|
54
|
+
}
|
55
|
+
it "should set itself from member list page" do
|
56
|
+
subject.send(:member_page_count).should == 98
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return 0 on terrible, terrible failures" do
|
60
|
+
stub_request("<invalid></xml>")
|
61
|
+
subject.send(:member_page_count).should == 0
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#member_page" do
|
66
|
+
before(:each) {
|
67
|
+
stub_request('<?xml version="1.0" encoding="UTF-8"?>
|
68
|
+
<members current_page="2" next_page="3" total_pages="74" total_entries="2943">
|
69
|
+
<member>
|
70
|
+
<id>26371</id>
|
71
|
+
<outside_id></outside_id>
|
72
|
+
<website_id>53</website_id>
|
73
|
+
<login>aurelius</login>
|
74
|
+
<email>aurelius@mail.ru</email>
|
75
|
+
<first_name>Marcus</first_name>
|
76
|
+
<last_name>Aurelius</last_name>
|
77
|
+
<referring_member_id></referring_member_id>
|
78
|
+
<address_1></address_1>
|
79
|
+
<address_2></address_2>
|
80
|
+
<aim></aim>
|
81
|
+
<skype></skype>
|
82
|
+
<phone></phone>
|
83
|
+
<yahoo></yahoo>
|
84
|
+
<city></city>
|
85
|
+
<state></state>
|
86
|
+
<zip_code></zip_code>
|
87
|
+
<country></country>
|
88
|
+
<created_at>2006-10-11 19:00:00 -0500</created_at>
|
89
|
+
<date_of_birth>1964-07-06</date_of_birth>
|
90
|
+
<gender></gender>
|
91
|
+
</member>
|
92
|
+
<member>
|
93
|
+
<id>26380</id>
|
94
|
+
<outside_id></outside_id>
|
95
|
+
<website_id>53</website_id>
|
96
|
+
<login>durachok</login>
|
97
|
+
<email>durachok@yandex.ru</email>
|
98
|
+
<first_name>Dumbo</first_name>
|
99
|
+
<last_name>Shmumbo</last_name>
|
100
|
+
<referring_member_id></referring_member_id>
|
101
|
+
<address_1></address_1>
|
102
|
+
<address_2></address_2>
|
103
|
+
<aim></aim>
|
104
|
+
<skype></skype>
|
105
|
+
<phone></phone>
|
106
|
+
<yahoo></yahoo>
|
107
|
+
<city></city>
|
108
|
+
<state></state>
|
109
|
+
<zip_code></zip_code>
|
110
|
+
<country></country>
|
111
|
+
<created_at>2006-10-12 19:00:00 -0500</created_at>
|
112
|
+
<date_of_birth></date_of_birth>
|
113
|
+
<gender></gender>
|
114
|
+
</member>
|
115
|
+
</members>
|
116
|
+
')
|
117
|
+
}
|
118
|
+
|
119
|
+
it "should parse members out of a member page" do
|
120
|
+
members = subject.member_page(2)
|
121
|
+
members[0][:id].should == 26371
|
122
|
+
members[0][:login].should == "aurelius"
|
123
|
+
members[0][:first_name].should == "Marcus"
|
124
|
+
members[0][:last_name].should == "Aurelius"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should return empty error on failures" do
|
128
|
+
stub_request("<invalid></xml>")
|
129
|
+
subject.member_page(2).should == []
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
describe "#all_members" do
|
135
|
+
before(:each) {
|
136
|
+
stub_request('<?xml version="1.0" encoding="UTF-8"?>
|
137
|
+
<members current_page="1" next_page="1" total_pages="2" total_entries="2">
|
138
|
+
<member>
|
139
|
+
<id>26371</id>
|
140
|
+
<outside_id></outside_id>
|
141
|
+
<website_id>53</website_id>
|
142
|
+
<login>aurelius</login>
|
143
|
+
<email>aurelius@mail.ru</email>
|
144
|
+
<first_name>Marcus</first_name>
|
145
|
+
<last_name>Aurelius</last_name>
|
146
|
+
<referring_member_id></referring_member_id>
|
147
|
+
<address_1></address_1>
|
148
|
+
<address_2></address_2>
|
149
|
+
<aim></aim>
|
150
|
+
<skype></skype>
|
151
|
+
<phone></phone>
|
152
|
+
<yahoo></yahoo>
|
153
|
+
<city></city>
|
154
|
+
<state></state>
|
155
|
+
<zip_code></zip_code>
|
156
|
+
<country></country>
|
157
|
+
<created_at>2006-10-11 19:00:00 -0500</created_at>
|
158
|
+
<date_of_birth>1964-07-06</date_of_birth>
|
159
|
+
<gender></gender>
|
160
|
+
</member>
|
161
|
+
<member>
|
162
|
+
<id>26380</id>
|
163
|
+
<outside_id></outside_id>
|
164
|
+
<website_id>53</website_id>
|
165
|
+
<login>durachok</login>
|
166
|
+
<email>durachok@yandex.ru</email>
|
167
|
+
<first_name>Dumbo</first_name>
|
168
|
+
<last_name>Shmumbo</last_name>
|
169
|
+
<referring_member_id></referring_member_id>
|
170
|
+
<address_1></address_1>
|
171
|
+
<address_2></address_2>
|
172
|
+
<aim></aim>
|
173
|
+
<skype></skype>
|
174
|
+
<phone></phone>
|
175
|
+
<yahoo></yahoo>
|
176
|
+
<city></city>
|
177
|
+
<state></state>
|
178
|
+
<zip_code></zip_code>
|
179
|
+
<country></country>
|
180
|
+
<created_at>2006-10-12 19:00:00 -0500</created_at>
|
181
|
+
<date_of_birth></date_of_birth>
|
182
|
+
<gender></gender>
|
183
|
+
</member>
|
184
|
+
</members>
|
185
|
+
')
|
186
|
+
}
|
187
|
+
|
188
|
+
it "should get all pages of members" do
|
189
|
+
subject.should_receive(:member_page).with(1).and_return([])
|
190
|
+
subject.should_receive(:member_page).with(2).and_return([])
|
191
|
+
subject.all_members
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should return a hash accessible by member id" do
|
195
|
+
subject.all_members[26380][:first_name].should == "Dumbo"
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should return a hash accessible by member login" do
|
199
|
+
subject.all_members["durachok"][:first_name].should == "Dumbo"
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should return empty hash on failures" do
|
203
|
+
stub_request("<invalid></xml>")
|
204
|
+
subject.all_members.should == {}
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "#get_member_trackers" do
|
209
|
+
before(:each) {
|
210
|
+
stub_request('<?xml version="1.0" encoding="UTF-8"?>
|
211
|
+
<statistics start_date="2010-10-01" end_date="2010-10-31">
|
212
|
+
<member_id>26857</member_id>
|
213
|
+
<mgr>-0.39</mgr>
|
214
|
+
<rakeback>-0.13</rakeback>
|
215
|
+
<member_trackers type="array">
|
216
|
+
<member_tracker>
|
217
|
+
<id>9489</id>
|
218
|
+
<identifier>kit_the_kid</identifier>
|
219
|
+
<poker_room_id>5</poker_room_id>
|
220
|
+
<poker_room>UB.com</poker_room>
|
221
|
+
<mgr>0.00</mgr>
|
222
|
+
<rakeback>0.00</rakeback>
|
223
|
+
</member_tracker>
|
224
|
+
<member_tracker>
|
225
|
+
<id>9706</id>
|
226
|
+
<identifier>renevacio</identifier>
|
227
|
+
<poker_room_id>12</poker_room_id>
|
228
|
+
<poker_room>Sun Poker</poker_room>
|
229
|
+
<mgr>0.00</mgr>
|
230
|
+
<rakeback>0.00</rakeback>
|
231
|
+
</member_tracker>
|
232
|
+
<member_tracker>
|
233
|
+
<id>24308</id>
|
234
|
+
<identifier>KitVetrogon</identifier>
|
235
|
+
<poker_room_id>29</poker_room_id>
|
236
|
+
<poker_room>Full Tilt Poker</poker_room>
|
237
|
+
<mgr>-0.39</mgr>
|
238
|
+
<rakeback>-0.13</rakeback>
|
239
|
+
</member_tracker>
|
240
|
+
<member_tracker>
|
241
|
+
<id>25477</id>
|
242
|
+
<identifier>Alan_Dzazoev</identifier>
|
243
|
+
<poker_room_id>85</poker_room_id>
|
244
|
+
<poker_room>Minted Poker</poker_room>
|
245
|
+
<mgr>0.00</mgr>
|
246
|
+
<rakeback>0.00</rakeback>
|
247
|
+
</member_tracker>
|
248
|
+
</member_trackers>
|
249
|
+
</statistics>
|
250
|
+
')
|
251
|
+
}
|
252
|
+
|
253
|
+
it "should get all the member trackers for given member id" do
|
254
|
+
trackers = subject.get_member_trackers(26857)
|
255
|
+
trackers[0][:id].should == 9489
|
256
|
+
trackers[0][:identifier].should == "kit_the_kid"
|
257
|
+
trackers[1][:id].should == 9706
|
258
|
+
trackers[1][:identifier].should == "renevacio"
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should return empty array on failure" do
|
262
|
+
stub_request("<invalid></xml>")
|
263
|
+
subject.get_member_trackers(26857).should == []
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
describe "#get_member_trackers_stats" do
|
269
|
+
before(:each) {
|
270
|
+
stub_request('<?xml version="1.0" encoding="UTF-8"?>
|
271
|
+
<statistics start_date="2010-08-01" end_date="2010-08-18">
|
272
|
+
<member_id>12345</member_id>
|
273
|
+
<mgr>484.91</mgr>
|
274
|
+
<rakeback>218.21</rakeback>
|
275
|
+
<member_trackers type="array">
|
276
|
+
<member_tracker>
|
277
|
+
<id>6</id>
|
278
|
+
<identifier>qq124</identifier>
|
279
|
+
<poker_room_id>293</poker_room_id>
|
280
|
+
<poker_room>Poker Heaven</poker_room>
|
281
|
+
<mgr>484.91</mgr>
|
282
|
+
<rakeback>218.21</rakeback>
|
283
|
+
</member_tracker>
|
284
|
+
<member_tracker>
|
285
|
+
<id>2195</id>
|
286
|
+
<identifier>qq1244343</identifier>
|
287
|
+
<poker_room_id>293</poker_room_id>
|
288
|
+
<poker_room>Poker Heaven</poker_room>
|
289
|
+
<mgr>0</mgr>
|
290
|
+
<rakeback>0</rakeback>
|
291
|
+
</member_tracker>
|
292
|
+
</member_trackers>
|
293
|
+
</statistics>')
|
294
|
+
}
|
295
|
+
|
296
|
+
let(:member_id) { 12345 }
|
297
|
+
|
298
|
+
it "should parse out members" do
|
299
|
+
members = subject.get_member_trackers_stats(member_id, Date.parse("2010-08-01"), Date.parse("2010-08-18"))
|
300
|
+
members[6][:identifier].should == "qq124"
|
301
|
+
members[2195][:identifier].should == "qq1244343"
|
302
|
+
members["qq124"].should == members[6]
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should return nil on terrible, terrible failures" do
|
306
|
+
stub_request("<invalid></xml>")
|
307
|
+
subject.get_member_trackers_stats(member_id, Date.parse("2010-08-01"), Date.parse("2010-08-18")).should == nil
|
308
|
+
end
|
309
|
+
end
|
310
|
+
describe "#get_member_tracker_stats" do
|
311
|
+
before(:each) {
|
312
|
+
stub_request('<?xml version="1.0" encoding="UTF-8"?>
|
313
|
+
<statistics start_date="2010-08-01" end_date="2010-08-18">
|
314
|
+
<member_id>12345</member_id>
|
315
|
+
<mgr>484.91</mgr>
|
316
|
+
<rakeback>218.21</rakeback>
|
317
|
+
<member_trackers type="array">
|
318
|
+
<member_tracker>
|
319
|
+
<id>6</id>
|
320
|
+
<identifier>qq124</identifier>
|
321
|
+
<poker_room_id>293</poker_room_id>
|
322
|
+
<poker_room>Poker Heaven</poker_room>
|
323
|
+
<mgr>484.91</mgr>
|
324
|
+
<rakeback>218.21</rakeback>
|
325
|
+
</member_tracker>
|
326
|
+
<member_tracker>
|
327
|
+
<id>2195</id>
|
328
|
+
<identifier>qq1244343</identifier>
|
329
|
+
<poker_room_id>293</poker_room_id>
|
330
|
+
<poker_room>Poker Heaven</poker_room>
|
331
|
+
<mgr>0</mgr>
|
332
|
+
<rakeback>0</rakeback>
|
333
|
+
</member_tracker>
|
334
|
+
</member_trackers>
|
335
|
+
</statistics>')
|
336
|
+
}
|
337
|
+
|
338
|
+
let(:member_id) { 12345 }
|
339
|
+
|
340
|
+
it "should use members stats for specific member" do
|
341
|
+
subject.get_member_tracker_stats(member_id, "qq124", Date.parse("2010-08-01"), Date.parse("2010-08-18"))[:rakeback].should == 218.21
|
342
|
+
end
|
343
|
+
|
344
|
+
it "should return nil on terrible, terrible failures" do
|
345
|
+
stub_request("<invalid></xml>")
|
346
|
+
subject.get_member_tracker_stats(member_id, "qq124", Date.parse("2010-08-01"), Date.parse("2010-08-18")).should == nil
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
describe "#create_member_tracker" do
|
351
|
+
before(:each) {
|
352
|
+
stub_request('<?xml version="1.0" encoding="UTF-8"?>
|
353
|
+
<member_tracker>
|
354
|
+
<affiliate_id type="integer">6</affiliate_id>
|
355
|
+
<created_at type="datetime">2010-07-09T13:15:47-05:00</created_at>
|
356
|
+
<id type="integer">120070</id>
|
357
|
+
<identifier>NEWTESTRACKER</identifier>
|
358
|
+
<member_id type="integer">222384334</member_id>
|
359
|
+
<poker_room_id type="integer">6</poker_room_id>
|
360
|
+
<signup_url>http://www.absolutepoker.com/main.asp?host=1751</signup_url>
|
361
|
+
<website_id type="integer">4201</website_id>
|
362
|
+
<member_rakeback_rate>30%</member_rakeback_rate>
|
363
|
+
</member_tracker>')
|
364
|
+
}
|
365
|
+
let(:identifier) { "NEWTESTRACKER" }
|
366
|
+
let(:website_offer_id) { 6 }
|
367
|
+
let(:member_id) { 222384334 }
|
368
|
+
it "should send a post request creating a member tracker" do
|
369
|
+
response = subject.create_member_tracker(member_id, identifier, website_offer_id)
|
370
|
+
response[:id].should == 120070
|
371
|
+
response[:identifier].should == "NEWTESTRACKER"
|
372
|
+
response[:member_rakeback_rate].should == "30%"
|
373
|
+
end
|
374
|
+
|
375
|
+
it "should return nil on terrible, terrible failures" do
|
376
|
+
stub_request("<invalid></xml>")
|
377
|
+
subject.create_member_tracker(member_id, identifier, website_offer_id).should == nil
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pasrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Markiz
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-19 00:00:00 +04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: mechanize
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: xml-simple
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: PokerAffiliateSupport api querying via ruby
|
50
|
+
email: markizko@gmail.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- CHANGELOG
|
57
|
+
- LICENSE
|
58
|
+
- README
|
59
|
+
- lib/pas.rb
|
60
|
+
files:
|
61
|
+
- CHANGELOG
|
62
|
+
- LICENSE
|
63
|
+
- Manifest
|
64
|
+
- README
|
65
|
+
- Rakefile
|
66
|
+
- autotest/discover.rb
|
67
|
+
- lib/pas.rb
|
68
|
+
- spec/pas_spec.rb
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
- pasrb.gemspec
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://github.com/markiz/pasrb
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options:
|
77
|
+
- --line-numbers
|
78
|
+
- --inline-source
|
79
|
+
- --title
|
80
|
+
- Pasrb
|
81
|
+
- --main
|
82
|
+
- README
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 11
|
100
|
+
segments:
|
101
|
+
- 1
|
102
|
+
- 2
|
103
|
+
version: "1.2"
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project: pasrb
|
107
|
+
rubygems_version: 1.3.7
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: PokerAffiliateSupport api querying via ruby
|
111
|
+
test_files: []
|
112
|
+
|