hanami_email 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 235d5d0ea018a5ef0980d90baad6c1e864257c5814cf26ee452e3ae7b0a78e95
4
+ data.tar.gz: 59061e24cfc83b644483e6349d1152fc0bef5b0a49f0306dd892225fadd77985
5
+ SHA512:
6
+ metadata.gz: 56c00ca58935b0ee9e43311cfdec87f2838b33e1d1c49340daff73533c08e4f74e0e5202dc8389229c712b753b2bf9709253e50e003747c165da61c383e914cb
7
+ data.tar.gz: e17fa4181fea71067a586e05d2028e14cae06a91829bed3351491f43e2cf3c90f0ff32b35044058c9379abb9eb6e387ff66f7c796c55661dc77f741dbea617b1
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/tmp
9
+ /tmp/
10
+ Gemfile.lock
11
+ Gemfile*.lock
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
15
+
16
+ .ruby-version
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
6
+
7
+ gem "rake", "~> 10.0"
8
+
9
+ group :test do
10
+ gem "rspec", "~> 3.0"
11
+ gem "generator_spec"
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Abe Voelker, Gorgon LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # HanamiEmail
2
+
3
+ A Ruby API client for the [Hanami email forwarding service][]
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ HanamiEmail.configure do |x|
9
+ x.default_domain = "example.com"
10
+ x.api_key = "sk_ZX_igr4rZWD8sveAPLNJZ3jRWsuuu"
11
+ end
12
+
13
+ x = HanamiEmail::Alias.create({from: "foo", to: "bar@gmail.com"})
14
+ # => {"id"=>12345, "from"=>"foo", "to"=>"bar@gmail.com", "status"=>"activated"}
15
+
16
+ x = HanamiEmail::Alias.list
17
+ # => {"data"=>[{"from"=>"foo", "to"=>"bar@gmail.com"}]}
18
+
19
+ x = HanamiEmail::Alias.delete({from: "foo", to: "bar@gmail.com"})
20
+ # => {"data"=>{"success"=>true}}
21
+ ```
22
+
23
+ ## License
24
+
25
+ The gem is available as open source under the terms of the [MIT License][].
26
+
27
+ [Hanami email forwarding service]: https://hanami.run/faq
28
+ [MIT License]: https://opensource.org/licenses/MIT
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "hanami_email/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hanami_email"
8
+ spec.version = HanamiEmail::VERSION
9
+ spec.authors = ["Abe Voelker"]
10
+ spec.email = ["_@abevoelker.com"]
11
+
12
+ spec.summary = %q{Ruby API client for Hanami email forwarding}
13
+ spec.homepage = "https://github.com/GorgonLLC/hanami_email"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = spec.homepage
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+ spec.required_ruby_version = ">= 2.6.0"
37
+
38
+ spec.add_dependency "typhoeus"
39
+ end
@@ -0,0 +1,3 @@
1
+ class HanamiEmail
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,96 @@
1
+ require "json"
2
+ require "typhoeus"
3
+
4
+ class HanamiEmail
5
+ class << self
6
+ [:default_domain, :api_key, :timeout, :connecttimeout].each do |opt|
7
+ define_method(:"#{opt}=") {|val| instance_variable_set(:"@#{opt}", val)}
8
+ define_method(opt) { begin; instance_variable_get(:"@#{opt}"); rescue NameError; nil; end }
9
+ end
10
+ end
11
+
12
+ def self.configure
13
+ yield self
14
+ end
15
+
16
+ class TimeoutError < StandardError; end
17
+ class NoHTTPResponseError < StandardError; end
18
+ class NonSuccessfulHTTPError < StandardError; end
19
+
20
+ class BaseRequest
21
+ attr_reader :domain, :api_key, :params
22
+
23
+ def initialize(params={})
24
+ @api_key = params.delete(:api_key) || ::HanamiEmail.api_key
25
+ raise ":api_key param or config option is required" unless @api_key
26
+ @domain = params.delete(:domain) || ::HanamiEmail.default_domain
27
+ raise ":domain param or :default_domain config option is required" unless @domain
28
+ @params = params
29
+ end
30
+
31
+ def default_params
32
+ {
33
+ timeout: ::HanamiEmail.timeout || 15,
34
+ connecttimeout: ::HanamiEmail.connecttimeout || 15,
35
+ followlocation: true,
36
+ headers: {
37
+ "Content-Type" => "application/json",
38
+ "apikey" => api_key,
39
+ },
40
+ }
41
+ end
42
+
43
+ def wrap_error(response)
44
+ response.tap do |response|
45
+ if response.timed_out?
46
+ raise TimeoutError, response
47
+ elsif response.code == 0
48
+ raise NoHTTPResponseError, response
49
+ elsif !response.success?
50
+ raise NonSuccessfulHTTPError, response
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ class Alias < BaseRequest
57
+ def self.list(*args, &blk)
58
+ self.new(*args, &blk).list
59
+ end
60
+
61
+ def self.create(*args, &blk)
62
+ self.new(*args, &blk).create
63
+ end
64
+
65
+ def self.delete(*args, &blk)
66
+ self.new(*args, &blk).delete
67
+ end
68
+
69
+ def list
70
+ JSON.parse(wrap_error(
71
+ Typhoeus.get(
72
+ "https://api.mailwip.com/v1/domains/#{domain}/aliases",
73
+ default_params,
74
+ )
75
+ ).body)
76
+ end
77
+
78
+ def create
79
+ JSON.parse(wrap_error(
80
+ Typhoeus.post(
81
+ "https://api.mailwip.com/v1/domains/#{domain}/aliases",
82
+ default_params.merge({ body: params.to_json }),
83
+ )
84
+ ).body)
85
+ end
86
+
87
+ def delete
88
+ JSON.parse(wrap_error(
89
+ Typhoeus.delete(
90
+ "https://api.mailwip.com/v1/domains/#{domain}/aliases",
91
+ default_params.merge({ body: params.to_json }),
92
+ )
93
+ ).body)
94
+ end
95
+ end
96
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hanami_email
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Abe Voelker
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - _@abevoelker.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE.txt
37
+ - README.md
38
+ - hanami_email.gemspec
39
+ - lib/hanami_email.rb
40
+ - lib/hanami_email/version.rb
41
+ homepage: https://github.com/GorgonLLC/hanami_email
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ homepage_uri: https://github.com/GorgonLLC/hanami_email
46
+ source_code_uri: https://github.com/GorgonLLC/hanami_email
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.6.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.1.6
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Ruby API client for Hanami email forwarding
66
+ test_files: []