Class: Improvmx::Client
- Inherits:
-
Object
- Object
- Improvmx::Client
- Defined in:
- lib/improvmx/client.rb
Instance Method Summary collapse
- #delete(resource_path) ⇒ Object
- #get(resource_path, params = nil, accept = '*/*') ⇒ Object
-
#initialize(api_key = Improvmx.api_key) ⇒ Client
constructor
A new instance of Client.
- #post(resource_path, data, headers = {}) ⇒ Object
- #put(resource_path, data) ⇒ Object
Methods included from Utils
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
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 24 |
# 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}", headers: { content_type: "application/json" } } @http_client = RestClient::Resource.new('https://api.improvmx.com/v3', rest_client_params) end |
Instance Method Details
#delete(resource_path) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/improvmx/client.rb', line 47 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
33 34 35 36 37 38 |
# File 'lib/improvmx/client.rb', line 33 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
26 27 28 29 30 31 |
# File 'lib/improvmx/client.rb', line 26 def post(resource_path, data, headers = {}) response = @http_client[resource_path].post(data.to_json, headers) Response.new(response) rescue StandardError => e raise communication_error e end |