Class: AlphaMail::EmailService

Inherits:
Object
  • Object
show all
Defined in:
lib/alphamail.rb

Overview

AlphaMail email service

Instance Method Summary collapse

Constructor Details

#initialize(service_url, api_token) ⇒ EmailService

Returns a new instance of EmailService.



78
79
80
81
# File 'lib/alphamail.rb', line 78

def initialize(service_url, api_token)
	@service_url = service_url + '/email/queue'
	@api_token = api_token
end

Instance Method Details

#queue(payload = '') ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/alphamail.rb', line 83

def queue(payload = '')
	# Queue the message
	uri = URI.parse(@service_url)
	req = Net::HTTP::Post.new(uri.path)
	req.basic_auth '', @api_token
	req.body = payload.to_json
	req.content_type = 'application/json'
	res = Net::HTTP.start(uri.host, uri.port) {|http|
		http.request(req)
	}

	# Check response
	case res.code
		when '200' then
			am_res = JSON.parse(res.body)
			return Result.new(am_res['error_code'], am_res['message'])
		else
			am_res = JSON.parse(res.body)
			return Result.new(am_res['error_code'], am_res['message'])
	end 
	return Result.new
end