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.



18
19
20
21
22
# File 'lib/paytrace/configuration.rb', line 18

def initialize
  @domain = "paytrace.com"
  @connection = Faraday.new
  @path = "api/default.pay"
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



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

def connection
  @connection
end

#domainObject

Returns the value of attribute domain.



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

def domain
  @domain
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#user_nameObject

Returns the value of attribute user_name.



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

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/paytrace/configuration.rb', line 26

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.



44
45
46
# File 'lib/paytrace/configuration.rb', line 44

def url
  "https://#{@domain}/#{@path}"
end