Class: PayTrace::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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

#connectionObject

:nodoc:



5
6
7
# File 'lib/paytrace/configuration.rb', line 5

def connection
  @connection
end

#domainObject

:nodoc:



5
6
7
# File 'lib/paytrace/configuration.rb', line 5

def domain
  @domain
end

#passwordObject

:nodoc:



5
6
7
# File 'lib/paytrace/configuration.rb', line 5

def password
  @password
end

#pathObject

:nodoc:



5
6
7
# File 'lib/paytrace/configuration.rb', line 5

def path
  @path
end

#user_nameObject

: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

#urlObject

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