-
Notifications
You must be signed in to change notification settings - Fork 14
v4.13.0: New resources, external-id operations, and disable toggles #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e6656f8
Add SDK features for v4.12.0
jessicahearn 0fe33d7
Add handle_as_user_edit parameter to write methods
jessicahearn b53e9c8
Add errors field to LineItem and Transaction resources
wscourge b84ff8c
Add account ID to Retrieve Account Details response
wscourge 343d8fd
Support flat params for SubscriptionEvent destroy action
wscourge 1bb31e2
Remove outdated post-install gem message
wscourge fe170b0
Add tests for standalone LineItem and Transaction resources
wscourge 915baa9
Add tests for Invoice toggle_disabled, update_status, and by_external…
wscourge ab9a165
Add tests for SubscriptionEvent toggle_disabled and by_external_id me…
wscourge ab45cb8
Add tests for Account include parameter and id field
wscourge e07775a
Add tests for DataSource empty! and soft_purge! methods
wscourge 575b79b
Add tests for JsonImport and Upload resources
wscourge 5d7208c
URL-encode user-supplied query parameters in API request paths
wscourge 6e256e2
Add missing middleware to Upload multipart connection
wscourge e2b6945
Extract shared concerns and helpers to reduce duplication
wscourge 4797ca2
Update changelog date and remove unused VALID_INCLUDE_FIELDS constant
wscourge ba8a9f8
Remove DataSource empty! and soft_purge! methods
wscourge 8c2ed0c
Add gem faraday-multipart as a dependency
wscourge c00f425
Fix self-review
wscourge 4601e32
Merge branch 'main' into jessica/pip-309-ruby-sdk-feature-updates
wscourge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module ChartMogul | ||
| module Concerns | ||
| # Shared class methods for resources that support CRUD by data_source_uuid + external_id. | ||
| # These resources use query-parameter-based lookups (not path-based). | ||
| module ExternalIdOperations | ||
| def self.included(base) | ||
| base.extend ClassMethods | ||
| end | ||
|
|
||
| module ClassMethods | ||
| # Retrieve a resource by data_source_uuid and external_id | ||
| def retrieve_by_external_id(data_source_uuid:, external_id:) | ||
| path = build_query_path( | ||
| resource_path.path, | ||
| data_source_uuid: data_source_uuid, | ||
| external_id: external_id | ||
| ) | ||
| resp = handling_errors { connection.get(path) } | ||
| json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: immutable_keys) | ||
| new_from_json(json) | ||
| end | ||
|
|
||
| # Update a resource by data_source_uuid and external_id | ||
| # @param handle_as_user_edit [Boolean] If true, the change is treated as a user edit | ||
| def update_by_external_id!(data_source_uuid:, external_id:, handle_as_user_edit: nil, **attributes) | ||
| path = build_query_path( | ||
| resource_path.path, | ||
| data_source_uuid: data_source_uuid, | ||
| external_id: external_id, | ||
| handle_as_user_edit: handle_as_user_edit | ||
| ) | ||
| resp = handling_errors { json_patch(path, attributes) } | ||
| json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: immutable_keys) | ||
| new_from_json(json) | ||
| end | ||
|
|
||
| # Delete a resource by data_source_uuid and external_id | ||
| # @param handle_as_user_edit [Boolean] If true, the change is treated as a user edit | ||
| def destroy_by_external_id!(data_source_uuid:, external_id:, handle_as_user_edit: nil) | ||
| path = build_query_path( | ||
| resource_path.path, | ||
| data_source_uuid: data_source_uuid, | ||
| external_id: external_id, | ||
| handle_as_user_edit: handle_as_user_edit | ||
| ) | ||
| handling_errors { connection.delete(path) } | ||
| true | ||
| end | ||
|
|
||
| # Toggle disabled state of a resource by data_source_uuid and external_id | ||
| # @param handle_as_user_edit [Boolean] If true, the change is treated as a user edit | ||
| def toggle_disabled_by_external_id!(data_source_uuid:, external_id:, disabled:, handle_as_user_edit: nil) | ||
| path = build_query_path( | ||
| "#{resource_path.path}/disabled_state", | ||
| data_source_uuid: data_source_uuid, | ||
| external_id: external_id, | ||
| handle_as_user_edit: handle_as_user_edit | ||
| ) | ||
| resp = handling_errors { json_patch(path, { disabled: disabled }) } | ||
| json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: immutable_keys) | ||
| new_from_json(json) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module ChartMogul | ||
| module Concerns | ||
| # Shared toggle_disabled! instance method for resources that support disabling. | ||
| # Expects the including class to have a `uuid` attribute. | ||
| module ToggleDisabled | ||
| # Toggle the disabled state of the resource | ||
| # @param disabled [Boolean] Whether to disable the resource | ||
| # @param handle_as_user_edit [Boolean] If true, the change is treated as a user edit | ||
| # @return [self] the updated resource | ||
| def toggle_disabled!(disabled:, handle_as_user_edit: nil) | ||
| path = "#{resource_path.path}/#{uuid}/disabled_state" | ||
| path = self.class.build_query_path(path, handle_as_user_edit: handle_as_user_edit) | ||
| resp = handling_errors do | ||
| self.class.json_patch(path, { disabled: disabled }) | ||
| end | ||
| json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: self.class.immutable_keys) | ||
| assign_all_attributes(json) | ||
| self | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module ChartMogul | ||
| # JsonImport resource for bulk importing data via JSON. | ||
| # Use this to efficiently upload large datasets to a data source. | ||
| class JsonImport < APIResource | ||
| set_resource_name 'JsonImport' | ||
| set_resource_path '/v1/data_sources/:data_source_uuid/json_imports' | ||
|
|
||
| readonly_attr :id | ||
| readonly_attr :external_id | ||
| readonly_attr :status | ||
| readonly_attr :created_at | ||
| readonly_attr :updated_at | ||
| readonly_attr :error_count | ||
| readonly_attr :processed_count | ||
|
|
||
| # Create a new JSON import batch for a data source | ||
| # @param data_source_uuid [String] The UUID of the data source | ||
| # @param data [Hash] The import data (customers, plans, invoices, etc.) | ||
| def self.create!(data_source_uuid:, **data) | ||
| path = "/v1/data_sources/#{data_source_uuid}/json_imports" | ||
| resp = handling_errors do | ||
| connection.post(path) do |req| | ||
| req.headers['Content-Type'] = 'application/json' | ||
| req.body = JSON.dump(data) | ||
| end | ||
| end | ||
| json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys:) | ||
| new_from_json(json) | ||
| end | ||
|
wscourge marked this conversation as resolved.
|
||
|
|
||
| # Retrieve the status of a JSON import | ||
| # @param data_source_uuid [String] The UUID of the data source | ||
| # @param id [String, Integer] The ID of the import | ||
| def self.retrieve(data_source_uuid:, id:) | ||
| path = "/v1/data_sources/#{data_source_uuid}/json_imports/#{id}" | ||
| resp = handling_errors do | ||
| connection.get(path) | ||
| end | ||
| json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys:) | ||
| new_from_json(json) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module ChartMogul | ||
| # Standalone LineItem resource for CRUD operations on existing line items. | ||
| # Note: For creating line items on invoices, use LineItems::Subscription or LineItems::OneTime. | ||
| class LineItem < APIResource | ||
| set_resource_name 'LineItem' | ||
| set_resource_path '/v1/line_items' | ||
|
|
||
| readonly_attr :uuid | ||
| readonly_attr :disabled | ||
| readonly_attr :disabled_at | ||
| readonly_attr :disabled_by | ||
| readonly_attr :invoice_uuid | ||
| readonly_attr :subscription_uuid | ||
| readonly_attr :edit_history_summary | ||
| readonly_attr :errors | ||
|
|
||
| writeable_attr :type | ||
| writeable_attr :subscription_external_id | ||
| writeable_attr :subscription_set_external_id | ||
| writeable_attr :plan_uuid | ||
| writeable_attr :service_period_start, type: :time | ||
| writeable_attr :service_period_end, type: :time | ||
| writeable_attr :amount_in_cents | ||
| writeable_attr :quantity | ||
| writeable_attr :discount_amount_in_cents | ||
| writeable_attr :discount_code | ||
| writeable_attr :discount_description | ||
| writeable_attr :tax_amount_in_cents | ||
| writeable_attr :transaction_fees_in_cents | ||
| writeable_attr :transaction_fees_currency | ||
| writeable_attr :external_id | ||
| writeable_attr :data_source_uuid | ||
| writeable_attr :prorated | ||
| writeable_attr :proration_type | ||
| writeable_attr :cancelled_at, type: :time | ||
| writeable_attr :description | ||
| writeable_attr :account_code | ||
| writeable_attr :event_order | ||
|
|
||
| include API::Actions::Retrieve | ||
| include API::Actions::Update | ||
| include API::Actions::Destroy | ||
| include Concerns::ToggleDisabled | ||
| include Concerns::ExternalIdOperations | ||
|
|
||
| # Create a line item for an invoice | ||
| # @param handle_as_user_edit [Boolean] If true, the change is treated as a user edit | ||
| def self.create!(invoice_uuid:, handle_as_user_edit: nil, **attributes) | ||
| path = build_query_path( | ||
| "/v1/import/invoices/#{invoice_uuid}/line_items", | ||
| handle_as_user_edit: handle_as_user_edit | ||
| ) | ||
| resp = handling_errors { json_post(path, attributes) } | ||
| json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys:) | ||
| new_from_json(json) | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.