Class: RewardStation::Client
- Inherits:
-
Object
- Object
- RewardStation::Client
- Defined in:
- lib/reward_station/client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #award_points(user_id, points, description, program_id = nil, point_reason_code_id = nil) ⇒ Object
- #create_user(attrs = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #logger ⇒ Object
- #new_token_callback(&block) ⇒ Object
- #return_point_summary(user_id) ⇒ Object
- #return_popular_products(user_id) ⇒ Object
- #return_token ⇒ Object
- #return_user(user_id) ⇒ Object
- #return_user_by_user_name(user_name) ⇒ Object
- #update_user(user_id, attrs = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/reward_station/client.rb', line 6 def initialize = {} [:client_id, :client_password].each do |arg| raise ArgumentError, "Missing required option '#{arg}'" unless .has_key? arg end @client_id = [:client_id] @client_password = [:client_password] @token = [:token] @organization_id = [:organization_id] @program_id = [:program_id] @point_reason_code_id = [:point_reason_code_id] if [:new_token_callback] raise ArgumentError, "new_token_callback option should be proc or lambda" unless [:new_token_callback].is_a?(Proc) @new_token_callback = [:new_token_callback] end end |
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
4 5 6 |
# File 'lib/reward_station/client.rb', line 4 def token @token end |
Class Method Details
.get_client ⇒ Object
36 37 38 39 40 |
# File 'lib/reward_station/client.rb', line 36 def get_client @@client ||= Savon::Client.new do |wsdl| wsdl.document = File.join(File.dirname(__FILE__), '..', 'wsdl', 'reward_services.xml') end end |
.logger ⇒ Object
42 43 44 |
# File 'lib/reward_station/client.rb', line 42 def logger @@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT) end |
.stub(options = {}) ⇒ Object
32 33 34 |
# File 'lib/reward_station/client.rb', line 32 def stub = {} RewardStation::StubClient.new end |
Instance Method Details
#award_points(user_id, points, description, program_id = nil, point_reason_code_id = nil) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/reward_station/client.rb', line 70 def award_points user_id, points, description, program_id = nil, point_reason_code_id = nil request_with_token(:award_points, :body => { 'UserID' => user_id, 'Points' => points, 'ProgramID' => program_id || @program_id, 'PointReasonCodeID' => point_reason_code_id || @point_reason_code_id, 'Description' => description })[:confirmation_number] end |
#create_user(attrs = {}) ⇒ Object
117 118 119 |
# File 'lib/reward_station/client.rb', line 117 def create_user attrs = {} update_user -1, attrs end |
#logger ⇒ Object
47 48 49 |
# File 'lib/reward_station/client.rb', line 47 def logger Client.logger end |
#new_token_callback(&block) ⇒ Object
26 27 28 |
# File 'lib/reward_station/client.rb', line 26 def new_token_callback &block @new_token_callback = block end |
#return_point_summary(user_id) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/reward_station/client.rb', line 81 def return_point_summary user_id request_with_token(:return_point_summary, :body => { 'clientId' => @client_id, 'userId' => user_id })[:point_summary_collection][:point_summary] end |
#return_popular_products(user_id) ⇒ Object
121 122 123 |
# File 'lib/reward_station/client.rb', line 121 def return_popular_products user_id request_with_token(:return_popular_products , :body => { 'userId' => user_id} )[:products][:product] end |
#return_token ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/reward_station/client.rb', line 51 def return_token result = request :return_token, :body => { 'AccountNumber' => @client_id, 'AccountCode' => @client_password } logger.info "xceleration token #{result[:token]}" result[:token] end |
#return_user(user_id) ⇒ Object
62 63 64 |
# File 'lib/reward_station/client.rb', line 62 def return_user user_id request_with_token(:return_user, :body => { 'UserID' => user_id} )[:user_profile] end |
#return_user_by_user_name(user_name) ⇒ Object
66 67 68 |
# File 'lib/reward_station/client.rb', line 66 def return_user_by_user_name user_name request_with_token(:return_user_by_user_name , :body => { 'UserName' => user_name} )[:user_profile] end |
#update_user(user_id, attrs = {}) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/reward_station/client.rb', line 88 def update_user user_id, attrs = {} organization_id = attrs[:organization_id] || @organization_id raise(ArgumentError, "organization_id should be numeric") if organization_id.to_i.zero? [:email, :first_name, :last_name].each do |f| raise(ArgumentError, "#{f} required and should not be empty") if attrs[f].to_s.blank? end user_name = attrs[:user_name] || attrs[:email] balance = attrs[:balance] || 0 request_with_token(:update_user , :body => { 'updateUser' => { 'UserID' => user_id, 'ClientID' => @client_id, 'UserName' => user_name, 'FirstName' => attrs[:first_name], 'LastName' => attrs[:last_name], 'CountryCode' => 'USA', 'Email' => attrs[:email], 'IsActive' => true, 'PointBalance' => balance, 'OrganizationID' => organization_id } })[:update_user] end |