reward_station 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,8 @@
1
1
  module RewardStation
2
2
  class Client
3
3
 
4
+ attr_accessor :token
5
+
4
6
  def initialize options = {}
5
7
  [:client_id, :client_password].each do |arg|
6
8
  raise ArgumentError, "Missing required option '#{arg}'" unless options.has_key? arg
@@ -115,22 +117,8 @@ module RewardStation
115
117
 
116
118
  protected
117
119
 
118
- def update_token
119
- @token = return_token
120
- @new_token_callback.call(@token) if @new_token_callback
121
- end
122
-
123
- def inject_token params = {}
124
- (params[:body] ||= {})['Token'] = @token
125
- end
126
-
127
- def request_with_token method_name, params
128
- update_token unless @token
129
-
130
- retry_with_token :tries => 2 do
131
- inject_token params
132
- request method_name, params
133
- end
120
+ def get_response method_name, params
121
+ Client.get_client.request(:wsdl, method_name , params).to_hash
134
122
  end
135
123
 
136
124
  def request method_name, params
@@ -141,10 +129,10 @@ module RewardStation
141
129
  result = response[:"#{method_name}_response"][:"#{method_name}_result"]
142
130
 
143
131
  unless (error_message = result.delete(:error_message).to_s).nil?
144
- raise InvalidToken if error_message.start_with?("Invalid Token")
132
+ raise(InvalidToken, error_message) if error_message.start_with?("Invalid Token")
145
133
  raise InvalidAccount if error_message.start_with?("Invalid Account Number")
146
134
  raise InvalidUser if error_message.start_with?("Invalid User")
147
- raise UserAlreadyExists if error_message.start_with?("User Name:") && error_message.end_with?("Please enter a different user name.")
135
+ raise(UserAlreadyExists, error_message) if error_message.start_with?("User Name:") && error_message.end_with?("Please enter a different user name.")
148
136
  raise MissingInformation if error_message.start_with?("The following information is missing:")
149
137
  end
150
138
 
@@ -155,8 +143,22 @@ module RewardStation
155
143
  raise ConnectionError.new
156
144
  end
157
145
 
158
- def get_response method_name, params
159
- Client.get_client.request(:wsdl, method_name , params).to_hash
146
+ def update_token
147
+ @token = return_token
148
+ @new_token_callback.call(@token) if @new_token_callback
149
+ end
150
+
151
+ def inject_token params = {}
152
+ (params[:body] ||= {})['Token'] = @token
153
+ end
154
+
155
+ def request_with_token method_name, params
156
+ update_token unless @token
157
+
158
+ retry_with_token :tries => 2 do
159
+ inject_token params
160
+ request method_name, params.dup
161
+ end
160
162
  end
161
163
 
162
164
  private
@@ -1,3 +1,3 @@
1
1
  module RewardStation
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reward_station
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stepan Filatov
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-07-21 00:00:00 +04:00
19
+ date: 2011-07-29 00:00:00 +04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency