deliverhq 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +2 -0
  6. data/Gemfile.lock +69 -0
  7. data/LICENSE +12 -0
  8. data/README.md +115 -0
  9. data/Rakefile +20 -0
  10. data/deliverhq.gemspec +27 -0
  11. data/lib/deliverhq.rb +33 -0
  12. data/lib/deliverhq/models/domain.rb +29 -0
  13. data/lib/deliverhq/models/mailbox.rb +47 -0
  14. data/lib/deliverhq/models/message.rb +39 -0
  15. data/lib/deliverhq/request/base.rb +36 -0
  16. data/lib/deliverhq/request/domain/create.rb +11 -0
  17. data/lib/deliverhq/request/domain/delete.rb +11 -0
  18. data/lib/deliverhq/request/domain/list.rb +10 -0
  19. data/lib/deliverhq/request/mailbox/create.rb +19 -0
  20. data/lib/deliverhq/request/mailbox/delete.rb +11 -0
  21. data/lib/deliverhq/request/mailbox/list.rb +10 -0
  22. data/lib/deliverhq/request/message/list.rb +10 -0
  23. data/lib/deliverhq/request/message/show.rb +10 -0
  24. data/lib/deliverhq/response.rb +17 -0
  25. data/test/all.rb +6 -0
  26. data/test/integration/domains_test.rb +23 -0
  27. data/test/integration/mailboxes_test.rb +33 -0
  28. data/test/integration/messages_test.rb +24 -0
  29. data/test/integration/send_test.rb +21 -0
  30. data/test/integration_test_helper.rb +9 -0
  31. data/test/test_helper.rb +15 -0
  32. data/test/unit/lib/deliverhq/models/domain_test.rb +36 -0
  33. data/test/unit/lib/deliverhq/models/mailbox_test.rb +30 -0
  34. data/test/unit/lib/deliverhq/models/message_test.rb +26 -0
  35. data/test/unit/lib/deliverhq/requests/base_test.rb +60 -0
  36. data/test/unit/lib/deliverhq/requests/domain/create_test.rb +26 -0
  37. data/test/unit/lib/deliverhq/requests/domain/destroy_test.rb +19 -0
  38. data/test/unit/lib/deliverhq/requests/domain/list_test.rb +25 -0
  39. data/test/unit/lib/deliverhq/requests/mailbox/create_test.rb +24 -0
  40. data/test/unit/lib/deliverhq/requests/mailbox/destroy_test.rb +19 -0
  41. data/test/unit/lib/deliverhq/requests/mailbox/list_test.rb +21 -0
  42. data/test/unit/lib/deliverhq/requests/message/list_test.rb +22 -0
  43. data/test/unit/lib/deliverhq/requests/message/show_test.rb +22 -0
  44. data/test/unit/lib/deliverhq/response_test.rb +27 -0
  45. data/test/vcr_cassettes/crd_domains.yml +236 -0
  46. data/test/vcr_cassettes/crd_mailboxes.yml +238 -0
  47. data/test/vcr_cassettes/messages_list.yml +54 -0
  48. data/test/vcr_cassettes/messages_show.yml +142 -0
  49. data/test/vcr_cassettes/send_email.yml +99 -0
  50. metadata +204 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e462abbcfd6e358d7e20738bd40256f8a8c566f2
