Class: MHVAC::Client

Inherits:
Common::Client::Base show all
Defined in:
lib/mhv_ac/client.rb

Overview

Core class responsible for MHVAC API interface operations

Instance Method Summary collapse

Methods inherited from Common::Client::Base

#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Instance Method Details

#get_countriesHash

Note:

These two lists (state and country) should be cached for any given day.

Get a list of available countries (used for registraion)

Returns:

  • (Hash)

    an object containing the body of the response



49
50
51
# File 'lib/mhv_ac/client.rb', line 49

def get_countries
  perform(:get, 'enum/countries', nil, nonauth_headers).body
end

#get_statesHash

Note:

These two lists (state and country) should be cached for any given day

Get a list of available states (used for registration)

Returns:

  • (Hash)

    an object containing the body of the response



40
41
42
# File 'lib/mhv_ac/client.rb', line 40

def get_states
  perform(:get, 'enum/states', nil, nonauth_headers).body
end

#nonauth_headersObject (private)



55
56
57
# File 'lib/mhv_ac/client.rb', line 55

def nonauth_headers
  config.base_request_headers.merge('appToken' => config.app_token)
end

#post_register(params) ⇒ Hash

Create an MHV account

Parameters:

  • params (Hash)

    A hash of user parameters

Returns:

  • (Hash)

    an object containing the body of the response



20
21
22
23
# File 'lib/mhv_ac/client.rb', line 20

def post_register(params)
  form = MHVAC::RegistrationForm.new(params)
  perform(:post, 'account/register', form.mhv_params, nonauth_headers).body
end

#post_upgrade(params) ⇒ Hash

Upgrade an MHV account

Parameters:

  • params (Hash)

    A hash of user parameters

Returns:

  • (Hash)

    an object containing the body of the response



30
31
32
33
# File 'lib/mhv_ac/client.rb', line 30

def post_upgrade(params)
  form = MHVAC::UpgradeForm.new(params)
  perform(:post, 'account/upgrade', form.mhv_params, nonauth_headers).body
end