Class: Espago::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/espago/client.rb

Constant Summary collapse

NotAuthenticated =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
# File 'lib/espago/client.rb', line 9

def initialize(options = {})
  @public_key, @app_id, @app_password, @api_version, @checksum_key = options.values_at( :public_key, :app_id, :app_password, :api_version, :checksum_key)
  @connection = options[:connection] || ApiConnection
end

Instance Attribute Details

#api_versionObject

Returns the value of attribute api_version.



6
7
8
# File 'lib/espago/client.rb', line 6

def api_version
  @api_version
end

#app_idObject

Returns the value of attribute app_id.



6
7
8
# File 'lib/espago/client.rb', line 6

def app_id
  @app_id
end

#app_passwordObject

Returns the value of attribute app_password.



6
7
8
# File 'lib/espago/client.rb', line 6

def app_password
  @app_password
end

#checksum_keyObject

Returns the value of attribute checksum_key.



6
7
8
# File 'lib/espago/client.rb', line 6

def checksum_key
  @checksum_key
end

#productionObject

Returns the value of attribute production.



6
7
8
# File 'lib/espago/client.rb', line 6

def production
  @production
end

#public_keyObject

Returns the value of attribute public_key.



6
7
8
# File 'lib/espago/client.rb', line 6

def public_key
  @public_key
end

Instance Method Details

#parse_response(request) ⇒ Object



27
28
29
# File 'lib/espago/client.rb', line 27

def parse_response(request)
  Response.new(request)
end

#send_request(path, method, params = {}) ⇒ Object

Raises:



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/espago/client.rb', line 14

def send_request(path, method, params = {})

  app_id = params[:app_id].present? ?  params.delete(:app_id) : @app_id
  app_password = params[:app_password].present? ? params.delete(:app_password) : @app_password
  production_param = !params[:production].nil? ? params.delete(:production) : production

  raise NotAuthenticated unless valid?(app_id, app_password)

  connection = @connection.new(enviroment(production_param),api_version_header)
  connection.authenticate(app_id, app_password)
  connection.create(path, method, params)
end