4
+ data.tar.gz: 83c3930d8c6b9c28fce1d882b6f95102d2947d67
5
+ SHA512:
6
+ metadata.gz: fee3b3845568a30620a9190747862a72ee7e6235f531edda741754f5ac53098b4527ccd772e36978bfea2650cd1e2431d544265145071114a1aef64ea3815895
7
+ data.tar.gz: 84970634bc7d6a533819426cd3db0845bf619f41a04a8bd9de6962e6d6c7d60963cee5b7fa6118e88450ca2e26f24790698cb3cf2cd6232bce10a766be7a2bdb
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ .DS_Store
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deliverhq (0.0.1)
5
+ faraday (~> 0.9)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.3.8)
11
+ coveralls (0.8.2)
12
+ json (~> 1.8)
13
+ rest-client (>= 1.6.8, < 2)
14
+ simplecov (~> 0.10.0)
15
+ term-ansicolor (~> 1.3)
16
+ thor (~> 0.19.1)
17
+ crack (0.4.2)
18
+ safe_yaml (~> 1.0.0)
19
+ docile (1.1.5)
20
+ domain_name (0.5.24)
21
+ unf (>= 0.0.5, < 1.0.0)
22
+ faraday (0.9.1)
23
+ multipart-post (>= 1.2, < 3)
24
+ http-cookie (1.0.2)
25
+ domain_name (~> 0.5)
26
+ json (1.8.3)
27
+ mime-types (2.6.1)
28
+ minitest (5.8.0)
29
+ multipart-post (2.0.0)
30
+ netrc (0.10.3)
31
+ rake (10.4.2)
32
+ rest-client (1.8.0)
33
+ http-cookie (>= 1.0.2, < 2.0)
34
+ mime-types (>= 1.16, < 3.0)
35
+ netrc (~> 0.7)
36
+ safe_yaml (1.0.4)
37
+ simplecov (0.10.0)
38
+ docile (~> 1.1.0)
39
+ json (~> 1.8)
40
+ simplecov-html (~> 0.10.0)
41
+ simplecov-html (0.10.0)
42
+ term-ansicolor (1.3.2)
43
+ tins (~> 1.0)
44
+ thor (0.19.1)
45
+ tins (1.5.4)
46
+ unf (0.1.4)
47
+ unf_ext
48
+ unf_ext (0.0.7.1)
49
+ vcr (2.9.3)
50
+ webmock (1.21.0)
51
+ addressable (>= 2.3.6)
52
+ crack (>= 0.3.2)
53
+ yard (0.8.7.6)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ coveralls (~> 0.8)
60
+ deliverhq!
61
+ minitest (~> 5.3)
62
+ rake (~> 10.4)
63
+ simplecov (~> 0.9)
64
+ vcr (~> 2.8)
65
+ webmock (~> 1.8)
66
+ yard (~> 0.8)
67
+
68
+ BUNDLED WITH
69
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2015, DataCentred Ltd
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # DeliverHQ
2
+
3
+ Rubygem wrapper for [deliverHQ](http://www.deliverhq.com/) API.
4
+
5
+ [![Build Status](https://travis-ci.org/datacentred/deliverhq.svg)](https://travis-ci.org/datacentred/deliverhq) [![Coverage Status](https://coveralls.io/repos/datacentred/deliverhq/badge.svg?branch=master&service=github)](https://coveralls.io/github/datacentred/deliverhq?branch=master)
6
+
7
+ ## Installing
8
+
9
+ ```
10
+ gem install deliverhq
11
+ ```
12
+
13
+ or
14
+
15
+ (in Gemfile or .gemspec)
16
+ ```ruby
17
+ gem 'deliverhq'
18
+ ```
19
+
20
+ then
21
+
22
+ ```ruby
23
+ require 'deliverhq'
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ### Authentication
29
+
30
+ Set your API ID and key using the two environment variables, `DELIVERHQ_ID` and `DELIVERHQ_KEY`. This can be found in the "Setup" section of your DeliverHQ account.
31
+
32
+ ### Sending E-Mail
33
+
34
+ ```ruby
35
+ Deliverhq::send(from: 'you@yourdomain.com', to: 'recipient@theirdomain.com', subject: 'Hello!', plain_body: 'This is a test.')
36
+ #=> #<Deliverhq::Message:0x007fc79...
37
+ ```
38
+
39
+ ### Domains
40
+
41
+ ```ruby
42
+ # Retrieve all domains associated with your account
43
+ Deliverhq::Domain.all
44
+ #=> [#<Deliverhq::Domain:0x007fc79c1..]
45
+
46
+ # Create a new domain
47
+ domain = Deliverhq::Domain.create(name: 'test.com')
48
+ #=> #<Deliverhq::Domain:0x007fc79c134a78 @id=7970, @account_id=506, @name="test.com", @verification_token="punqv7acjm", @verified_at=nil>
49
+
50
+ # And remove it
51
+ domain.destroy
52
+ #=> true
53
+ ```
54
+
55
+ ### Mailboxes
56
+
57
+ ```ruby
58
+ # Retrieve all mailboxes associated with your account
59
+ Deliverhq::Mailbox.all
60
+ #=> [#<Deliverhq::Mailbox:0x007fc79c2...
61
+
62
+ # Create a new mailbox
63
+ mailbox = Deliverhq::Mailbox.create(name: 'Incoming Support',
64
+ check_spam: 0,
65
+ destination_address: 'http://app.sirportly.com/modules/deliver2/accept',
66
+ destination_type: 'http',
67
+ domain_id: 6707,
68
+ encoding:'post',
69
+ format: 'full',
70
+ reply_stripping: false,
71
+ partial_address: 'support')
72
+
73
+ # And remove it
74
+ mailbox.destroy
75
+ #=> true
76
+ ```
77
+
78
+ ### Messages
79
+
80
+ ```ruby
81
+ # Retrieve messages by page
82
+ page = 1
83
+ Deliverhq::Message.all(page)
84
+ #=> [#<Deliverhq::Message:0x007f88e29...
85
+ page = 2
86
+ Deliverhq::Message.all(page)
87
+ #=> [#<Deliverhq::Message:0x008ef62a9...
88
+ page = 999
89
+ Deliverhq::Message.all(page)
90
+ #=> []
91
+
92
+ # Show individual message
93
+ Deliverhq::Message.find(226945)
94
+ #=> #<Deliverhq::Message:0x007f88e2998a28 @id=222697445, @envelope_to ...
95
+ ```
96
+
97
+ ### Handling Errors
98
+
99
+ If the API reports an error, the gem will raise the message as an exception of type `Deliverhq::RequestError`. e.g.
100
+
101
+ ```ruby
102
+ domain = Deliverhq::Domain.create(name: 'test.com')
103
+ #=> #<Deliverhq::Domain:0x007fc79c134a78 @id=7970, @account_id=506, @name="test.com", @verification_token="punqv7acjm", @verified_at=nil>
104
+
105
+ domain.destroy
106
+ #=> true
107
+
108
+ # Try to remove it after it's been removed
109
+ domain.destroy
110
+ #=> Deliverhq::RequestError: Server responded with 404: {"error":"Not Found"}
111
+ ```
112
+
113
+ ## Further Reading
114
+
115
+ You can learn more about the DeliverHQ API here: [http://deliver.apidoc.io/](http://deliver.apidoc.io/).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+ namespace :test do
6
+ Rake::TestTask.new("unit") do |t|
7
+ t.libs << 'test'
8
+ t.pattern = "#{File.dirname(__FILE__)}/test/all.rb"
9
+ end
10
+
11
+ Rake::TestTask.new("integration") do |t|
12
+ t.libs << 'test'
13
+ t.pattern = "#{File.dirname(__FILE__)}/test/integration/*_test.rb"
14
+ end
15
+ end
16
+
17
+ desc "Run tests"
18
+ task :test => ["test:integration", "test:unit"]
19
+
20
+ task :default => :test
data/deliverhq.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'deliverhq'
3
+ gem.version = '0.0.1'
4
+ gem.date = '2015-08-10'
5
+ gem.summary = 'deliverhq'
6
+ gem.description = 'DeliverHQ API wrapper'
7
+ gem.authors = [ 'Sean Handley' ]
8
+ gem.email = 'sean.handley@gmail.com'
9
+ gem.files = `git ls-files`.split("\n")
10
+ gem.homepage = 'https://github.com/datacentred/deliverhq'
11
+ gem.license = 'BSD-3-Clause'
12
+
13
+ gem.required_ruby_version = '> 2.1.0'
14
+
15
+ # Runtime Dependencies
16
+ gem.add_runtime_dependency 'faraday', '~> 0.9'
17
+
18
+ # Development Dependencies
19
+ gem.add_development_dependency 'vcr', '~> 2.8'
20
+ gem.add_development_dependency 'webmock', '~> 1.8'
21
+ gem.add_development_dependency 'minitest', '~> 5.3'
22
+ gem.add_development_dependency 'simplecov', '~> 0.9'
23
+ gem.add_development_dependency 'yard', '~> 0.8'
24
+ gem.add_development_dependency 'coveralls', '~> 0.8'
25
+ gem.add_development_dependency 'rake', '~> 10.4'
26
+
27
+ end
data/lib/deliverhq.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'date'
4
+
5
+ module Deliverhq
6
+
7
+ require_relative 'deliverhq/request/base'
8
+ require_relative 'deliverhq/response'
9
+
10
+ require_relative 'deliverhq/request/domain/create'
11
+ require_relative 'deliverhq/request/domain/delete'
12
+ require_relative 'deliverhq/request/domain/list'
13
+
14
+ require_relative 'deliverhq/request/mailbox/create'
15
+ require_relative 'deliverhq/request/mailbox/delete'
16
+ require_relative 'deliverhq/request/mailbox/list'
17
+
18
+ require_relative 'deliverhq/request/message/list'
19
+ require_relative 'deliverhq/request/message/show'
20
+
21
+ require_relative 'deliverhq/models/domain'
22
+ require_relative 'deliverhq/models/mailbox'
23
+ require_relative 'deliverhq/models/message'
24
+
25
+
26
+ class RequestError < StandardError; end
27
+
28
+ def self.send(params)
29
+ response = Request::Base.http_post('send', params.to_json)
30
+ message_id = response.split(':').last.to_i
31
+ Message.find(message_id)
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ module Deliverhq
2
+ class Domain
3
+
4
+ attr_reader :id, :account_id, :name, :verification_token, :verified_at
5
+
6
+ def initialize(params)
7
+ @id = params['id']
8
+ @account_id = params['account_id']
9
+ @name = params['name']
10
+ @verification_token = params['verification_token']
11
+ @verified_at = params['verified_at']
12
+ end
13
+
14
+ def self.create(params)
15
+ new(Request::Domain.create(params))
16
+ end
17
+
18
+ def self.all
19
+ Request::Domain.list.collect do |domain|
20
+ new domain
21
+ end
22
+ end
23
+
24
+ def destroy
25
+ Request::Domain.destroy(id)
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,47 @@
1
+ module Deliverhq
2
+ class Mailbox
3
+
4
+ attr_reader :id, :name, :check_spam, :destination_address,
5
+ :destination_type, :domain_id, :encoding, :format,
6
+ :reply_stripping, :partial_address,
7
+ :account_id, :server_id, :domain,
8
+ :address, :created_at, :forwarding_token,
9
+ :verification_token,:verified_at
10
+
11
+ def initialize(params)
12
+ @id = params['id']
13
+ @name = params['name']
14
+ @check_spam = params["check_spam"]
15
+ @destination_address = params["destination_address"]
16
+ @destination_type = params["destination_type"]
17
+ @domain_id = params["domain_id"]
18
+ @encoding = params["encoding"]
19
+ @format = params["format"]
20
+ @reply_stripping = params["reply_stripping"]
21
+ @partial_address = params["partial_address"]
22
+ @account_id = params["account_id"]
23
+ @server_id = params["server_id"]
24
+ @domain = params["domain"]
25
+ @address = params["address"]
26
+ @created_at = params["created_at"]
27
+ @forwarding_token = params["forwarding_token"]
28
+ @verification_token = params["verification_token"]
29
+ @verified_at = params["verified_at"]
30
+ end
31
+
32
+ def self.create(params)
33
+ new(Request::Mailbox.create(params))
34
+ end
35
+
36
+ def self.all
37
+ Request::Mailbox.list.collect do |mailbox|
38
+ new mailbox
39
+ end
40
+ end
41
+
42
+ def destroy
43
+ Request::Mailbox.destroy(id)
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,39 @@
1
+ module Deliverhq
2
+ class Message
3
+
4
+ attr_reader :id, :envelope_to, :envelope_from,
5
+ :subject, :status, :error, :server_id,
6
+ :mailbox_id, :status_code, :body,
7
+ :bounce_body, :spam, :address_identifier,
8
+ :body_to, :body_from
9
+
10
+ def initialize(params)
11
+ @id = params["id"]
12
+ @envelope_to = params["envelope_to"]
13
+ @envelope_from = params[ "envelope_from"]
14
+ @subject = params["subject"]
15
+ @status = params["status"]
16
+ @error = params["error"]
17
+ @server_id = params[ "server_id"]
18
+ @mailbox_id = params[ "mailbox_id"]
19
+ @status_code = params[ "status_code"]
20
+ @body = params[ "body"]
21
+ @bounce_body = params[ "bounce_body"]
22
+ @spam = params[ "spam"]
23
+ @address_identifier = params["address_identifier"]
24
+ @body_to = params[ "body_to"]
25
+ @body_from = params[ "body_from"]
26
+ end
27
+
28
+ def self.find(id)
29
+ new(Request::Message.show(id))
30
+ end
31
+
32
+ def self.all(page=1)
33
+ Request::Message.list(page).collect do |message|
34
+ new message
35
+ end
36
+ end
37
+
38
+ end
39
+ end