webmoney 0.0.4.6 → 0.0.4.8

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,5 +1,17 @@
1
1
  ChangeLog
2
2
 
3
+ Sat Oct 03 2009 16:18:00 + 0400
4
+ ----------------------------
5
+ V 0.0.4.8
6
+ * Refactor class Passport
7
+
8
+ Wed Sep 30 2009 16:09:00 + 0400
9
+ ----------------------------
10
+ V 0.0.4.7
11
+ * Class Webmoney refactor to module
12
+ * Add find_wm (X8) interface
13
+ * Add logger call when send message via simple queue
14
+
3
15
  Wed Aug 12 2009 20:31:00 + 0400
4
16
  ----------------------------
5
17
  V 0.0.4.6
data/README CHANGED
@@ -13,6 +13,7 @@ License:: MIT License
13
13
  Completed:
14
14
  - send_message - x6
15
15
  - get_passport - x11
16
+ - find_wm - x8
16
17
  - bussines_level
17
18
 
18
19
  Incompleted (help need!):
@@ -22,7 +23,6 @@ Incompleted (help need!):
22
23
  - outgoing_invoices - x4
23
24
  - finish_protect - x5
24
25
  - check_sign - x7
25
- - find_wm - x8
26
26
  - balance - x9
27
27
  - incoming_invoices - x10
28
28
  - reject_protection - x13
@@ -31,6 +31,9 @@ Incompleted (help need!):
31
31
  - trust_me - x15
32
32
  - trust_save - x15
33
33
  - create_purse - x16
34
+ - create_contract - x17
35
+ - transaction_get - x18
36
+
34
37
 
35
38
  Please, see relative documentation and parameters on wiki:
36
39
 
@@ -48,17 +51,26 @@ http://www.webmoney.ru/rus/developers/interfaces/xml/index.shtml (in russian)
48
51
 
49
52
  = Setup
50
53
 
51
- @wm = Webmoney.new(:wmid => '123456789012', :password => 'my_pass', :key => 'gQABAIR6...2cC8FZTyKyjBM=')
54
+ class MyWM
55
+ include Webmoney
56
+ end
57
+
58
+ @wm = MyWM.new(:wmid => '123456789012', :password => 'my_pass', :key => 'gQABAIR6...2cC8FZTyKyjBM=')
52
59
 
53
60
  wmid = '111222333444'
54
61
 
55
- = Passport (X11) request:
62
+ = Passport (X11)
56
63
 
57
- passport = @wm.request(:get_passport, :wmid => wmid)
64
+ Get attestat data:
65
+ passport = Passport.new(wmid)
66
+ passport.attestat # { # Hash
67
+ # :attestat => 110, # == FORMAL attestat, as example
68
+ # :created_at => Wed Feb 25 21:54:01 +0300 2004 # Time object
69
+ # }
58
70
 
59
- = Bussines level request:
71
+ = Bussines level
60
72
 
61
- bl = @wm.request(:bussines_level, :wmid => wmid)
73
+ bl = @wm.request(:bussines_level, :wmid => wmid) # => 15
62
74
 
63
75
  = Sending message
64
76
 
@@ -66,7 +78,24 @@ bl = @wm.request(:bussines_level, :wmid => wmid)
66
78
  @wm.request(:send_message, :wmid => wmid, :subj => 'Subject', :text => 'Body of \<b>message\</b>')
67
79
 
68
80
  ... for many messages (with queue):
69
- @wm.send_message(:wmid => wmid, :subj => 'Subject', :text => 'Body of \<b>message\</b>')
81
+ @wm.send_message(:wmid => wmid, :subj => 'Subject', :text => 'Body of \<b>message\</b>') do |msg, result|
82
+ File.open("logfile", "w") do |file|
83
+ case result
84
+ when Hash
85
+ file.puts "Message #{msg.inspect} sended in:#{result[:date]} with id:#{result[:id]}"
86
+ else
87
+ file.puts "Error sent message #{msg.inspect}: #{result.message}"
88
+ end
89
+ end
90
+ end
91
+
92
+ = Purses and WMIDs
93
+
94
+ @wm.wmid_exist?('123456789012') # => true
95
+
96
+ purse = Purse.new('Z123456789012')
97
+ purse.wmid # => '123456789012'
98
+ purse.belong_to?('123456789012') # => true
70
99
 
