customerio 5.5.1 → 5.6.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: 59f8952ef12e9dc16824c64aff0a01d7dcac0a01ebd1d4da3aa40a6a736fd587
4
- data.tar.gz: cf2ac45b16df73614fe3ece92dc69aee1b09cb86e9a203bd49059521094a348f
3
+ metadata.gz: e400cd48d515843a8d229b0d395c118f57b989d780220e187695c20cc6b13109
4
+ data.tar.gz: dd2c8d4a83fdfb02f6cda4084ed5f54d641b157ecffb6ff93357526fcad6eb73
5
5
  SHA512:
6
- metadata.gz: 99db9a311c52b3b8c9c68b12ea08028e5bdceb97d553d2ca2e859ef9d52159b71d1bf44bde8b9383519a74d89bb78d8a551b135f0d2e50b6521f2bdab42b1c59
7
- data.tar.gz: 978171bbc8b3f9d1ecdbfeecbe0d776c6a06aacdf435a4269cbb6cd4209b204207048cc7431de99a48619a7d9dbd541a1a22d400152f92ed8c510130378b961f
6
+ metadata.gz: 8515504c0a52b34fd5aca03393947270f8374c53bc6e7285ef2d49dbd9625602ca16b396189f879bc68ca4b1f8fee0dae5b0d91724638a9bee412cb12cda5092
7
+ data.tar.gz: 3b985d7390279186c3eb110ba7a43771ac10b8f764794db640b5daf49e7b876bdcd539772370c757a5f71db7285e6053bd29cf1b9afc5802b29e7e056f8a7488
@@ -71,6 +71,21 @@ module Customerio
71
71
  end
72
72
  end
73
73
 
74
+ def send_in_app(req)
75
+ raise "request must be an instance of Customerio::SendInAppRequest" unless req.is_a?(Customerio::SendInAppRequest)
76
+ response = @client.request(:post, send_in_app_path, req.message)
77
+
78
+ case response
79
+ when Net::HTTPSuccess then
80
+ JSON.parse(response.body)
81
+ when Net::HTTPBadRequest then
82
+ json = JSON.parse(response.body)
83
+ raise Customerio::InvalidResponse.new(response.code, json['meta']['error'], response)
84
+ else
85
+ raise InvalidResponse.new(response.code, response.body)
86
+ end
87
+ end
88
+
74
89
  private
75
90
 
76
91
  def send_email_path
@@ -88,5 +103,9 @@ module Customerio
88
103
  def send_inbox_message_path
89
104
  "/v1/send/inbox_message"
90
105
  end
106
+
107
+ def send_in_app_path
108
+ "/v1/send/in_app"
109
+ end
91
110
  end
92
111
  end
@@ -0,0 +1,31 @@
1
+ require 'base64'
2
+
3
+ module Customerio
4
+ class SendInAppRequest
5
+ attr_reader :message
6
+
7
+ def initialize(opts)
8
+ @message = opts.delete_if { |field| invalid_field?(field) }
9
+ end
10
+
11
+ private
12
+
13
+ REQUIRED_FIELDS = %i(identifiers transactional_message_id)
14
+
15
+ OPTIONAL_FIELDS = %i(
16
+ message_data
17
+ disable_message_retention
18
+ queue_draft
19
+ send_at
20
+ language
21
+ )
22
+
23
+ def invalid_field?(field)
24
+ !REQUIRED_FIELDS.include?(field) && !OPTIONAL_FIELDS.include?(field)
25
+ end
26
+
27
+ def encode(data)
28
+ Base64.strict_encode64(data)
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Customerio
2
- VERSION = "5.5.1"
2
+ VERSION = "5.6.0"
3
3
  end
data/lib/customerio.rb CHANGED
@@ -8,6 +8,7 @@ module Customerio
8
8
  require "customerio/requests/send_push_request"
9
9
  require "customerio/requests/send_sms_request"
10
10
  require "customerio/requests/send_inbox_message_request"
11
+ require "customerio/requests/send_in_app_request"
11
12
  require "customerio/api"
12
13
  require "customerio/param_encoder"
13
14
  end
@@ -370,4 +370,63 @@ describe Customerio::APIClient do
370
370
  )
371
371
  end
372
372
  end
373
+
374
+ describe "#send_in_app" do
375
+ it "sends a POST request to the /api/send/in_app path" do
376
+ req = Customerio::SendInAppRequest.new(
377
+ identifiers: {
378
+ id: 'c1',
379
+ },
380
+ transactional_message_id: 1,
381
+ )
382
+
383
+ stub_request(:post, api_uri('/v1/send/in_app'))
384
+ .with(headers: request_headers, body: req.message)
385
+ .to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})
386
+
387
+ client.send_in_app(req).should eq({ "delivery_id" => 1 })
388
+ end
389
+
390
+ it "handles validation failures (400)" do
391
+ req = Customerio::SendInAppRequest.new(
392
+ identifiers: {
393
+ id: 'c1',
394
+ },
395
+ transactional_message_id: 1,
396
+ )
397
+
398
+ err_json = { meta: { error: "example error" } }.to_json
399
+
400
+ stub_request(:post, api_uri('/v1/send/in_app'))
401
+ .with(headers: request_headers, body: req.message)
402
+ .to_return(status: 400, body: err_json, headers: {})
403
+
404
+ lambda { client.send_in_app(req) }.should(
405
+ raise_error(Customerio::InvalidResponse) { |error|
406
+ error.message.should eq "example error"
407
+ error.code.should eq "400"
408
+ }
409
+ )
410
+ end
411
+
412
+ it "handles other failures (5xx)" do
413
+ req = Customerio::SendInAppRequest.new(
414
+ identifiers: {
415
+ id: 'c1',
416
+ },
417
+ transactional_message_id: 1,
418
+ )
419
+
420
+ stub_request(:post, api_uri('/v1/send/in_app'))
421
+ .with(headers: request_headers, body: req.message)
422
+ .to_return(status: 500, body: "Server unavailable", headers: {})
423
+
424
+ lambda { client.send_in_app(req) }.should(
425
+ raise_error(Customerio::InvalidResponse) { |error|
426
+ error.message.should eq "Server unavailable"
427
+ error.code.should eq "500"
428
+ }
429
+ )
430
+ end
431
+ end
373
432
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: customerio
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.5.1
4
+ version: 5.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Allison
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-20 00:00:00.000000000 Z
11
+ date: 2026-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -131,6 +131,7 @@ files:
131
131
  - lib/customerio/param_encoder.rb
132
132
  - lib/customerio/regions.rb
133
133
  - lib/customerio/requests/send_email_request.rb
134
+ - lib/customerio/requests/send_in_app_request.rb
134
135
  - lib/customerio/requests/send_inbox_message_request.rb
135
136
  - lib/customerio/requests/send_push_request.rb
136
137
  - lib/customerio/requests/send_sms_request.rb
@@ -143,7 +144,7 @@ homepage: https://customer.io
143
144
  licenses:
144
145
  - MIT
145
146
  metadata: {}
146
- post_install_message:
147
+ post_install_message:
147
148
  rdoc_options: []
148
149
  require_paths:
149
150
  - lib
@@ -158,8 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
159
  - !ruby/object:Gem::Version
159
160
  version: '0'
160
161
  requirements: []
161
- rubygems_version: 3.0.3.1
162
- signing_key:
162
+ rubygems_version: 3.3.26
163
+ signing_key:
163
164
  specification_version: 4
164
165
  summary: A ruby client for the Customer.io event API.
165
166
  test_files: