Class: Improvmx::Client

Inherits:
Object
  • Object
show all
Includes:
Aliases, Utils
Defined in:
lib/improvmx/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#forward

Methods included from Aliases

#create_alias, #create_or_update_alias, #delete_alias, #get_alias, #list_aliases, #update_alias

Constructor Details

#initialize(api_key = Improvmx.api_key, domain = Improvmx.domain) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
# File 'lib/improvmx/client.rb', line 11

def initialize(api_key = Improvmx.api_key, domain = Improvmx.domain)
  rest_client_params = {
    user: 'api',
    password: api_key,
    user_agent: "improvmx-ruby/#{Improvmx::VERSION}"
  }

  @http_client = RestClient::Resource.new('https://api.improvmx.com/v3', rest_client_params)
  @domain = domain
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



78
79
80
# File 'lib/improvmx/client.rb', line 78

def domain
  @domain
end

Instance Method Details

#delete(resource_path) ⇒ Improvmx::Response

Generic Improvmx DELETE Handler

with.

Parameters:

  • resource_path (String)

    This is the API resource you wish to interact

Returns:



71
72
73
74
75
76
# File 'lib/improvmx/client.rb', line 71

def delete(resource_path)
  response = @http_client[resource_path].delete
  Response.new(response)
rescue StandardError => e
  raise communication_error e
end

#get(resource_path, params = nil, accept = '*/*') ⇒ Improvmx::Response

Generic Improvmx GET Handler

with. containing required parameters for the requested resource.

Parameters:

  • resource_path (String)

    This is the API resource you wish to interact

  • params (Hash) (defaults to: nil)

    This should be a standard Hash

  • accept (String) (defaults to: '*/*')

    Acceptable Content-Type of the response body.

Returns:



45
46
47
48
49
50
# File 'lib/improvmx/client.rb', line 45

def get(resource_path, params = nil, accept = '*/*')
  response = @http_client[resource_path].get(params: params, accept: accept)
  Response.new(response)
rescue StandardError => e
  raise communication_error e
end

#post(resource_path, data, headers = {}) ⇒ Improvmx::Response

Generic Improvmx POST Handler

with. Be sure to include your domain, where necessary. containing required parameters for the requested resource.

Parameters:

  • resource_path (String)

    This is the API resource you wish to interact

  • data (Hash)

    This should be a standard Hash

  • headers (Hash) (defaults to: {})

    Additional headers to pass to the resource.

Returns:



30
31
32
33
34
35
# File 'lib/improvmx/client.rb', line 30

def post(resource_path, data, headers = {})
  response = @http_client[resource_path].post(data, headers)
  Response.new(response)
rescue StandardError => e
  raise communication_error e
end

#put(resource_path, data) ⇒ Improvmx::Response

Generic Improvmx PUT Handler

with. containing required parameters for the requested resource.

Parameters:

  • resource_path (String)

    This is the API resource you wish to interact

  • data (Hash)

    This should be a standard Hash

Returns:



59
60
61
62
63
64
# File 'lib/improvmx/client.rb', line 59

def put(resource_path, data)
  response = @http_client[resource_path].put(data)
  Response.new(response)
rescue StandardError => e
  raise communication_error e
end