Class: Improvmx::Client

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

Instance Method Summary collapse

Methods included from Utils

#forward

Methods included from SMTP

#create_smtp, #delete_smtp, #list_smtp

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



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

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



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

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



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

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



23
24
25
26
27
28
# File 'lib/improvmx/client.rb', line 23

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



37
38
39
40
41
42
# File 'lib/improvmx/client.rb', line 37

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