webmoney 0.0.7 → 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.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .bundle
1
2
  doc/*
2
3
  lib/wmsigner.so
3
4
  pkg/*
data/ChangeLog CHANGED
@@ -1,5 +1,12 @@
1
1
  ChangeLog
2
2
 
3
+ Mon Aug 24 2010 12:00:00 +0300
4
+ ----------------------------
5
+ V 0.0.8
6
+ * Compatible with ruby 1.9.2
7
+ * Added Gemfile
8
+
9
+
3
10
  Mon Jun 07 2010 19:01:30 +0400
4
11
  ----------------------------
5
12
  V 0.0.7
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rake-compiler'
4
+ gem 'jeweler'
5
+ gem 'rspec'
6
+ gem 'nokogiri'
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ ---
2
+ dependencies:
3
+ rspec:
4
+ group:
5
+ - :default
6
+ version: ">= 0"
7
+ rake-compiler:
8
+ group:
9
+ - :default
10
+ version: ">= 0"
11
+ jeweler:
12
+ group:
13
+ - :default
14
+ version: ">= 0"
15
+ nokogiri:
16
+ group:
17
+ - :default
18
+ version: ">= 0"
19
+ specs:
20
+ - rake:
21
+ version: 0.8.7
22
+ - gemcutter:
23
+ version: 0.6.1
24
+ - git:
25
+ version: 1.2.5
26
+ - json_pure:
27
+ version: 1.4.6
28
+ - rubyforge:
29
+ version: 2.0.4
30
+ - jeweler:
31
+ version: 1.4.0
32
+ - nokogiri:
33
+ version: 1.4.3.1
34
+ - rake-compiler:
35
+ version: 0.7.1
36
+ - rspec:
37
+ version: 1.3.0
38
+ hash: 46b2419c1fae88ace745852a84f3ee395ef8a70e
39
+ sources:
40
+ - Rubygems:
41
+ uri: http://rubygems.org
data/README CHANGED
@@ -5,6 +5,7 @@ XML-interfaces: http://www.wmtransfer.com/eng/developers/interfaces/index.shtml
5
5
 
6
6
  Gem have built-in native *wmsigner*.
7
7
 
8
+ Compatible with ruby: 1.8.7, 1.9.2
8
9
  Reqirements: Nokogiri >= 1.4.1 built with libxml2 >= 2.7 (IMPORTANT!)
9
10
 
10
11
  Author:: Alexander Oryol (mailto:eagle.alex@gmail.com)
@@ -61,6 +62,12 @@ end
61
62
 
62
63
  wmid = '111222333444'
63
64
 
65
+ = Light
66
+
67
+ cert = OpenSSL::X509::Certificate.new(File.read("webmoney.cert"))
68
+ key = OpenSSL::PKey::RSA.new(File.read("webmoney.key"), "password")
69
+ mywm = MyWM.new(:wmid => '123456789012', :cert => cert, :key => key)
70
+
64
71
  = Passport (X11)
65
72
 
66
73
  Get attestat data:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  # Loads mkmf which is used to make makefiles for Ruby extensions
2
3
  require 'mkmf'
3
4
 
@@ -48,22 +48,22 @@ extern "C" VALUE signer_new(VALUE self, VALUE szWMID, VALUE szPwd, VALUE szKeyDa
48
48
  if(NIL_P(szWMID)) rb_raise(rb_eArgError, "nil wmid");
49
49
 
50
50
  // check WMID
51
- if (! IsWmid(RSTRING(szWMID)->ptr)) rb_raise(rb_eArgError, "Incorrect WMID");
51
+ if (! IsWmid(RSTRING_PTR(szWMID))) rb_raise(rb_eArgError, "Incorrect WMID");
52
52
 
53
53
  if(NIL_P(szPwd)) rb_raise(rb_eArgError, "nil password");
54
54
 
55
55
  if(NIL_P(szKeyData64)) rb_raise(rb_eArgError, "nil key");
56
56
 
57
57
  // check base64 data
58
- if ( RSTRING(szKeyData64)->len != 220 ) rb_raise(rb_eArgError, "Illegal size for base64 keydata");
58
+ if ( RSTRING_LEN(szKeyData64) != 220 ) rb_raise(rb_eArgError, "Illegal size for base64 keydata");
59
59
 
60
60
  char KeyBuffer[ASCII_SIZE];
61
- int bytes = code64( ENCODE, KeyBuffer, ASCII_SIZE, RSTRING(szKeyData64)->ptr, BUF_64_SIZE );
61
+ int bytes = code64( ENCODE, KeyBuffer, ASCII_SIZE, RSTRING_PTR(szKeyData64), BUF_64_SIZE );
62
62
 
63
63
  // check encoded key
64
64
  if ( bytes != 164) rb_raise(rb_eArgError, "Illegal size for keydata");
65
65
 
66
- pSign = new Signer(RSTRING(szWMID)->ptr, RSTRING(szPwd)->ptr, "");
66
+ pSign = new Signer(RSTRING_PTR(szWMID), RSTRING_PTR(szPwd), "");
67
67
  VALUE tdata = Data_Wrap_Struct(self, 0, signer_free, pSign);
68
68
 
69
69
  pSign->isIgnoreKeyFile = TRUE;
@@ -93,7 +93,7 @@ extern "C" VALUE signer_sign(VALUE self, VALUE szIn)
93
93
  if (pSign)
94
94
  {
95
95
  szptr szSign;
96
- if (pSign->Sign(RSTRING(szIn)->ptr, szSign))
96
+ if (pSign->Sign(RSTRING_PTR(szIn), szSign))
97
97
  {
98
98
  ret = rb_str_new2((char *)(const char *)szSign);
99
99
  }
data/lib/messenger.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  require 'thread'
2
3
 
3
4
  module Webmoney
data/lib/passport.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  # Class for store attestat information
2
3
  module Webmoney
3
4
 
data/lib/purse.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  # Support class
2
3
  module Webmoney
3
4
  class Purse < String
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  module Webmoney::RequestResult # :nodoc:all
2
3
 
3
4
  def result_check_sign(doc)
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  module Webmoney::RequestRetval # :nodoc:all
2
3
 
3
4
  def retval_common(doc)
data/lib/request_xml.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  module Webmoney::RequestXML # :nodoc:all
2
3
 
3
4
  def xml_get_passport(opt)
data/lib/webmoney.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  # :title:Webmoney library Documentation
2
3
  # :main:lib/webmoney.rb
3
4
  # :include:README
@@ -96,7 +97,7 @@ module Webmoney
96
97
  when OpenSSL::PKey::RSA, OpenSSL::PKey::DSA
97
98
  @key = opt[:key]
98
99
  @cert = opt[:cert]
99
- @password = opt[:password]
100
+ #@password = opt[:password]
100
101
  end
101
102
 
102
103
  # ca_cert or default
@@ -193,6 +194,10 @@ module Webmoney
193
194
  else
194
195
  raise CaCertificateError, @ca_cert
195
196
  end
197
+ unless classic?
198
+ http.cert = @cert
199
+ http.key = @key
200
+ end
196
201
  http.use_ssl = true
197
202
  @last_request = xml
198
203
  @last_response = result = http.post( url.path, xml, "Content-Type" => "text/xml" )
data/lib/wmid.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  # Support class
2
3
  module Webmoney
3
4
  class Wmid < String
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  require 'rubygems'
2
3
  require 'test/unit'
3
4
  require 'spec'
@@ -16,11 +17,14 @@ end
16
17
 
17
18
  class TestWM
18
19
  include Webmoney
19
- end
20
20
 
21
- def webmoney
22
- TestWM.new :wmid => WmConfig.wmid,
23
- :password => WmConfig.password,
24
- :key => WmConfig.key,
25
- :ca_cert => WmConfig.ca_cert
26
- end
21
+ def initialize(opt = {})
22
+ defaults = {:wmid => WmConfig.wmid,
23
+ :password => WmConfig.password,
24
+ :key => WmConfig.key,
25
+ :ca_cert => WmConfig.ca_cert}
26
+ defaults.merge!(opt)
27
+ super(defaults)
28
+ end
29
+
30
+ end
@@ -1,46 +1,43 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ #encoding: utf-8
2
+ require 'spec_helper'
2
3
 
3
- module Webmoney
4
+ describe Webmoney::Messenger, "class" do
4
5
 
5
- describe Messenger, "class" do
6
+ before(:each) do
7
+ @wm = TestWM.new
8
+ @params = { :wmid => @wm.wmid, :subj => 'FIRST', :text => 'BODY' }
9
+ end
6
10
 
7
- before(:each) do
8
- @wm = webmoney()
9
- @params = { :wmid => @wm.wmid, :subj => 'FIRST', :text => 'BODY' }
10
- end
11
-
12
- it "should create instance" do
13
- @wm.messenger.should be_nil
14
- @wm.send_message(@params)
15
- @wm.messenger.should be_instance_of(Messenger)
16
- end
11
+ it "should create instance" do
12
+ @wm.messenger.should be_nil
13
+ @wm.send_message(@params)
14
+ @wm.messenger.should be_instance_of(Webmoney::Messenger)
15
+ end
17
16
 
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
17
+ it "should send with logger call" do
18
+ self.should_receive(:log_it).once()
19
+ logger = Proc.new do |msg, result|
20
+ case result
21
+ when Hash
22
+ log_it "Message #{msg.inspect} sended in:#{result[:date]} with id:#{result[:id]}"
23
+ else
24
+ log_it "Error sent message #{msg.inspect}: #{result.message}"
27
25
  end
28
- @wm.messenger = Messenger.new(@wm, &logger)
29
- @wm.send_message(@params)
30
- sleep(2)
31
- end
32
-
33
- it "should call request(:send_message) twice" do
34
- # if spec failed here, increase sleep time
35
- @wm.should_receive(:request).
36
- with(:send_message, @params).twice().and_return({:test => 'test'})
37
- 2.times {@wm.send_message(@params)}
38
- # Don't take:
39
- # @wm.messenger.thread.join
40
- # this will create deadlock
41
- sleep(2)
42
26
  end
27
+ @wm.messenger = Webmoney::Messenger.new(@wm, &logger)
28
+ @wm.send_message(@params)
29
+ sleep(2)
30
+ end
43
31
 
32
+ it "should call request(:send_message) twice" do
33
+ # if spec failed here, increase sleep time
34
+ @wm.should_receive(:request).
35
+ with(:send_message, @params).twice().and_return({:test => 'test'})
36
+ 2.times {@wm.send_message(@params)}
37
+ # Don't take:
38
+ # @wm.messenger.thread.join
39
+ # this will create deadlock
40
+ sleep(2)
44
41
  end
45
42
 
46
43
  end
@@ -1,140 +1,126 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ #encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'date'
2
4
 
3
- module Webmoney
5
+ describe Webmoney::Passport, "class" do
4
6
 
5
- describe Passport, "class" do
7
+ before(:each) do
8
+ @wm = TestWM.new
9
+ end
6
10
 
7
- before(:each) do
8
- @wm = webmoney()
9
- end
10
-
11
- it "should return Passport instance" do
12
- Passport.new(@wm.wmid).should be_instance_of(Passport)
13
- end
11
+ it "should return Passport instance" do
12
+ Webmoney::Passport.new(@wm.wmid).should be_instance_of(Webmoney::Passport)
13
+ end
14
14
 
15
- it "request result get_passport should be hash with data" do
16
- wmid = '000000000007'
17
- created_at = Time.at(1077735241.37)
18
- res = @wm.request(:get_passport, :wmid => wmid, :dict => 1)
19
- res[:full_access].should be_false
20
- res[:wmids].should == {
21
- wmid => { :created_at=>Time.at(1077733193.353) }
22
- }
23
- res[:attestat].should == {
24
- :regcid=>"10",
25
- :locked=>"1",
26
- :recalled=>"0",
27
- :cid=>"103453",
28
- :admlocked=>"0",
29
- :created_at=>created_at,
30
- :datecrt=>"2004-02-25T21:54:01.370",
31
- :regnickname=>"WM Passport Service /Центр аттестации/",
32
- :regwmid=>"464889785562",
33
- :attestat=>150,
34
- :tid=>"150",
35
- :datediff=>(Date.today - created_at.send(:to_date)).to_s
36
- }
15
+ it "request result get_passport should be hash with data" do
16
+ wmid = '000000000007'
17
+ res = @wm.request(:get_passport, :wmid => wmid, :dict => 1)
18
+ res[:full_access].should be_false
19
+ res[:wmids][wmid][:created_at].should be_a(Time)
20
+ res[:attestat][:created_at].should be_a(Time)
21
+ [:regcid, :locked, :recalled, :cid, :admlocked, :created_at, :datecrt, :regnickname,
22
+ :regwmid, :attestat, :tid, :datediff].each do |key|
23
+ res[:attestat].should have_key(key)
24
+ end
37
25
 
38
- u_info = {
39
- :locked=>"0",
40
- :ctype=>"1",
41
- :citid=>"12918",
42
- :cap_owner=>"0",
43
- :region=>"Москва",
44
- :countryid=>"195",
45
- :city=>"Москва",
46
- :pasdoc=>"0",
47
- :nickname=>"Арбитр",
48
- :country=>"Россия",
49
- :inndoc=>"0",
50
- :sex=>"0",
51
- :email=>"", :pdateMMDDYYYY => "", :pday => "", :pmonth => "", :pyear => "",
52
- :iname=>"", :inn=>"", :okonx=>"", :bik=>"", :pbywhom=>"", :phonemobile=>"", :rcountry=>"",
53
- :bmonth=>"", :jadres=>"", :okpo=>"", :bday=>"", :pnomer=>"", :bankname=>"", :pcountry=>"", :pcountryid=>"",
54
- :jcountryid=>"", :ks=>"", :infoopen=>"", :icq=>"", :byear=>"", :oname=>"", :osnovainfo=>"", :dirfio=>"",
55
- :pdate=>"", :bplace=>"", :rs=>"", :rcity=>"", :adres=>"", :phone=>"", :buhfio=>"", :radres=>"", :fname=>"",
56
- :phonehome=>"", :jcity=>"", :name=>"", :pcity=>"", :jstatus=>"", :fax=>"", :zipcode=>"", :rcountryid=>"",
57
- :web=>"", :jzipcode=>"", :jcountry=>"", :jabberid=>""
58
- }
26
+ u_info = {
27
+ :locked=>"0",
28
+ :ctype=>"1",
29
+ :citid=>"12918",
30
+ :cap_owner=>"0",
31
+ :region=>"Москва",
32
+ :countryid=>"195",
33
+ :city=>"Москва",
34
+ :pasdoc=>"0",
35
+ :nickname=>"Арбитр",
36
+ :country=>"Россия",
37
+ :inndoc=>"0",
38
+ :sex=>"0",
39
+ :email=>"", :pdateMMDDYYYY => "", :pday => "", :pmonth => "", :pyear => "",
40
+ :iname=>"", :inn=>"", :okonx=>"", :bik=>"", :pbywhom=>"", :phonemobile=>"", :rcountry=>"",
41
+ :bmonth=>"", :jadres=>"", :okpo=>"", :bday=>"", :pnomer=>"", :bankname=>"", :pcountry=>"", :pcountryid=>"",
42
+ :jcountryid=>"", :ks=>"", :infoopen=>"", :icq=>"", :byear=>"", :oname=>"", :osnovainfo=>"", :dirfio=>"",
43
+ :pdate=>"", :bplace=>"", :rs=>"", :rcity=>"", :adres=>"", :phone=>"", :buhfio=>"", :radres=>"", :fname=>"",
44
+ :phonehome=>"", :jcity=>"", :name=>"", :pcity=>"", :jstatus=>"", :fax=>"", :zipcode=>"", :rcountryid=>"",
45
+ :web=>"", :jzipcode=>"", :jcountry=>"", :jabberid=>""
46
+ }
59
47
 
60
48
  # a1 = res[:userinfo].keys.map(&:to_s).sort
61
49
  # a2 = u_info.keys.map(&:to_s).sort
62
50
  # puts ((a1|a2) - (a1 & a2)).inspect
63
51
 
64
- res[:userinfo].should == u_info
65
-
66
- res[:directory].should == {
67
- :ctype=>{
68
- 1=>"Частное лицо",
69
- 2=>"Юридическое лицо"
70
- },
71
- :jstatus=>{
72
- 20=>"Директор юридического лица",
73
- 21=>"Бухгалтер юридического лица",
74
- 22=>"Представитель юридического лица",
75
- 23=>"ИП"
76
- },
77
- :types=>{
78
- 100=>"Аттестат псевдонима",
79
- 110=>"Формальный аттестат",
80
- 120=>"Начальный аттестат",
81
- 130=>"Персональный аттестат",
82
- 135=>"Аттестат продавца",
83
- 136=>"Аттестат Capitaller",
84
- 140=>"Аттестат разработчика",
85
- 150=>"Аттестат регистратора",
86
- 170=>"Аттестат Гаранта",
87
- 190=>"Аттестат сервиса WMT",
88
- 200=>"Аттестат сервиса WMT",
89
- 300=>"Аттестат Оператора"
90
- }
52
+ res[:userinfo].should == u_info
53
+
54
+ res[:directory].should == {
55
+ :ctype=>{
56
+ 1=>"Частное лицо",
57
+ 2=>"Юридическое лицо"
58
+ },
59
+ :jstatus=>{
60
+ 20=>"Директор юридического лица",
61
+ 21=>"Бухгалтер юридического лица",
62
+ 22=>"Представитель юридического лица",
63
+ 23=>"ИП"
64
+ },
65
+ :types=>{
66
+ 100=>"Аттестат псевдонима",
67
+ 110=>"Формальный аттестат",
68
+ 120=>"Начальный аттестат",
69
+ 130=>"Персональный аттестат",
70
+ 135=>"Аттестат продавца",
71
+ 136=>"Аттестат Capitaller",
72
+ 140=>"Аттестат разработчика",
73
+ 150=>"Аттестат регистратора",
74
+ 170=>"Аттестат Гаранта",
75
+ 190=>"Аттестат сервиса WMT",
76
+ 200=>"Аттестат сервиса WMT",
77
+ 300=>"Аттестат Оператора"
91
78
  }
92
- end
93
-
94
- it "should return userinfo attributes with checked/locked" do
95
- wmid = '000000000007'
96
- p = Passport.new(wmid)
97
- p.userinfo[:adres].should be_empty
98
- p.userinfo[:adres].checked.should be_true
99
- p.userinfo[:adres].locked.should be_true
100
- p.userinfo[:inn].should be_empty
101
- p.userinfo[:inn].checked.should be_false
102
- p.userinfo[:inn].locked.should be_true
103
- end
79
+ }
80
+ end
104
81
 
105
- it "should return correct fields" do
106
- wmid = '000000000007'
107
- p = Passport.new(wmid)
108
- p.wmid.should == wmid
109
- p.attestat[:attestat].should == Webmoney::Passport::REGISTRATOR
110
- p.attestat[:created_at].strftime('%Y-%m-%d %H:%M:%S').should == '2004-02-25 21:54:01'
111
- p.full_access.should be_false
112
-
113
- wmid = '370860915669'
114
- p = Passport.new(wmid)
115
- p.wmid.should == wmid
116
- p.attestat[:attestat].should == Webmoney::Passport::ALIAS
117
- p.attestat[:created_at].strftime('%Y-%m-%d %H:%M:%S').should == '2006-04-19 10:16:30'
118
-
119
- wmid = '210971342927'
120
- p = Passport.new(wmid)
121
- p.attestat.should_not be_nil
122
- end
82
+ it "should return userinfo attributes with checked/locked" do
83
+ wmid = '000000000007'
84
+ p = Webmoney::Passport.new(wmid)
85
+ p.userinfo[:adres].should be_empty
86
+ p.userinfo[:adres].checked.should be_true
87
+ p.userinfo[:adres].locked.should be_true
88
+ p.userinfo[:inn].should be_empty
89
+ p.userinfo[:inn].checked.should be_false
90
+ p.userinfo[:inn].locked.should be_true
91
+ end
123
92
 
124
- it "should raise exception on bad WMID" do
125
- lambda {@wm.request(:get_passport, :wmid => '111')}.should raise_error(Webmoney::ResultError)
126
- end
93
+ it "should return correct fields" do
94
+ wmid = '000000000007'
95
+ p = Webmoney::Passport.new(wmid)
96
+ p.wmid.should == wmid
97
+ p.attestat[:attestat].should == Webmoney::Passport::REGISTRATOR
98
+ p.attestat[:created_at].strftime('%Y-%m-%d %H:%M:%S').should == '2004-02-25 21:54:01'
99
+ p.full_access.should be_false
100
+
101
+ wmid = '370860915669'
102
+ p = Webmoney::Passport.new(wmid)
103
+ p.wmid.should == wmid
104
+ p.attestat[:attestat].should == Webmoney::Passport::ALIAS
105
+ p.attestat[:created_at].strftime('%Y-%m-%d %H:%M:%S').should == '2006-04-19 10:16:30'
106
+
107
+ wmid = '210971342927'
108
+ p = Webmoney::Passport.new(wmid)
109
+ p.attestat.should_not be_nil
110
+ end
127
111
 
128
- it "should raise exception on non existent WMID" do
129
- @wm.stub!(:http_request).and_return("<?xml version='1.0' encoding='windows-1251'?><response retval='0'><fullaccess>0</fullaccess><certinfo wmid='012345678901'/><retdesc>WMID not found</retdesc></response>")
130
- lambda {@wm.request(:get_passport, :wmid => '012345678901')}.should raise_error(Webmoney::NonExistentWmidError)
131
- end
112
+ it "should raise exception on bad WMID" do
113
+ lambda {@wm.request(:get_passport, :wmid => '111')}.should raise_error(Webmoney::ResultError)
114
+ end
132
115
 
133
- it "should raise exception on blank response" do
134
- @wm.stub!(:http_request).and_return(nil)
135
- lambda {@wm.request(:get_passport, :wmid => '012345678901')}.should raise_error(Webmoney::NonExistentWmidError)
136
- end
116
+ it "should raise exception on non existent WMID" do
117
+ @wm.stub!(:http_request).and_return("<?xml version='1.0' encoding='windows-1251'?><response retval='0'><fullaccess>0</fullaccess><certinfo wmid='012345678901'/><retdesc>WMID not found</retdesc></response>")
118
+ lambda {@wm.request(:get_passport, :wmid => '012345678901')}.should raise_error(Webmoney::NonExistentWmidError)
119
+ end
137
120
 
121
+ it "should raise exception on blank response" do
122
+ @wm.stub!(:http_request).and_return(nil)
123
+ lambda {@wm.request(:get_passport, :wmid => '012345678901')}.should raise_error(Webmoney::NonExistentWmidError)
138
124
  end
139
125
 
140
126
  end
@@ -1,54 +1,51 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ #encoding: utf-8
2
+ require 'spec_helper'
2
3
 
3
- module Webmoney
4
+ describe Webmoney::Purse, "class" do
4
5
 
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
6
+ before(:all) do
7
+ # initialize worker
8
+ @wm = TestWM.new
9
+ end
15
10
 
16
- it "should be kind of Wmid" do
17
- @t.should be_kind_of(Purse)
18
- end
11
+ before(:each) do
12
+ @t = Webmoney::Purse.new('Z136894439563')
13
+ end
19
14
 
20
- it "should be string" do
21
- @t.should == 'Z136894439563'
22
- end
15
+ it "should be kind of Wmid" do
16
+ @t.should be_kind_of(Webmoney::Purse)
17
+ end
23
18
 
24
- it "should raise error on incorrect" do
25
- lambda{ Purse.new('X123456789012') }.
26
- should raise_error(IncorrectPurseError)
27
- end
19
+ it "should be string" do
20
+ @t.should == 'Z136894439563'
21
+ end
28
22
 
29
- it "should return wmid" do
30
- @t.wmid.should == '405424574082'
31
- end
23
+ it "should raise error on incorrect" do
24
+ lambda{ Webmoney::Purse.new('X123456789012') }.
25
+ should raise_error(Webmoney::IncorrectPurseError)
26
+ end
32
27
 
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
28
+ it "should return wmid" do
29
+ @t.wmid.should == '405424574082'
30
+ end
37
31
 
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
32
+ it "should return true" do
33
+ @wm.should_receive(:request).with(:find_wm, :purse => @t).and_return(:retval=>1, :wmid => '405424574082')
34
+ @t.belong_to?('405424574082').should be_true
35
+ end
42
36
 
43
- context "memoize" do
37
+ it "should return false" do
38
+ @wm.should_receive(:request).with(:find_wm, :purse => @t).and_return(:retval=>0)
39
+ @t.belong_to?('123456789012').should be_false
40
+ end
44
41
 
45
- before(:each) { @t.wmid }
42
+ context "memoize" do
46
43
 
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
44
+ before(:each) { @t.wmid }
51
45
 
46
+ it "it" do
47
+ @wm.should_not_receive(:request).with(:find_wm, :purse => @t)
48
+ @t.belong_to?('405424574082').should be_true
52
49
  end
53
50
 
54
51
  end
@@ -1,4 +1,5 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ #encoding: utf-8
2
+ require 'spec_helper'
2
3
 
3
4
  describe Signer, "class" do
4
5
 
@@ -1,4 +1,5 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ #encoding: utf-8
2
+ require 'spec_helper'
2
3
 
3
4
  describe Time, "class" do
4
5
  it "should test time from_ms" do
@@ -1,144 +1,166 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ #encoding: utf-8
2
+ require 'spec_helper'
2
3
 
3
- module Webmoney
4
+ describe Webmoney, "class" do
4
5
 
5
- describe Webmoney, "class" do
6
+ before(:each) do
7
+ @wm = TestWM.new
8
+ end
6
9
 
7
- before(:each) do
8
- @wm = webmoney()
9
- end
10
+ it "should be classic" do
11
+ @wm.should be_classic # @wm.classic? == true
12
+ end
10
13
 
11
- it "should be classic" do
12
- @wm.should be_classic # @wm.classic? == true
13
- end
14
-
15
- it "should return reqn" do
16
- t1 = @wm.send(:reqn)
17
- sleep(0.1)
18
- t2 = @wm.send(:reqn)
19
- t1.should match(/^\d{16}$/)
20
- (t2 > t1).should be_true
21
- end
14
+ it "should return reqn" do
15
+ t1 = @wm.send(:reqn)
16
+ sleep(0.1)
17
+ t2 = @wm.send(:reqn)
18
+ t1.should match(/^\d{16}$/)
19
+ (t2 > t1).should be_true
20
+ end
22
21
 
23
- it "should correct prepare interfaces urls" do
24
- wm = TestWM.new :wmid => WmConfig.wmid
25
- wm.should_not be_classic
26
- wm.interfaces[:balance].class.should == URI::HTTPS
27
- # converted to light-auth version
28
- wm.interfaces[:balance].to_s.should == 'https://w3s.wmtransfer.com/asp/XMLPursesCert.asp'
29
- # non-converted to light-auth version
30
- wm.interfaces[:get_passport].to_s.should == 'https://passport.webmoney.ru/asp/XMLGetWMPassport.asp'
31
- end
22
+ it "should correct prepare interfaces urls" do
23
+ wm = TestWM.new :wmid => WmConfig.wmid , :key => nil
24
+ wm.should_not be_classic
25
+ wm.interfaces[:balance].class.should == URI::HTTPS
26
+ # converted to light-auth version
27
+ wm.interfaces[:balance].to_s.should == 'https://w3s.wmtransfer.com/asp/XMLPursesCert.asp'
28
+ # non-converted to light-auth version
29
+ wm.interfaces[:get_passport].to_s.should == 'https://passport.webmoney.ru/asp/XMLGetWMPassport.asp'
30
+ end
32
31
 
33
- it "should correct reqn" do
34
- Time.stub!(:now).and_return(Time.at(1244704683.69677))
35
- @wm.send(:reqn).should == '2009061111180369'
36
- end
32
+ it "should correct reqn" do
33
+ Time.stub!(:now).and_return(Time.at(1244704683.69677))
34
+ @wm.send(:reqn).should == '2009061111180369'
35
+ end
37
36
 
38
- it "should correct reqn with zero microsec" do
39
- Time.stub!(:now).and_return(Time.at(1244704683))
40
- @wm.send(:reqn).should == '2009061111180300'
41
- end
37
+ it "should correct reqn with zero microsec" do
38
+ Time.stub!(:now).and_return(Time.at(1244704683))
39
+ @wm.send(:reqn).should == '2009061111180300'
40
+ end
42
41
 
43
- it "should raise error on incorrect arg" do
44
- lambda { @wm.send(:request, :check_sign, 1) }.
45
- should raise_error(ArgumentError)
46
- end
47
-
48
- it "should send request" do
49
- doc = Nokogiri.XML(@wm.send(:https_request, :check_sign, '<w3s.request/>'))
50
- doc.root.should_not be_nil
51
- end
42
+ it "should raise error on incorrect arg" do
43
+ lambda { @wm.send(:request, :check_sign, 1) }.
44
+ should raise_error(ArgumentError)
45
+ end
52
46
 
53
- it"should raise error on bad response" do
54
- lambda { @wm.send(:https_request,
55
- 'https://w3s.wmtransfer.com/asp/XMLUnexistantIface.asp', '<w3s.request/>')}.
56
- should raise_error(RequestError)
57
- @wm.error.should == '404'
58
- @wm.errormsg.should match(/^<!DOCTYPE HTML PUBLIC/)
59
- end
47
+ it "should send request" do
48
+ doc = Nokogiri.XML(@wm.send(:https_request, :check_sign, '<w3s.request/>'))
49
+ doc.root.should_not be_nil
50
+ end
60
51
 
61
- it "should parse retval and raise error" do
62
- lambda { @wm.request(:send_message, :wmid => '')}.should raise_error(ResultError)
63
- @wm.error.should == -2
64
- @wm.errormsg.should match(%r{value of w3s.request/message/receiverwmid is incorrect})
65
- end
52
+ it"should raise error on bad response" do
53
+ lambda { @wm.send(:https_request,
54
+ 'https://w3s.wmtransfer.com/asp/XMLUnexistantIface.asp', '<w3s.request/>')}.
55
+ should raise_error(Webmoney::RequestError)
56
+ @wm.error.should == '404'
57
+ @wm.errormsg.should match(/^<!DOCTYPE HTML PUBLIC/)
58
+ end
66
59
 
67
- it "should sign string" do
68
- @wm.send(:sign, 'Test123').should match(/^[0-9a-f]{132}$/)
69
- end
70
-
71
- it "should return nil on sign empty string" do
72
- @wm.send(:sign, '').should be_nil
73
- end
74
-
75
- it "should check_sign" do
76
- plan = 'test123'
77
- @wm.request(:check_sign,
78
- :wmid => @wm.wmid, :plan => plan, :sign => @wm.send(:sign, plan)).
79
- should be_true
80
- end
60
+ it "should parse retval and raise error" do
61
+ lambda { @wm.request(:send_message, :wmid => '')}.should raise_error(Webmoney::ResultError)
62
+ @wm.error.should == -2
63
+ @wm.errormsg.should match(%r{value of w3s.request/message/receiverwmid is incorrect})
64
+ end
81
65
 
82
- it "should check_sign broken" do
83
- plan = 'test123'
84
- @wm.request(:check_sign,
85
- :wmid => @wm.wmid, :plan => plan, :sign => 'abcd').
86
- should be_false
87
- end
88
-
89
- it "should check_sign with specials" do
90
- plan = '<test>текст</test>'
91
- real_plan = Iconv.conv('CP1251', 'UTF-8', plan)
92
- begin
93
- @wm.request(:check_sign,
94
- :wmid => @wm.wmid,
95
- :plan => plan,
96
- :sign => @wm.send(:sign, real_plan )
97
- ).should be_true
98
- end
99
- end
100
-
101
- it "should parse retval and raise error on broken get_passport" do
102
- lambda { @wm.request(:get_passport, :wmid => '') }.should raise_error(ResultError)
103
- @wm.error.should == 2
104
- @wm.errormsg.should match(%r{неверно указан проверяемый WMID})
105
- end
66
+ it "should sign string" do
67
+ @wm.send(:sign, 'Test123').should match(/^[0-9a-f]{132}$/)
68
+ end
106
69
 
107
- it "should raise exception on bad WMID" do
108
- lambda {@wm.request(:get_passport, :wmid => '111')}.should raise_error(Webmoney::ResultError)
109
- end
70
+ it "should return nil on sign empty string" do
71
+ @wm.send(:sign, '').should be_nil
72
+ end
110
73
 
111
- it "should raise exception on non existent WMID" do
112
- lambda {@wm.request(:get_passport, :wmid => '012345678901')}.should raise_error(Webmoney::NonExistentWmidError)
113
- end
74
+ it "should check_sign" do
75
+ plan = 'test123'
76
+ @wm.request(:check_sign,
77
+ :wmid => @wm.wmid, :plan => plan, :sign => @wm.send(:sign, plan)).
78
+ should be_true
79
+ end
114
80
 
115
- it "should return correct BL" do
116
- wmid = '370860915669'
117
- @wm.request(:bussines_level, :wmid => wmid).should == 0
81
+ it "should check_sign broken" do
82
+ plan = 'test123'
83
+ @wm.request(:check_sign,
84
+ :wmid => @wm.wmid, :plan => plan, :sign => 'abcd').
85
+ should be_false
86
+ end
118
87
 
119
- wmid = Wmid.new '000000000007'
120
- bl = @wm.request(:bussines_level, :wmid => wmid)
121
- (bl > 1000).should be_true
122
- end
123
-
124
- it "should send message" do
125
- result = @wm.request( :send_message,
126
- :wmid => @wm.wmid,
127
- :subj => 'Текст',
128
- :text => 'Тело <b>сообщения</b>')
129
- result.should be_kind_of(Hash)
130
- result[:id].should match(/^\d*$/)
131
- ((result[:date] + 60) > Time.now).should be_true
88
+ it "should check_sign with specials" do
89
+ plan = '<test>текст</test>'
90
+ real_plan = Iconv.conv('CP1251', 'UTF-8', plan)
91
+ begin
92
+ @wm.request(:check_sign,
93
+ :wmid => @wm.wmid,
94
+ :plan => plan,
95
+ :sign => @wm.send(:sign, real_plan )
96
+ ).should be_true
132
97
  end
98
+ end
133
99
 
134
- it "should create transaction" do
135
- # TODO @wm.request( :create_transaction, ...)
136
- end
100
+ it "should parse retval and raise error on broken get_passport" do
101
+ lambda { @wm.request(:get_passport, :wmid => '') }.should raise_error(Webmoney::ResultError)
102
+ @wm.error.should == 2
103
+ @wm.errormsg.should match(%r{неверно указан проверяемый WMID})
104
+ end
137
105
 
138
- it "should raise error on undefined xml func" do
139
- lambda { @wm.request(:unexistent_interface) }.should raise_error(::NoMethodError)
140
- end
106
+ it "should raise exception on bad WMID" do
107
+ lambda {@wm.request(:get_passport, :wmid => '111')}.should raise_error(Webmoney::ResultError)
108
+ end
109
+
110
+ it "should raise exception on non existent WMID" do
111
+ lambda {@wm.request(:get_passport, :wmid => '012345678901')}.should raise_error(Webmoney::NonExistentWmidError)
112
+ end
113
+
114
+ it "should return correct BL" do
115
+ wmid = '370860915669'
116
+ @wm.request(:bussines_level, :wmid => wmid).should == 0
117
+
118
+ wmid = Webmoney::Wmid.new '000000000007'
119
+ bl = @wm.request(:bussines_level, :wmid => wmid)
120
+ (bl > 1000).should be_true
121
+ end
122
+
123
+ it "should send message" do
124
+ result = @wm.request( :send_message,
125
+ :wmid => @wm.wmid,
126
+ :subj => 'Текст',
127
+ :text => 'Тело <b>сообщения</b>')
128
+ result.should be_kind_of(Hash)
129
+ result[:id].should match(/^\d*$/)
130
+ ((result[:date] + 60) > Time.now).should be_true
131
+ end
132
+
133
+ it "should create invoice" do
134
+ # TODO
135
+ #@wm.request(
136
+ # :create_invoice,
137
+ # :orderid => 3,
138
+ # :amount => 10.0,
139
+ # :customerwmid => "TEST_WMID",
140
+ # :storepurse => "Z161888783954",
141
+ # :desc => "Test invoice",
142
+ # :address => "Address"
143
+ #)
144
+ end
145
+
146
+ it "should return operation history" do
147
+ # TODO
148
+ #@mywm.request(:operation_history,
149
+ # :purse => "Z161888783954",
150
+ # :tranid => 148696631,
151
+ # :wminvid => 148613215,
152
+ # :orderid => 1,
153
+ # :datestart => Date.today() - 1,
154
+ # :datefinish => Date.today() + 1
155
+ #)
156
+ end
157
+
158
+ it "should create transaction" do
159
+ # TODO @wm.request( :create_transaction, ...)
160
+ end
141
161
 
162
+ it "should raise error on undefined xml func" do
163
+ lambda { @wm.request(:unexistent_interface) }.should raise_error(::NoMethodError)
142
164
  end
143
165
 
144
- end
166
+ end
@@ -1,30 +1,27 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ #encoding: utf-8
2
+ require 'spec_helper'
2
3
 
3
- module Webmoney
4
+ describe Webmoney::Wmid, "class" do
4
5
 
5
- describe Wmid, "class" do
6
-
7
- before(:each) do
8
- @t = Wmid.new('123456789012')
9
- end
10
-
11
- it "should be kind of Wmid" do
12
- @t.should be_kind_of(Wmid)
13
- end
6
+ before(:each) do
7
+ @t = Webmoney::Wmid.new('123456789012')
8
+ end
14
9
 
15
- it "should be string" do
16
- @t.should == '123456789012'
17
- end
10
+ it "should be kind of Wmid" do
11
+ @t.should be_kind_of(Webmoney::Wmid)
12
+ end
18
13
 
19
- it "should permit initialize by integer" do
20
- Wmid.new(123456789012).should == '123456789012'
21
- end
14
+ it "should be string" do
15
+ @t.should == '123456789012'
16
+ end
22
17
 
23
- it "should raise error on incorrect wmid" do
24
- lambda{Wmid.new('abc')}.
25
- should raise_error(IncorrectWmidError)
26
- end
18
+ it "should permit initialize by integer" do
19
+ Webmoney::Wmid.new(123456789012).should == '123456789012'
20
+ end
27
21
 
22
+ it "should raise error on incorrect wmid" do
23
+ lambda{Webmoney::Wmid.new('abc')}.
24
+ should raise_error(Webmoney::IncorrectWmidError)
28
25
  end
29
26
 
30
27
  end
data/webmoney.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{webmoney}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexander Oryol"]
12
- s.date = %q{2010-06-07}
12
+ s.date = %q{2010-08-24}
13
13
  s.email = %q{eagle.alex@gmail.com}
14
14
  s.extensions = ["ext/wmsigner/extconf.rb"]
15
15
  s.extra_rdoc_files = [
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".gitignore",
21
21
  "ChangeLog",
22
+ "Gemfile",
23
+ "Gemfile.lock",
22
24
  "README",
23
25
  "RUNNING_TESTS",
24
26
  "VERSION",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmoney
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexander Oryol
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-07 00:00:00 +04:00
18
+ date: 2010-08-24 00:00:00 +04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -44,6 +44,8 @@ extra_rdoc_files:
44
44
  files:
45
45
  - .gitignore
46
46
  - ChangeLog
47
+ - Gemfile
48
+ - Gemfile.lock
47
49
  - README
48
50
  - RUNNING_TESTS
49
51
  - VERSION