Class: MxHero::API::EmailSync

Inherits:
Object
  • Object
show all
Includes:
Communication, Urls
Defined in:
lib/email-sync.rb

Instance Method Summary collapse

Methods included from Urls

#domain_by_id_url, #domains_url, #service_url

Methods included from Communication

#call, #headers, #json_parse

Constructor Details

#initialize(config = {}) ⇒ EmailSync

Returns a new instance of EmailSync.

Parameters:

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

    the options of configuration

Options Hash (config):

  • :api_url (String)

    The URL to consume the API

  • :username (String)

    The username for access the API

  • :password (String)

    The password for the user that access the API

  • :verbose (Boolean) — default: false

    If true puts information about http operations

  • :as_user (String)

    Send to the API to indentify the end user (app user email)



20
21
22
23
24
25
26
# File 'lib/email-sync.rb', line 20

def initialize(config = {})
	@service_url = config[:api_url]
	@username    = config[:username]
	@password    = config[:password]
	@verbose     = config[:verbose] || false
	@as_user     = config[:as_user]
end

Instance Method Details

#all(domain, params = {}) ⇒ Object



28
29
30
# File 'lib/email-sync.rb', line 28

def all(domain, params = {})
	wrap_response_from call(:get, url(domain, params))
end

#delete(domain, id) ⇒ Object



37
38
39
40
# File 'lib/email-sync.rb', line 37

def delete(domain, id)
	return if id.nil? || id.empty?
	wrap_response_from call(:delete, "#{url(domain)}#{id}")
end

#request(domain, method, path = '/', more = {}) ⇒ HTTP::Message

Make a request in the endpoin /emailsync/#domain

Parameters:

  • method (Symbol)

    indicate the HTTP verb (:get, :post, :put, etc)

  • path (String) (defaults to: '/')

    the path after the base URL (base url: #api_url/emailsync/#domain)

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

Options Hash (more):

  • :params (Hash)

    the URL parameters to add in the URL (ex. 10 => ?limit=10)

  • :body (Hash)

    the body content to send in POST or PUT

Returns:



51
52
53
54
# File 'lib/email-sync.rb', line 51

def request(domain, method, path = '/', more = {})
	url = "#{@service_url}/emailsync/#{domain}#{path}#{parse_params(more[:params])}"
	call(method, url, more[:body])
end

#task_by_id(domain, id) ⇒ Object



32
33
34
35
# File 'lib/email-sync.rb', line 32

def task_by_id(domain, id)
	return if id.nil? || id.empty?
	wrap_response_from call(:get, "#{url(domain)}#{id}")
end