rasket 0.1.1

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: 65795257d04fa448a54177b857a3d9d317ceccc72ad67615716bd687c2cfdf8c
4
+ data.tar.gz: 9b9efa31889a4b3862aa181979a75bb569279d14ad7fddb84861b936aeca9d42
5
+ SHA512:
6
+ metadata.gz: 3851580a2b95d4ee501e4d8729405c7e97146f67577912975f1ea6c739cb708f5453d24fa8b47f27da1a616ffc1eca54b1d057017baa3507a28783d94b3375d1
7
+ data.tar.gz: 978e5b3195685421e18d78f7329e14f9711f926bbaaf3130d42a76ab6a8072766ac613a916f106504006876ce831558d990c35c067cd323becaed7651b8df5d3
data/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+
3
+ All notable changes to the rasket gem are recorded here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## Unreleased
8
+
9
+ ## 0.1.1
10
+
11
+ ### Changed
12
+
13
+ - Published from its public repository, github.com/Rasket-HQ/rasket-ruby, which the gem now
14
+ links as its source code.
15
+
16
+ ## 0.1.0
17
+
18
+ ### Added
19
+
20
+ - The first release: emails (send, get, list, update, cancel, share, metrics, events, diagnose,
21
+ shares, attachments and received mail), batch sends, domains, contacts, segments, broadcasts,
22
+ webhooks with a local signature check, and suppressions. Generated from the API's OpenAPI
23
+ document; retries only what is safe to repeat; a helper walks every page of a list.
24
+ - The README and the gem's summary open with what Rasket is, and the README links the docs.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rasket
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,97 @@
1
+ # rasket
2
+
3
+ [Rasket](https://www.rasket.com/) is one platform for transactional email, marketing email, SMS, sign-up forms, automations and free business email with Rasket Mail.
4
+
5
+ The `rasket` gem is its official Ruby client: transactional sends, domains, contacts, segments,
6
+ broadcasts, webhooks and suppressions. Generated from the API's own OpenAPI document, Ruby 3.3+,
7
+ with no dependencies. RBS signatures ship in `sig/`.
8
+
9
+ ```sh
10
+ gem install rasket
11
+ ```
12
+
13
+ ```ruby
14
+ require "rasket"
15
+
16
+ rasket = Rasket::Client.new(api_key: ENV.fetch("RASKET_API_KEY"), user_agent: "acme-billing/1.0")
17
+
18
+ sent = rasket.emails.send(
19
+ {
20
+ from: "Acme <billing@acme.example>",
21
+ to: ["ronald.williams@example.com"],
22
+ subject: "Your receipt",
23
+ html: "<p>Thanks.</p>"
24
+ },
25
+ idempotency_key: "receipt-1042"
26
+ )
27
+
28
+ puts sent.body[:id]
29
+ ```
30
+
31
+ Docs: [rasket.com/docs/sdk/ruby](https://www.rasket.com/docs/sdk/ruby).
32
+
33
+ ## What every call returns
34
+
35
+ A `Rasket::Response`, or an error:
36
+
37
+ ```ruby
38
+ result = rasket.emails.get(email_id)
39
+
40
+ result.body # the parsed JSON body, symbol keys
41
+ result.rate_limit # #<data Rasket::RateLimit limit=10, remaining=9, reset_seconds=1, ...>
42
+ result.request_id # the x-request-id to quote when asking about a request
43
+ result.idempotent_replayed # true when this answers an earlier request with the same key
44
+ ```
45
+
46
+ ## The surface
47
+
48
+ `rasket.emails`, `batch`, `domains`, `contacts`, `segments`, `broadcasts`, `webhooks` and
49
+ `suppressions`, with the Node client's methods in snake_case: `rasket.webhooks.rotate_secret(id)`,
50
+ `rasket.emails.receiving.attachments.list(email_id)`. Path parameters come first, then the body
51
+ Hash (symbol or string keys); a query is `query:`, an idempotency key `idempotency_key:` where the
52
+ route takes one, and every method takes `timeout:`. A `nil` in a body is sent as `null`.
53
+
54
+ Every list method that pages has an `_all` twin, an Enumerator over every page:
55
+
56
+ ```ruby
57
+ rasket.domains.list_all.each { |domain| puts domain[:name] }
58
+ ```
59
+
60
+ ## Errors
61
+
62
+ ```ruby
63
+ begin
64
+ rasket.emails.send(message)
65
+ rescue Rasket::ApiError => e
66
+ case e.name
67
+ when Rasket::ErrorNames::VALIDATION_ERROR then e.errors # [ValidationIssue(path:, message:)]
68
+ when Rasket::ErrorNames::RATE_LIMIT_EXCEEDED then e.rate_limit&.retry_after_seconds
69
+ else raise # e.status_code, e.message, e.request_id
70
+ end
71
+ rescue Rasket::ConnectionError => e
72
+ e.reason # :network or :timeout; no answer arrived
73
+ end
74
+ ```
75
+
76
+ ## Retries
77
+
78
+ Only what is safe to repeat is retried: a `GET`, or a send carrying an idempotency key. The client
79
+ retries a network error, a `429 rate_limit_exceeded` (never a quota), a `5xx` other than `501`, and
80
+ `409 concurrent_idempotent_requests`; it obeys `retry-after` up to the longest wait and otherwise
81
+ backs off with jitter. `timeout:` (seconds per attempt, default 30), `retry_attempts:` (3),
82
+ `retry_min_delay:` (0.5) and `retry_max_delay:` (8) tune it.
83
+
84
+ ## Webhooks
85
+
86
+ ```ruby
87
+ # Rails
88
+ def create
89
+ event = Rasket::Webhooks.verify(request.raw_post, request.headers, ENV.fetch("RASKET_WEBHOOK_SECRET"))
90
+ handle(event)
91
+ head :ok
92
+ rescue Rasket::WebhookVerificationError
93
+ head :bad_request
94
+ end
95
+ ```
96
+
97
+ Documentation: <https://www.rasket.com/docs/sdk/ruby>. MIT licensed.
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rasket
4
+ # The Rasket API client.
5
+ #
6
+ # api_key is the rk_... key, sent as Authorization: Bearer. base_url is the origin, or origin
7
+ # plus prefix (https://<deployment-host>/api/v1). user_agent is appended to the client's own
8
+ # (rasket-ruby/<version>), never a replacement. timeout is seconds per attempt. retry_attempts
9
+ # counts the first try; a retry-after above retry_max_delay is not waited for. transport is any
10
+ # object with call(method, url, headers, body, timeout) returning a Rasket::TransportResponse.
11
+ class Client
12
+ include ClientResources
13
+
14
+ def initialize(api_key:, base_url: nil, user_agent: nil, timeout: 30, retry_attempts: 3, retry_min_delay: 0.5,
15
+ retry_max_delay: 8.0, transport: nil, sleep: nil, random: nil)
16
+ http = HttpClient.new(api_key: api_key, base_url: base_url, user_agent: user_agent, timeout: timeout,
17
+ retry_attempts: retry_attempts, retry_min_delay: retry_min_delay,
18
+ retry_max_delay: retry_max_delay, transport: transport, sleep: sleep, random: random)
19
+ init_resources(http)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rasket
4
+ # Everything this gem raises on purpose. Rescue it to rescue them all.
5
+ class Error < StandardError; end
6
+
7
+ # The three rate-limit headers the API sets on every response, plus retry-after.
8
+ RateLimit = Data.define(:limit, :remaining, :reset_seconds, :retry_after_seconds)
9
+
10
+ # One entry of the errors array a validation error may carry.
11
+ ValidationIssue = Data.define(:path, :message)
12
+
13
+ # details on the 403 a send gets while its region is still in our sending sandbox.
14
+ SandboxRefusal = Data.define(:recipient, :region, :allowed)
15
+
16
+ # details on a refusal whose answer is a different surface; next is "checkout".
17
+ NextStepRefusal = Data.define(:next_step)
18
+
19
+ # One pre-send check's verdict.
20
+ EmailCheckResult = Data.define(:code, :status, :title, :message, :block_id)
21
+
22
+ # details on the 422 a broadcast send gets when its content fails a pre-send check.
23
+ ChecksRefusal = Data.define(:checks)
24
+
25
+ # The API refused the request, or answered with something that was not a Rasket response.
26
+ #
27
+ # name is the stable vocabulary value (Rasket::ErrorNames::VALIDATION_ERROR, NOT_FOUND,
28
+ # RATE_LIMIT_EXCEEDED, ...) and is what a caller branches on. A name newer than this copy of the
29
+ # client is passed through unchanged; "unknown_error" means the body was not ours. source is
30
+ # :client for the one refusal this gem makes on its own: an Idempotency-Key outside 1-256
31
+ # characters, raised before any request is spent.
32
+ class ApiError < Error
33
+ UNKNOWN_ERROR = "unknown_error"
34
+
35
+ attr_reader :status_code, :name, :source, :code, :errors, :claimable, :details, :request_id, :rate_limit
36
+
37
+ def initialize(status_code:, name:, message:, source:, code: nil, errors: nil, claimable: nil, details: nil,
38
+ request_id: nil, rate_limit: nil)
39
+ super(message)
40
+ @status_code = status_code
41
+ @name = name
42
+ @source = source
43
+ @code = code
44
+ @errors = errors
45
+ @claimable = claimable
46
+ @details = details
47
+ @request_id = request_id
48
+ @rate_limit = rate_limit
49
+ end
50
+ end
51
+
52
+ # The request never got an answer: the connection failed, or the per-attempt timeout elapsed.
53
+ # For a request that was safe to repeat the client has already retried before raising this; for
54
+ # a send without an idempotency key it has not, and whether the email was accepted is unknown.
55
+ class ConnectionError < Error
56
+ attr_reader :reason
57
+
58
+ # reason is :network or :timeout.
59
+ def initialize(reason, message)
60
+ super(message)
61
+ @reason = reason
62
+ end
63
+ end
64
+
65
+ # The only error Rasket::Webhooks.verify raises. reason says why without parsing a message.
66
+ class WebhookVerificationError < Error
67
+ attr_reader :reason
68
+
69
+ def initialize(reason, message)
70
+ super(message)
71
+ @reason = reason
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by scripts/sdk-codegen/run.mjs from packages/api/openapi.json and
4
+ # packages/sdk/surface.json. DO NOT EDIT.
5
+ # Document sha256: 3f790b5e9b4526641b1d17f9b3cdbfcef6fef890214ee69cbaf158bd8163bda8
6
+
7
+ module Rasket
8
+ # The error names the API sends, from its Error schema. Compare ApiError#name with these; a
9
+ # name newer than this list still arrives unchanged.
10
+ module ErrorNames
11
+ INVALID_IDEMPOTENCY_KEY = "invalid_idempotency_key"
12
+ VALIDATION_ERROR = "validation_error"
13
+ MISSING_API_KEY = "missing_api_key"
14
+ INVALID_API_KEY = "invalid_api_key"
15
+ RESTRICTED_API_KEY = "restricted_api_key"
16
+ EMAIL_ABOVE_QUOTA = "email_above_quota"
17
+ INVALID_PERMISSION = "invalid_permission"
18
+ SUSPENDED_API_KEY = "suspended_api_key"
19
+ INBOX_NOT_SET_UP = "inbox_not_set_up"
20
+ NOT_FOUND = "not_found"
21
+ METHOD_NOT_ALLOWED = "method_not_allowed"
22
+ CONCURRENT_IDEMPOTENT_REQUESTS = "concurrent_idempotent_requests"
23
+ INVALID_IDEMPOTENT_REQUEST = "invalid_idempotent_request"
24
+ RESOURCE_LOCKED = "resource_locked"
25
+ RECEIVING_MX_IN_USE = "receiving_mx_in_use"
26
+ CONVERSATION_CONFLICT = "conversation_conflict"
27
+ SITE_MOVED = "site_moved"
28
+ PRECONDITION_FAILED = "precondition_failed"
29
+ INVALID_ATTACHMENT = "invalid_attachment"
30
+ UNSUPPORTED_DESTINATION = "unsupported_destination"
31
+ INVALID_PARAMETER = "invalid_parameter"
32
+ MISSING_REQUIRED_FIELD = "missing_required_field"
33
+ MISSING_REQUIRED_PARAMETER = "missing_required_parameter"
34
+ SNOOZE_NEEDS_A_PERSON = "snooze_needs_a_person"
35
+ DAILY_QUOTA_EXCEEDED = "daily_quota_exceeded"
36
+ MONTHLY_QUOTA_EXCEEDED = "monthly_quota_exceeded"
37
+ MARKETING_QUOTA_EXCEEDED = "marketing_quota_exceeded"
38
+ SMS_QUOTA_EXCEEDED = "sms_quota_exceeded"
39
+ RATE_LIMIT_EXCEEDED = "rate_limit_exceeded"
40
+ APPLICATION_ERROR = "application_error"
41
+ NOT_IMPLEMENTED = "not_implemented"
42
+ SERVICE_UNAVAILABLE = "service_unavailable"
43
+ end
44
+ end