reward_station 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +2 -2
- data/README.md +121 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/award_points/award_points.xml +0 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/award_points/award_points_invalid_token.xml +0 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/return_point_summary/return_point_summary.xml +0 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/return_point_summary/return_point_summary_invalid_token.xml +0 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/return_popular_products/return_popular_products.xml +0 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/return_popular_products/return_popular_products_invalid_token.xml +0 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/return_token/return_token.xml +0 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/return_token/return_token_invalid.xml +0 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/return_user/return_user.xml +0 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/return_user/return_user_invalid_token.xml +0 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/return_user/return_user_invalid_user.xml +0 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/update_user/create_user.xml +0 -0
- data/{spec/fixtures/savon/reward_station → lib/responses}/update_user/create_user_exists.xml +0 -0
- data/lib/reward_station.rb +10 -1
- data/lib/reward_station/errors.rb +31 -0
- data/lib/reward_station/service.rb +167 -0
- data/lib/reward_station/version.rb +1 -1
- data/lib/saml/auth_response.rb +174 -0
- data/lib/savon/macros.rb +12 -0
- data/lib/savon/mock.rb +70 -0
- data/lib/savon/mock_response.rb +45 -0
- data/reward_station.gemspec +5 -3
- data/spec/reward_station/service_spec.rb +326 -0
- data/spec/spec_helper.rb +1 -8
- metadata +44 -24
- data/lib/xceleration/reward_station.rb +0 -122
- data/spec/savon_helper.rb +0 -129
- data/spec/xceleration/reward_station_spec.rb +0 -348
data/spec/spec_helper.rb
CHANGED
@@ -1,18 +1,11 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler.setup
|
3
3
|
|
4
|
-
require 'rubygems'
|
5
|
-
|
6
|
-
require 'savon'
|
7
|
-
|
8
4
|
require 'reward_station'
|
9
5
|
|
10
|
-
require "savon_helper"
|
11
|
-
|
12
6
|
RSpec.configure do |config|
|
13
7
|
config.mock_with :rspec
|
14
|
-
|
15
|
-
config.include Savon::Spec::Macros
|
8
|
+
config.include Savon::Macros
|
16
9
|
end
|
17
10
|
|
18
11
|
|
metadata
CHANGED
@@ -1,25 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reward_station
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Stepan Filatov
|
14
|
+
- Cloud Castle Inc.
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2011-07-
|
19
|
+
date: 2011-07-18 00:00:00 +04:00
|
19
20
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
22
|
-
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: savon
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 55
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
- 9
|
34
|
+
- 6
|
35
|
+
version: 0.9.6
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
description: ""
|
23
39
|
email:
|
24
40
|
- filatov.st@gmail.com
|
25
41
|
executables: []
|
@@ -36,27 +52,31 @@ files:
|
|
36
52
|
- LICENSE
|
37
53
|
- README.md
|
38
54
|
- Rakefile
|
55
|
+
- lib/responses/award_points/award_points.xml
|
56
|
+
- lib/responses/award_points/award_points_invalid_token.xml
|
57
|
+
- lib/responses/return_point_summary/return_point_summary.xml
|
58
|
+
- lib/responses/return_point_summary/return_point_summary_invalid_token.xml
|
59
|
+
- lib/responses/return_popular_products/return_popular_products.xml
|
60
|
+
- lib/responses/return_popular_products/return_popular_products_invalid_token.xml
|
61
|
+
- lib/responses/return_token/return_token.xml
|
62
|
+
- lib/responses/return_token/return_token_invalid.xml
|
63
|
+
- lib/responses/return_user/return_user.xml
|
64
|
+
- lib/responses/return_user/return_user_invalid_token.xml
|
65
|
+
- lib/responses/return_user/return_user_invalid_user.xml
|
66
|
+
- lib/responses/update_user/create_user.xml
|
67
|
+
- lib/responses/update_user/create_user_exists.xml
|
39
68
|
- lib/reward_station.rb
|
69
|
+
- lib/reward_station/errors.rb
|
70
|
+
- lib/reward_station/service.rb
|
40
71
|
- lib/reward_station/version.rb
|
72
|
+
- lib/saml/auth_response.rb
|
73
|
+
- lib/savon/macros.rb
|
74
|
+
- lib/savon/mock.rb
|
75
|
+
- lib/savon/mock_response.rb
|
41
76
|
- lib/wsdl/reward_services.xml
|
42
|
-
- lib/xceleration/reward_station.rb
|
43
77
|
- reward_station.gemspec
|
44
|
-
- spec/
|
45
|
-
- spec/fixtures/savon/reward_station/award_points/award_points_invalid_token.xml
|
46
|
-
- spec/fixtures/savon/reward_station/return_point_summary/return_point_summary.xml
|
47
|
-
- spec/fixtures/savon/reward_station/return_point_summary/return_point_summary_invalid_token.xml
|
48
|
-
- spec/fixtures/savon/reward_station/return_popular_products/return_popular_products.xml
|
49
|
-
- spec/fixtures/savon/reward_station/return_popular_products/return_popular_products_invalid_token.xml
|
50
|
-
- spec/fixtures/savon/reward_station/return_token/return_token.xml
|
51
|
-
- spec/fixtures/savon/reward_station/return_token/return_token_invalid.xml
|
52
|
-
- spec/fixtures/savon/reward_station/return_user/return_user.xml
|
53
|
-
- spec/fixtures/savon/reward_station/return_user/return_user_invalid_token.xml
|
54
|
-
- spec/fixtures/savon/reward_station/return_user/return_user_invalid_user.xml
|
55
|
-
- spec/fixtures/savon/reward_station/update_user/create_user.xml
|
56
|
-
- spec/fixtures/savon/reward_station/update_user/create_user_exists.xml
|
57
|
-
- spec/savon_helper.rb
|
78
|
+
- spec/reward_station/service_spec.rb
|
58
79
|
- spec/spec_helper.rb
|
59
|
-
- spec/xceleration/reward_station_spec.rb
|
60
80
|
has_rdoc: true
|
61
81
|
homepage: https://github.com/sfilatov/reward_station
|
62
82
|
licenses: []
|
@@ -90,6 +110,6 @@ rubyforge_project: reward_station
|
|
90
110
|
rubygems_version: 1.3.7
|
91
111
|
signing_key:
|
92
112
|
specification_version: 3
|
93
|
-
summary: Reward Station is a client
|
113
|
+
summary: Reward Station is a client library for rewardstation.com
|
94
114
|
test_files: []
|
95
115
|
|
@@ -1,122 +0,0 @@
|
|
1
|
-
module Xceleration
|
2
|
-
class InvalidAccount < StandardError; end
|
3
|
-
class InvalidToken < StandardError; end
|
4
|
-
class InvalidUser < StandardError; end
|
5
|
-
class ConnectionError < StandardError; end
|
6
|
-
class UserAlreadyExists < StandardError; end
|
7
|
-
|
8
|
-
class RewardStation
|
9
|
-
|
10
|
-
PROGRAM_ID = 90
|
11
|
-
POINT_REASON_CODE_ID = 129
|
12
|
-
|
13
|
-
attr_reader :client
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@client = Savon::Client.new do |wsdl|
|
17
|
-
wsdl.document = File.join(File.dirname(__FILE__), '..', 'wsdl', 'reward_services.xml')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def return_token client_id, client_password
|
22
|
-
result = request :return_token, :body => {
|
23
|
-
'AccountNumber' => client_id,
|
24
|
-
'AccountCode' => client_password
|
25
|
-
}
|
26
|
-
|
27
|
-
puts "xceleration token #{result[:token]}"
|
28
|
-
|
29
|
-
result[:token]
|
30
|
-
end
|
31
|
-
|
32
|
-
def return_user token, xceleration_id
|
33
|
-
result = request :return_user, :body => { 'UserID' => xceleration_id, 'Token' => token}
|
34
|
-
result[:user_profile]
|
35
|
-
end
|
36
|
-
|
37
|
-
def award_points token, xceleration_id, points, description, program_id = PROGRAM_ID, point_reason_code_id = POINT_REASON_CODE_ID
|
38
|
-
result = request :award_points, :body => {
|
39
|
-
'UserID' => xceleration_id,
|
40
|
-
'Points' => points,
|
41
|
-
'ProgramID' => program_id,
|
42
|
-
'PointReasonCodeID' => point_reason_code_id,
|
43
|
-
'Description' => description,
|
44
|
-
'Token' => token
|
45
|
-
}
|
46
|
-
result[:confirmation_number]
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
def return_point_summary token, xceleration_id, client_id
|
51
|
-
result = request :return_point_summary, :body => {
|
52
|
-
'clientId' => client_id,
|
53
|
-
'userId' => xceleration_id,
|
54
|
-
'Token' => token
|
55
|
-
}
|
56
|
-
result[:point_summary_collection][:point_summary]
|
57
|
-
end
|
58
|
-
|
59
|
-
def update_user token, xceleration_id, client_id, organization_id, attrs = {}
|
60
|
-
|
61
|
-
email = attrs[:email] || ""
|
62
|
-
first_name = attrs[:first_name] || ""
|
63
|
-
last_name = attrs[:last_name] || ""
|
64
|
-
user_name = attrs[:user_name] || email
|
65
|
-
balance = attrs[:balance] || 0
|
66
|
-
|
67
|
-
result = request :update_user , :body => {
|
68
|
-
'updateUser' => {
|
69
|
-
'UserID' => xceleration_id,
|
70
|
-
'ClientID' => client_id,
|
71
|
-
'UserName' => user_name,
|
72
|
-
'FirstName' => first_name,
|
73
|
-
'LastName' => last_name,
|
74
|
-
'CountryCode' => 'USA',
|
75
|
-
'Email' => email,
|
76
|
-
'IsActive' => true,
|
77
|
-
'PointBalance' => balance,
|
78
|
-
'OrganizationID' => organization_id
|
79
|
-
},
|
80
|
-
'Token' => token
|
81
|
-
}
|
82
|
-
|
83
|
-
result[:update_user]
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
def create_user token, client_id, organization_id, attrs = {}
|
88
|
-
update_user token, -1, client_id, organization_id, attrs
|
89
|
-
end
|
90
|
-
|
91
|
-
def return_popular_products token, xceleration_id
|
92
|
-
result = request :return_popular_products , :body => {
|
93
|
-
'userId' => xceleration_id,
|
94
|
-
'Token' => token
|
95
|
-
}
|
96
|
-
|
97
|
-
result[:products][:product]
|
98
|
-
end
|
99
|
-
|
100
|
-
protected
|
101
|
-
|
102
|
-
def request method_name, params
|
103
|
-
|
104
|
-
response = @client.request(:wsdl, method_name , params).to_hash
|
105
|
-
|
106
|
-
result = response[:"#{method_name}_response"][:"#{method_name}_result"]
|
107
|
-
|
108
|
-
unless (error_message = result.delete(:error_message).to_s).nil?
|
109
|
-
raise Xceleration::InvalidToken if error_message.start_with?("Invalid Token")
|
110
|
-
raise Xceleration::InvalidAccount if error_message.start_with?("Invalid Account Number")
|
111
|
-
raise Xceleration::InvalidUser if error_message.start_with?("Invalid User")
|
112
|
-
raise Xceleration::UserAlreadyExists if error_message.start_with?("User Name:") && error_message.end_with?("Please enter a different user name.")
|
113
|
-
end
|
114
|
-
|
115
|
-
result
|
116
|
-
rescue Savon::SOAP::Fault, Savon::HTTP::Error => ex
|
117
|
-
puts ex.to_s
|
118
|
-
puts ex.backtrace.inspect
|
119
|
-
raise ConnectionError, ex.message
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
data/spec/savon_helper.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
module Savon
|
2
|
-
module Spec
|
3
|
-
|
4
|
-
# = Savon::Spec::Macros
|
5
|
-
#
|
6
|
-
# Include this module into your RSpec tests to mock/stub Savon SOAP requests.
|
7
|
-
module Macros
|
8
|
-
|
9
|
-
def savon
|
10
|
-
Savon::SOAP::Response.any_instance.stub(:soap_fault?).and_return(false)
|
11
|
-
Savon::SOAP::Response.any_instance.stub(:http_error?).and_return(false)
|
12
|
-
|
13
|
-
Savon::Spec::Mock.new
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
class Fixture
|
19
|
-
class << self
|
20
|
-
|
21
|
-
def path
|
22
|
-
@path ||= Rails.root.join("spec", "fixtures").to_s if defined? Rails
|
23
|
-
|
24
|
-
raise ArgumentError, "Savon::Spec::Fixture.path needs to be specified" unless @path
|
25
|
-
@path
|
26
|
-
end
|
27
|
-
|
28
|
-
attr_writer :path
|
29
|
-
|
30
|
-
def load(*args)
|
31
|
-
file = args.map { |arg| arg.to_s.snakecase }.join("/")
|
32
|
-
fixtures[file] ||= load_file file
|
33
|
-
end
|
34
|
-
|
35
|
-
alias [] load
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def fixtures
|
40
|
-
@fixtures ||= {}
|
41
|
-
end
|
42
|
-
|
43
|
-
def load_file(file)
|
44
|
-
full_path = File.expand_path File.join(path, "#{file}.xml")
|
45
|
-
raise ArgumentError, "Unable to load: #{full_path}" unless File.exist? full_path
|
46
|
-
|
47
|
-
File.read full_path
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# = Savon::Spec::Mock
|
54
|
-
#
|
55
|
-
# Mocks/stubs SOAP requests executed by Savon.
|
56
|
-
class Mock
|
57
|
-
|
58
|
-
def expects(soap_action)
|
59
|
-
setup :expects, soap_action
|
60
|
-
self
|
61
|
-
end
|
62
|
-
|
63
|
-
def stub(soap_action)
|
64
|
-
setup :stub, soap_action
|
65
|
-
self
|
66
|
-
end
|
67
|
-
|
68
|
-
# Expects a given SOAP body Hash to be used.
|
69
|
-
def with(soap_body)
|
70
|
-
Savon::SOAP::XML.any_instance.expects(:body=).with(soap_body) if mock_method == :expects
|
71
|
-
self
|
72
|
-
end
|
73
|
-
|
74
|
-
def never
|
75
|
-
httpi_mock.never
|
76
|
-
self
|
77
|
-
end
|
78
|
-
|
79
|
-
# Sets up HTTPI to return a given +response+.
|
80
|
-
def and_return(response = nil)
|
81
|
-
http = { :code => 200, :headers => {}, :body => "" }
|
82
|
-
|
83
|
-
case response
|
84
|
-
when Symbol then http[:body] = Fixture[soap_action, response]
|
85
|
-
when Hash then http.merge! response
|
86
|
-
when String then http[:body] = response
|
87
|
-
end
|
88
|
-
|
89
|
-
httpi_mock.and_return HTTPI::Response.new(http[:code], http[:headers], http[:body])
|
90
|
-
self
|
91
|
-
end
|
92
|
-
|
93
|
-
# Sets up Savon to respond like there was a SOAP fault.
|
94
|
-
def raises_soap_fault
|
95
|
-
Savon::SOAP::Response.any_instance.stub(:soap_fault?).and_return(true)
|
96
|
-
self
|
97
|
-
end
|
98
|
-
|
99
|
-
def raises_http_error
|
100
|
-
Savon::SOAP::Response.any_instance.stub(:soap_fault?).and_return(false)
|
101
|
-
Savon::SOAP::Response.any_instance.stub(:http_error?).and_return(true)
|
102
|
-
self
|
103
|
-
end
|
104
|
-
|
105
|
-
private
|
106
|
-
|
107
|
-
def setup(mock_method, soap_action)
|
108
|
-
self.mock_method = mock_method
|
109
|
-
self.soap_action = soap_action
|
110
|
-
self.httpi_mock = new_httpi_mock
|
111
|
-
end
|
112
|
-
|
113
|
-
attr_accessor :mock_method
|
114
|
-
|
115
|
-
def soap_action=(soap_action)
|
116
|
-
@soap_action = soap_action.kind_of?(Symbol) ? soap_action.to_s.lower_camelcase : soap_action
|
117
|
-
end
|
118
|
-
|
119
|
-
attr_reader :soap_action
|
120
|
-
|
121
|
-
def new_httpi_mock
|
122
|
-
HTTPI.send(mock_method, :post)
|
123
|
-
end
|
124
|
-
|
125
|
-
attr_accessor :httpi_mock
|
126
|
-
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,348 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Xceleration::RewardStation do
|
4
|
-
|
5
|
-
before(:all) {
|
6
|
-
Savon::Spec::Fixture.path = File.join(File.dirname(__FILE__), "..", "fixtures", "savon", "reward_station").to_s
|
7
|
-
}
|
8
|
-
|
9
|
-
before(:each) { @service = Xceleration::RewardStation.new }
|
10
|
-
|
11
|
-
describe "return_token" do
|
12
|
-
|
13
|
-
describe "on valid response" do
|
14
|
-
before do
|
15
|
-
savon.stub(:return_token).and_return(:return_token)
|
16
|
-
end
|
17
|
-
it "should return valid token" do
|
18
|
-
@service.return_token('100080', 'fM6Rv4moz#').should eq("e285e1ed-2356-4676-a554-99d79e6284b0")
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should not raise InvalidAccount exception" do
|
22
|
-
lambda{ @service.return_token('100080', 'fM6Rv4moz#') }.should_not raise_error(Xceleration::InvalidAccount)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "on invalid account response" do
|
27
|
-
before do
|
28
|
-
savon.stub(:return_token).and_return(:return_token_invalid)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should raise InvalidAccount exception" do
|
32
|
-
lambda{ @service.return_token('100080', 'fM6Rv4moz#') }.should raise_error(Xceleration::InvalidAccount)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "on soap error" do
|
37
|
-
before do
|
38
|
-
savon.stub(:return_token).and_return.raises_soap_fault
|
39
|
-
# mock_client.stub!(:request).and_raise(Savon::SOAP::Fault.new(HTTPI::Response.new(404, {}, {})))
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should raise ConnectionError exception" do
|
43
|
-
lambda{ @service.return_token('100080', 'fM6Rv4moz#') }.should raise_error(Xceleration::ConnectionError)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "on http error" do
|
48
|
-
before do
|
49
|
-
savon.stub(:return_token).and_return(:code => 404).raises_http_error
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should raise HttpError exception" do
|
53
|
-
lambda{ @service.return_token('100080', 'fM6Rv4moz#') }.should raise_error(Xceleration::ConnectionError)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "award_points" do
|
59
|
-
describe "on valid response" do
|
60
|
-
before do
|
61
|
-
savon.stub(:award_points).and_return(:award_points)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should return valid confirm code" do
|
65
|
-
@service.award_points("e285e1ed-2356-4676-a554-99d79e6284b0", 130, 10, "Action 'Some' taken").should eq("9376")
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should not raise InvalidToken exception" do
|
69
|
-
lambda{ @service.award_points("e285e1ed-2356-4676-a554-99d79e6284b0", 130, 10, "Action 'Some' taken") }.should_not raise_error(Xceleration::InvalidToken)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "on invalid token response" do
|
74
|
-
before do
|
75
|
-
savon.stub(:award_points).and_return(:award_points_invalid_token)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should raise InvalidToken exception" do
|
79
|
-
lambda{ @service.award_points("", 130, 10, "Action 'Some' taken") }.should raise_error(Xceleration::InvalidToken)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "on soap error" do
|
84
|
-
before do
|
85
|
-
savon.stub(:award_points).and_return.raises_soap_fault
|
86
|
-
# mock_client.stub!(:request).and_raise(Savon::SOAP::Fault.new(HTTPI::Response.new(404, {}, {})))
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should raise ConnectionError exception" do
|
90
|
-
lambda{ @service.award_points("e285e1ed-2356-4676-a554-99d79e6284b0", 130, 10, "Action 'Some' taken") }.should raise_error(Xceleration::ConnectionError)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "on http error" do
|
95
|
-
before do
|
96
|
-
savon.stub(:award_points).and_return(:code => 404).raises_http_error
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should raise HttpError exception" do
|
100
|
-
lambda{ @service.award_points("e285e1ed-2356-4676-a554-99d79e6284b0", 130, 10, "Action 'Some' taken") }.should raise_error(Xceleration::ConnectionError)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "return_user" do
|
106
|
-
describe "on valid response" do
|
107
|
-
before do
|
108
|
-
savon.stub(:return_user).and_return(:return_user)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should return valid user data" do
|
112
|
-
@service.return_user("e285e1ed-2356-4676-a554-99d79e6284b0", 130).should eq(:user_id => '6725',
|
113
|
-
:client_id => '100080',
|
114
|
-
:user_name => 'john3@company.com',
|
115
|
-
:encrypted_password => nil,
|
116
|
-
:first_name => 'John',
|
117
|
-
:last_name => 'Smith',
|
118
|
-
:address_one => nil,
|
119
|
-
:address_two => nil,
|
120
|
-
:city => nil,
|
121
|
-
:state_code => nil,
|
122
|
-
:province => nil,
|
123
|
-
:postal_code => nil,
|
124
|
-
:country_code => 'USA',
|
125
|
-
:phone => nil,
|
126
|
-
:email => 'john@company.com',
|
127
|
-
:organization_id => '0',
|
128
|
-
:organization_name => nil,
|
129
|
-
:rep_type_id => '0',
|
130
|
-
:client_region_id => '0',
|
131
|
-
:is_active => true,
|
132
|
-
:point_balance => '10',
|
133
|
-
:manager_id => '0',
|
134
|
-
:error_message => nil)
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should not raise InvalidToken exception" do
|
138
|
-
lambda{ @service.return_user("e285e1ed-2356-4676-a554-99d79e6284b0", 130) }.should_not raise_error(Xceleration::InvalidToken)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe "on invalid token response" do
|
143
|
-
before do
|
144
|
-
savon.stub(:return_user).and_return(:return_user_invalid_token)
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should raise InvalidToken exception" do
|
148
|
-
lambda{ @service.return_user("", 130) }.should raise_error(Xceleration::InvalidToken)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe "on invalid user response" do
|
153
|
-
before do
|
154
|
-
savon.stub(:return_user).and_return(:return_user_invalid_user)
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should raise InvalidUser exception" do
|
158
|
-
lambda{ @service.return_user("e285e1ed-2356-4676-a554-99d79e6284b0", 130) }.should raise_error(Xceleration::InvalidUser)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
describe "on soap error" do
|
163
|
-
before do
|
164
|
-
savon.stub(:return_user).and_return.raises_soap_fault
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should raise ConnectionError exception" do
|
168
|
-
lambda{ @service.return_user("e285e1ed-2356-4676-a554-99d79e6284b0", 130) }.should raise_error(Xceleration::ConnectionError)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe "on http error" do
|
173
|
-
before do
|
174
|
-
savon.stub(:return_user).and_return(:code => 404).raises_http_error
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should raise HttpError exception" do
|
178
|
-
lambda{ @service.return_user("e285e1ed-2356-4676-a554-99d79e6284b0", 130) }.should raise_error(Xceleration::ConnectionError)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe "return_point_summary" do
|
184
|
-
describe "on valid request" do
|
185
|
-
before do
|
186
|
-
savon.stub(:return_point_summary).and_return(:return_point_summary)
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should return valid summary" do
|
190
|
-
@service.return_point_summary("e285e1ed-2356-4676-a554-99d79e6284b0", 130, '100080').should eq(:user_id => '577',
|
191
|
-
:is_active => true,
|
192
|
-
:points_earned => '465',
|
193
|
-
:points_redeemed => '0',
|
194
|
-
:points_credited => '0',
|
195
|
-
:points_balance => '465')
|
196
|
-
end
|
197
|
-
|
198
|
-
it "should not raise InvalidToken exception" do
|
199
|
-
lambda{ @service.return_point_summary("e285e1ed-2356-4676-a554-99d79e6284b0", 130, '100080') }.should_not raise_error(Xceleration::InvalidToken)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
describe "on invalid token request" do
|
204
|
-
before do
|
205
|
-
savon.stub(:return_point_summary).and_return(:return_point_summary_invalid_token)
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should raise InvalidToken exception" do
|
209
|
-
lambda{ @service.return_point_summary("", 130, '100080') }.should raise_error(Xceleration::InvalidToken)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
describe "on soap error" do
|
214
|
-
before do
|
215
|
-
savon.stub(:return_point_summary).and_return.raises_soap_fault
|
216
|
-
end
|
217
|
-
|
218
|
-
it "should raise ConnectionError exception" do
|
219
|
-
lambda{ @service.return_point_summary("e285e1ed-2356-4676-a554-99d79e6284b0", 130, '100080') }.should raise_error(Xceleration::ConnectionError)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
describe "on http error" do
|
224
|
-
before do
|
225
|
-
savon.stub(:return_point_summary).and_return(:code => 404).raises_http_error
|
226
|
-
end
|
227
|
-
|
228
|
-
it "should raise HttpError exception" do
|
229
|
-
lambda{ @service.return_point_summary("e285e1ed-2356-4676-a554-99d79e6284b0", 130, '100080') }.should raise_error(Xceleration::ConnectionError)
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
describe "update_user" do
|
235
|
-
describe "on create user valid request" do
|
236
|
-
before do
|
237
|
-
savon.stub(:update_user).and_return(:create_user)
|
238
|
-
end
|
239
|
-
|
240
|
-
it "should return valid response" do
|
241
|
-
@service.create_user("e285e1ed-2356-4676-a554-99d79e6284b0",
|
242
|
-
'100080',
|
243
|
-
'150', {
|
244
|
-
:email => 'john5@company.com',
|
245
|
-
:first_name => 'John',
|
246
|
-
:last_name => 'Smith',
|
247
|
-
:user_name => 'john5@company.com',
|
248
|
-
:balance => 0
|
249
|
-
}).should eq(:user_id => '6727',
|
250
|
-
:client_id => '100080',
|
251
|
-
:user_name => 'john5@company.com',
|
252
|
-
:email => 'john5@company.com',
|
253
|
-
:encrypted_password => nil,
|
254
|
-
:first_name => 'John',
|
255
|
-
:last_name => 'Smith',
|
256
|
-
:address_one => nil,
|
257
|
-
:address_two => nil,
|
258
|
-
:city => nil,
|
259
|
-
:state_code => nil,
|
260
|
-
:province => nil,
|
261
|
-
:postal_code => nil,
|
262
|
-
:country_code => 'USA',
|
263
|
-
:phone => nil,
|
264
|
-
:organization_id => '150',
|
265
|
-
:organization_name => nil,
|
266
|
-
:rep_type_id => '0',
|
267
|
-
:client_region_id => '0',
|
268
|
-
|
269
|
-
:is_active => true,
|
270
|
-
:point_balance => '0',
|
271
|
-
:manager_id => '0',
|
272
|
-
:error_message => nil)
|
273
|
-
end
|
274
|
-
|
275
|
-
it "should not raise InvalidToken exception" do
|
276
|
-
lambda{ @service.create_user("e285e1ed-2356-4676-a554-99d79e6284b0",
|
277
|
-
'100080',
|
278
|
-
'150', {
|
279
|
-
:email => 'john5@company.com',
|
280
|
-
:first_name => 'John',
|
281
|
-
:last_name => 'Smith',
|
282
|
-
:user_name => 'john5@company.com',
|
283
|
-
:balance => 0
|
284
|
-
})
|
285
|
-
}.should_not raise_error(Xceleration::InvalidToken)
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
describe "on create user invalid request" do
|
290
|
-
before do
|
291
|
-
savon.stub(:update_user).and_return(:create_user_exists)
|
292
|
-
end
|
293
|
-
|
294
|
-
it "should raise UserAlreadyExists exception" do
|
295
|
-
lambda{ @service.update_user("e285e1ed-2356-4676-a554-99d79e6284b0",
|
296
|
-
130,
|
297
|
-
'100080',
|
298
|
-
'150', {
|
299
|
-
:email => 'john5@company.com',
|
300
|
-
:first_name => 'John',
|
301
|
-
:last_name => 'Smith',
|
302
|
-
:user_name => 'john5@company.com',
|
303
|
-
:balance => 0
|
304
|
-
})
|
305
|
-
}.should raise_error(Xceleration::UserAlreadyExists)
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
end
|
310
|
-
|
311
|
-
describe "return_popular_products" do
|
312
|
-
describe "on valid request" do
|
313
|
-
before do
|
314
|
-
savon.stub(:return_popular_products).and_return(:return_popular_products)
|
315
|
-
end
|
316
|
-
|
317
|
-
it "should return valid response" do
|
318
|
-
products = @service.return_popular_products("e285e1ed-2356-4676-a554-99d79e6284b0", 130)
|
319
|
-
products.should be_a(Array)
|
320
|
-
products.size.should eq(35)
|
321
|
-
products.first.should eq(:product_id => 'MC770LLA',
|
322
|
-
:name => 'iPad 2 with Wifi - 32GB',
|
323
|
-
:description => 'The NEW Apple iPad 2 - Thinner, lighter, and full of great ideas. Once you pick up iPad 2, it’ll be hard to put down. That’s the idea behind the all-new design. It’s 33 percent thinner and up to 15 percent lighter, so it feels even more comfortable in your hands. And, it makes surfing the web, checking email, watching movies, and reading books so natural, you might forget there’s incredible technology under your fingers.<br><br><b>Dual-core A5 chip</b>.<br> Two powerful cores in one A5 chip mean iPad can do twice the work at once. You’ll notice the difference when you’re surfing the web, watching movies, making FaceTime video calls, gaming, and going from app to app to app. Multitasking is smoother, apps load faster, and everything just works better.<br><br><b>Superfast graphics</b>. <br>With up to nine times the graphics performance, gameplay on iPad is even smoother and more realistic. And faster graphics help apps perform better — especially those with video. You’ll see it when you’re scrolling through your photo library, editing video with iMovie, and viewing animations in Keynote.<br><br><b>Battery life keeps on going. So you can, too.</b><br> Even with the new thinner and lighter design, iPad has the same amazing 10-hour battery life. That’s enough juice for one flight across the ocean, or one movie-watching all-nighter, or a week’s commute across town. The power-efficient A5 chip and iOS keep battery life from fading away, so you can get carried away.<br><br><b>Two cameras.</b><br> You’ll see two cameras on iPad — one on the front and one on the back. They may be tiny, but they’re a big deal. They’re designed for FaceTime video calling, and they work together so you can talk to your favorite people and see them smile and laugh back at you. The front camera puts you and your friend face-to-face. Switch to the back camera during your video call to share where you are, who you’re with, or what’s going on around you. When you’re not using FaceTime, let the back camera roll if you see something movie-worthy. It’s HD, so whatever you shoot is a mini-masterpiece. And you can take wacky snapshots in Photo Booth. It’s the most fun a face can have.<br><br><b>Due to the demand for this item, please allow up to 8-10 weeks for delivery</b>.',
|
324
|
-
:points => '10927',
|
325
|
-
:category => 'Office & Computer',
|
326
|
-
:manufacturer => 'Apple',
|
327
|
-
:small_image_url => 'https://www.rewardstation.com/catalogimages/MC769LLA.gif',
|
328
|
-
:large_image_url => 'https://www.rewardstation.com/catalogimages/MC769LLA.jpg')
|
329
|
-
end
|
330
|
-
|
331
|
-
it "should not raise InvalidToken exception" do
|
332
|
-
lambda{ @service.return_popular_products("e285e1ed-2356-4676-a554-99d79e6284b0", 130) }.should_not raise_error(Xceleration::InvalidToken)
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
describe "on create user invalid token request" do
|
337
|
-
before do
|
338
|
-
savon.stub(:return_popular_products).and_return(:return_popular_products_invalid_token)
|
339
|
-
end
|
340
|
-
|
341
|
-
it "should raise InvalidToken exception" do
|
342
|
-
lambda{ @service.return_popular_products("e285e1ed-2356-4676-a554-99d79e6284b0", 130) }.should raise_error(Xceleration::InvalidToken)
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
end
|
347
|
-
|
348
|
-
end
|