simple_connect-client 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/CHANGELOG.md +21 -1
- data/README.md +42 -17
- data/lib/simple_connect/api/events.rb +37 -9
- data/lib/simple_connect/client.rb +1 -1
- data/lib/simple_connect/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a7ccdbb67c4b168087543c5244805676d3e81d7b4522396047828cba666a56a
|
|
4
|
+
data.tar.gz: 723170ac99fdd68572c96d883337ef29715fca4741997d65b2b4a53827595ac3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 71a6195f53d733026560728f7c1d93774c5aa196ec54400fad876296ff387d59000166d0141e5a3a6eb661a813e0c09f2e76bf90b87bd156670f965291cfe513
|
|
7
|
+
data.tar.gz: bb9c5d523968ae07cf3306dab93a2302f389bac9992dac0bee67b37693b06222aa1562fdc46f230db251c97d99a535f8d6566510101ecc53621f489b90e878bf
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.0] - 2026-04-21
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **BREAKING** — outgoing event body reshaped to match the new server
|
|
15
|
+
contract. The flat envelope (`{ event, event_id, occurred_at, language,
|
|
16
|
+
customer_name, customer_mobile_no, ... }`) is now nested as
|
|
17
|
+
`{ "recipient": { name, mobile_no }, "event": { event_id, name,
|
|
18
|
+
occurred_at, language, ...fields } }`. The server (SimpleWaConnect ≥ this
|
|
19
|
+
release) rejects the old flat shape with 422.
|
|
20
|
+
- **BREAKING** — `events.deliver` signature simplified to mirror the wire
|
|
21
|
+
body: `deliver(event_key, recipient:, event: {})`. `recipient` is a hash
|
|
22
|
+
(`mobile_no:` required, `name:` optional); `event` is a hash of
|
|
23
|
+
event-specific fields plus optional envelope overrides (`event_id`,
|
|
24
|
+
`occurred_at`, `language`). Old callers that passed `customer_mobile_no:`
|
|
25
|
+
as routing info, a positional `fields` hash, or envelope kwargs directly
|
|
26
|
+
(`event_id:`, `language:`, `occurred_at:`) must move all of those into
|
|
27
|
+
the two hashes.
|
|
28
|
+
|
|
10
29
|
## [0.1.0] - 2026-04-20
|
|
11
30
|
|
|
12
31
|
### Added
|
|
@@ -32,5 +51,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
32
51
|
- Ruby 3.2+.
|
|
33
52
|
- No runtime gem dependencies (stdlib only).
|
|
34
53
|
|
|
35
|
-
[unreleased]: https://github.com/GemsEssence/SimpleWaConnect/compare/simple_connect-client-v0.
|
|
54
|
+
[unreleased]: https://github.com/GemsEssence/SimpleWaConnect/compare/simple_connect-client-v0.2.0...HEAD
|
|
55
|
+
[0.2.0]: https://github.com/GemsEssence/SimpleWaConnect/compare/simple_connect-client-v0.1.0...simple_connect-client-v0.2.0
|
|
36
56
|
[0.1.0]: https://github.com/GemsEssence/SimpleWaConnect/releases/tag/simple_connect-client-v0.1.0
|
data/README.md
CHANGED
|
@@ -71,19 +71,34 @@ The client groups calls into two resource objects — `events` and `integrations
|
|
|
71
71
|
```ruby
|
|
72
72
|
SIMPLECONNECT.events.deliver(
|
|
73
73
|
"customer_payment_received",
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
recipient: {
|
|
75
|
+
mobile_no: "+919812345678", # required — routing target
|
|
76
|
+
name: "Ramesh Kumar" # optional
|
|
77
|
+
},
|
|
78
|
+
event: {
|
|
79
|
+
event_id: "pp_payment_#{payment.id}", # idempotency key
|
|
80
|
+
customer_name: "Ramesh Kumar",
|
|
81
|
+
agency_name: "Acme Dairy",
|
|
82
|
+
payment_date: "2026-04-16",
|
|
83
|
+
payment_mode: "UPI",
|
|
84
|
+
payment_amount: "450.00",
|
|
85
|
+
customer_total_due_amount: "0.00"
|
|
86
|
+
}
|
|
82
87
|
)
|
|
83
88
|
```
|
|
84
89
|
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
The two hashes mirror the wire body 1:1:
|
|
91
|
+
|
|
92
|
+
- `recipient` is used by SimpleConnect to route the outbound WhatsApp message.
|
|
93
|
+
`mobile_no` is required, `name` is optional. Fields here are **not** accessible
|
|
94
|
+
to template variable mappings — to show the customer's name in a message body,
|
|
95
|
+
duplicate it under `event:` (e.g. `customer_name:`).
|
|
96
|
+
- `event` carries the envelope plus all template-variable fields. Pass an explicit
|
|
97
|
+
`event_id` (unique per domain event) for safe retries — duplicate `event_id`s
|
|
98
|
+
are treated as no-ops by the server. If omitted, the client generates
|
|
99
|
+
`evt_<hex>`. `occurred_at` defaults to now, `language` to `"en"`. Any `name:`
|
|
100
|
+
you pass inside `event` is ignored — it's always set to the positional
|
|
101
|
+
`event_key`.
|
|
87
102
|
|
|
88
103
|
### Fetch a previously-ingested event
|
|
89
104
|
|
|
@@ -113,7 +128,11 @@ Every resource call returns a `Result` struct with:
|
|
|
113
128
|
| `data` | Response?| Typed response object (see below) when the body was parseable; `nil` otherwise |
|
|
114
129
|
|
|
115
130
|
```ruby
|
|
116
|
-
result = SIMPLECONNECT.events.deliver(
|
|
131
|
+
result = SIMPLECONNECT.events.deliver(
|
|
132
|
+
"customer_payment_received",
|
|
133
|
+
recipient: { mobile_no: "+919812345678", name: "Ramesh" },
|
|
134
|
+
event: fields
|
|
135
|
+
)
|
|
117
136
|
if result.success?
|
|
118
137
|
Rails.logger.info("delivered in #{result.attempts} attempt(s); id=#{result.data.event_id}")
|
|
119
138
|
else
|
|
@@ -139,7 +158,9 @@ Always check `result.success?` first, then read `result.data`.
|
|
|
139
158
|
|
|
140
159
|
```ruby
|
|
141
160
|
result = SIMPLECONNECT.events.deliver(
|
|
142
|
-
"customer_payment_received",
|
|
161
|
+
"customer_payment_received",
|
|
162
|
+
recipient: { mobile_no: "+919812345678", name: "Ramesh" },
|
|
163
|
+
event: fields.merge(event_id: "pp_pay_42")
|
|
143
164
|
)
|
|
144
165
|
|
|
145
166
|
if result.success?
|
|
@@ -209,7 +230,11 @@ end
|
|
|
209
230
|
### Error path → `ErrorResponse`
|
|
210
231
|
|
|
211
232
|
```ruby
|
|
212
|
-
result = SIMPLECONNECT.events.deliver(
|
|
233
|
+
result = SIMPLECONNECT.events.deliver(
|
|
234
|
+
"some_event",
|
|
235
|
+
recipient: { mobile_no: "+919812345678" },
|
|
236
|
+
event: fields
|
|
237
|
+
)
|
|
213
238
|
|
|
214
239
|
unless result.success?
|
|
215
240
|
if result.data # ErrorResponse (or nil for non-JSON / network errors)
|
|
@@ -251,15 +276,15 @@ SIMPLECONNECT = SimpleConnect::Client.new(
|
|
|
251
276
|
)
|
|
252
277
|
|
|
253
278
|
class DeliverSimpleConnectEventJob < ApplicationJob
|
|
254
|
-
def perform(event_key,
|
|
255
|
-
SIMPLECONNECT.events.deliver(event_key,
|
|
279
|
+
def perform(event_key, recipient, event)
|
|
280
|
+
SIMPLECONNECT.events.deliver(event_key, recipient: recipient, event: event)
|
|
256
281
|
end
|
|
257
282
|
end
|
|
258
283
|
|
|
259
284
|
DeliverSimpleConnectEventJob.perform_later(
|
|
260
285
|
"customer_payment_received",
|
|
261
|
-
{
|
|
262
|
-
event_id: "pp_payment_#{payment.id}"
|
|
286
|
+
{ mobile_no: "+919812345678", name: "Ramesh" },
|
|
287
|
+
{ customer_name: "Ramesh", agency_name: "Acme", event_id: "pp_payment_#{payment.id}" }
|
|
263
288
|
)
|
|
264
289
|
```
|
|
265
290
|
|
|
@@ -21,16 +21,37 @@ module SimpleConnect
|
|
|
21
21
|
@event_keys = event_keys&.map(&:to_s)&.freeze
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
# Deliver a domain event.
|
|
25
|
+
#
|
|
26
|
+
# events.deliver(
|
|
27
|
+
# "customer_payment_received",
|
|
28
|
+
# recipient: { mobile_no: "+919812345678", name: "Ramesh Kumar" },
|
|
29
|
+
# event: {
|
|
30
|
+
# event_id: "pp_payment_42",
|
|
31
|
+
# customer_name: "Ramesh Kumar",
|
|
32
|
+
# payment_amount: "450.00"
|
|
33
|
+
# }
|
|
34
|
+
# )
|
|
35
|
+
#
|
|
36
|
+
# The two hashes mirror the wire body 1:1 — `recipient` is used for
|
|
37
|
+
# routing, `event` carries template-variable fields. The envelope
|
|
38
|
+
# (`event_id`, `occurred_at`, `language`) is auto-filled into `event`
|
|
39
|
+
# when omitted: `event_id` defaults to a random `evt_<hex>`,
|
|
40
|
+
# `occurred_at` to now, `language` to "en". `event[:name]` is always
|
|
41
|
+
# set to `event_key` — passing one is ignored.
|
|
42
|
+
def deliver(event_key, recipient:, event: {})
|
|
25
43
|
event_key = event_key.to_s
|
|
26
44
|
raise ArgumentError, "event_key is required" if event_key.empty?
|
|
45
|
+
|
|
46
|
+
recipient = stringify_keys(recipient)
|
|
47
|
+
raise ArgumentError, "recipient[:mobile_no] is required" if recipient["mobile_no"].to_s.strip.empty?
|
|
48
|
+
|
|
27
49
|
if @event_keys && !@event_keys.include?(event_key)
|
|
28
50
|
raise SimpleConnect::UnknownEventError,
|
|
29
51
|
"Unknown event_key '#{event_key}'. Must be one of: #{@event_keys.join(", ")}"
|
|
30
52
|
end
|
|
31
53
|
|
|
32
|
-
|
|
33
|
-
body = build_body(event_key, merged_fields, event_id: event_id, language: language, occurred_at: occurred_at)
|
|
54
|
+
body = build_body(event_key, recipient: recipient, event: stringify_keys(event))
|
|
34
55
|
attach_response(@request.post(@endpoint_uri, body: body), Responses::DeliverResponse)
|
|
35
56
|
end
|
|
36
57
|
|
|
@@ -46,14 +67,21 @@ module SimpleConnect
|
|
|
46
67
|
URI.parse("#{@endpoint_uri}/#{URI.encode_www_form_component(event_id.to_s)}")
|
|
47
68
|
end
|
|
48
69
|
|
|
49
|
-
def build_body(event_key,
|
|
70
|
+
def build_body(event_key, recipient:, event:)
|
|
50
71
|
envelope = {
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"occurred_at" => format_timestamp(occurred_at),
|
|
54
|
-
"language"
|
|
72
|
+
"event_id" => resolve_event_id(event["event_id"]),
|
|
73
|
+
"name" => event_key,
|
|
74
|
+
"occurred_at" => format_timestamp(event["occurred_at"]),
|
|
75
|
+
"language" => resolve_language(event["language"])
|
|
55
76
|
}
|
|
56
|
-
|
|
77
|
+
|
|
78
|
+
{
|
|
79
|
+
"recipient" => {
|
|
80
|
+
"name" => recipient["name"].to_s,
|
|
81
|
+
"mobile_no" => recipient["mobile_no"].to_s
|
|
82
|
+
},
|
|
83
|
+
"event" => event.merge(envelope)
|
|
84
|
+
}.to_json
|
|
57
85
|
end
|
|
58
86
|
|
|
59
87
|
def resolve_event_id(value)
|
|
@@ -4,7 +4,7 @@ module SimpleConnect
|
|
|
4
4
|
# Entry point for the SimpleWaConnect integration client. Assembles the
|
|
5
5
|
# signed-request transport once, then exposes two resource objects:
|
|
6
6
|
#
|
|
7
|
-
# SIMPLECONNECT.events.deliver(event_key,
|
|
7
|
+
# SIMPLECONNECT.events.deliver(event_key, recipient: { mobile_no: }, event: { ... })
|
|
8
8
|
# SIMPLECONNECT.events.detail(event_id)
|
|
9
9
|
# SIMPLECONNECT.integrations.verify
|
|
10
10
|
#
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_connect-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ramkrishan Patidar
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|