Class: Improvmx::Client

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

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) ⇒ Client

Returns a new instance of Client.



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

def initialize(api_key = Improvmx.api_key)
  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)
end

Instance Method Details

#delete(resource_path) ⇒ Object



42
43
44
45
46
47
# File 'lib/improvmx/client.rb', line 42

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 = '*/*') ⇒ Object



28
29
30
31
32
33
# File 'lib/improvmx/client.rb', line 28

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 = {}) ⇒ Object



21
22
23
24
25
26
# File 'lib/improvmx/client.rb', line 21

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) ⇒ Object



35
36
37
38
39
40
# File 'lib/improvmx/client.rb', line 35

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