rack-webmoney 0.0.5 → 0.0.6

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/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/SkyEagle/rack-webmoney"
12
12
  gem.authors = ['Anton Orel', 'Alexander Orel']
13
13
  gem.add_dependency(%q<rack>, ">= 1.1.0")
14
- gem.add_dependency(%q<savon>, ">= 0.7.9")
14
+ gem.add_dependency(%q<webmoney>, ">= 0.0.9")
15
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
16
  end
17
17
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
data/lib/rack/webmoney.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  #encoding: utf-8
2
2
  require 'rack/request'
3
3
  require 'rack/utils'
4
+ require 'logger'
4
5
 
5
- require "savon"
6
+ require "webmoney"
6
7
 
7
8
  module Rack #:nodoc:
8
9
  # A Rack middleware that provides a more HTTPish API around Webmoney authentication
@@ -14,8 +15,14 @@ module Rack #:nodoc:
14
15
  # On competition, the Webmoney response is automatically verified and
15
16
  # assigned to <tt>env["rack.webmoney.response"]</tt>.
16
17
  class Webmoney
18
+ class WmLib
19
+ include ::Webmoney
20
+ end
21
+
17
22
  class Response
18
23
  ERROR_MESSAGES = {
24
+ # -3 unknown response
25
+ :server_not_available => "Unknown response",
19
26
  # -2 raised network error
20
27
  :server_not_available => "Sorry, the Webmoney Login server is not available",
21
28
  # -1
@@ -70,14 +77,10 @@ module Rack #:nodoc:
70
77
  end
71
78
 
72
79
  def wmid
73
- @info[:wmid]
80
+ @info[:WmLogin_WMID]
74
81
  end
75
82
  end
76
83
 
77
- #SOAP driver setup
78
- #@@driver = SOAP::WSDLDriverFactory.new('https://login.wmtransfer.com/ws/Security.asmx?WSDL').create_rpc_driver
79
- #@@driver.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_PEER
80
-
81
84
  #
82
85
  # Helper method for building the "WWW-Authenticate" header value.
83
86
  #
@@ -133,18 +136,25 @@ module Rack #:nodoc:
133
136
 
134
137
  URL_FIELD_SELECTOR = lambda { |field| field.to_s =~ %r{^https://} }
135
138
 
136
- attr_reader :credentials, :mode
139
+ attr_reader :credentials, :mode, :wm_instance
137
140
 
138
141
  # :startdoc:
139
142
 
140
143
  # Initialize middleware with application
141
144
  #
142
- # use Rack::Webmoney, :credentials => {:site_holder_wmid => 'your_site_holder_wmid', :site_rid => 'your_site_rid'}, :mode => Rails.env
145
+ # use Rack::Webmoney, :credentials => {:site_holder_wmid => 'your_site_holder_wmid',
146
+ # :site_rid => 'your_site_rid'},
147
+ # :mode => Rails.env
143
148
  #
144
149
  def initialize(app, opts ={})
145
150
  @app = app
146
151
  @credentials = opts[:credentials]
147
152
  @mode = opts[:mode]
153
+ @wm_instance = if defined?(Rails)
154
+ Rails.webmoney
155
+ else
156
+ WmLib.new(:wmid => @credentials[:site_holder_wmid])
157
+ end
148
158
  end
149
159
 
150
160
  # Standard Rack +call+ dispatch that accepts an +env+ and
@@ -185,57 +195,48 @@ module Rack #:nodoc:
185
195
  end
186
196
 
187
197
  wminfo =
188
- { :ticket => req.params["WmLogin_Ticket"],
189
- :url_id => req.params["WmLogin_UrlID"],
190
- :expires => req.params["WmLogin_Expires"],
191
- :auth_type => req.params["WmLogin_AuthType"],
192
- :last_access => req.params["WmLogin_LastAccess"],
193
- :created => req.params["WmLogin_Created"],
194
- :wmid => req.params["WmLogin_WMID"],
195
- :user_ip => req.params["WmLogin_UserAddress"] }
198
+ { :WmLogin_Ticket => req.params["WmLogin_Ticket"],
199
+ :WmLogin_UrlID => req.params["WmLogin_UrlID"],
200
+ :WmLogin_Expire => req.params["WmLogin_Expires"],
201
+ :WmLogin_AuthType => req.params["WmLogin_AuthType"],
202
+ :WmLogin_LastAccess => req.params["WmLogin_LastAccess"],
203
+ :WmLogin_Created => req.params["WmLogin_Created"],
204
+ :WmLogin_WMID => req.params["WmLogin_WMID"],
205
+ :WmLogin_UserAddress => req.params["WmLogin_UserAddress"] }
196
206
 
197
207
  # work around for local development
198
- ip_to_check = %w(development test).include?(mode) ? wminfo[:user_ip] : req.ip
199
-
200
- check_req_params = {
201
- :SiteHolderWMID => credentials[:site_holder_wmid],
202
- :wmId => wminfo[:wmid],
203
- :ticket => wminfo[:ticket],
204
- :urlId => wminfo[:url_id],
205
- :authType => wminfo[:auth_type],
206
- :userAddress => ip_to_check
207
- }
208
+ ip_to_check = %w(development test).include?(mode) ? wminfo[:WmLogin_UserAddress] : req.ip
209
+
210
+ check_req_params = wminfo.merge({:remote_ip => ip_to_check})
208
211
 
209
212
  begin
210
- soap_client = Savon::Client.new "https://login.wmtransfer.com/ws/Security.asmx"
211
- response = soap_client.authorize! do |soap| # (!) disable WSDL
212
- soap.namespace = "http://WmLogin.webmoney.ru/"
213
- soap.action = "http://WmLogin.webmoney.ru/Authorize"
214
- soap.body = check_req_params
215
- end.to_hash[:authorize_response][:authorize_result]
216
- rescue Errno::ECONNRESET, Errno::ECONNREFUSED, Timeout::Error
217
- response = '-2'
213
+ response = wm_instance.request(:login, check_req_params)[:retval]
214
+ rescue Errno::ECONNRESET, Errno::ECONNREFUSED, Timeout::Error => e
215
+ logger.info("Rack webmoney exception: #{e}")
216
+ response = -2
217
+ rescue ::Webmoney::ResultError => e
218
+ logger.info("Rack webmoney exception: #{e}")
219
+ response = wm_instance.error
218
220
  end
219
221
 
220
222
  status = case response
221
- when '0' then :successful
222
- when '-2' then :server_not_available
223
- when '-1' then :internal_error
224
- when '1' then :invalid_arguments
225
- when '2' then :ticket_invalid
226
- when '3' then :ticket_expired
227
- when '4' then :user_not_found
228
- when '5' then :holder_not_found
229
- when '6' then :website_not_found
230
- when '7' then :url_not_found
231
- when '8' then :settings_not_found
232
- when '9' then :invalid_password
233
- when '10' then :not_trusted
234
- when '11' then :pwd_access_blocked
235
- when '12' then :user_blocked
236
- when '201' then :ip_differs
237
- else
238
- "Unknown response code(#{response})"
223
+ when 0 then :successful
224
+ when -3 then :unknown_response
225
+ when -2 then :server_not_available
226
+ when -1 then :internal_error
227
+ when 1 then :invalid_arguments
228
+ when 2 then :ticket_invalid
229
+ when 3 then :ticket_expired
230
+ when 4 then :user_not_found
231
+ when 5 then :holder_not_found
232
+ when 6 then :website_not_found
233
+ when 7 then :url_not_found
234
+ when 8 then :settings_not_found
235
+ when 9 then :invalid_password
236
+ when 10 then :not_trusted
237
+ when 11 then :pwd_access_blocked
238
+ when 12 then :user_blocked
239
+ when 201 then :ip_differs
239
240
  end
240
241
 
241
242
  env[RESPONSE] = Response.new(status, wminfo)
@@ -248,7 +249,7 @@ module Rack #:nodoc:
248
249
  end
249
250
 
250
251
  def logger
251
- @logger ||= Rails.logger if defined?(Rails)
252
+ @logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
252
253
  end
253
254
  end
254
255
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rack-webmoney}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Anton Orel", "Alexander Orel"]
12
- s.date = %q{2010-09-03}
12
+ s.date = %q{2010-09-24}
13
13
  s.description = %q{Rack webmoney authentication}
14
14
  s.email = ["eagle.anton@gmail.com", "eagle.alex@gmail.com"]
15
15
  s.extra_rdoc_files = [
@@ -36,14 +36,14 @@ Gem::Specification.new do |s|
36
36
 
37
37
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
38
38
  s.add_runtime_dependency(%q<rack>, [">= 1.1.0"])
39
- s.add_runtime_dependency(%q<savon>, [">= 0.7.9"])
39
+ s.add_runtime_dependency(%q<webmoney>, [">= 0.0.9"])
40
40
  else
41
41
  s.add_dependency(%q<rack>, [">= 1.1.0"])
42
- s.add_dependency(%q<savon>, [">= 0.7.9"])
42
+ s.add_dependency(%q<webmoney>, [">= 0.0.9"])
43
43
  end
44
44
  else
45
45
  s.add_dependency(%q<rack>, [">= 1.1.0"])
46
- s.add_dependency(%q<savon>, [">= 0.7.9"])
46
+ s.add_dependency(%q<webmoney>, [">= 0.0.9"])
47
47
  end
48
48
  end
49
49
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Anton Orel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-03 00:00:00 +04:00
18
+ date: 2010-09-24 00:00:00 +04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,7 +34,7 @@ dependencies:
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
37
- name: savon
37
+ name: webmoney
38
38
  prerelease: false
39
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
@@ -43,9 +43,9 @@ dependencies:
43
43
  - !ruby/object:Gem::Version
44
44
  segments:
45
45
  - 0
46
- - 7
46
+ - 0
47
47
  - 9
48
- version: 0.7.9
48
+ version: 0.0.9
49
49
  type: :runtime
50
50
  version_requirements: *id002
51
51
  description: Rack webmoney authentication