dynect_email 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +56 -0
- data/Rakefile +10 -0
- data/dynect_email.gemspec +25 -0
- data/lib/dynect_email.rb +46 -0
- data/lib/dynect_email/version.rb +3 -0
- data/test/dynect_email_test.rb +134 -0
- data/test/fixtures/missing_or_invalid_api_key.json +1 -0
- data/test/fixtures/missing_or_invalid_fields.json +1 -0
- data/test/fixtures/object_already_exists.json +1 -0
- data/test/fixtures/ok.json +1 -0
- data/test/test_helper.rb +14 -0
- metadata +98 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2011 Shopify
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# DynectEmail
|
|
2
|
+
|
|
3
|
+
A Ruby library for interacting with DynECT Email Delivery API.
|
|
4
|
+
|
|
5
|
+
[DynECT Email](http://dyn.com/enterprise-email/dynect-email)
|
|
6
|
+
[DynECT Email API](https://dynectemail.tenderapp.com/help/kb/api/introduction-to-dynect-email-deliverys-api)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
### From Git
|
|
11
|
+
|
|
12
|
+
You can check out the latest source from git:
|
|
13
|
+
|
|
14
|
+
git clone git://github.com/Shopify/dynect_email.git
|
|
15
|
+
|
|
16
|
+
## Usage Example
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
require 'rubygems'
|
|
20
|
+
require 'dynect_email'
|
|
21
|
+
|
|
22
|
+
# Set your API key
|
|
23
|
+
DynectEmail.api_key = "your-api-key"
|
|
24
|
+
|
|
25
|
+
# Add a sender to your account
|
|
26
|
+
DynectEmail.add_sender("myemail@example.com")
|
|
27
|
+
|
|
28
|
+
# Add a sub account with username, password, company, phone
|
|
29
|
+
response = DynectEmail.add_account("myemail@example.com", "secretpassword", "Shopify", "1231231231")
|
|
30
|
+
|
|
31
|
+
# response hash includes the api key for the account that was created
|
|
32
|
+
# Add a sender to the sub account
|
|
33
|
+
DynectEmail.add_sender("myemail@example.com", response['apikey'])
|
|
34
|
+
|
|
35
|
+
# Set headers
|
|
36
|
+
DynectEmail.set_headers({:xheader1 => "X-Sample1", :xheader2 => "X-Sample2"})
|
|
37
|
+
|
|
38
|
+
# Remove sender
|
|
39
|
+
DynectEmail.remove_sender("myemail@example.com")
|
|
40
|
+
|
|
41
|
+
# Remove account
|
|
42
|
+
DynectEmail.remove_account("myemail@example.com")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Check out the [API docs](https://dynectemail.tenderapp.com/help/kb/api/introduction-to-dynect-email-deliverys-api) for more information on what parameters are available.
|
|
46
|
+
|
|
47
|
+
## Contributing
|
|
48
|
+
|
|
49
|
+
1. Fork the [official repository](https://github.com/Shopify/dynect_email).
|
|
50
|
+
2. Make your changes in a topic branch.
|
|
51
|
+
3. Send a pull request.
|
|
52
|
+
|
|
53
|
+
Notes:
|
|
54
|
+
|
|
55
|
+
* Contributions without tests won't be accepted.
|
|
56
|
+
* Please don't update the Gem version.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "dynect_email/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "dynect_email"
|
|
7
|
+
s.version = DynectEmail::VERSION
|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
|
9
|
+
s.authors = ["John Duff"]
|
|
10
|
+
s.email = ["john.duff@shopify.com"]
|
|
11
|
+
s.homepage = "https://github.com/Shopify/dynect_email"
|
|
12
|
+
s.summary = %q{Integrate with the DynECT Email API.}
|
|
13
|
+
s.description = %q{Provides integration with the DynECT Email API.}
|
|
14
|
+
|
|
15
|
+
s.rubyforge_project = "dynect_email"
|
|
16
|
+
|
|
17
|
+
s.add_runtime_dependency("httparty")
|
|
18
|
+
s.add_development_dependency("fakeweb")
|
|
19
|
+
s.add_development_dependency("mocha")
|
|
20
|
+
|
|
21
|
+
s.files = `git ls-files`.split("\n")
|
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
24
|
+
s.require_paths = ["lib"]
|
|
25
|
+
end
|
data/lib/dynect_email.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
require 'ostruct'
|
|
3
|
+
module DynectEmail
|
|
4
|
+
class Error < StandardError; end
|
|
5
|
+
|
|
6
|
+
include HTTParty
|
|
7
|
+
base_uri 'http://emailapi.dynect.net/rest/json'
|
|
8
|
+
class << self
|
|
9
|
+
attr_accessor :api_key
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.add_sender(email, apikey=nil)
|
|
13
|
+
post_data("/senders", {:emailaddress => email}, apikey)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.remove_sender(email, apikey=nil)
|
|
17
|
+
post_data("/senders/delete", {:emailaddress => email}, apikey)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.add_account(username, password, company, phone, options={})
|
|
21
|
+
post_data("/accounts", options.merge({:username => username, :password => password, :companyname => company, :phone => phone}))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.remove_account(username)
|
|
25
|
+
post_data("/accounts/delete", :username => username)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# {:xheader1 => "X-header", xheader2 => ....}
|
|
29
|
+
def self.set_headers(headers, apikey=nil)
|
|
30
|
+
post_data("/accounts/xheaders", headers, apikey)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
def self.handle_response(response)
|
|
35
|
+
message = response['response']['message']
|
|
36
|
+
raise DynectEmail::Error, message unless message == 'OK'
|
|
37
|
+
response['response']['data']
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.post_data(url, options={}, apikey=nil)
|
|
41
|
+
options.merge!(:apikey => apikey || DynectEmail.api_key)
|
|
42
|
+
result = post(url, :body => options)
|
|
43
|
+
|
|
44
|
+
handle_response(result)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class DynectEmailTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
DynectEmail.api_key = "12345"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def teardown
|
|
10
|
+
FakeWeb.allow_net_connect = false
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_missing_or_invalid_api_key
|
|
14
|
+
DynectEmail.api_key = ""
|
|
15
|
+
FakeWeb.register_uri(:post, "http://emailapi.dynect.net/rest/json/senders", :body => load_fixture('missing_or_invalid_api_key'), :status => 451, :content_type => "text/json")
|
|
16
|
+
|
|
17
|
+
DynectEmail.api_key = ""
|
|
18
|
+
error = assert_raise DynectEmail::Error do
|
|
19
|
+
result = DynectEmail.add_sender("test@example.com")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
assert_equal "Missing or Invalid API Key", error.message
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_missing_or_invalid_field
|
|
26
|
+
FakeWeb.register_uri(:post, "http://emailapi.dynect.net/rest/json/accounts", :body => load_fixture('missing_or_invalid_fields'), :status => 451, :content_type => "text/json")
|
|
27
|
+
|
|
28
|
+
error = assert_raise DynectEmail::Error do
|
|
29
|
+
DynectEmail.add_account("test@example.com", "test", nil, nil)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
assert_equal "Missing or Invalid Required Fields", error.message
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_add_account
|
|
36
|
+
FakeWeb.register_uri(:post, "http://emailapi.dynect.net/rest/json/accounts", :body => load_fixture('ok'), :status => 200, :content_type => "text/json")
|
|
37
|
+
|
|
38
|
+
response = DynectEmail.add_account("test@example.com", "test", "Shopify", "1231231234")
|
|
39
|
+
|
|
40
|
+
assert_equal "1234", response['apikey']
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_add_account_sends_correct_parameters
|
|
44
|
+
DynectEmail.expects(:post).with("/accounts", :body => {:username => "test@example.com", :password => "test", :companyname => "Shopify", :phone => "1231231234", :apikey => "12345"})
|
|
45
|
+
DynectEmail.expects(:handle_response)
|
|
46
|
+
|
|
47
|
+
DynectEmail.add_account("test@example.com", "test", "Shopify", "1231231234")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_add_sender
|
|
51
|
+
FakeWeb.register_uri(:post, "http://emailapi.dynect.net/rest/json/senders", :body => load_fixture('ok'), :status => 200, :content_type => "text/json")
|
|
52
|
+
|
|
53
|
+
assert_nothing_raised do
|
|
54
|
+
DynectEmail.add_sender("test@example.com")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_add_sender_sends_correct_parameters
|
|
59
|
+
DynectEmail.expects(:post).with("/senders", :body => {:emailaddress => "test@example.com", :apikey => "12345"})
|
|
60
|
+
DynectEmail.expects(:handle_response)
|
|
61
|
+
|
|
62
|
+
DynectEmail.add_sender("test@example.com")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_add_sender_duplicate
|
|
66
|
+
FakeWeb.register_uri(:post, "http://emailapi.dynect.net/rest/json/senders", :body => load_fixture('object_already_exists'), :status => 453, :content_type => "text/json")
|
|
67
|
+
|
|
68
|
+
error = assert_raise DynectEmail::Error do
|
|
69
|
+
DynectEmail.add_sender("test@example.com")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
assert_equal "Object Already Exists", error.message
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_add_sender_with_apikey
|
|
76
|
+
FakeWeb.register_uri(:post, "http://emailapi.dynect.net/rest/json/senders", :body => load_fixture('ok'), :status => 200, :content_type => "text/json")
|
|
77
|
+
|
|
78
|
+
assert_nothing_raised do
|
|
79
|
+
DynectEmail.add_sender("test@example.com", "123")
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_add_sender_with_api_key_sends_correct_parameters
|
|
84
|
+
DynectEmail.expects(:post).with("/senders", :body => {:emailaddress => "test@example.com", :apikey => "123"})
|
|
85
|
+
DynectEmail.expects(:handle_response)
|
|
86
|
+
|
|
87
|
+
DynectEmail.add_sender("test@example.com", "123")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_remove_sender
|
|
91
|
+
FakeWeb.register_uri(:post, "http://emailapi.dynect.net/rest/json/senders/delete", :body => load_fixture('ok'), :status => 200, :content_type => "text/json")
|
|
92
|
+
|
|
93
|
+
assert_nothing_raised do
|
|
94
|
+
DynectEmail.remove_sender("test@example.com")
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_remove_sender_sends_correct_parameters
|
|
99
|
+
DynectEmail.expects(:post).with("/senders/delete", :body => {:emailaddress => "test@example.com", :apikey => "12345"})
|
|
100
|
+
DynectEmail.expects(:handle_response)
|
|
101
|
+
|
|
102
|
+
DynectEmail.remove_sender("test@example.com")
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_remove_account
|
|
106
|
+
FakeWeb.register_uri(:post, "http://emailapi.dynect.net/rest/json/accounts/delete", :body => load_fixture('ok'), :status => 200, :content_type => "text/json")
|
|
107
|
+
|
|
108
|
+
assert_nothing_raised do
|
|
109
|
+
DynectEmail.remove_account("test@example.com")
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_remove_account_sends_correct_parameters
|
|
114
|
+
DynectEmail.expects(:post).with("/accounts/delete", :body => {:username => "test@example.com", :apikey => "12345"})
|
|
115
|
+
DynectEmail.expects(:handle_response)
|
|
116
|
+
|
|
117
|
+
DynectEmail.remove_account("test@example.com")
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def test_set_headers
|
|
121
|
+
FakeWeb.register_uri(:post, "http://emailapi.dynect.net/rest/json/accounts/xheaders", :body => load_fixture('ok'), :status => 200, :content_type => "text/json")
|
|
122
|
+
|
|
123
|
+
assert_nothing_raised do
|
|
124
|
+
DynectEmail.set_headers({:xheader1 => "X-Sample1", :xheader2 => "X-Sample2"})
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_set_headers_sends_correct_parameters
|
|
129
|
+
DynectEmail.expects(:post).with("/accounts/xheaders", :body => {:xheader1 => "X-Sample1", :xheader2 => "X-Sample2", :apikey => "12345"})
|
|
130
|
+
DynectEmail.expects(:handle_response)
|
|
131
|
+
|
|
132
|
+
DynectEmail.set_headers({:xheader1 => "X-Sample1", :xheader2 => "X-Sample2"})
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"response":{"status":453,"message":"Missing or Invalid API Key","data":{}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"response":{"status":452,"message":"Missing or Invalid Required Fields","data":["The company name can not be blank.","The phone number can not be blank."]}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"response":{"status":451,"message":"Object Already Exists","data":{}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"response":{"status":200,"message":"OK","data":{"apikey":"1234"}}}
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'fakeweb'
|
|
4
|
+
require 'mocha'
|
|
5
|
+
require 'lib/dynect_email'
|
|
6
|
+
|
|
7
|
+
FakeWeb.allow_net_connect = false
|
|
8
|
+
|
|
9
|
+
class Test::Unit::TestCase
|
|
10
|
+
|
|
11
|
+
def load_fixture(name)
|
|
12
|
+
File.read(File.dirname(__FILE__) + "/fixtures/#{name}.json")
|
|
13
|
+
end
|
|
14
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dynect_email
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- John Duff
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-02-09 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: httparty
|
|
16
|
+
requirement: &2156801220 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *2156801220
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: fakeweb
|
|
27
|
+
requirement: &2156800780 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *2156800780
|
|
36
|
+
- !ruby/object:Gem::Dependency
|
|
37
|
+
name: mocha
|
|
38
|
+
requirement: &2156800360 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ! '>='
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
type: :development
|
|
45
|
+
prerelease: false
|
|
46
|
+
version_requirements: *2156800360
|
|
47
|
+
description: Provides integration with the DynECT Email API.
|
|
48
|
+
email:
|
|
49
|
+
- john.duff@shopify.com
|
|
50
|
+
executables: []
|
|
51
|
+
extensions: []
|
|
52
|
+
extra_rdoc_files: []
|
|
53
|
+
files:
|
|
54
|
+
- .gitignore
|
|
55
|
+
- Gemfile
|
|
56
|
+
- MIT-LICENSE
|
|
57
|
+
- README.md
|
|
58
|
+
- Rakefile
|
|
59
|
+
- dynect_email.gemspec
|
|
60
|
+
- lib/dynect_email.rb
|
|
61
|
+
- lib/dynect_email/version.rb
|
|
62
|
+
- test/dynect_email_test.rb
|
|
63
|
+
- test/fixtures/missing_or_invalid_api_key.json
|
|
64
|
+
- test/fixtures/missing_or_invalid_fields.json
|
|
65
|
+
- test/fixtures/object_already_exists.json
|
|
66
|
+
- test/fixtures/ok.json
|
|
67
|
+
- test/test_helper.rb
|
|
68
|
+
homepage: https://github.com/Shopify/dynect_email
|
|
69
|
+
licenses: []
|
|
70
|
+
post_install_message:
|
|
71
|
+
rdoc_options: []
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
none: false
|
|
76
|
+
requirements:
|
|
77
|
+
- - ! '>='
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0'
|
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
none: false
|
|
82
|
+
requirements:
|
|
83
|
+
- - ! '>='
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
requirements: []
|
|
87
|
+
rubyforge_project: dynect_email
|
|
88
|
+
rubygems_version: 1.8.11
|
|
89
|
+
signing_key:
|
|
90
|
+
specification_version: 3
|
|
91
|
+
summary: Integrate with the DynECT Email API.
|
|
92
|
+
test_files:
|
|
93
|
+
- test/dynect_email_test.rb
|
|
94
|
+
- test/fixtures/missing_or_invalid_api_key.json
|
|
95
|
+
- test/fixtures/missing_or_invalid_fields.json
|
|
96
|
+
- test/fixtures/object_already_exists.json
|
|
97
|
+
- test/fixtures/ok.json
|
|
98
|
+
- test/test_helper.rb
|