gettestmail 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4295033a8ba3b2b4703cc7be78766e180eeac5d13d38ef09971b89a7533f7df3
4
+ data.tar.gz: d5df117c7bccb60623b51fdadcc6e045dd24f69c8391da747f6ac52cd8aee919
5
+ SHA512:
6
+ metadata.gz: '049ed152470173ebd6f460c98f9d23d2b356eaf2a1a3661f0de38c2b7b9ed0e2233d9054ee0a996a2e68e7f794899c347b2573c9575118423b9aff2a15d48959'
7
+ data.tar.gz: a9971a16f0cd03cdbbc74904c10dc4af5169a1a4b42e2b361e4c56f397fe094befed38eeeb3c2a9ea1d36b447c54fa039545d236d33cea9838e936a46419eef6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 GetTestMail
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # ruby-sdk
2
+ Ruby SDK for GetTestMail
data/lib/api_error.rb ADDED
@@ -0,0 +1,8 @@
1
+ class ApiError < StandardError
2
+ attr_reader :problem_dto
3
+
4
+ def initialize(problem_dto)
5
+ @problem_dto = problem_dto
6
+ super(problem_dto.detail)
7
+ end
8
+ end
data/lib/client.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'httparty'
2
+ require_relative 'api_error'
3
+ require_relative 'models/get_test_mail'
4
+ require_relative 'models/problem_dto'
5
+
6
+ class GetTestMailClient
7
+ include HTTParty
8
+
9
+ base_uri 'https://gettestmail.com/api'
10
+
11
+ def initialize(api_key)
12
+ @api_key = api_key
13
+ end
14
+
15
+ def create_new(expires_at = nil)
16
+ payload = {}
17
+ payload[:expiresAt] = expires_at if expires_at
18
+
19
+ response = self.class.post(
20
+ '/gettestmail',
21
+ headers: headers,
22
+ body: payload.to_json
23
+ )
24
+
25
+ handle_response(response)
26
+ end
27
+
28
+ def wait_for_message(id)
29
+ response = self.class.get(
30
+ "/gettestmail/#{id}",
31
+ headers: headers,
32
+ follow_redirects: true
33
+ )
34
+
35
+ handle_response(response, id)
36
+ end
37
+
38
+ private
39
+
40
+ def headers
41
+ {
42
+ 'X-API-Key' => @api_key,
43
+ 'Content-Type' => 'application/json',
44
+ 'Accept' => 'application/json'
45
+ }
46
+ end
47
+
48
+ def handle_response(response, id = nil)
49
+ case response.code
50
+ when 200, 201
51
+ GetTestMail.new(response.parsed_response)
52
+ else
53
+ raise ApiError.new(ProblemDTO.from_json(response.body))
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,11 @@
1
+ class Attachment
2
+ attr_accessor :filename, :mime_type, :content
3
+
4
+ def initialize(json)
5
+ json.each { |key, value| instance_variable_set("@#{key}", value) }
6
+ end
7
+
8
+ def to_s
9
+ "Name: #{filename}, Mime-Type: #{mime_type}"
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ class BaseDTO
2
+ def self.from_json(json)
3
+ new(json)
4
+ end
5
+
6
+ def initialize(json)
7
+ from_json(json)
8
+ end
9
+
10
+ def from_json(json)
11
+ data = json.is_a?(String) ? JSON.parse(json) : json
12
+ data.each { |key, value| instance_variable_set("@#{key}", value) }
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'base_dto'
2
+ require_relative 'message'
3
+
4
+ class GetTestMail < BaseDTO
5
+ attr_accessor :emailAddress, :expiresAt, :message
6
+
7
+ def initialize(json)
8
+ super(json)
9
+
10
+ if @message
11
+ @message = Message.new(@message)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require_relative 'attachment'
2
+
3
+ class Message
4
+ attr_accessor :id, :from, :to, :subject, :text, :html, :attachments
5
+
6
+ def initialize(json)
7
+ json.each { |key, value| instance_variable_set("@#{key}", value) }
8
+ @attachments = @attachments&.map { |attachment| Attachment.new(attachment) }
9
+ end
10
+
11
+ def to_s
12
+ <<~MESSAGE
13
+ ID: #{@id}
14
+ From: #{@from}
15
+ To: #{@to}
16
+ Subject: #{@subject}
17
+ Text: #{@text}
18
+ HTML: #{@html}
19
+ Attachments: #{@attachments.map(&:to_s).join("\n")}
20
+ MESSAGE
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'base_dto'
2
+
3
+ class ProblemDTO < BaseDTO
4
+ attr_accessor :type, :title, :detail, :status
5
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gettestmail
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Bobby Donchev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-04-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.20'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.20'
27
+ description: A Ruby cleint SDK so you can easily integrate GetTestMail into your Ruby
28
+ application. GetTestMail is a service that allows you to easily create email addresses
29
+ that you can use to test your application.
30
+ email:
31
+ - support@gettestmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - LICENSE
37
+ - README.md
38
+ - lib/api_error.rb
39
+ - lib/client.rb
40
+ - lib/models/attachment.rb
41
+ - lib/models/base_dto.rb
42
+ - lib/models/get_test_mail.rb
43
+ - lib/models/message.rb
44
+ - lib/models/problem_dto.rb
45
+ homepage: https://github.com/gettestmail/ruby-sdk
46
+ licenses:
47
+ - MIT
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.3.26
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: A Ruby client SDK for the GetTestMail API
68
+ test_files: []