71
100
 
72
- Also, see examples into spec's.
101
+ Also, see spec/* for examples.
data/lib/messenger.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require 'thread'
2
2
 
3
- class Webmoney
3
+ module Webmoney
4
4
 
5
5
  class Messenger
6
-
7
- def initialize(owner)
6
+
7
+ attr_reader :thread
8
+
9
+ def initialize(owner, &logger)
8
10
  @webmoney = owner
9
11
  @queue = Queue.new
10
12
  @thread = Thread.new(@queue) do |q|
@@ -13,16 +15,16 @@ class Webmoney
13
15
  unless msg.nil?
14
16
  begin
15
17
  result = @webmoney.request(:send_message, msg)
16
- # Requeue if fail
18
+ logger.call(msg, result)
19
+ # Requeue message on fail
17
20
  @queue.push(msg) unless result.kind_of?(Hash)
18
21
  rescue ResultError, ResponseError => e
19
- # TODO Replace this to logger call
20
- # puts "#{e}: #{@webmoney.error} #{@webmoney.errormsg}"
21
-
22
+ logger.call(msg, e)
22
23
  # Requeue message
23
24
  @queue.push(msg)
24
25
  end
25
26
  end
27
+ sleep(0.2)
26
28
  end
27
29
  end
28
30
  end
data/lib/passport.rb CHANGED
@@ -1,33 +1,9 @@
1
1
  require 'hpricot'
2
2
 
3
3
  # Class for store attestat information
4
- class Webmoney
4
+ module Webmoney
5
5
  class Passport < Wmid
6
6
 
7
- # doc - Hpricot::Doc or xml-string
8
- def initialize(doc)
9
- doc = Hpricot.XML(doc) unless doc.kind_of?(Hpricot::Doc)
10
- root = doc.at('/response')
11
- if root && root['retval'] && root['retval'].to_i == 0
12
- super(doc.at('/response/certinfo')['wmid'])
13
- raise NonExistentWmidError unless doc.at('/response/certinfo/attestat')
14
- tid = doc.at('/response/certinfo/attestat/row')['tid'].to_i
15
- recalled = doc.at('/response/certinfo/attestat/row')['recalled'].to_i
16
- locked = doc.at('/response/certinfo/userinfo/value/row')['locked'].to_i
17
- @attestat = ( recalled + locked > 0) ? ALIAS : tid
18
- @created_at = Time.xmlschema(doc.at('/response/certinfo/attestat/row')['datecrt'])
19
-
20
- # TODO more attestat fields...
21
-
22
- # Make all instance variables readable
23
- instance_variables.each do |n|
24
- class << self; self; end.instance_eval {
25
- attr_reader n.sub(/^@/, '')
26
- }
27
- end
28
- end
29
- end
30
-
31
7
  # Attestate types
32
8
  ALIAS = 100
33
9
  FORMAL = 110
@@ -41,5 +17,21 @@ class Webmoney
41
17
  SERVICE = 190
42
18
  SERVICE2 = 200
43
19
  OPERATOR = 300
20
+
21
+ attr_reader :attestat
22
+
23
+ def self.worker= (worker)
24
+ @@worker = worker
25
+ end
26
+
27
+ def self.worker
28
+ @@worker
29
+ end
30
+
31
+ def attestat
32
+ # memoize
33
+ @attestat ||= @@worker.request(:get_passport, :wmid => self)
34
+ end
35
+
44
36
  end
45
37
  end
data/lib/purse.rb ADDED
@@ -0,0 +1,39 @@
1
+ # Support class
2
+ module Webmoney
3
+ class Purse < String
4
+
5
+ # Parameter: purse - String or Purse
6
+
7
+ def initialize(str)
8
+ str = str.to_s unless str.kind_of?(String)
9
+ raise IncorrectPurseError, str unless str =~ /^[BCDEGRUYZ]\d{12}$/
10
+ super(str)
11
+ end
12
+
13
+ def purse; self end
14
+
15
+ def self.worker= (worker)
16
+ @@worker = worker
17
+ end
18
+
19
+ def self.worker
20
+ @@worker
21
+ end
22
+
23
+ # Get WMID for this purse
24
+ def wmid
25
+ # memoize
26
+ @wmid ||=
27
+ begin
28
+ res = @@worker.request(:find_wm, :purse => self)
29
+ res[:retval] == 1 ? Wmid.new(res[:wmid]) : nil
30
+ end
31
+ end
32
+
33
+ # Purse is belong to wmid?
34
+ def belong_to?(wmid)
35
+ self.wmid == Wmid.new(wmid)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,36 @@
1
+ module Webmoney::RequestResult # :nodoc:all
2
+
3
+ def result_check_sign(doc)
4
+ doc.at('//testsign/res').inner_html == 'yes' ? true : false
5
+ end
6
+
7
+ def result_get_passport(doc)
8
+ tid = doc.at('/response/certinfo/attestat/row')['tid'].to_i
9
+ recalled = doc.at('/response/certinfo/attestat/row')['recalled'].to_i
10
+ locked = doc.at('/response/certinfo/userinfo/value/row')['locked'].to_i
11
+ { # TODO more attestat fields...
12
+ :attestat => ( recalled + locked > 0) ? Webmoney::Passport::ALIAS : tid,
13
+ :created_at => Time.xmlschema(doc.at('/response/certinfo/attestat/row')['datecrt'])
14
+ }
15
+ end
16
+
17
+ def result_bussines_level(doc)
18
+ doc.at('//level').inner_html.to_i
19
+ end
20
+
21
+ def result_send_message(doc)
22
+ time = doc.at('//message/datecrt').inner_html
23
+ m = time.match(/(\d{4})(\d{2})(\d{2}) (\d{2}):(\d{2}):(\d{2})/)
24
+ time = Time.mktime(*m[1..6])
25
+ { :id => doc.at('//message')['id'], :date => time }
26
+ end
27
+
28
+ def result_find_wm(doc)
29
+ {
30
+ :retval => doc.at('//retval').inner_html.to_i,
31
+ :wmid => (doc.at('//testwmpurse/wmid').inner_html rescue nil),
32
+ :purse => (doc.at('//testwmpurse/purse').inner_html rescue nil)
33
+ }
34
+ end
35
+
36
+ end
@@ -0,0 +1,23 @@
1
+ module Webmoney::RequestRetval # :nodoc:all
2
+
3
+ def retval_common(doc)
4
+ retval_element = doc.at('//retval')
5
+ @error = retval_element.inner_html.to_i
6
+ @errormsg = doc.at('//retdesc') ? doc.at('//retdesc').inner_html : ''
7
+ raise Webmoney::ResultError, [@error, @errormsg].join(' ') unless @error == 0
8
+ end
9
+
10
+ def retval_get_passport(doc)
11
+ # retval is attribute <response>
12
+ @error = doc.at('//response')['retval'].to_i
13
+ @errormsg = doc.at('//response')['retdesc']
14
+ raise Webmoney::ResultError, [@error, @errormsg].join(' ') unless @error == 0
15
+ raise Webmoney::NonExistentWmidError unless doc.at('/response/certinfo/attestat')
16
+ end
17
+
18
+ def retval_find_wm(doc)
19
+ # do nothing
20
+ # retval = { 1 - found; 0 - not found }
21
+ end
22
+
23
+ end
@@ -1,11 +1,11 @@
1
- module Webmoney::XMLRequest # :nodoc:all
1
+ module Webmoney::RequestXML # :nodoc:all
2
2
 
3
3
  def envelope(utf = true)
4
4
  x = Builder::XmlMarkup.new(:indent => 1)
5
5
  encoding = utf ? "utf-8" : "windows-1251"
6
6
  x.instruct!(:xml, :version => "1.0", :encoding => encoding)
7
7
  x
8
- end
8
+ end
9
9
 
10
10
  def xml_get_passport(opt)
11
11
  x = envelope(false)
@@ -66,4 +66,22 @@ module Webmoney::XMLRequest # :nodoc:all
66
66
  x
67
67
  end
68
68
 
69
+ def xml_find_wm(opt)
70
+ x = envelope(false)
71
+ req = reqn()
72
+ x.tag!('w3s.request') do
73
+ x.wmid @wmid
74
+ x.reqn req
75
+ x.testwmpurse do
76
+ x.wmid( opt[:wmid] || '' )
77
+ x.purse( opt[:purse] || '' )
78
+ end
79
+ if classic?
80
+ @plan = "#{opt[:wmid]}#{opt[:purse]}"
81
+ x.sign sign(@plan)
82
+ end
83
+ end
84
+ x
85
+ end
86
+
69
87
  end
data/lib/webmoney.rb CHANGED
@@ -11,20 +11,15 @@ require 'builder'
11
11
  require 'hpricot'
12
12
 
13
13
  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
14
+ %w(wmsigner wmid passport purse request_xml request_retval request_result messenger).each { |lib| require lib }
14
15
 
15
- require 'wmsigner'
16
- require 'wmid'
17
- require 'passport'
18
- require 'request'
19
- require 'result'
20
- require 'messenger'
21
-
22
- # Main class for Webmoney lib. Instance contain info
16
+ # Module for Webmoney lib. Instance contain info
23
17
  # for WMT-interfaces requests (wmid, key, etc).
24
18
  # Implement general requests.
25
- class Webmoney
19
+ module Webmoney
26
20
 
27
- include XMLRequest
21
+ include RequestXML
22
+ include RequestRetval
28
23
  include RequestResult
29
24
 
30
25
  # Error classes
@@ -32,12 +27,14 @@ class Webmoney
32
27
  class RequestError < WebmoneyError; end
33
28
  class ResultError < WebmoneyError; end
34
29
  class IncorrectWmidError < WebmoneyError; end
30
+ class IncorrectPurseError < WebmoneyError; end
35
31
  class NonExistentWmidError < WebmoneyError; end
36
32
  class CaCertificateError < WebmoneyError; end
37
33
 
38
- attr_reader :wmid, :error, :errormsg, :last_request, :messenger
39
- attr_accessor :interfaces
40
-
34
+ attr_reader :wmid, :error, :errormsg, :last_request
35
+ attr_accessor :interfaces, :messenger
36
+
37
+
41
38
  # Required options:
42
39
  #
43
40
  # - :wmid - WMID
@@ -51,11 +48,12 @@ class Webmoney
51
48
  #
52
49
  # Optional:
53
50
  #
54
- # - :ca_cert - path of a CA certification file in PEM format
51
+ # - :ca_cert - file CA certificate or path to directory with certs (in PEM format)
55
52
 
56
53
  def initialize(opt = {})
54
+
57
55
  @wmid = Wmid.new(opt[:wmid])
58
-
56
+
59
57
  # classic or light
60
58
  case opt[:key]
61
59
  when String
@@ -65,9 +63,9 @@ class Webmoney
65
63
  @cert = opt[:cert]
66
64
  @password = opt[:password]
67
65
  end
68
-
66
+
69
67
  # ca_cert or default
70
- @ca_cert =
68
+ @ca_cert =
71
69
  if opt[:ca_cert].nil?
72
70
  File.dirname(__FILE__) + '/../lib/certs/'
73
71
  else
@@ -75,7 +73,7 @@ class Webmoney
75
73
  end
76
74
 
77
75
  w3s = 'https://w3s.wmtransfer.com/asp/'
78
-
76
+
79
77
  @interfaces = {
80
78
  'create_invoice' => URI.parse( w3s + 'XMLInvoice.asp' ), # x1
81
79
  'create_transaction' => URI.parse( w3s + 'XMLTrans.asp' ), # x2
@@ -94,17 +92,22 @@ class Webmoney
94
92
  'trust_me' => URI.parse( w3s + 'XMLTrustList2.asp'), # x15
95
93
  'trust_save' => URI.parse( w3s + 'XMLTrustSave2.asp'), # x15
96
94
  'create_purse' => URI.parse( w3s + 'XMLCreatePurse.asp'), # x16
95
+ 'create_contract' => URI.parse( 'https://arbitrage.webmoney.ru/xml/X17_CreateContract.aspx'), # x17
96
+ 'transaction_get' => URI.parse( 'https://merchant.webmoney.ru/conf/xml/XMLTransGet.asp'), # x18
97
97
  'bussines_level' => URI.parse( 'https://stats.wmtransfer.com/levels/XMLWMIDLevel.aspx')
98
98
  }
99
99
  # Iconv.new(to, from)
100
100
  @ic_in = Iconv.new('UTF-8', 'CP1251')
101
101
  @ic_out = Iconv.new('CP1251', 'UTF-8')
102
+
103
+ # initialize workers by self
104
+ Purse.worker = self
105
+ Passport.worker = self
102
106
  end
103
107
 
104
108
  # Webmoney instance is classic type?
105
-
106
109
  def classic?
107
- ! @signer.nil?
110
+ !! @signer
108
111
  end
109
112
 
110
113
  # Send message through Queue and Thread
@@ -112,23 +115,32 @@ class Webmoney
112
115
  # Params: { :wmid, :subj, :text }
113
116
 
114
117
  def send_message(params)
115
- @messenger = Messenger.new(self) if @messenger.nil?
118
+ @messenger = Messenger.new(self){} if @messenger.nil?
116
119
  @messenger.push(params)
117
120
  end
121
+
122
+ # Check existent WMID or not
123
+ #
124
+ # Params: wmid
125
+ def wmid_exist?(wmid)
126
+ request(:find_wm, :wmid => Wmid.new(wmid))[:retval] == 1
127
+ end
118
128
 
119
129
  # Generic function for request to WMT-interfaces
120
130
 
121
131
  def request(iface, opt ={})
122
- reqn = reqn()
123
- raise ArgumentError unless opt.kind_of?(Hash)
124
- opt[:wmid] = @wmid if opt[:wmid].nil?
132
+ raise ArgumentError, "should be hash" unless opt.kind_of?(Hash)
133
+
134
+ # Use self wmid when not defined
135
+ opt[:wmid] ||= @wmid
125
136
 
126
137
  # Do request
127
138
  res = https_request(iface, make_xml(iface, opt))
128
139
 
129
140
  # Parse response
130
- parse_retval(res)
131
- make_result(iface, res)
141
+ doc = Hpricot.XML(res)
142
+ parse_retval(iface, doc)
143
+ make_result(iface, doc)
132
144
  end
133
145
 
134
146
  # Signing string by instance wmid's,
@@ -173,24 +185,6 @@ class Webmoney
173
185
  end
174
186
  end
175
187
 
176
- def parse_retval(response_xml) # :nodoc:
177
- doc = Hpricot.XML(response_xml)
178
- retval_element = doc.at('//retval')
179
- # Workaround for passport interface
180
- unless retval_element.nil?
181
- retval = retval_element.inner_html.to_i
182
- retdesc = doc.at('//retdesc').inner_html unless doc.at('//retdesc').nil?
183
- else
184
- retval = doc.at('//response')['retval'].to_i
185
- retdesc = doc.at('//response')['retdesc']
186
- end
187
- unless retval == 0
188
- @error = retval
189
- @errormsg = retdesc
190
- raise ResultError, [@error, @errormsg].join(' ')
191
- end
192
- end
193
-
194
188
  # Create unique Request Number based on time,
195
189
  # return 16 digits string
196
190
  def reqn
@@ -200,18 +194,22 @@ class Webmoney
200
194
  end
201
195
 
202
196
  def make_xml(iface, opt) # :nodoc:
203
- iface_func = ('xml_'+iface.to_s).to_sym
204
- self.send(iface_func, opt).target!
205
- rescue NoMethodError
206
- raise NotImplementedError, "#{iface_func}()"
197
+ iface_func = "xml_#{iface}"
198
+ send(iface_func, opt).target!
207
199
  end
208
200
 
209
- def make_result(iface, res) # :nodoc:
210
- doc = Hpricot.XML(res)
211
- iface_result = ('result_'+iface.to_s).to_sym
212
- self.send(iface_result, doc)
213
- rescue NoMethodError
214
- raise NotImplementedError, "#{iface_result}()"
201
+ def parse_retval(iface, doc) # :nodoc:
202
+ method = "retval_#{iface}"
203
+ if respond_to?(method)
204
+ send(method, doc)
205
+ else
206
+ retval_common(doc)
207
+ end
208
+ end
209
+
210
+ def make_result(iface, doc) # :nodoc:
211
+ iface_result = "result_#{iface}"
212
+ send(iface_result, doc)
215
213
  end
216
214
 
217
215
  end
data/lib/wmid.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # Support class
2
- class Webmoney
2
+ module Webmoney
3
3
  class Wmid < String
4
4
 
5
5
  # Parameter: wmid - String or Wmid
data/rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake/clean'
4
4
  require 'tools/rakehelp'
5
5
  require 'spec/rake/spectask'
6
6
 
7
- GEM_VERSION="0.0.4.6"
7
+ GEM_VERSION="0.0.4.7"
8
8
 
9
9
  setup_extension('wmsigner', 'wmsigner')
10
10
 
data/spec/spec_helper.rb CHANGED
@@ -15,8 +15,12 @@ if ENV['WM_ENV']
15
15
  end
16
16
  ::WmConfig = OpenStruct.new(config.common)
17
17
 
18
+ class TestWM
19
+ include Webmoney
20
+ end
21
+
18
22
  def webmoney
19
- Webmoney.new :wmid => WmConfig.wmid,
23
+ TestWM.new :wmid => WmConfig.wmid,
20
24
  :password => WmConfig.password,
21
25
  :key => WmConfig.key,
22
26
  :ca_cert => WmConfig.ca_cert
@@ -1,25 +1,40 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- class Webmoney
3
+ module Webmoney
4
4
 
5
5
  describe Messenger, "class" do
6
6
 
7
7
  before(:each) do
8
- @wm = webmoney()
8
+ @wm = webmoney()
9
+ @params = { :wmid => @wm.wmid, :subj => 'FIRST', :text => 'BODY' }
9
10
  end
10
11
 
11
12
  it "should create instance" do
12
13
  @wm.messenger.should be_nil
13
- @wm.send_message(:wmid => @wm.wmid, :subj => 'FIRST', :text => 'BODY')
14
+ @wm.send_message(@params)
14
15
  @wm.messenger.should be_instance_of(Messenger)
15
16
  end
16
-
17
+
18
+ it "should send with logger call" do
19
+ self.should_receive(:log_it).once()
20
+ logger = Proc.new do |msg, result|
21
+ case result
22
+ when Hash
23
+ log_it "Message #{msg.inspect} sended in:#{result[:date]} with id:#{result[:id]}"
24
+ else
25
+ log_it "Error sent message #{msg.inspect}: #{result.message}"
26
+ end
27
+ end
28
+ @wm.messenger = Messenger.new(@wm, &logger)
29
+ @wm.send_message(@params)
30
+ sleep(2)
31
+ end
32
+
17
33
  it "should call request(:send_message) twice" do
18
- params = { :wmid => @wm.wmid, :subj => 'FIRST', :text => 'BODY' }
19
34
  @wm.should_receive(:request).
20
- with(:send_message, params).twice().and_return({:test => 'test'})
21
- @wm.send_message(params)
22
- @wm.send_message(params)
35
+ with(:send_message, @params).twice().and_return({:test => 'test'})
36
+ 2.times {@wm.send_message(@params)}
37
+ sleep(2)
23
38
  end
24
39
 
25
40
  end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- class Webmoney
3
+ module Webmoney
4
4
 
5
5
  describe Passport, "class" do
6
6
 
@@ -8,38 +8,34 @@ class Webmoney
8
8
  @wm = webmoney()
9
9
  end
10
10
 
11
- def make_request(wmid=nil) # :nodoc:
12
- test_wmid = wmid || @wm.wmid
13
- x = Builder::XmlMarkup.new
14
- x.request do
15
- x.wmid @wm.wmid
16
- x.passportwmid test_wmid
17
- x.sign @wm.send(:sign, @wm.wmid + test_wmid)
18
- x.params { x.dict 0; x.info 1; x.mode 0 }
19
- end
20
- x.target!
21
- end
22
-
23
- it "should return empty on incorrect xml" do
24
- Passport.new('<response/>').should == ''
11
+ it "should return Passport instance" do
12
+ Passport.new(@wm.wmid).should be_instance_of(Passport)
25
13
  end
26
14
 
27
- it "should return Passport instance" do
28
- Passport.new(@wm.send(:https_request, :get_passport, make_request)).should be_instance_of(Passport)
15
+ it "request result get_passport should be Hash" do
16
+ @wm.request(:get_passport, :wmid => @wm.wmid).should be_instance_of(Hash)
29
17
  end
30
18
 
31
19
  it "should return correct data" do
32
20
  wmid = '000000000007'
33
- p = Passport.new(@wm.send(:https_request, :get_passport, make_request(wmid)))
21
+ p = Passport.new(wmid)
34
22
  p.wmid.should == wmid
35
- p.attestat.should == Webmoney::Passport::REGISTRATOR
36
- p.created_at.strftime('%Y-%m-%d %H:%M:%S').should == '2004-02-25 21:54:01'
23
+ p.attestat[:attestat].should == Webmoney::Passport::REGISTRATOR
24
+ p.attestat[:created_at].strftime('%Y-%m-%d %H:%M:%S').should == '2004-02-25 21:54:01'
37
25
 
38
26
  wmid = '370860915669'
39
- p = Passport.new(@wm.send(:https_request, :get_passport, make_request(wmid)))
27
+ p = Passport.new(wmid)
40
28
  p.wmid.should == wmid
41
- p.attestat.should == Webmoney::Passport::ALIAS
42
- p.created_at.strftime('%Y-%m-%d %H:%M:%S').should == '2006-04-19 10:16:30'
29
+ p.attestat[:attestat].should == Webmoney::Passport::ALIAS
30
+ p.attestat[:created_at].strftime('%Y-%m-%d %H:%M:%S').should == '2006-04-19 10:16:30'
31
+ end
32
+
33
+ it "should raise exception on bad WMID" do
34
+ lambda {@wm.request(:get_passport, :wmid => '111')}.should raise_error(Webmoney::ResultError)
35
+ end
36
+
37
+ it "should raise exception on non existent WMID" do
38
+ lambda {@wm.request(:get_passport, :wmid => '012345678901')}.should raise_error(Webmoney::NonExistentWmidError)
43
39
  end
44
40
 
45
41
  end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module Webmoney
4
+
5
+ describe Purse, "class" do
6
+
7
+ before(:all) do
8
+ # initialize worker
9
+ @wm = webmoney
10
+ end
11
+
12
+ before(:each) do
13
+ @t = Purse.new('Z136894439563')
14
+ end
15
+
16
+ it "should be kind of Wmid" do
17
+ @t.should be_kind_of(Purse)
18
+ end
19
+
20
+ it "should be string" do
21
+ @t.should == 'Z136894439563'
22
+ end
23
+
24
+ it "should raise error on incorrect" do
25
+ lambda{ Purse.new('X123456789012') }.
26
+ should raise_error(IncorrectPurseError)
27
+ end
28
+
29
+ it "should return wmid" do
30
+ @t.wmid.should == '405424574082'
31
+ end
32
+
33
+ it "should return true" do
34
+ @wm.should_receive(:request).with(:find_wm, :purse => @t).and_return(:retval=>1, :wmid => '405424574082')
35
+ @t.belong_to?('405424574082').should be_true
36
+ end
37
+
38
+ it "should return false" do
39
+ @wm.should_receive(:request).with(:find_wm, :purse => @t).and_return(:retval=>0)
40
+ @t.belong_to?('123456789012').should be_false
41
+ end
42
+
43
+ context "memoize" do
44
+
45
+ before(:each) { @t.wmid }
46
+
47
+ it "it" do
48
+ @wm.should_not_receive(:request).with(:find_wm, :purse => @t)
49
+ @t.belong_to?('405424574082').should be_true
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- class Webmoney
3
+ module Webmoney
4
4
 
5
5
  describe Webmoney, "class" do
6
6
 
@@ -8,10 +8,6 @@ class Webmoney
8
8
  @wm = webmoney()
9
9
  end
10
10
 
11
- it "should be instance of Webmoney" do
12
- @wm.should be_instance_of(Webmoney)
13
- end
14
-
15
11
  it "should be classic" do
16
12
  @wm.classic?.should be_true
17
13
  end
@@ -95,10 +91,6 @@ class Webmoney
95
91
  @wm.errormsg.should match(%r{неверно указан проверяемый WMID})
96
92
  end
97
93
 
98
- it "should get_passport" do
99
- @wm.request(:get_passport, :wmid => @wm.wmid).should be_instance_of(Passport)
100
- end
101
-
102
94
  it "should raise exception on bad WMID" do
103
95
  lambda {@wm.request(:get_passport, :wmid => '111')}.should raise_error(Webmoney::ResultError)
104
96
  end
@@ -117,15 +109,17 @@ class Webmoney
117
109
  end
118
110
 
119
111
  it "should send message" do
120
- result = @wm.request(:send_message,
121
- :wmid => @wm.wmid, :subj => 'Текст', :text => 'Тело <b>сообщения</b>')
112
+ result = @wm.request( :send_message,
113
+ :wmid => @wm.wmid,
114
+ :subj => 'Текст',
115
+ :text => 'Тело <b>сообщения</b>')
122
116
  result.should be_kind_of(Hash)
123
117
  result[:id].should match(/^\d*$/)
124
118
  ((result[:date] + 60) > Time.now).should be_true
125
119
  end
126
120
 
127
121
  it "should raise error on undefined xml func" do
128
- lambda { @wm.request(:unexistent_interface) }.should raise_error(::NotImplementedError)
122
+ lambda { @wm.request(:unexistent_interface) }.should raise_error(::NoMethodError)
129
123
  end
130
124
 
131
125
  end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- class Webmoney
3
+ module Webmoney
4
4
 
5
5
  describe Wmid, "class" do
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmoney
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.6
4
+ version: 0.0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Oryol
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-12 00:00:00 +04:00
12
+ date: 2009-10-03 00:00:00 +04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,11 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: "0"
34
34
  version:
35
- description:
35
+ description: |
36
+ This library should help to make requests to WebMoney Transfer http://www.wmtransfer.com
37
+ XML-interfaces: http://www.wmtransfer.com/eng/developers/interfaces/index.shtml
38
+ Gem have built-in native wmsigner tool.
39
+
36
40
  email: eagle.alex@gmail.com
37
41
  executables: []
38
42
 
@@ -50,9 +54,11 @@ files:
50
54
  - lib/certs/AddTrust_External_Root.crt
51
55
  - lib/certs/WebMoneyCA.crt
52
56
  - lib/messenger.rb
53
- - lib/request.rb
54
- - lib/result.rb
57
+ - lib/request_result.rb
58
+ - lib/request_retval.rb
59
+ - lib/request_xml.rb
55
60
  - lib/passport.rb
61
+ - lib/purse.rb
56
62
  - lib/webmoney.rb
57
63
  - lib/wmid.rb
58
64
  - ext/wmsigner/extconf.rb
@@ -104,6 +110,7 @@ test_files:
104
110
  - spec/spec_helper.rb
105
111
  - spec/unit/messenger_spec.rb
106
112
  - spec/unit/passport_spec.rb
113
+ - spec/unit/purse_spec.rb
107
114
  - spec/unit/signer_spec.rb
108
115
  - spec/unit/time_spec.rb
109
116
  - spec/unit/webmoney_spec.rb
data/lib/result.rb DELETED
@@ -1,21 +0,0 @@
1
- module Webmoney::RequestResult # :nodoc:all
2
-
3
- def result_check_sign(doc)
4
- doc.at('//testsign/res').inner_html == 'yes' ? true : false
5
- end
6
-
7
- def result_get_passport(doc)
8
- Webmoney::Passport.new(doc)
9
- end
10
-
11
- def result_bussines_level(doc)
12
- doc.at('//level').inner_html.to_i
13
- end
14
-
15
- def result_send_message(doc)
16
- time = doc.at('//message/datecrt').inner_html
17
- m = time.match(/(\d{4})(\d{2})(\d{2}) (\d{2}):(\d{2}):(\d{2})/)
18
- time = Time.mktime(*m[1..6])
19
- { :id => doc.at('//message')['id'], :date => time }
20
- end
21
- end