Class: EmailOpened
- Inherits:
-
Object
- Object
- EmailOpened
- Defined in:
- lib/email-opened.rb,
lib/email-opened/version.rb
Constant Summary collapse
- VERSION =
"0.0.19"
Instance Method Summary collapse
- #add_contact(contacts = {}) ⇒ Object
- #api_path ⇒ Object
- #headers ⇒ Object
-
#initialize(api_key, version = 1, sandbox = false) ⇒ EmailOpened
constructor
A new instance of EmailOpened.
- #messages ⇒ Object
- #send(message = {}) ⇒ Object
Constructor Details
#initialize(api_key, version = 1, sandbox = false) ⇒ EmailOpened
Returns a new instance of EmailOpened.
4 5 6 7 8 |
# File 'lib/email-opened.rb', line 4 def initialize(api_key, version = 1, sandbox = false) @eo_api_key = api_key @eo_version = version @eo_sandbox = sandbox end |
Instance Method Details
#add_contact(contacts = {}) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/email-opened.rb', line 31 def add_contact(contacts = {}) contacts = contacts[:contacts] response = RestClient.post api_path + "contacts", { "contacts[]" => contacts }, headers puts response end |
#api_path ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/email-opened.rb', line 38 def api_path if @eo_sandbox == "development" "http://localhost:3000/api/" elsif @eo_sandbox == "edge" "http://edge.emailopened.com/api/" elsif @eo_sandbox == "staging" "http://staging.emailopened.com/api/" else "https://app.emailopened.com/api/" end end |
#headers ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/email-opened.rb', line 10 def headers { "Authorization" => "Token token=\"#{@eo_api_key}\"", "Content-Type" => "application/json", "Accept" => "application/vnd.email-opened.v#{@eo_version}" } end |
#messages ⇒ Object
26 27 28 29 |
# File 'lib/email-opened.rb', line 26 def response = RestClient.get api_path + "messages", headers puts response end |
#send(message = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/email-opened.rb', line 18 def send( = {}) to = [:to] token = [:message_token] response = RestClient.post api_path + "messages", { "to[]" => to, token: token }, headers puts response end |