yield-sdk 0.5.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a1c01b6992df20194391554bdb67f4aaeee7917bcb0777e10a42e12ce87ab7b2
4
+ data.tar.gz: 02ccb6e5186a10d8dc492ecc6a4ea5b70c009be9fdae0e02b190c0d2e4ed320c
5
+ SHA512:
6
+ metadata.gz: a50b6d78e0f76f7ce0974167cb8e504c7ff73682bd030f0b921fafb270ce6f374121d4568fd24c4c26468a38ea36f433c40bfe40ea59c13e66fdf8623f5f8bb3
7
+ data.tar.gz: 9fc4a44b8122f18328d584af006b05512a2f7d256f9cb10b8d9b9cb20f2f67ff2545ec60dbfbbe8f7f1d39c8895588839a8122f812ef121be2855c6ffe5bcbd0
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 3.2
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # The official Yield SDK for Ruby
2
+
3
+ ## Installation
4
+
5
+ ```sh
6
+ gem install yield-sdk
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ require "yield/sdk"
13
+
14
+ # for security, never commit the actual key in your code
15
+ client = Yield::SDK::Client(ENV["YIELD_API_KEY"])
16
+
17
+ # fetch an existing order
18
+ order = client.order.fetch("ord_...")
19
+ p order.customer.registered_name
20
+
21
+ # or create a new one
22
+ new_order = client.order.create({
23
+ customer_id: "org_...",
24
+ total_amount: "PHP 1234.50",
25
+ note: "Test order from the Ruby SDK!"
26
+ })
27
+ ```
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "standard/rake"
13
+
14
+ task default: %i[test standard]
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "base64"
4
+ require "json"
5
+ require "faraday"
6
+ require "openssl"
7
+ require "time"
8
+ require "uri"
9
+
10
+ require_relative "../version"
11
+ require_relative "api_result"
12
+
13
+ module Yield
14
+ module SDK
15
+ module API
16
+ class Client
17
+ def self.process_response(response, &from_payload_block)
18
+ status_code = response.status
19
+ request_id = response["X-Request-Id"]
20
+
21
+ if !response.success?
22
+ error_type = "unexpected_error"
23
+ body = nil
24
+
25
+ begin
26
+ body = JSON.parse(response.body)
27
+ error_type = body["error"] if body["error"].is_a?(String)
28
+ rescue
29
+ # ignore
30
+ end
31
+
32
+ return Result.failure(status_code, request_id, error_type)
33
+ end
34
+
35
+ begin
36
+ data = from_payload_block.call(JSON.parse(response.body, symbolize_names: true))
37
+ rescue
38
+ return Result.failure(status_code, request_id, "unexpected_payload")
39
+ end
40
+
41
+ Result.success(status_code, request_id, data)
42
+ end
43
+
44
+ def initialize(api_key, base_url: nil, faraday_conn: nil)
45
+ @base_url = base_url || "https://integrate.withyield.com/api/v1"
46
+
47
+ key_parts = api_key.split("$")
48
+ raise ArgumentError, "Invalid Yield API key" if key_parts.length != 3
49
+ @api_key_token = "#{key_parts[0]}$#{key_parts[1]}"
50
+ @api_key_hmac_key = Base64.urlsafe_decode64(key_parts[2])
51
+
52
+ @faraday_conn = faraday_conn || Faraday.new
53
+ @client_version = SDK.client_version
54
+ end
55
+
56
+ def run_query(path, params = nil)
57
+ full_path = params.nil? ? path : "#{path}?#{URI.encode_www_form(params)}"
58
+ call_endpoint(:get, full_path, nil)
59
+ end
60
+
61
+ def run_command(path, payload)
62
+ call_endpoint(:post, path, payload)
63
+ end
64
+
65
+ def build_signature(path, body = nil, now = Time.now)
66
+ timestamp = now.utc.iso8601
67
+
68
+ parts = body.nil? ? [timestamp, path] : [timestamp, path, body]
69
+ message = parts.join("\n")
70
+
71
+ signature_bytes = OpenSSL::HMAC.digest("sha512", @api_key_hmac_key, message)
72
+ signature_b64 = Base64.urlsafe_encode64(signature_bytes, padding: false)
73
+
74
+ "#{@api_key_token}$#{timestamp}$#{signature_b64}"
75
+ end
76
+
77
+ private
78
+
79
+ def call_endpoint(method, path, payload)
80
+ headers = {"X-Yield-Client" => @client_version}
81
+
82
+ body = payload&.to_json
83
+ headers["Content-Type"] = "application/json" if body
84
+
85
+ signature = build_signature(path, body)
86
+ headers["Authorization"] = "Yield-Sig #{signature}"
87
+
88
+ @faraday_conn.run_request(method, @base_url + path, body, headers)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yield
4
+ module SDK
5
+ module API
6
+ class Result < Data.define(:status_code, :request_id, :data, :error)
7
+ def ok?
8
+ error.nil?
9
+ end
10
+
11
+ def data
12
+ raise Error, "Yield API error: #{error} [status_code=#{status_code}]" unless ok?
13
+ super
14
+ end
15
+
16
+ def self.success(status_code, request_id, data)
17
+ new(status_code:, request_id:, data:, error: nil)
18
+ end
19
+
20
+ def self.failure(status_code, request_id, error)
21
+ new(status_code:, request_id:, data: nil, error:)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "api/api_client"
4
+ require_relative "modules/order/order_base_client"
5
+ require_relative "modules/self/self_base_client"
6
+
7
+ module Yield
8
+ module SDK
9
+ class BaseClient
10
+ attr_reader :api
11
+
12
+ attr_reader :self
13
+ attr_reader :order
14
+
15
+ def initialize(api_key, base_url: nil, faraday_conn: nil)
16
+ @api = API::Client.new(api_key, base_url:, faraday_conn:)
17
+
18
+ @self = Self::BaseClient.new(@api)
19
+ @order = Order::BaseClient.new(@api)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base_client"
4
+ require_relative "modules/order/order_client"
5
+ require_relative "modules/self/self_client"
6
+
7
+ module Yield
8
+ module SDK
9
+ class Client
10
+ attr_reader :base
11
+
12
+ attr_reader :self
13
+ attr_reader :order
14
+
15
+ def initialize(api_key, base_url: nil, faraday_conn: nil)
16
+ @base = BaseClient.new(api_key, base_url:, faraday_conn:)
17
+
18
+ @self = Self::Client.new(@base.self)
19
+ @order = Order::Client.new(@base.order)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../api/api_client"
4
+ require_relative "payloads/order"
5
+ require_relative "payloads/order_create_payload"
6
+
7
+ module Yield
8
+ module SDK
9
+ module Order
10
+ class BaseClient
11
+ def initialize(api_client)
12
+ @api = api_client
13
+ end
14
+
15
+ def fetch(id)
16
+ response = @api.run_query("/order/fetch/#{id}")
17
+
18
+ API::Client.process_response(response, &Order.method(:from_payload))
19
+ end
20
+
21
+ def create(params)
22
+ payload = OrderCreatePayload.build(params)
23
+ response = @api.run_command("/order/create", payload)
24
+
25
+ API::Client.process_response(response, &Order.method(:from_payload))
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "order_base_client"
4
+
5
+ module Yield
6
+ module SDK
7
+ module Order
8
+ class Client
9
+ def initialize(base_client)
10
+ @base = base_client
11
+ end
12
+
13
+ def fetch(id)
14
+ @base.fetch(id).data
15
+ end
16
+
17
+ def create(params)
18
+ @base.create(params).data
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+
5
+ require_relative "../../../types/money"
6
+ require_relative "../../../utils"
7
+ require_relative "order_customer_info"
8
+ require_relative "order_status"
9
+
10
+ module Yield
11
+ module SDK
12
+ module Order
13
+ class Order < Data.define(:id, :order_number, :status, :customer, :date, :total_amount, :note, :payment_link, :creation_time)
14
+ def self.from_payload(payload)
15
+ new(
16
+ id: Utils.assert_string(payload[:id]),
17
+ order_number: Utils.assert_string(payload[:order_number]),
18
+ status: Utils.assert_variant(OrderStatus::ALL, payload[:status]),
19
+ customer: payload[:customer].nil? ? nil : OrderCustomerInfo.from_payload(Utils.assert_hash(payload[:customer])),
20
+ date: Date.parse(Utils.assert_string(payload[:date])),
21
+ total_amount: Money.from_payload(Utils.assert_string(payload[:total_amount])),
22
+ note: payload[:note].nil? ? nil : Utils.assert_string(payload[:note]),
23
+ payment_link: payload[:payment_link].nil? ? nil : Utils.assert_string(payload[:payment_link]),
24
+ creation_time: Time.parse(Utils.assert_string(payload[:creation_time]))
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../types/money_payload"
4
+
5
+ module Yield
6
+ module SDK
7
+ module Order
8
+ class OrderCreatePayload
9
+ def self.build(params)
10
+ {
11
+ customer_id: params[:customer_id],
12
+ total_amount: MoneyPayload.build(params[:total_amount]),
13
+ note: params[:note]
14
+ }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../utils"
4
+
5
+ module Yield
6
+ module SDK
7
+ module Order
8
+ class OrderCustomerInfo < Data.define(:id, :registered_name, :trade_name)
9
+ def self.from_payload(payload)
10
+ new(
11
+ id: Utils.assert_string(payload[:id]),
12
+ registered_name: Utils.assert_string(payload[:registered_name]),
13
+ trade_name: payload[:trade_name].nil? ? nil : Utils.assert_string(payload[:trade_name])
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yield
4
+ module SDK
5
+ module Order
6
+ module OrderStatus
7
+ ALL = [:pending, :confirmed, :fulfilled, :cancelled].freeze
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../utils"
4
+ require_relative "self_organization_info"
5
+
6
+ module Yield
7
+ module SDK
8
+ module Self
9
+ class SelfInfo < Data.define(:id, :name, :organization)
10
+ def self.from_payload(payload)
11
+ new(
12
+ id: Utils.assert_string(payload[:id]),
13
+ name: Utils.assert_string(payload[:name]),
14
+ organization: SelfOrganizationInfo.from_payload(Utils.assert_hash(payload[:organization]))
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../utils"
4
+
5
+ module Yield
6
+ module SDK
7
+ module Self
8
+ class SelfOrganizationInfo < Data.define(:id, :registered_name, :trade_name)
9
+ def self.from_payload(payload)
10
+ new(
11
+ id: Utils.assert_string(payload[:id]),
12
+ registered_name: Utils.assert_string(payload[:registered_name]),
13
+ trade_name: payload[:trade_name].nil? ? nil : Utils.assert_string(payload[:trade_name])
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../api/api_client"
4
+ require_relative "payloads/self_info"
5
+
6
+ module Yield
7
+ module SDK
8
+ module Self
9
+ class BaseClient
10
+ def initialize(api_client)
11
+ @api = api_client
12
+ end
13
+
14
+ def info
15
+ response = @api.run_query("/self/info")
16
+
17
+ API::Client.process_response(response, &SelfInfo.method(:from_payload))
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "self_base_client"
4
+
5
+ module Yield
6
+ module SDK
7
+ module Self
8
+ class Client
9
+ def initialize(base_client)
10
+ @base = base_client
11
+ end
12
+
13
+ def info
14
+ @base.info.data
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bigdecimal"
4
+
5
+ module Yield
6
+ module SDK
7
+ class Money < Data.define(:currency_code, :value)
8
+ def self.from_payload(payload)
9
+ m = payload.match(/^([A-Z]{3}) (-?\d+(?:\.\d+)?)$/)
10
+ raise ArgumentError, "Invalid money: #{payload}" if m.nil?
11
+
12
+ new(currency_code: m[1].to_sym, value: BigDecimal(m[2]))
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yield
4
+ module SDK
5
+ class MoneyPayload
6
+ def self.build(money)
7
+ return money if money.is_a?(String)
8
+
9
+ "#{money.currency_code} #{money.value.to_s("F")}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yield
4
+ module SDK
5
+ module Utils
6
+ module_function
7
+
8
+ def assert_boolean(data)
9
+ raise ArgumentError, "Expected Boolean, got #{data.class}" unless data == true || data == false
10
+ data
11
+ end
12
+
13
+ def assert_integer(data)
14
+ raise ArgumentError, "Expected Integer, got #{data.class}" unless data.is_a?(Integer)
15
+ data
16
+ end
17
+
18
+ def assert_string(data)
19
+ raise ArgumentError, "Expected String, got #{data.class}" unless data.is_a?(String)
20
+ data
21
+ end
22
+
23
+ def self.assert_variant(variants, data)
24
+ raise ArgumentError, "Expected String, got #{data.class}" unless data.is_a?(String)
25
+ symbol = data.downcase.to_sym
26
+ raise ArgumentError, "Invalid variant: \"#{data}\"" unless variants.include?(symbol)
27
+ symbol
28
+ end
29
+
30
+ def self.assert_hash(data)
31
+ raise ArgumentError, "Expected Hash, got #{data.class}" unless data.is_a?(Hash)
32
+ data
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yield
4
+ module SDK
5
+ VERSION = "0.5.0"
6
+
7
+ module_function
8
+
9
+ def client_version
10
+ runtime_major_version = RUBY_ENGINE_VERSION.match(/^\d+(\.\d+)?/)[0]
11
+ runtime_version = "#{RUBY_ENGINE} #{runtime_major_version}"
12
+
13
+ "Yield-SDK-Ruby/#{VERSION} (#{runtime_version})"
14
+ end
15
+ end
16
+ end
data/lib/yield/sdk.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sdk/client"
4
+ require_relative "sdk/version"
5
+
6
+ module Yield
7
+ module SDK
8
+ class Error < StandardError; end
9
+ end
10
+ end
data/sig/yield/sdk.rbs ADDED
@@ -0,0 +1,6 @@
1
+ module Yield
2
+ module Sdk
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yield-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Yield
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-05-23 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.13'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.13'
26
+ executables: []
27
+ extensions: []
28
+ extra_rdoc_files: []
29
+ files:
30
+ - ".standard.yml"
31
+ - LICENSE
32
+ - README.md
33
+ - Rakefile
34
+ - lib/yield/sdk.rb
35
+ - lib/yield/sdk/api/api_client.rb
36
+ - lib/yield/sdk/api/api_result.rb
37
+ - lib/yield/sdk/base_client.rb
38
+ - lib/yield/sdk/client.rb
39
+ - lib/yield/sdk/modules/order/order_base_client.rb
40
+ - lib/yield/sdk/modules/order/order_client.rb
41
+ - lib/yield/sdk/modules/order/payloads/order.rb
42
+ - lib/yield/sdk/modules/order/payloads/order_create_payload.rb
43
+ - lib/yield/sdk/modules/order/payloads/order_customer_info.rb
44
+ - lib/yield/sdk/modules/order/payloads/order_status.rb
45
+ - lib/yield/sdk/modules/self/payloads/self_info.rb
46
+ - lib/yield/sdk/modules/self/payloads/self_organization_info.rb
47
+ - lib/yield/sdk/modules/self/self_base_client.rb
48
+ - lib/yield/sdk/modules/self/self_client.rb
49
+ - lib/yield/sdk/types/money.rb
50
+ - lib/yield/sdk/types/money_payload.rb
51
+ - lib/yield/sdk/utils.rb
52
+ - lib/yield/sdk/version.rb
53
+ - sig/yield/sdk.rbs
54
+ homepage: https://www.paywithyield.com
55
+ licenses:
56
+ - Apache-2.0
57
+ metadata: {}
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 3.2.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.6.6
73
+ specification_version: 4
74
+ summary: The official Yield SDK for Ruby
75
+ test_files: []