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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10179adca67dec7ba097d6b2595055038f15fa27f65cf87ac5c37df34b3b13fe
4
- data.tar.gz: e7b1c6feff097229fa8dfc5b3735ef82531fa75cb64a169930cbbfb23dadb258
3
+ metadata.gz: 338741ca97eeaac7b12ef8283c7c5b75c267249484fbd439df699c7aed430233
4
+ data.tar.gz: 1f7fab3b820bf570c8998682ebedb01b454b57ecfd670a336d686fa030ea08e6
5
5
  SHA512:
6
- metadata.gz: 478a9cb9bea050a2ecf89ee3009863c3ce36a7dcc2cf1b58a4ed72429bf7619c98d56f1e8174c22441cacaf7cac1cb9c02abe23ea6dfc1c63cb8fb3464c5810f
7
- data.tar.gz: d3ed0c692a0df8003c172982bbe8f5fc7734296dddc2b15a97864999dbc4f418160552424863def77c07d00cc3db3607aee60dce83fa6f959f4745ba96d76bf3
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`, `TERNWIRE_API_ORIGIN`, `TERNWIRE_FROM`, and `TERNWIRE_TO`
39
- before deliberately running `ruby -Ilib examples/send.rb` from this directory.
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
- Use `https://ternwire.com` as the API origin. Read the full documentation at
42
- [ternwire.com/docs](https://ternwire.com/docs), or contact support@ternwire.com.
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
@@ -2,7 +2,7 @@ require "ternwire"
2
2
 
3
3
  client = Ternwire::Client.new(
4
4
  api_key: ENV.fetch("TERNWIRE_API_KEY"),
5
- base_url: ENV.fetch("TERNWIRE_API_ORIGIN")
5
+ base_url: ENV["TERNWIRE_API_ORIGIN"]
6
6
  )
7
7
  accepted = client.submit_email({
8
8
  "from" => ENV.fetch("TERNWIRE_FROM"),
@@ -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:, timeout: 30)
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
@@ -1,3 +1,3 @@
1
1
  module Ternwire
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ternwire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ternwire