orb-billing 0.3.2 → 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.
Files changed (246) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/README.md +95 -55
  4. data/lib/orb/client.rb +4 -4
  5. data/lib/orb/errors.rb +1 -1
  6. data/lib/orb/internal/transport/base_client.rb +74 -5
  7. data/lib/orb/internal/transport/pooled_net_requester.rb +17 -1
  8. data/lib/orb/internal/type/array_of.rb +1 -1
  9. data/lib/orb/internal/type/base_model.rb +70 -30
  10. data/lib/orb/internal/type/converter.rb +18 -0
  11. data/lib/orb/internal/type/enum.rb +1 -0
  12. data/lib/orb/internal/type/hash_of.rb +1 -1
  13. data/lib/orb/internal/type/union.rb +1 -0
  14. data/lib/orb/internal/util.rb +56 -0
  15. data/lib/orb/internal.rb +6 -0
  16. data/lib/orb/models/coupon.rb +4 -0
  17. data/lib/orb/models/coupon_create_params.rb +6 -0
  18. data/lib/orb/models/customer_create_params.rb +9 -0
  19. data/lib/orb/models/customer_update_by_external_id_params.rb +9 -0
  20. data/lib/orb/models/customer_update_params.rb +9 -0
  21. data/lib/orb/models/customers/credits/ledger_create_entry_by_external_id_response.rb +14 -0
  22. data/lib/orb/models/customers/credits/ledger_create_entry_response.rb +14 -0
  23. data/lib/orb/models/customers/credits/ledger_list_by_external_id_response.rb +14 -0
  24. data/lib/orb/models/customers/credits/ledger_list_response.rb +14 -0
  25. data/lib/orb/models/discount.rb +6 -0
  26. data/lib/orb/models/evaluate_price_group.rb +4 -0
  27. data/lib/orb/models/invoice.rb +22 -0
  28. data/lib/orb/models/invoice_fetch_upcoming_response.rb +22 -0
  29. data/lib/orb/models/invoice_level_discount.rb +4 -0
  30. data/lib/orb/models/invoice_line_item_create_response.rb +22 -0
  31. data/lib/orb/models/plan.rb +12 -0
  32. data/lib/orb/models/plan_create_params.rb +32 -0
  33. data/lib/orb/models/price.rb +35 -0
  34. data/lib/orb/models/subscription.rb +22 -0
  35. data/lib/orb/models/subscription_cancel_response.rb +22 -0
  36. data/lib/orb/models/subscription_change_apply_response.rb +22 -0
  37. data/lib/orb/models/subscription_change_cancel_response.rb +22 -0
  38. data/lib/orb/models/subscription_change_retrieve_response.rb +22 -0
  39. data/lib/orb/models/subscription_create_params.rb +88 -0
  40. data/lib/orb/models/subscription_create_response.rb +22 -0
  41. data/lib/orb/models/subscription_price_intervals_params.rb +89 -0
  42. data/lib/orb/models/subscription_price_intervals_response.rb +22 -0
  43. data/lib/orb/models/subscription_schedule_plan_change_params.rb +88 -0
  44. data/lib/orb/models/subscription_schedule_plan_change_response.rb +22 -0
  45. data/lib/orb/models/subscription_trigger_phase_response.rb +22 -0
  46. data/lib/orb/models/subscription_unschedule_cancellation_response.rb +22 -0
  47. data/lib/orb/models/subscription_unschedule_fixed_fee_quantity_updates_response.rb +22 -0
  48. data/lib/orb/models/subscription_unschedule_pending_plan_changes_response.rb +22 -0
  49. data/lib/orb/models/subscription_update_fixed_fee_quantity_response.rb +22 -0
  50. data/lib/orb/models/subscription_update_trial_params.rb +4 -0
  51. data/lib/orb/models/subscription_update_trial_response.rb +22 -0
  52. data/lib/orb/models/subscription_usage.rb +9 -0
  53. data/lib/orb/models.rb +24 -0
  54. data/lib/orb/request_options.rb +4 -0
  55. data/lib/orb/version.rb +1 -1
  56. data/lib/orb.rb +2 -0
  57. data/rbi/orb/internal/page.rbi +2 -1
  58. data/rbi/orb/internal/transport/base_client.rbi +31 -8
  59. data/rbi/orb/internal/transport/pooled_net_requester.rbi +10 -5
  60. data/rbi/orb/internal/type/base_model.rbi +31 -15
  61. data/rbi/orb/internal/type/base_page.rbi +1 -1
  62. data/rbi/orb/internal/type/converter.rbi +2 -0
  63. data/rbi/orb/internal/type/enum.rbi +1 -0
  64. data/rbi/orb/internal/type/union.rbi +1 -0
  65. data/rbi/orb/internal/util.rbi +28 -7
  66. data/rbi/orb/internal.rbi +2 -0
  67. data/rbi/orb/models/alert.rbi +13 -6
  68. data/rbi/orb/models/alert_create_for_customer_params.rbi +11 -2
  69. data/rbi/orb/models/alert_create_for_external_customer_params.rbi +14 -2
  70. data/rbi/orb/models/alert_create_for_subscription_params.rbi +11 -2
  71. data/rbi/orb/models/alert_disable_params.rbi +2 -1
  72. data/rbi/orb/models/alert_enable_params.rbi +2 -1
  73. data/rbi/orb/models/alert_list_params.rbi +2 -1
  74. data/rbi/orb/models/alert_retrieve_params.rbi +2 -1
  75. data/rbi/orb/models/alert_update_params.rbi +6 -2
  76. data/rbi/orb/models/amount_discount.rbi +2 -1
  77. data/rbi/orb/models/billable_metric.rbi +2 -1
  78. data/rbi/orb/models/coupon.rbi +1 -1
  79. data/rbi/orb/models/coupon_archive_params.rbi +2 -1
  80. data/rbi/orb/models/coupon_create_params.rbi +16 -3
  81. data/rbi/orb/models/coupon_fetch_params.rbi +2 -1
  82. data/rbi/orb/models/coupon_list_params.rbi +2 -1
  83. data/rbi/orb/models/coupons/subscription_list_params.rbi +4 -1
  84. data/rbi/orb/models/credit_note.rbi +45 -9
  85. data/rbi/orb/models/credit_note_create_params.rbi +8 -2
  86. data/rbi/orb/models/credit_note_fetch_params.rbi +4 -1
  87. data/rbi/orb/models/credit_note_list_params.rbi +4 -1
  88. data/rbi/orb/models/customer.rbi +41 -10
  89. data/rbi/orb/models/customer_create_params.rbi +61 -10
  90. data/rbi/orb/models/customer_delete_params.rbi +4 -1
  91. data/rbi/orb/models/customer_fetch_by_external_id_params.rbi +4 -1
  92. data/rbi/orb/models/customer_fetch_params.rbi +2 -1
  93. data/rbi/orb/models/customer_list_params.rbi +2 -1
  94. data/rbi/orb/models/customer_sync_payment_methods_from_gateway_by_external_customer_id_params.rbi +7 -1
  95. data/rbi/orb/models/customer_sync_payment_methods_from_gateway_params.rbi +7 -1
  96. data/rbi/orb/models/customer_update_by_external_id_params.rbi +67 -10
  97. data/rbi/orb/models/customer_update_params.rbi +61 -10
  98. data/rbi/orb/models/customers/balance_transaction_create_params.rbi +7 -1
  99. data/rbi/orb/models/customers/balance_transaction_create_response.rbi +21 -3
  100. data/rbi/orb/models/customers/balance_transaction_list_params.rbi +7 -1
  101. data/rbi/orb/models/customers/balance_transaction_list_response.rbi +21 -3
  102. data/rbi/orb/models/customers/cost_list_by_external_id_params.rbi +7 -1
  103. data/rbi/orb/models/customers/cost_list_by_external_id_response.rbi +21 -3
  104. data/rbi/orb/models/customers/cost_list_params.rbi +4 -1
  105. data/rbi/orb/models/customers/cost_list_response.rbi +21 -3
  106. data/rbi/orb/models/customers/credit_list_by_external_id_params.rbi +7 -1
  107. data/rbi/orb/models/customers/credit_list_by_external_id_response.rbi +7 -1
  108. data/rbi/orb/models/customers/credit_list_params.rbi +4 -1
  109. data/rbi/orb/models/customers/credit_list_response.rbi +7 -1
  110. data/rbi/orb/models/customers/credits/ledger_create_entry_by_external_id_params.rbi +14 -2
  111. data/rbi/orb/models/customers/credits/ledger_create_entry_by_external_id_response.rbi +133 -21
  112. data/rbi/orb/models/customers/credits/ledger_create_entry_params.rbi +14 -2
  113. data/rbi/orb/models/customers/credits/ledger_create_entry_response.rbi +133 -21
  114. data/rbi/orb/models/customers/credits/ledger_list_by_external_id_params.rbi +7 -1
  115. data/rbi/orb/models/customers/credits/ledger_list_by_external_id_response.rbi +133 -21
  116. data/rbi/orb/models/customers/credits/ledger_list_params.rbi +7 -1
  117. data/rbi/orb/models/customers/credits/ledger_list_response.rbi +133 -21
  118. data/rbi/orb/models/customers/credits/top_up_create_by_external_id_params.rbi +14 -2
  119. data/rbi/orb/models/customers/credits/top_up_create_by_external_id_response.rbi +14 -2
  120. data/rbi/orb/models/customers/credits/top_up_create_params.rbi +14 -2
  121. data/rbi/orb/models/customers/credits/top_up_create_response.rbi +14 -2
  122. data/rbi/orb/models/customers/credits/top_up_delete_by_external_id_params.rbi +7 -1
  123. data/rbi/orb/models/customers/credits/top_up_delete_params.rbi +7 -1
  124. data/rbi/orb/models/customers/credits/top_up_list_by_external_id_params.rbi +7 -1
  125. data/rbi/orb/models/customers/credits/top_up_list_by_external_id_response.rbi +14 -2
  126. data/rbi/orb/models/customers/credits/top_up_list_params.rbi +7 -1
  127. data/rbi/orb/models/customers/credits/top_up_list_response.rbi +14 -2
  128. data/rbi/orb/models/dimensional_price_group.rbi +4 -1
  129. data/rbi/orb/models/dimensional_price_group_create_params.rbi +4 -1
  130. data/rbi/orb/models/dimensional_price_group_list_params.rbi +4 -1
  131. data/rbi/orb/models/dimensional_price_group_retrieve_params.rbi +7 -1
  132. data/rbi/orb/models/dimensional_price_groups/external_dimensional_price_group_id_retrieve_params.rbi +7 -1
  133. data/rbi/orb/models/dimensional_price_groups.rbi +4 -1
  134. data/rbi/orb/models/evaluate_price_group.rbi +2 -1
  135. data/rbi/orb/models/event_deprecate_params.rbi +4 -1
  136. data/rbi/orb/models/event_deprecate_response.rbi +4 -1
  137. data/rbi/orb/models/event_ingest_params.rbi +6 -2
  138. data/rbi/orb/models/event_ingest_response.rbi +18 -3
  139. data/rbi/orb/models/event_search_params.rbi +2 -1
  140. data/rbi/orb/models/event_search_response.rbi +11 -2
  141. data/rbi/orb/models/event_update_params.rbi +2 -1
  142. data/rbi/orb/models/event_update_response.rbi +4 -1
  143. data/rbi/orb/models/events/backfill_close_params.rbi +4 -1
  144. data/rbi/orb/models/events/backfill_close_response.rbi +7 -1
  145. data/rbi/orb/models/events/backfill_create_params.rbi +4 -1
  146. data/rbi/orb/models/events/backfill_create_response.rbi +7 -1
  147. data/rbi/orb/models/events/backfill_fetch_params.rbi +4 -1
  148. data/rbi/orb/models/events/backfill_fetch_response.rbi +7 -1
  149. data/rbi/orb/models/events/backfill_list_params.rbi +4 -1
  150. data/rbi/orb/models/events/backfill_list_response.rbi +7 -1
  151. data/rbi/orb/models/events/backfill_revert_params.rbi +4 -1
  152. data/rbi/orb/models/events/backfill_revert_response.rbi +7 -1
  153. data/rbi/orb/models/events/event_volumes.rbi +8 -2
  154. data/rbi/orb/models/events/volume_list_params.rbi +4 -1
  155. data/rbi/orb/models/invoice.rbi +156 -31
  156. data/rbi/orb/models/invoice_create_params.rbi +13 -3
  157. data/rbi/orb/models/invoice_fetch_params.rbi +2 -1
  158. data/rbi/orb/models/invoice_fetch_upcoming_params.rbi +4 -1
  159. data/rbi/orb/models/invoice_fetch_upcoming_response.rbi +212 -31
  160. data/rbi/orb/models/invoice_issue_params.rbi +2 -1
  161. data/rbi/orb/models/invoice_line_item_create_params.rbi +4 -1
  162. data/rbi/orb/models/invoice_line_item_create_response.rbi +119 -17
  163. data/rbi/orb/models/invoice_list_params.rbi +2 -1
  164. data/rbi/orb/models/invoice_mark_paid_params.rbi +4 -1
  165. data/rbi/orb/models/invoice_pay_params.rbi +2 -1
  166. data/rbi/orb/models/invoice_update_params.rbi +2 -1
  167. data/rbi/orb/models/invoice_void_params.rbi +2 -1
  168. data/rbi/orb/models/item.rbi +5 -2
  169. data/rbi/orb/models/item_create_params.rbi +2 -1
  170. data/rbi/orb/models/item_fetch_params.rbi +2 -1
  171. data/rbi/orb/models/item_list_params.rbi +2 -1
  172. data/rbi/orb/models/item_update_params.rbi +9 -2
  173. data/rbi/orb/models/metric_create_params.rbi +2 -1
  174. data/rbi/orb/models/metric_fetch_params.rbi +2 -1
  175. data/rbi/orb/models/metric_list_params.rbi +2 -1
  176. data/rbi/orb/models/metric_update_params.rbi +2 -1
  177. data/rbi/orb/models/pagination_metadata.rbi +2 -1
  178. data/rbi/orb/models/percentage_discount.rbi +2 -1
  179. data/rbi/orb/models/plan.rbi +50 -14
  180. data/rbi/orb/models/plan_create_params.rbi +604 -89
  181. data/rbi/orb/models/plan_fetch_params.rbi +2 -1
  182. data/rbi/orb/models/plan_list_params.rbi +2 -1
  183. data/rbi/orb/models/plan_update_params.rbi +2 -1
  184. data/rbi/orb/models/plans/external_plan_id_fetch_params.rbi +4 -1
  185. data/rbi/orb/models/plans/external_plan_id_update_params.rbi +7 -1
  186. data/rbi/orb/models/price.rbi +1624 -270
  187. data/rbi/orb/models/price_create_params.rbi +100 -18
  188. data/rbi/orb/models/price_evaluate_params.rbi +2 -1
  189. data/rbi/orb/models/price_evaluate_response.rbi +4 -1
  190. data/rbi/orb/models/price_fetch_params.rbi +2 -1
  191. data/rbi/orb/models/price_list_params.rbi +2 -1
  192. data/rbi/orb/models/price_update_params.rbi +2 -1
  193. data/rbi/orb/models/prices/external_price_id_fetch_params.rbi +7 -1
  194. data/rbi/orb/models/prices/external_price_id_update_params.rbi +7 -1
  195. data/rbi/orb/models/subscription.rbi +109 -19
  196. data/rbi/orb/models/subscription_cancel_params.rbi +4 -1
  197. data/rbi/orb/models/subscription_cancel_response.rbi +137 -20
  198. data/rbi/orb/models/subscription_change_apply_params.rbi +4 -1
  199. data/rbi/orb/models/subscription_change_apply_response.rbi +142 -21
  200. data/rbi/orb/models/subscription_change_cancel_params.rbi +4 -1
  201. data/rbi/orb/models/subscription_change_cancel_response.rbi +142 -21
  202. data/rbi/orb/models/subscription_change_retrieve_params.rbi +4 -1
  203. data/rbi/orb/models/subscription_change_retrieve_response.rbi +142 -21
  204. data/rbi/orb/models/subscription_create_params.rbi +1257 -198
  205. data/rbi/orb/models/subscription_create_response.rbi +137 -20
  206. data/rbi/orb/models/subscription_fetch_costs_params.rbi +4 -1
  207. data/rbi/orb/models/subscription_fetch_costs_response.rbi +21 -3
  208. data/rbi/orb/models/subscription_fetch_params.rbi +4 -1
  209. data/rbi/orb/models/subscription_fetch_schedule_params.rbi +4 -1
  210. data/rbi/orb/models/subscription_fetch_schedule_response.rbi +14 -2
  211. data/rbi/orb/models/subscription_fetch_usage_params.rbi +4 -1
  212. data/rbi/orb/models/subscription_list_params.rbi +4 -1
  213. data/rbi/orb/models/subscription_price_intervals_params.rbi +731 -115
  214. data/rbi/orb/models/subscription_price_intervals_response.rbi +140 -20
  215. data/rbi/orb/models/subscription_schedule_plan_change_params.rbi +1260 -198
  216. data/rbi/orb/models/subscription_schedule_plan_change_response.rbi +140 -20
  217. data/rbi/orb/models/subscription_trigger_phase_params.rbi +4 -1
  218. data/rbi/orb/models/subscription_trigger_phase_response.rbi +140 -20
  219. data/rbi/orb/models/subscription_unschedule_cancellation_params.rbi +7 -1
  220. data/rbi/orb/models/subscription_unschedule_cancellation_response.rbi +140 -20
  221. data/rbi/orb/models/subscription_unschedule_fixed_fee_quantity_updates_params.rbi +7 -1
  222. data/rbi/orb/models/subscription_unschedule_fixed_fee_quantity_updates_response.rbi +140 -20
  223. data/rbi/orb/models/subscription_unschedule_pending_plan_changes_params.rbi +7 -1
  224. data/rbi/orb/models/subscription_unschedule_pending_plan_changes_response.rbi +140 -20
  225. data/rbi/orb/models/subscription_update_fixed_fee_quantity_params.rbi +7 -1
  226. data/rbi/orb/models/subscription_update_fixed_fee_quantity_response.rbi +140 -20
  227. data/rbi/orb/models/subscription_update_params.rbi +4 -1
  228. data/rbi/orb/models/subscription_update_trial_params.rbi +4 -1
  229. data/rbi/orb/models/subscription_update_trial_response.rbi +140 -20
  230. data/rbi/orb/models/subscription_usage.rbi +63 -9
  231. data/rbi/orb/models/subscriptions.rbi +2 -1
  232. data/rbi/orb/models/top_level_ping_params.rbi +2 -1
  233. data/rbi/orb/models/top_level_ping_response.rbi +4 -1
  234. data/rbi/orb/models/trial_discount.rbi +2 -1
  235. data/rbi/orb/models/usage_discount.rbi +2 -1
  236. data/rbi/orb/request_options.rbi +1 -1
  237. data/sig/orb/internal/transport/base_client.rbs +16 -1
  238. data/sig/orb/internal/transport/pooled_net_requester.rbs +4 -0
  239. data/sig/orb/internal/type/base_model.rbs +11 -5
  240. data/sig/orb/internal/type/base_page.rbs +1 -1
  241. data/sig/orb/internal/type/converter.rbs +2 -0
  242. data/sig/orb/internal/type/enum.rbs +1 -0
  243. data/sig/orb/internal/type/union.rbs +1 -0
  244. data/sig/orb/internal/util.rbs +13 -0
  245. data/sig/orb/internal.rbs +2 -0
  246. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a8aab7ea27e9f429fb79d85663cb238393ef06c60acb43e7c1f4285658cdd2f
