Class: EmailOctopus::API

Inherits:
Object
  • Object
show all
Defined in:
lib/email_octopus/api.rb,
lib/email_octopus/api/error.rb,
lib/email_octopus/api/response.rb,
lib/email_octopus/api/error/not_found.rb,
lib/email_octopus/api/error/unauthorized.rb,
lib/email_octopus/api/error/api_key_invalid.rb,
lib/email_octopus/api/error/invalid_parameters.rb

Overview

HTTP API gateway to communicate with Email Octopus.

Defined Under Namespace

Classes: Error, Response

Constant Summary collapse

HOST =
'emailoctopus.com/api/1.1'
PORT =
443
HEADERS =
{
  'Content-Type' => 'application/json'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ API

Returns a new instance of API.



15
16
17
18
# File 'lib/email_octopus/api.rb', line 15

def initialize(api_key)
  @http = Net::HTTP.new HOST, PORT, use_ssl: true
  @api_key = api_key
end

Instance Method Details

#delete(path) ⇒ Object



39
40
41
# File 'lib/email_octopus/api.rb', line 39

def delete(path)
  Response.new @http.delete("#{path}?api_key=#{@api_key}", HEADERS)
end

#get(path) ⇒ Object



20
21
22
# File 'lib/email_octopus/api.rb', line 20

def get(path)
  Response.new @http.get("#{path}?api_key=#{@api_key}", HEADERS)
end

#patch(path, body = {}) ⇒ Object



29
30
31
32
# File 'lib/email_octopus/api.rb', line 29

def patch(path, body = {})
  body['api_key'] = @api_key
  Response.new @http.patch(path, body.to_json, HEADERS)
end

#post(path, body = {}) ⇒ Object



24
25
26
27
# File 'lib/email_octopus/api.rb', line 24

def post(path, body = {})
  body['api_key'] = @api_key
  Response.new @http.post(path, body.to_json, HEADERS)
end

#put(path, body = {}) ⇒ Object



34
35
36
37
# File 'lib/email_octopus/api.rb', line 34

def put(path, body = {})
  body['api_key'] = @api_key
  Response.new @http.put(path, body.to_json, HEADERS)
end