parcelwing 0.1.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +209 -0
- data/examples/send_email.rb +18 -0
- data/lib/parcelwing/client.rb +30 -0
- data/lib/parcelwing/error.rb +17 -0
- data/lib/parcelwing/http_client.rb +172 -0
- data/lib/parcelwing/resources/automations.rb +16 -0
- data/lib/parcelwing/resources/contacts.rb +40 -0
- data/lib/parcelwing/resources/emails.rb +16 -0
- data/lib/parcelwing/resources/segments.rb +40 -0
- data/lib/parcelwing/resources/topics.rb +40 -0
- data/lib/parcelwing/version.rb +5 -0
- data/lib/parcelwing.rb +5 -0
- metadata +58 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d1b3ca45dc11f64e6621fe16e1b2cd9cc71db8678a21ee2ec1aea59f54d81df1
|
|
4
|
+
data.tar.gz: 5e275098ddd05f093167b1baba93d8d6de546c66528f69fabd7443e270851246
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: cb471826a1e01804e195d7a0a195ea821c290a815c4500134f69cd4339be945a0712c57ff19b4652b8da760437fefe0f7a88680f2cf416594bbd6ab8f2aa58aa
|
|
7
|
+
data.tar.gz: ca50220fdb5063b3ba69e325e579a1db68f5caf30f43b3c5ef7bca7240cf2dac494d0515180a7f26a498c9fb75a8446d23741e140fdeb74ea2356c1199405571
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Parcel Wing
|
|
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,209 @@
|
|
|
1
|
+
# Parcel Wing Ruby SDK
|
|
2
|
+
|
|
3
|
+
Official Ruby SDK for the [Parcel Wing](https://parcelwing.com) API.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
gem install parcelwing
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Or add it to your `Gemfile`:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem "parcelwing"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- Ruby 3.0+
|
|
18
|
+
- A Parcel Wing API key
|
|
19
|
+
- A verified sending domain in Parcel Wing
|
|
20
|
+
|
|
21
|
+
## Send an email
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
require "parcelwing"
|
|
25
|
+
|
|
26
|
+
parcelwing = ParcelWing::Client.new(api_key: "pw_live_your_api_key_here")
|
|
27
|
+
|
|
28
|
+
emails = parcelwing.emails.send(
|
|
29
|
+
from: "Parcel Wing <hello@yourdomain.com>",
|
|
30
|
+
to: "you@example.com",
|
|
31
|
+
subject: "Hello from Parcel Wing",
|
|
32
|
+
html: "<strong>It works!</strong>",
|
|
33
|
+
text: "It works!"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
puts emails
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`emails.send` returns an array of queued email objects:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
[
|
|
43
|
+
{
|
|
44
|
+
"object" => "email",
|
|
45
|
+
"id" => "...",
|
|
46
|
+
"to" => "you@example.com",
|
|
47
|
+
"status" => "queued"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Configuration
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
parcelwing = ParcelWing::Client.new(
|
|
56
|
+
api_key: ENV.fetch("PARCELWING_API_KEY"),
|
|
57
|
+
base_url: ENV.fetch("PARCELWING_BASE_URL", "https://parcelwing.com"),
|
|
58
|
+
timeout: 30,
|
|
59
|
+
headers: {
|
|
60
|
+
"X-My-App" => "my-ruby-app"
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Emails
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
parcelwing.emails.send(
|
|
69
|
+
from: "Parcel Wing <hello@yourdomain.com>",
|
|
70
|
+
to: ["alice@example.com", "bob@example.com"],
|
|
71
|
+
subject: "Hello from Parcel Wing",
|
|
72
|
+
text: "Plain text body",
|
|
73
|
+
html: "<p>HTML body</p>",
|
|
74
|
+
reply_to: "support@yourdomain.com",
|
|
75
|
+
tags: {
|
|
76
|
+
campaign: "welcome"
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
You can also send using a stored template:
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
parcelwing.emails.send(
|
|
85
|
+
from: "Parcel Wing <hello@yourdomain.com>",
|
|
86
|
+
to: "you@example.com",
|
|
87
|
+
template_alias: "welcome",
|
|
88
|
+
template_params: {
|
|
89
|
+
first_name: "Ada"
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Contacts
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
contact = parcelwing.contacts.create(
|
|
98
|
+
email: "ada@example.com",
|
|
99
|
+
first_name: "Ada",
|
|
100
|
+
last_name: "Lovelace",
|
|
101
|
+
attributes: {
|
|
102
|
+
plan: "flight"
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
contacts = parcelwing.contacts.list(limit: 25, status: "active")
|
|
107
|
+
contact = parcelwing.contacts.get(contact.fetch("id"))
|
|
108
|
+
updated = parcelwing.contacts.update(contact.fetch("id"), first_name: "Augusta")
|
|
109
|
+
parcelwing.contacts.delete(contact.fetch("id"))
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Batch create contacts by passing an array:
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
result = parcelwing.contacts.create([
|
|
116
|
+
{ email: "alice@example.com" },
|
|
117
|
+
{ email: "bob@example.com" }
|
|
118
|
+
])
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Segments
|
|
122
|
+
|
|
123
|
+
```ruby
|
|
124
|
+
segment = parcelwing.segments.create(
|
|
125
|
+
name: "Active customers",
|
|
126
|
+
filter_criteria: {
|
|
127
|
+
version: 1,
|
|
128
|
+
match: "all",
|
|
129
|
+
conditions: [
|
|
130
|
+
{
|
|
131
|
+
field: "status",
|
|
132
|
+
operator: "equals",
|
|
133
|
+
value: "active"
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
segments = parcelwing.segments.list(include_counts: true)
|
|
140
|
+
segment = parcelwing.segments.get(segment.fetch("id"))
|
|
141
|
+
parcelwing.segments.update(segment.fetch("id"), name: "Active subscribers")
|
|
142
|
+
parcelwing.segments.delete(segment.fetch("id"))
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Topics
|
|
146
|
+
|
|
147
|
+
```ruby
|
|
148
|
+
topic = parcelwing.topics.create(
|
|
149
|
+
name: "Product updates",
|
|
150
|
+
description: "News and feature announcements",
|
|
151
|
+
default_subscription: "opt_in",
|
|
152
|
+
visibility: "public"
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
topics = parcelwing.topics.list(active: true)
|
|
156
|
+
topic = parcelwing.topics.get(topic.fetch("id"))
|
|
157
|
+
parcelwing.topics.update(topic.fetch("id"), description: "Product news")
|
|
158
|
+
parcelwing.topics.delete(topic.fetch("id"))
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Automations
|
|
162
|
+
|
|
163
|
+
```ruby
|
|
164
|
+
event = parcelwing.automations.track(
|
|
165
|
+
event_name: "signup_completed",
|
|
166
|
+
contact_id: "contact-id",
|
|
167
|
+
payload: {
|
|
168
|
+
plan: "launch"
|
|
169
|
+
},
|
|
170
|
+
event_id: "signup-123"
|
|
171
|
+
)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Error handling
|
|
175
|
+
|
|
176
|
+
API and transport errors raise `ParcelWing::Error`.
|
|
177
|
+
|
|
178
|
+
```ruby
|
|
179
|
+
begin
|
|
180
|
+
parcelwing.emails.send(
|
|
181
|
+
from: "Parcel Wing <hello@yourdomain.com>",
|
|
182
|
+
to: "you@example.com",
|
|
183
|
+
subject: "Hello",
|
|
184
|
+
text: "Hello!"
|
|
185
|
+
)
|
|
186
|
+
rescue ParcelWing::Error => e
|
|
187
|
+
warn "Parcel Wing error: #{e.message}"
|
|
188
|
+
warn "status=#{e.status} type=#{e.type} code=#{e.code} request_id=#{e.request_id}"
|
|
189
|
+
end
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Development
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
bundle install
|
|
196
|
+
bundle exec rake test
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Build the gem locally:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
gem build parcelwing.gemspec
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Install the local build:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
gem install ./parcelwing-0.1.0.gem
|
|
209
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "parcelwing"
|
|
4
|
+
|
|
5
|
+
client = ParcelWing::Client.new(
|
|
6
|
+
api_key: ENV.fetch("PARCELWING_API_KEY"),
|
|
7
|
+
base_url: ENV.fetch("PARCELWING_BASE_URL", "https://parcelwing.com")
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
emails = client.emails.send(
|
|
11
|
+
from: "Parcel Wing <hello@yourdomain.com>",
|
|
12
|
+
to: "you@example.com",
|
|
13
|
+
subject: "Hello from Parcel Wing",
|
|
14
|
+
html: "<strong>It works!</strong>",
|
|
15
|
+
text: "It works!"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
puts emails.inspect
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "http_client"
|
|
4
|
+
require_relative "resources/emails"
|
|
5
|
+
require_relative "resources/contacts"
|
|
6
|
+
require_relative "resources/segments"
|
|
7
|
+
require_relative "resources/topics"
|
|
8
|
+
require_relative "resources/automations"
|
|
9
|
+
|
|
10
|
+
module ParcelWing
|
|
11
|
+
class Client
|
|
12
|
+
attr_reader :emails, :contacts, :segments, :topics, :automations, :http
|
|
13
|
+
|
|
14
|
+
def initialize(api_key:, base_url: HttpClient::DEFAULT_BASE_URL, timeout: HttpClient::DEFAULT_TIMEOUT, headers: {}, transport: nil)
|
|
15
|
+
@http = HttpClient.new(
|
|
16
|
+
api_key: api_key,
|
|
17
|
+
base_url: base_url,
|
|
18
|
+
timeout: timeout,
|
|
19
|
+
headers: headers,
|
|
20
|
+
transport: transport
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
@emails = Resources::Emails.new(@http)
|
|
24
|
+
@contacts = Resources::Contacts.new(@http)
|
|
25
|
+
@segments = Resources::Segments.new(@http)
|
|
26
|
+
@topics = Resources::Topics.new(@http)
|
|
27
|
+
@automations = Resources::Automations.new(@http)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ParcelWing
|
|
4
|
+
class Error < StandardError
|
|
5
|
+
attr_reader :status, :type, :code, :request_id, :details, :metadata
|
|
6
|
+
|
|
7
|
+
def initialize(message:, status:, type: "api_error", code: nil, request_id: nil, details: nil, metadata: {})
|
|
8
|
+
super(message)
|
|
9
|
+
@status = status
|
|
10
|
+
@type = type
|
|
11
|
+
@code = code
|
|
12
|
+
@request_id = request_id
|
|
13
|
+
@details = details
|
|
14
|
+
@metadata = metadata || {}
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "uri"
|
|
6
|
+
require "cgi"
|
|
7
|
+
require_relative "error"
|
|
8
|
+
require_relative "version"
|
|
9
|
+
|
|
10
|
+
module ParcelWing
|
|
11
|
+
class HttpClient
|
|
12
|
+
DEFAULT_BASE_URL = "https://parcelwing.com"
|
|
13
|
+
DEFAULT_TIMEOUT = 30
|
|
14
|
+
|
|
15
|
+
attr_reader :api_key, :base_url, :timeout, :headers
|
|
16
|
+
|
|
17
|
+
def initialize(api_key:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, headers: {}, transport: nil)
|
|
18
|
+
raise ArgumentError, "ParcelWing client requires a non-empty api_key." if api_key.to_s.strip.empty?
|
|
19
|
+
|
|
20
|
+
@api_key = api_key.to_s.strip
|
|
21
|
+
@base_url = base_url.to_s.sub(%r{/+\z}, "")
|
|
22
|
+
@timeout = timeout
|
|
23
|
+
@headers = headers || {}
|
|
24
|
+
@transport = transport
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def request(method:, path:, body: nil, query: nil, headers: {})
|
|
28
|
+
url = build_url(path, query)
|
|
29
|
+
request_headers = default_headers.merge(@headers).merge(headers || {})
|
|
30
|
+
encoded_body = nil
|
|
31
|
+
|
|
32
|
+
unless body.nil?
|
|
33
|
+
request_headers["Content-Type"] = "application/json"
|
|
34
|
+
encoded_body = JSON.generate(body)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
response = perform_request(method: method, url: url, headers: request_headers, body: encoded_body)
|
|
38
|
+
parsed = parse_json(response[:body])
|
|
39
|
+
|
|
40
|
+
raise build_error(response[:status], parsed, response[:body]) unless response[:status].between?(200, 299)
|
|
41
|
+
|
|
42
|
+
parsed
|
|
43
|
+
rescue Error
|
|
44
|
+
raise
|
|
45
|
+
rescue Net::OpenTimeout, Net::ReadTimeout
|
|
46
|
+
raise Error.new(
|
|
47
|
+
status: 408,
|
|
48
|
+
type: "api_error",
|
|
49
|
+
code: "request_timeout",
|
|
50
|
+
message: "Request timed out after #{@timeout}s."
|
|
51
|
+
)
|
|
52
|
+
rescue StandardError => e
|
|
53
|
+
raise Error.new(
|
|
54
|
+
status: 0,
|
|
55
|
+
type: "api_error",
|
|
56
|
+
code: "network_error",
|
|
57
|
+
message: e.message
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def default_headers
|
|
64
|
+
{
|
|
65
|
+
"Accept" => "application/json",
|
|
66
|
+
"Authorization" => "Bearer #{@api_key}",
|
|
67
|
+
"User-Agent" => "parcelwing-ruby/#{ParcelWing::VERSION}",
|
|
68
|
+
"X-ParcelWing-SDK" => "ruby/#{ParcelWing::VERSION}"
|
|
69
|
+
}
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def build_url(path, query)
|
|
73
|
+
uri = URI.parse("#{@base_url}#{path}")
|
|
74
|
+
encoded_query = encode_query(query || {})
|
|
75
|
+
uri.query = encoded_query unless encoded_query.empty?
|
|
76
|
+
uri
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def encode_query(params)
|
|
80
|
+
params.each_with_object([]) do |(key, value), pairs|
|
|
81
|
+
next if value.nil?
|
|
82
|
+
|
|
83
|
+
if value.is_a?(Array)
|
|
84
|
+
value.each { |entry| pairs << [key, entry] unless entry.nil? }
|
|
85
|
+
else
|
|
86
|
+
pairs << [key, value]
|
|
87
|
+
end
|
|
88
|
+
end.map do |key, value|
|
|
89
|
+
"#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
|
|
90
|
+
end.join("&")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def perform_request(method:, url:, headers:, body:)
|
|
94
|
+
return normalize_transport_response(@transport.call(method: method, url: url, headers: headers, body: body, timeout: @timeout)) if @transport
|
|
95
|
+
|
|
96
|
+
http = Net::HTTP.new(url.host, url.port)
|
|
97
|
+
http.use_ssl = url.scheme == "https"
|
|
98
|
+
http.open_timeout = @timeout
|
|
99
|
+
http.read_timeout = @timeout
|
|
100
|
+
|
|
101
|
+
request_class = case method.to_s.upcase
|
|
102
|
+
when "GET" then Net::HTTP::Get
|
|
103
|
+
when "POST" then Net::HTTP::Post
|
|
104
|
+
when "PATCH" then Net::HTTP::Patch
|
|
105
|
+
when "DELETE" then Net::HTTP::Delete
|
|
106
|
+
else
|
|
107
|
+
raise ArgumentError, "Unsupported HTTP method: #{method}"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
request = request_class.new(url)
|
|
111
|
+
headers.each { |key, value| request[key] = value }
|
|
112
|
+
request.body = body if body
|
|
113
|
+
|
|
114
|
+
response = http.request(request)
|
|
115
|
+
{ status: response.code.to_i, body: response.body.to_s, headers: response.to_hash }
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def normalize_transport_response(response)
|
|
119
|
+
if response.is_a?(Hash)
|
|
120
|
+
return {
|
|
121
|
+
status: response.fetch(:status).to_i,
|
|
122
|
+
body: response.fetch(:body, "").to_s,
|
|
123
|
+
headers: response.fetch(:headers, {}) || {}
|
|
124
|
+
}
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
{
|
|
128
|
+
status: response.status.to_i,
|
|
129
|
+
body: response.body.to_s,
|
|
130
|
+
headers: response.respond_to?(:headers) ? response.headers : {}
|
|
131
|
+
}
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def parse_json(body)
|
|
135
|
+
return nil if body.to_s.strip.empty?
|
|
136
|
+
|
|
137
|
+
JSON.parse(body)
|
|
138
|
+
rescue JSON::ParserError
|
|
139
|
+
nil
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def build_error(status, parsed, fallback_body)
|
|
143
|
+
error = parsed.is_a?(Hash) ? parsed["error"] : nil
|
|
144
|
+
|
|
145
|
+
unless error.is_a?(Hash)
|
|
146
|
+
return Error.new(
|
|
147
|
+
status: status,
|
|
148
|
+
type: "api_error",
|
|
149
|
+
code: "http_error",
|
|
150
|
+
message: fallback_body.to_s.empty? ? "Parcel Wing API request failed with status #{status}." : fallback_body.to_s
|
|
151
|
+
)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
metadata = error.dup
|
|
155
|
+
message = metadata.delete("message") || "Parcel Wing API request failed with status #{status}."
|
|
156
|
+
type = metadata.delete("type") || "api_error"
|
|
157
|
+
code = metadata.delete("code")
|
|
158
|
+
request_id = metadata.delete("request_id")
|
|
159
|
+
details = metadata.delete("details")
|
|
160
|
+
|
|
161
|
+
Error.new(
|
|
162
|
+
status: status,
|
|
163
|
+
type: type,
|
|
164
|
+
code: code,
|
|
165
|
+
request_id: request_id,
|
|
166
|
+
details: details,
|
|
167
|
+
metadata: metadata,
|
|
168
|
+
message: message
|
|
169
|
+
)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ParcelWing
|
|
4
|
+
module Resources
|
|
5
|
+
class Automations
|
|
6
|
+
def initialize(http)
|
|
7
|
+
@http = http
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def track(params)
|
|
11
|
+
response = @http.request(method: :post, path: "/api/automations/events", body: params)
|
|
12
|
+
response.fetch("data")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ParcelWing
|
|
4
|
+
module Resources
|
|
5
|
+
class Contacts
|
|
6
|
+
def initialize(http)
|
|
7
|
+
@http = http
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def list(params = {})
|
|
11
|
+
@http.request(method: :get, path: "/api/contacts", query: params)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create(params)
|
|
15
|
+
response = @http.request(method: :post, path: "/api/contacts", body: params)
|
|
16
|
+
response.fetch("data")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get(id)
|
|
20
|
+
response = @http.request(method: :get, path: "/api/contacts/#{escape(id)}")
|
|
21
|
+
response.fetch("data")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def update(id, params)
|
|
25
|
+
response = @http.request(method: :patch, path: "/api/contacts/#{escape(id)}", body: params)
|
|
26
|
+
response.fetch("data")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def delete(id)
|
|
30
|
+
@http.request(method: :delete, path: "/api/contacts/#{escape(id)}")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def escape(value)
|
|
36
|
+
CGI.escape(value.to_s)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ParcelWing
|
|
4
|
+
module Resources
|
|
5
|
+
class Emails
|
|
6
|
+
def initialize(http)
|
|
7
|
+
@http = http
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def send(params)
|
|
11
|
+
response = @http.request(method: :post, path: "/api/emails", body: params)
|
|
12
|
+
response.fetch("data")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ParcelWing
|
|
4
|
+
module Resources
|
|
5
|
+
class Segments
|
|
6
|
+
def initialize(http)
|
|
7
|
+
@http = http
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def list(params = {})
|
|
11
|
+
@http.request(method: :get, path: "/api/segments", query: params)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create(params)
|
|
15
|
+
response = @http.request(method: :post, path: "/api/segments", body: params)
|
|
16
|
+
response.fetch("data")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get(id)
|
|
20
|
+
response = @http.request(method: :get, path: "/api/segments/#{escape(id)}")
|
|
21
|
+
response.fetch("data")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def update(id, params)
|
|
25
|
+
response = @http.request(method: :patch, path: "/api/segments/#{escape(id)}", body: params)
|
|
26
|
+
response.fetch("data")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def delete(id)
|
|
30
|
+
@http.request(method: :delete, path: "/api/segments/#{escape(id)}")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def escape(value)
|
|
36
|
+
CGI.escape(value.to_s)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ParcelWing
|
|
4
|
+
module Resources
|
|
5
|
+
class Topics
|
|
6
|
+
def initialize(http)
|
|
7
|
+
@http = http
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def list(params = {})
|
|
11
|
+
@http.request(method: :get, path: "/api/topics", query: params)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create(params)
|
|
15
|
+
response = @http.request(method: :post, path: "/api/topics", body: params)
|
|
16
|
+
response.fetch("data")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get(id)
|
|
20
|
+
response = @http.request(method: :get, path: "/api/topics/#{escape(id)}")
|
|
21
|
+
response.fetch("data")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def update(id, params)
|
|
25
|
+
response = @http.request(method: :patch, path: "/api/topics/#{escape(id)}", body: params)
|
|
26
|
+
response.fetch("data")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def delete(id)
|
|
30
|
+
@http.request(method: :delete, path: "/api/topics/#{escape(id)}")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def escape(value)
|
|
36
|
+
CGI.escape(value.to_s)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/lib/parcelwing.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: parcelwing
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Parcel Wing
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Send emails and manage Parcel Wing contacts, segments, topics, and automation
|
|
13
|
+
events from Ruby.
|
|
14
|
+
email:
|
|
15
|
+
- support@parcelwing.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- examples/send_email.rb
|
|
23
|
+
- lib/parcelwing.rb
|
|
24
|
+
- lib/parcelwing/client.rb
|
|
25
|
+
- lib/parcelwing/error.rb
|
|
26
|
+
- lib/parcelwing/http_client.rb
|
|
27
|
+
- lib/parcelwing/resources/automations.rb
|
|
28
|
+
- lib/parcelwing/resources/contacts.rb
|
|
29
|
+
- lib/parcelwing/resources/emails.rb
|
|
30
|
+
- lib/parcelwing/resources/segments.rb
|
|
31
|
+
- lib/parcelwing/resources/topics.rb
|
|
32
|
+
- lib/parcelwing/version.rb
|
|
33
|
+
homepage: https://github.com/parcelwing/parcelwing-ruby
|
|
34
|
+
licenses:
|
|
35
|
+
- MIT
|
|
36
|
+
metadata:
|
|
37
|
+
homepage_uri: https://github.com/parcelwing/parcelwing-ruby
|
|
38
|
+
source_code_uri: https://github.com/parcelwing/parcelwing-ruby
|
|
39
|
+
changelog_uri: https://github.com/parcelwing/parcelwing-ruby/releases
|
|
40
|
+
rubygems_mfa_required: 'true'
|
|
41
|
+
rdoc_options: []
|
|
42
|
+
require_paths:
|
|
43
|
+
- lib
|
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '3.0'
|
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
requirements: []
|
|
55
|
+
rubygems_version: 4.0.6
|
|
56
|
+
specification_version: 4
|
|
57
|
+
summary: Official Ruby SDK for the Parcel Wing API.
|
|
58
|
+
test_files: []
|