4
- data.tar.gz: b48c4f83c56e09e04e50e10bb89c865c5fb72143f4a42dbd96e83cc183975fa8
3
+ metadata.gz: 4ce1529e168d4f47f75f48505cf8e528afc2056e95f075f4611382b97374d1a2
4
+ data.tar.gz: c4f6bd8086298f6950ddeed3480ee75a60836463355acd7f0bb5d70fff40b359
5
5
  SHA512:
6
- metadata.gz: a5e2ba15a48f4b458f9758393a6f421d4b795e44b3ecf5f7f7e7dfdba71c139b26a229cd4956d2d4269d1f5df689e9fc583ced8da055ab59403f0372b24ed1d4
7
- data.tar.gz: ca4923f45449e5f4187ad9bd4cabf2abbdea4c2e593f2f294607e1e2cf8ce5efe3e2f311ee2371a85cbf4ceba724fa2de98d30d9521fa8f10f9262214fd52a54
6
+ metadata.gz: d6a7ff2c8e6ec173a053c6ad9635cd97f372b08baf61bee105e1c736706fa265ebcc90b1a2dbeb05c0d67f5adfb56d157ccc5d355e06b3ce2340c78cdb056a20
7
+ data.tar.gz: 90bc92e99e52b0cb51a208337ccd2d4a6d6cb39cad3990db8518b886c3b471188e0a2981cbb769058cef19f2e391ef78b80eaa721befe6180cc531bcc4bd68aa
data/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0 (2025-05-14)
4
+
5
+ Full Changelog: [v0.4.0...v0.5.0](https://github.com/orbcorp/orb-ruby/compare/v0.4.0...v0.5.0)
6
+
7
+ ### Features
8
+
9
+ * bump default connection pool size limit to minimum of 99 ([79f9994](https://github.com/orbcorp/orb-ruby/commit/79f9994e2a77d786a7e1ffaa52c56916835b9b5f))
10
+
11
+
12
+ ### Chores
13
+
14
+ * **internal:** version bump ([cfc1793](https://github.com/orbcorp/orb-ruby/commit/cfc17939f09ece0217ea7683991e509c30491e96))
15
+
16
+
17
+ ### Documentation
18
+
19
+ * rewrite much of README.md for readability ([ac8a45d](https://github.com/orbcorp/orb-ruby/commit/ac8a45d8765183d41fbeaf23d1bd03c372908b45))
20
+
21
+ ## 0.4.0 (2025-05-13)
22
+
23
+ Full Changelog: [v0.3.2...v0.4.0](https://github.com/orbcorp/orb-ruby/compare/v0.3.2...v0.4.0)
24
+
25
+ ### Features
26
+
27
+ * expose base client options as read only attributes ([1f638b6](https://github.com/orbcorp/orb-ruby/commit/1f638b60ad1679bc7969f441650ba61fb9a65e8a))
28
+ * expose recursive `#to_h` conversion ([cfd49a1](https://github.com/orbcorp/orb-ruby/commit/cfd49a15d805ffaa5828249c5b91565661ae7e52))
29
+ * support sorbet aliases at the runtime ([786d1e3](https://github.com/orbcorp/orb-ruby/commit/786d1e3dd882054bd298e33a448a194f1d68bac4))
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * **internal:** update gemspec name ([852ab56](https://github.com/orbcorp/orb-ruby/commit/852ab562ee4948d3fe4de8dd877f9301f36c8a4b))
35
+
36
+
37
+ ### Chores
38
+
39
+ * fix misc linting / minor issues ([0e7dd84](https://github.com/orbcorp/orb-ruby/commit/0e7dd846c906cc2e72827f5477a93e4799ab9482))
40
+ * **internal:** version bump ([359839c](https://github.com/orbcorp/orb-ruby/commit/359839c734c4bcf8051490b1e8723674ef634753))
41
+
3
42
  ## 0.3.2 (2025-05-07)
4
43
 
5
44
  Full Changelog: [v0.3.1...v0.3.2](https://github.com/orbcorp/orb-ruby/compare/v0.3.1...v0.3.2)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Orb Ruby API library
2
2
 
3
- The Orb Ruby library provides convenient access to the Orb REST API from any Ruby 3.2.0+ application.
3
+ The Orb Ruby library provides convenient access to the Orb REST API from any Ruby 3.2.0+ application. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/orbcorp/orb-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
4
4
 
5
5
  ## Documentation
6
6
 
@@ -15,7 +15,7 @@ To use this gem, install via Bundler by adding the following to your application
15
15
  <!-- x-release-please-start-version -->
16
16
 
17
17
  ```ruby
18
- gem "orb-billing", "~> 0.3.2"
18
+ gem "orb-billing", "~> 0.5.0"
19
19
  ```
20
20
 
21
21
  <!-- x-release-please-end -->
@@ -35,16 +35,6 @@ customer = orb.customers.create(email: "example-customer@withorb.com", name: "My
35
35
  puts(customer.id)
36
36
  ```
37
37
 
38
- ## Sorbet
39
-
40
- This library is written with [Sorbet type definitions](https://sorbet.org/docs/rbi). However, there is no runtime dependency on the `sorbet-runtime`.
41
-
42
- When using sorbet, it is recommended to use model classes as below. This provides stronger type checking and tooling integration.
43
-
44
- ```ruby
45
- orb.customers.create(email: "example-customer@withorb.com", name: "My Customer")
46
- ```
47
-
48
38
  ### Pagination
49
39
 
50
40
  List methods in the Orb API are paginated.
@@ -64,15 +54,30 @@ page.auto_paging_each do |coupon|
64
54
  end
65
55
  ```
66
56
 
67
- ### Errors
57
+ Alternatively, you can use the `#next_page?` and `#next_page` methods for more granular control working with pages.
58
+
59
+ ```ruby
60
+ if page.next_page?
61
+ new_page = page.next_page
62
+ puts(new_page.data[0].id)
63
+ end
64
+ ```
65
+
66
+ ### Handling errors
68
67
 
69
68
  When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `Orb::Errors::APIError` will be thrown:
70
69
 
71
70
  ```ruby
72
71
  begin
73
72
  customer = orb.customers.create(email: "example-customer@withorb.com", name: "My Customer")
74
- rescue Orb::Errors::APIError => e
75
- puts(e.status) # 400
73
+ rescue Orb::Errors::APIConnectionError => e
74
+ puts("The server could not be reached")
75
+ puts(e.cause) # an underlying Exception, likely raised within `net/http`
76
+ rescue Orb::Errors::RateLimitError => e
77
+ puts("A 429 status code was received; we should back off a bit.")
78
+ rescue Orb::Errors::APIStatusError => e
79
+ puts("Another non-200-range status code was received")
80
+ puts(e.status)
76
81
  end
77
82
  ```
78
83
 
@@ -116,11 +121,7 @@ orb.customers.create(
116
121
 
117
122
  ### Timeouts
118
123
 
119
- By default, requests will time out after 60 seconds.
120
-
121
- Timeouts are applied separately to the initial connection and the overall request time, so in some cases a request could wait 2\*timeout seconds before it fails.
122
-
123
- You can use the `timeout` option to configure or disable this:
124
+ By default, requests will time out after 60 seconds. You can use the timeout option to configure or disable this:
124
125
 
125
126
  ```ruby
126
127
  # Configure the default for all requests:
@@ -136,40 +137,54 @@ orb.customers.create(
136
137
  )
137
138
  ```
138
139
 
139
- ## Model DSL
140
+ On timeout, `Orb::Errors::APITimeoutError` is raised.
140
141
 
141
- This library uses a simple DSL to represent request parameters and response shapes in `lib/orb/models`.
142
+ Note that requests that time out are retried by default.
142
143
 
143
- With the right [editor plugins](https://shopify.github.io/ruby-lsp), you can ctrl-click on elements of the DSL to navigate around and explore the library.
144
+ ## Advanced concepts
144
145
 
145
- In all places where a `BaseModel` type is specified, vanilla Ruby `Hash` can also be used. For example, the following are interchangeable as arguments:
146
+ ### BaseModel
146
147
 
147
- ```ruby
148
- # This has tooling readability, for auto-completion, static analysis, and goto definition with supported language services
149
- params = Orb::Models::CustomerCreateParams.new(email: "example-customer@withorb.com", name: "My Customer")
148
+ All parameter and response objects inherit from `Orb::Internal::Type::BaseModel`, which provides several conveniences, including:
150
149
 
151
- # This also works
152
- params = {
153
- email: "example-customer@withorb.com",
154
- name: "My Customer"
155
- }
156
- ```
150
+ 1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax, and can be destructured with `obj => {prop: prop}` or pattern-matching syntax.
157
151
 
158
- ## Editor support
152
+ 2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
159
153
 
160
- A combination of [Shopify LSP](https://shopify.github.io/ruby-lsp) and [Solargraph](https://solargraph.org/) is recommended for non-[Sorbet](https://sorbet.org) users. The former is especially good at go to definition, while the latter has much better auto-completion support.
154
+ 3. Both instances and the classes themselves can be pretty-printed.
161
155
 
162
- ## Advanced concepts
156
+ 4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml`.
157
+
158
+ ### Making custom or undocumented requests
159
+
160
+ #### Undocumented properties
163
161
 
164
- ### Making custom/undocumented requests
162
+ You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
163
+
164
+ Note: the `extra_` parameters of the same name overrides the documented parameters.
165
+
166
+ ```ruby
167
+ customer =
168
+ orb.customers.create(
169
+ email: "example-customer@withorb.com",
170
+ name: "My Customer",
171
+ request_options: {
172
+ extra_query: {my_query_parameter: value},
173
+ extra_body: {my_body_parameter: value},
174
+ extra_headers: {"my-header": value}
175
+ }
176
+ )
177
+
178
+ puts(customer[:my_undocumented_property])
179
+ ```
165
180
 
166
181
  #### Undocumented request params
167
182
 
168
- If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a requests as seen in examples above.
183
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a request as seen in examples above.
169
184
 
170
185
  #### Undocumented endpoints
171
186
 
172
- To make requests to undocumented endpoints, you can make requests using `client.request`. Options on the client will be respected (such as retries) when making this request.
187
+ To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using `client.request`, like so:
173
188
 
174
189
  ```ruby
175
190
  response = client.request(
@@ -177,42 +192,67 @@ response = client.request(
177
192
  path: '/undocumented/endpoint',
178
193
  query: {"dog": "woof"},
179
194
  headers: {"useful-header": "interesting-value"},
180
- body: {"he": "llo"},
195
+ body: {"hello": "world"}
181
196
  )
182
197
  ```
183
198
 
184
199
  ### Concurrency & connection pooling
185
200
 
186
- The `Orb::Client` instances are thread-safe, and should be re-used across multiple threads. By default, each `Client` have their own HTTP connection pool, with a maximum number of connections equal to thread count.
201
+ The `Orb::Client` instances are threadsafe, but only are fork-safe when there are no in-flight HTTP requests.
202
+
203
+ Each instance of `Orb::Client` has its own HTTP connection pool with a default size of 99. As such, we recommend instantiating the client once per application in most settings.
187
204
 
188
- When the maximum number of connections has been checked out from the connection pool, the `Client` will wait for an in use connection to become available. The queue time for this mechanism is accounted for by the per-request timeout.
205
+ When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout.
189
206
 
190
207
  Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
191
208
 
192
- Currently, `Orb::Client` instances are only fork-safe if there are no in-flight HTTP requests.
209
+ ## Sorbet
193
210
 
194
- ### Sorbet
211
+ This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
195
212
 
196
- #### Enums
213
+ You can provide typesafe request parameters like so:
197
214
 
198
- Sorbet's typed enums require sub-classing of the [`T::Enum` class](https://sorbet.org/docs/tenum) from the `sorbet-runtime` gem.
215
+ ```ruby
216
+ orb.customers.create(email: "example-customer@withorb.com", name: "My Customer")
217
+ ```
199
218
 
200
- Since this library does not depend on `sorbet-runtime`, it uses a [`T.all` intersection type](https://sorbet.org/docs/intersection-types) with a ruby primitive type to construct a "tagged alias" instead.
219
+ Or, equivalently:
201
220
 
202
221
  ```ruby
203
- module Orb::BillingCycleRelativeDate
204
- # This alias aids language service driven navigation.
205
- TaggedSymbol = T.type_alias { T.all(Symbol, Orb::BillingCycleRelativeDate) }
206
- end
222
+ # Hashes work, but are not typesafe:
223
+ orb.customers.create(email: "example-customer@withorb.com", name: "My Customer")
224
+
225
+ # You can also splat a full Params class:
226
+ params = Orb::CustomerCreateParams.new(email: "example-customer@withorb.com", name: "My Customer")
227
+ orb.customers.create(**params)
207
228
  ```
208
229
 
209
- #### Argument passing trick
230
+ ### Enums
210
231
 
211
- It is possible to pass a compatible model / parameter class to a method that expects keyword arguments by using the `**` splat operator.
232
+ Since this library does not depend on `sorbet-runtime`, it cannot provide [`T::Enum`](https://sorbet.org/docs/tenum) instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:
212
233
 
213
234
  ```ruby
214
- params = Orb::Models::CustomerCreateParams.new(email: "example-customer@withorb.com", name: "My Customer")
215
- orb.customers.create(**params)
235
+ # :duplicate
236
+ puts(Orb::CreditNoteCreateParams::Reason::DUPLICATE)
237
+
238
+ # Revealed type: `T.all(Orb::CreditNoteCreateParams::Reason, Symbol)`
239
+ T.reveal_type(Orb::CreditNoteCreateParams::Reason::DUPLICATE)
240
+ ```
241
+
242
+ Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
243
+
244
+ ```ruby
245
+ # Using the enum constants preserves the tagged type information:
246
+ orb.credit_notes.create(
247
+ reason: Orb::CreditNoteCreateParams::Reason::DUPLICATE,
248
+ # …
249
+ )
250
+
251
+ # Literal values is also permissible:
252
+ orb.credit_notes.create(
253
+ reason: :duplicate,
254
+ # …
255
+ )
216
256
  ```
217
257
 
218
258
  ## Versioning
data/lib/orb/client.rb CHANGED
@@ -91,10 +91,10 @@ module Orb
91
91
  def initialize(
92
92
  api_key: ENV["ORB_API_KEY"],
93
93
  base_url: ENV["ORB_BASE_URL"],
94
- max_retries: Orb::Client::DEFAULT_MAX_RETRIES,
95
- timeout: Orb::Client::DEFAULT_TIMEOUT_IN_SECONDS,
96
- initial_retry_delay: Orb::Client::DEFAULT_INITIAL_RETRY_DELAY,
97
- max_retry_delay: Orb::Client::DEFAULT_MAX_RETRY_DELAY,
94
+ max_retries: self.class::DEFAULT_MAX_RETRIES,
95
+ timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
96
+ initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
97
+ max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY,
98
98
  idempotency_header: "Idempotency-Key"
99
99
  )
100
100
  base_url ||= "https://api.withorb.com/v1"
data/lib/orb/errors.rb CHANGED
@@ -99,7 +99,7 @@ module Orb
99
99
  # @param response [nil]
100
100
  # @param message [String, nil]
101
101
  #
102
- # @return [Orb::Errors::APIStatusError]
102
+ # @return [self]
103
103
  def self.for(url:, status:, body:, request:, response:, message: nil)
104
104
  key = Orb::Internal::Util.dig(body, :type)
105
105
  kwargs = {
@@ -7,6 +7,8 @@ module Orb
7
7
  #
8
8
  # @abstract
9
9
  class BaseClient
10
+ extend Orb::Internal::Util::SorbetRuntimeSupport
11
+
10
12
  # from whatwg fetch spec
11
13
  MAX_REDIRECTS = 20
12
14
 
@@ -151,6 +153,27 @@ module Orb
151
153
  end
152
154
  end
153
155
 
156
+ # @return [URI::Generic]
157
+ attr_reader :base_url
158
+
159
+ # @return [Float]
160
+ attr_reader :timeout
161
+
162
+ # @return [Integer]
163
+ attr_reader :max_retries
164
+
165
+ # @return [Float]
166
+ attr_reader :initial_retry_delay
167
+
168
+ # @return [Float]
169
+ attr_reader :max_retry_delay
170
+
171
+ # @return [Hash{String=>String}]
172
+ attr_reader :headers
173
+
174
+ # @return [String, nil]
175
+ attr_reader :idempotency_header
176
+
154
177
  # @api private
155
178
  # @return [Orb::Internal::Transport::PooledNetRequester]
156
179
  attr_reader :requester
@@ -182,10 +205,11 @@ module Orb
182
205
  },
183
206
  headers
184
207
  )
185
- @base_url = Orb::Internal::Util.parse_uri(base_url)
208
+ @base_url_components = Orb::Internal::Util.parse_uri(base_url)
209
+ @base_url = Orb::Internal::Util.unparse_uri(@base_url_components)
186
210
  @idempotency_header = idempotency_header&.to_s&.downcase
187
- @max_retries = max_retries
188
211
  @timeout = timeout
212
+ @max_retries = max_retries
189
213
  @initial_retry_delay = initial_retry_delay
190
214
  @max_retry_delay = max_retry_delay
191
215
  end
@@ -276,10 +300,11 @@ module Orb
276
300
  Orb::Internal::Util.deep_merge(*[req[:body], opts[:extra_body]].compact)
277
301
  end
278
302
 
303
+ url = Orb::Internal::Util.join_parsed_uri(@base_url_components, {**req, path: path, query: query})
279
304
  headers, encoded = Orb::Internal::Util.encode_content(headers, body)
280
305
  {
281
306
  method: method,
282
- url: Orb::Internal::Util.join_parsed_uri(@base_url, {**req, path: path, query: query}),
307
+ url: url,
283
308
  headers: headers,
284
309
  body: encoded,
285
310
  max_retries: opts.fetch(:max_retries, @max_retries),
@@ -473,10 +498,54 @@ module Orb
473
498
  # @return [String]
474
499
  def inspect
475
500
  # rubocop:disable Layout/LineLength
476
- base_url = Orb::Internal::Util.unparse_uri(@base_url)
477
- "#<#{self.class.name}:0x#{object_id.to_s(16)} base_url=#{base_url} max_retries=#{@max_retries} timeout=#{@timeout}>"
501
+ "#<#{self.class.name}:0x#{object_id.to_s(16)} base_url=#{@base_url} max_retries=#{@max_retries} timeout=#{@timeout}>"
478
502
  # rubocop:enable Layout/LineLength
479
503
  end
504
+
505
+ define_sorbet_constant!(:RequestComponents) do
506
+ T.type_alias do
507
+ {
508
+ method: Symbol,
509
+ path: T.any(String, T::Array[String]),
510
+ query: T.nilable(T::Hash[String, T.nilable(T.any(T::Array[String], String))]),
511
+ headers: T.nilable(
512
+ T::Hash[String,
513
+ T.nilable(
514
+ T.any(
515
+ String,
516
+ Integer,
517
+ T::Array[T.nilable(T.any(String, Integer))]
518
+ )
519
+ )]
520
+ ),
521
+ body: T.nilable(T.anything),
522
+ unwrap: T.nilable(
523
+ T.any(
524
+ Symbol,
525
+ Integer,
526
+ T::Array[T.any(Symbol, Integer)],
527
+ T.proc.params(arg0: T.anything).returns(T.anything)
528
+ )
529
+ ),
530
+ page: T.nilable(T::Class[Orb::Internal::Type::BasePage[Orb::Internal::Type::BaseModel]]),
531
+ stream: T.nilable(T::Class[T.anything]),
532
+ model: T.nilable(Orb::Internal::Type::Converter::Input),
533
+ options: T.nilable(Orb::RequestOptions::OrHash)
534
+ }
535
+ end
536
+ end
537
+ define_sorbet_constant!(:RequestInput) do
538
+ T.type_alias do
539
+ {
540
+ method: Symbol,
541
+ url: URI::Generic,
542
+ headers: T::Hash[String, String],
543
+ body: T.anything,
544
+ max_retries: Integer,
545
+ timeout: Float
546
+ }
547
+ end
548
+ end
480
549
  end
481
550
  end
482
551
  end
@@ -5,10 +5,14 @@ module Orb
5
5
  module Transport
6
6
  # @api private
7
7
  class PooledNetRequester
8
+ extend Orb::Internal::Util::SorbetRuntimeSupport
9
+
8
10
  # from the golang stdlib
9
11
  # https://github.com/golang/go/blob/c8eced8580028328fde7c03cbfcb720ce15b2358/src/net/http/transport.go#L49
10
12
  KEEP_ALIVE_TIMEOUT = 30
11
13
 
14
+ DEFAULT_MAX_CONNECTIONS = [Etc.nprocessors, 99].max
15
+
12
16
  class << self
13
17
  # @api private
14
18
  #
@@ -182,11 +186,23 @@ module Orb
182
186
  # @api private
183
187
  #
184
188
  # @param size [Integer]
185
- def initialize(size: Etc.nprocessors)
189
+ def initialize(size: self.class::DEFAULT_MAX_CONNECTIONS)
186
190
  @mutex = Mutex.new
187
191
  @size = size
188
192
  @pools = {}
189
193
  end
194
+
195
+ define_sorbet_constant!(:Request) do
196
+ T.type_alias do
197
+ {
198
+ method: Symbol,
199
+ url: URI::Generic,
200
+ headers: T::Hash[String, String],
201
+ body: T.anything,
202
+ deadline: Float
203
+ }
204
+ end
205
+ end
190
206
  end
191
207
  end
192
208
  end
@@ -29,7 +29,7 @@ module Orb
29
29
  #
30
30
  # @option spec [Boolean] :"nil?"
31
31
  #
32
- # @return [Orb::Internal::Type::ArrayOf]
32
+ # @return [self]
33
33
  def self.[](...) = new(...)
34
34
 
35
35
  # @api public
@@ -6,6 +6,7 @@ module Orb
6
6
  # @abstract
7
7
  class BaseModel
8
8
  extend Orb::Internal::Type::Converter
9
+ extend Orb::Internal::Util::SorbetRuntimeSupport
9
10
 
10
11
  class << self
11
12
  # @api private
@@ -13,11 +14,17 @@ module Orb
13
14
  # Assumes superclass fields are totally defined before fields are accessed /
14
15
  # defined on subclasses.
15
16
  #
16
- # @return [Hash{Symbol=>Hash{Symbol=>Object}}]
17
- def known_fields
18
- @known_fields ||= (self < Orb::Internal::Type::BaseModel ? superclass.known_fields.dup : {})
17
+ # @param child [Class<Orb::Internal::Type::BaseModel>]
18
+ def inherited(child)
19
+ super
20
+ child.known_fields.replace(known_fields.dup)
19
21
  end
20
22
 
23
+ # @api private
24
+ #
25
+ # @return [Hash{Symbol=>Hash{Symbol=>Object}}]
26
+ def known_fields = @known_fields ||= {}
27
+
21
28
  # @api private
22
29
  #
23
30
  # @return [Hash{Symbol=>Hash{Symbol=>Object}}]
@@ -199,7 +206,7 @@ module Orb
199
206
  #
200
207
  # @option state [Integer] :branched
201
208
  #
202
- # @return [Orb::Internal::Type::BaseModel, Object]
209
+ # @return [self, Object]
203
210
  def coerce(value, state:)
204
211
  exactness = state.fetch(:exactness)
205
212
 
@@ -258,7 +265,7 @@ module Orb
258
265
 
259
266
  # @api private
260
267
  #
261
- # @param value [Orb::Internal::Type::BaseModel, Object]
268
+ # @param value [self, Object]
262
269
  #
263
270
  # @param state [Hash{Symbol=>Object}] .
264
271
  #
@@ -299,6 +306,39 @@ module Orb
299
306
  end
300
307
  end
301
308
 
309
+ class << self
310
+ # @api private
311
+ #
312
+ # @param model [Orb::Internal::Type::BaseModel]
313
+ # @param convert [Boolean]
314
+ #
315
+ # @return [Hash{Symbol=>Object}]
316
+ def recursively_to_h(model, convert:)
317
+ rec = ->(x) do
318
+ case x
319
+ in Orb::Internal::Type::BaseModel
320
+ if convert
321
+ fields = x.class.known_fields
322
+ x.to_h.to_h do |key, val|
323
+ [key, rec.call(fields.key?(key) ? x.public_send(key) : val)]
324
+ rescue Orb::Errors::ConversionError
325
+ [key, rec.call(val)]
326
+ end
327
+ else
328
+ rec.call(x.to_h)
329
+ end
330
+ in Hash
331
+ x.transform_values(&rec)
332
+ in Array
333
+ x.map(&rec)
334
+ else
335
+ x
336
+ end
337
+ end
338
+ rec.call(model)
339
+ end
340
+ end
341
+
302
342
  # @api public
303
343
  #
304
344
  # Returns the raw value associated with the given key, if found. Otherwise, nil is
@@ -335,9 +375,25 @@ module Orb
335
375
 
336
376
  alias_method :to_hash, :to_h
337
377
 
378
+ # @api public
379
+ #
380
+ # In addition to the behaviour of `#to_h`, this method will recursively call
381
+ # `#to_h` on nested models.
382
+ #
383
+ # @return [Hash{Symbol=>Object}]
384
+ def deep_to_h = self.class.recursively_to_h(@data, convert: false)
385
+
338
386
  # @param keys [Array<Symbol>, nil]
339
387
  #
340
388
  # @return [Hash{Symbol=>Object}]
389
+ #
390
+ # @example
391
+ # # `amount_discount` is a `Orb::AmountDiscount`
392
+ # amount_discount => {
393
+ # amount_discount: amount_discount,
394
+ # applies_to_price_ids: applies_to_price_ids,
395
+ # discount_type: discount_type
396
+ # }
341
397
  def deconstruct_keys(keys)
342
398
  (keys || self.class.known_fields.keys)
343
399
  .filter_map do |k|
@@ -350,29 +406,6 @@ module Orb
350
406
  .to_h
351
407
  end
352
408
 
353
- class << self
354
- # @api private
355
- #
356
- # @param model [Orb::Internal::Type::BaseModel]
357
- #
358
- # @return [Hash{Symbol=>Object}]
359
- def walk(model)
360
- walk = ->(x) do
361
- case x
362
- in Orb::Internal::Type::BaseModel
363
- walk.call(x.to_h)
364
- in Hash
365
- x.transform_values(&walk)
366
- in Array
367
- x.map(&walk)
368
- else
369
- x
370
- end
371
- end
372
- walk.call(model)
373
- end
374
- end
375
-
376
409
  # @api public
377
410
  #
378
411
  # @param a [Object]
@@ -418,12 +451,19 @@ module Orb
418
451
  # @api public
419
452
  #
420
453
  # @return [String]
421
- def to_s = self.class.walk(@data).to_s
454
+ def to_s = deep_to_h.to_s
422
455
 
423
456
  # @api private
424
457
  #
425
458
  # @return [String]
426
- def inspect = "#<#{self.class}:0x#{object_id.to_s(16)} #{self}>"
459
+ def inspect
460
+ converted = self.class.recursively_to_h(self, convert: true)
461
+ "#<#{self.class}:0x#{object_id.to_s(16)} #{converted}>"
462
+ end
463
+
464
+ define_sorbet_constant!(:KnownField) do
465
+ T.type_alias { {mode: T.nilable(Symbol), required: T::Boolean, nilable: T::Boolean} }
466
+ end
427
467
  end
428
468
  end
429
469
  end