ternwire 0.1.0 → 0.2.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 +4 -4
- data/README.md +12 -9
- data/examples/send.rb +1 -1
- data/lib/ternwire/client.rb +4 -1
- data/lib/ternwire/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 338741ca97eeaac7b12ef8283c7c5b75c267249484fbd439df699c7aed430233
|
|
4
|
+
data.tar.gz: 1f7fab3b820bf570c8998682ebedb01b454b57ecfd670a336d686fa030ea08e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c545aa3654bcc0f7d0cc00fd8a99952f159ceec33e48d4b9364a33d7b594645741bbbe852cf6468b48e7d2c73b76a5b0b441a9a0ae89bf1dd48f6a3ebcea4836
|
|
7
|
+
data.tar.gz: d7745a25d65d85fab3e4ab9660ebd8688a580fc459dfe155b89dadcdfc69b96ea16ea395cc14e0626b48981a2c03ed55317cd0793a02b07c85f99b49ac202dff
|
data/README.md
CHANGED
|
@@ -8,11 +8,7 @@ Add `gem "ternwire"` to your Gemfile, or run `gem install ternwire`.
|
|
|
8
8
|
```ruby
|
|
9
9
|
require "ternwire"
|
|
10
10
|
|
|
11
|
-
client = Ternwire::Client.new(
|
|
12
|
-
api_key: ENV.fetch("TERNWIRE_API_KEY"),
|
|
13
|
-
base_url: ENV.fetch("TERNWIRE_API_ORIGIN"),
|
|
14
|
-
timeout: 30
|
|
15
|
-
)
|
|
11
|
+
client = Ternwire::Client.new(api_key: ENV.fetch("TERNWIRE_API_KEY"))
|
|
16
12
|
message = client.submit_email({
|
|
17
13
|
"from" => "notifications@your-verified-domain.com",
|
|
18
14
|
"to" => ["recipient@example.com"],
|
|
@@ -22,6 +18,12 @@ message = client.submit_email({
|
|
|
22
18
|
puts client.get_message(message.fetch("id"))
|
|
23
19
|
```
|
|
24
20
|
|
|
21
|
+
The client sends requests to `Ternwire::DEFAULT_BASE_URL`, `https://ternwire.com`.
|
|
22
|
+
Pass `base_url:` only to reach another origin, such as a local or staging server, as
|
|
23
|
+
in `Ternwire::Client.new(api_key: key, base_url: "http://localhost:3001")`. Plain HTTP
|
|
24
|
+
is accepted only for localhost and loopback addresses. The optional `timeout:`
|
|
25
|
+
keyword sets the per-request timeout in seconds and defaults to 30.
|
|
26
|
+
|
|
25
27
|
All 17 operations use snake_case names and accept or return hashes with camelCase
|
|
26
28
|
JSON keys. Template deletion returns `nil`. The client is synchronous.
|
|
27
29
|
`list_email_templates(cursor: nil, limit: nil)` returns one page of summaries;
|
|
@@ -35,9 +37,10 @@ Use `Ternwire::Webhooks.verify(signature_header, raw_body, signing_secret)` befo
|
|
|
35
37
|
parsing the request. The optional `tolerance_seconds:` keyword defaults to 300.
|
|
36
38
|
Use the exact body string without re-encoding or normalizing it.
|
|
37
39
|
|
|
38
|
-
Set `TERNWIRE_API_KEY`, `
|
|
39
|
-
|
|
40
|
+
Set `TERNWIRE_API_KEY`, `TERNWIRE_FROM`, and `TERNWIRE_TO` before deliberately
|
|
41
|
+
running `ruby -Ilib examples/send.rb` from this directory. Set `TERNWIRE_API_ORIGIN`
|
|
42
|
+
as well only to send to another origin, such as `http://localhost:3001`.
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
Read the full documentation at [ternwire.com/docs](https://ternwire.com/docs), or
|
|
45
|
+
contact support@ternwire.com.
|
|
43
46
|
Released under the MIT License.
|
data/examples/send.rb
CHANGED
data/lib/ternwire/client.rb
CHANGED
|
@@ -4,6 +4,8 @@ require "net/http"
|
|
|
4
4
|
require "uri"
|
|
5
5
|
|
|
6
6
|
module Ternwire
|
|
7
|
+
DEFAULT_BASE_URL = "https://ternwire.com"
|
|
8
|
+
|
|
7
9
|
class APIError < StandardError
|
|
8
10
|
attr_reader :status, :raw_body, :body, :headers
|
|
9
11
|
|
|
@@ -19,10 +21,11 @@ module Ternwire
|
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
class Client
|
|
22
|
-
def initialize(api_key:, base_url
|
|
24
|
+
def initialize(api_key:, base_url: nil, timeout: 30)
|
|
23
25
|
unless /\Aem_(live|test)_[A-Za-z0-9_-]+\z/.match?(api_key)
|
|
24
26
|
raise ArgumentError, "Use an em_live_ or em_test_ API key"
|
|
25
27
|
end
|
|
28
|
+
base_url = DEFAULT_BASE_URL if base_url.nil?
|
|
26
29
|
origin = URI.parse(base_url)
|
|
27
30
|
unless %w[http https].include?(origin.scheme) && origin.host && !origin.userinfo &&
|
|
28
31
|
["", "/"].include?(origin.path) && !origin.query && !origin.fragment
|
data/lib/ternwire/version.rb
CHANGED