email-opened 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  class EmailOpened
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/lib/email-opened.rb CHANGED
@@ -2,8 +2,10 @@ require "email-opened/version"
2
2
  require "rest_client"
3
3
 
4
4
  class EmailOpened
5
- def initialize(api_key)
5
+ def initialize(api_key, version = 1, sandbox = false)
6
6
  @eo_api_key = api_key
7
+ @eo_version = version
8
+ @eo_sandbox = sandbox
7
9
  end
8
10
 
9
11
  # To send a message:
@@ -24,13 +26,34 @@ class EmailOpened
24
26
  # ],
25
27
  # message_token: "dz5t0r"
26
28
  # )
29
+
30
+ def headers
31
+ {
32
+ "Authorization" => "Token token=\"#{@eo_api_key}\"",
33
+ "Content-Type" => "application/json",
34
+ "Accept" => "application/vnd.emailopened.v#{@eo_version}"
35
+ }
36
+ end
27
37
 
28
38
  def send(message = {})
29
- url = "https://app.emailopened.com/#{@eo_api_key}/api/v1/messages"
30
39
  to = message[:to]
31
40
  token = message[:token]
32
- response = RestClient.post url, { accept: :json, "to[]" => to, token: token }
41
+
42
+ response = RestClient.post api_path + "messages", { "to[]" => to, token: token }, headers
33
43
  puts response
34
44
  end
45
+
46
+ def messages
47
+ response = RestClient.get api_path + "messages", {}, headers
48
+ puts response
49
+ end
50
+
51
+ def api_path
52
+ if @eo_sandbox
53
+ "http://localhost:3000/api/"
54
+ else
55
+ "https://app.emailopened.com/api/"
56
+ end
57
+ end
35
58
  end
36
59
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email-opened
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-16 00:00:00.000000000 Z
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client