payload-api 0.6.0 → 0.6.2

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: 74c2fd7f99fba4cf6b0f1950d013debc81c56629a5b280e7ac79e4e4abd88838
4
- data.tar.gz: abf8b305b33a0e9a5241f5664807842989b7d423781f35606607298c9297d35a
3
+ metadata.gz: 3ed53d5dcc3451ce907cbc5a4c28b294abd0c7819a3b1d20505e077378f1bfb5
4
+ data.tar.gz: 27d17e508ae166fce7dbad51d86ffdf6986c6c0a11624e4c4609b1733895ea03
5
5
  SHA512:
6
- metadata.gz: 0e34c4a1a585078565d876af179d8e9b3344888ca44a08f9465ac2e740f5f112990d8b7564b7c0394e21dc4eae22c9b5e0e804850c23cb39d5ffd789ad055319
7
- data.tar.gz: ad8721f83c061113c6abcf4e26f7077e9c07b7a4d34b60d8cdaa9d4f61ad599443cc1e8511d46983d7acd368601b6596b42cd6cef9509dd3cc4a0a89c9492202
6
+ metadata.gz: ca2f23bb36bdb05dfadf24fc931e55986e9f856c393685a5e07540e9325b05fb33eda290dc2cd2c1910e1cc0c312ec9bfc99a7dab598bd6260f8b6a04d2b6e8e
7
+ data.tar.gz: 90166f672175b2cddc3a3b8be0450f028bcc1da8060d519775cce6f462ea08b613f70a6811bfcc69786a0fdfa216d1cd999f964ff36cafe9b69b4ea9632cee0c
@@ -152,6 +152,10 @@ module Payload
152
152
 
153
153
  data = { object: 'list', values: data }
154
154
  else
155
+ if data.kind_of?(ARMObject)
156
+ @cls = data.class
157
+ data = data.data
158
+ end
155
159
  if @cls.poly
156
160
  data = data.merge(@cls.poly)
157
161
  end
@@ -179,12 +183,14 @@ module Payload
179
183
  if @cls.spec.key?("endpoint")
180
184
  endpoint = @cls.spec["endpoint"]
181
185
  else
182
- endpoint = "/"+@cls.spec["object"]+"s"
186
+ obj = @cls.spec["object"]
187
+ endpoint = "/" + (obj.end_with?("s") ? obj : obj + "s")
183
188
  end
184
189
  else
185
190
  if json.is_a? Array
186
191
  if json.all? {|obj| obj.key?("object") }
187
- endpoint = json[0]["object"]+"s"
192
+ obj = json[0]["object"]
193
+ endpoint = (obj.end_with?("s") ? obj : obj + "s")
188
194
  end
189
195
  end
190
196
  end
@@ -1,3 +1,3 @@
1
1
  module Payload
2
- VERSION = '0.6.0'
3
- end
2
+ VERSION = '0.6.2'
3
+ end
@@ -299,6 +299,57 @@ RSpec.describe Payload::ARMRequest do
299
299
  expect(customers[2].session).to eq(instance.instance_variable_get(:@session))
300
300
  end
301
301
  end
302
+
303
+ context "when the user creates a single ARMObject via Session#create" do
304
+ it "executes the appropriate request and returns the appropriate object" do
305
+
306
+ $test_access_token = 'tok_' + rand(900000..999999).to_s
307
+ $test_refresh_token = 'ref_' + rand(900000..999999).to_s
308
+
309
+ Payload::api_key = 'test_key'
310
+ pl = Payload::Session.new('test_key', 'https://api.payload.com')
311
+
312
+ expect_any_instance_of(Payload::ARMRequest).to receive(:_execute_request) do |_req, http, request|
313
+ expect(request.method).to eq("POST")
314
+ expect(http.address).to eq("api.payload.com")
315
+ expect(Base64.decode64(request['authorization'].split(' ')[1]).split(':')[0]).to eq('test_key')
316
+ expect(request.path).to eq("/oauth/token?")
317
+ expect(request.body).to eq("{\"code\":\"auth_code_123\",\"grant_type\":\"authorization_code\",\"client_id\":\"org_abc\",\"client_secret\":\"secret_key_xyz\"}")
318
+
319
+ class MockResponse
320
+ def initialize
321
+ end
322
+
323
+ def code
324
+ '200'
325
+ end
326
+
327
+ def body
328
+ '{
329
+ "object": "oauth_token",
330
+ "access_token": "' + $test_access_token + '",
331
+ "refresh_token": "' + $test_refresh_token + '"
332
+ }'
333
+ end
334
+ end
335
+
336
+ MockResponse.new
337
+ end
338
+
339
+ oauth_token = pl.create(Payload::OAuthToken.new({
340
+ code: 'auth_code_123',
341
+ grant_type: 'authorization_code',
342
+ client_id: 'org_abc',
343
+ client_secret: 'secret_key_xyz'
344
+ }))
345
+
346
+ expect(oauth_token).to be_a(Payload::OAuthToken)
347
+ expect(oauth_token.object).to eq("oauth_token")
348
+ expect(oauth_token.access_token).to eq($test_access_token)
349
+ expect(oauth_token.refresh_token).to eq($test_refresh_token)
350
+ expect(oauth_token.session).to eq(pl)
351
+ end
352
+ end
302
353
  end
303
354
 
304
355
  describe "#get" do
@@ -1017,4 +1068,41 @@ RSpec.describe Payload::ARMRequest do
1017
1068
  end
1018
1069
  end
1019
1070
  end
1071
+
1072
+ describe "default endpoint pluralization (object name → path)" do
1073
+ context "when spec object name ends with 's' (e.g. processing_settings)" do
1074
+ it "uses object name as path segment without appending 's'" do
1075
+ klass = Class.new(Payload::ARMObject) do
1076
+ @spec = { "object" => "processing_settings" }
1077
+ end
1078
+ session = Payload::Session.new("test_key", "https://api.test.com")
1079
+ instance = Payload::ARMRequest.new(klass, session)
1080
+
1081
+ expect(instance).to receive(:_execute_request) do |_http, request|
1082
+ expect(request.path).to start_with("/processing_settings/")
1083
+ expect(request.path).not_to include("processing_settingss")
1084
+ double(code: "200", body: '{"object":"processing_settings","id":"ps_123"}')
1085
+ end
1086
+
1087
+ instance.get("ps_123")
1088
+ end
1089
+ end
1090
+
1091
+ context "when spec object name does not end with 's' (e.g. transaction)" do
1092
+ it "appends 's' to build path segment" do
1093
+ klass = Class.new(Payload::ARMObject) do
1094
+ @spec = { "object" => "transaction" }
1095
+ end
1096
+ session = Payload::Session.new("test_key", "https://api.test.com")
1097
+ instance = Payload::ARMRequest.new(klass, session)
1098
+
1099
+ expect(instance).to receive(:_execute_request) do |_http, request|
1100
+ expect(request.path).to start_with("/transactions/")
1101
+ double(code: "200", body: '{"object":"transaction","id":"txn_456"}')
1102
+ end
1103
+
1104
+ instance.get("txn_456")
1105
+ end
1106
+ end
1107
+ end
1020
1108
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payload-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Payload
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-09 00:00:00.000000000 Z
11
+ date: 2026-02-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple library to interface with the Payload API. See https://docs.payload.com
14
14
  for details.