Class: PayTrace::Configuration
- Inherits:
-
Object
- Object
- PayTrace::Configuration
- Defined in:
- lib/paytrace/configuration.rb
Overview
Contains necessary configuration to access the API server; notably the user name, password, and URL information
Constant Summary collapse
- RESET_PASSWORD_METHOD =
"UpdatePassword"
Instance Attribute Summary collapse
-
#connection ⇒ Object
:nodoc:.
-
#domain ⇒ Object
:nodoc:.
-
#password ⇒ Object
:nodoc:.
-
#path ⇒ Object
:nodoc:.
-
#user_name ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
Default initializer.
-
#update_password(params) ⇒ Object
Updates the API password.
-
#url ⇒ Object
Returns the API URL, based off the domain and path configured.
Constructor Details
#initialize ⇒ Configuration
Default initializer. Do not call directly; instead use the PayTrace.configure method Example:
PayTrace.configure do |config|
config.user_name = "demo123"
config.password = "password"
config.domain = "stage.paytrace.com"
config.path = "api/default.pay"
end
Note: sane defaults are provided for the domain and path; typically you only need to supply the user name and password.
20 21 22 23 24 |
# File 'lib/paytrace/configuration.rb', line 20 def initialize @domain = "paytrace.com" @connection = Faraday.new @path = "api/default.pay" end |
Instance Attribute Details
#connection ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/paytrace/configuration.rb', line 5 def connection @connection end |
#domain ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/paytrace/configuration.rb', line 5 def domain @domain end |
#password ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/paytrace/configuration.rb', line 5 def password @password end |
#path ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/paytrace/configuration.rb', line 5 def path @path end |
#user_name ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/paytrace/configuration.rb', line 5 def user_name @user_name end |
Instance Method Details
#update_password(params) ⇒ Object
Updates the API password. Parameters are passed in a hash. They are:
-
:new_password – the new password to use
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/paytrace/configuration.rb', line 28 def update_password(params) request = PayTrace::API::Request.new request.set_param(:method, RESET_PASSWORD_METHOD) request.set_param(:new_password, params[:new_password]) request.set_param(:new_password_confirmation, params[:new_password]) gateway = PayTrace::API::Gateway.new response = gateway.send_request(request) unless response.has_errors? PayTrace.configure do |config| config.password = params[:new_password] end end response end |
#url ⇒ Object
Returns the API URL, based off the domain and path configured.
46 47 48 |
# File 'lib/paytrace/configuration.rb', line 46 def url "https://#{@domain}/#{@path}" end |