chartmogul-ruby 4.12.0 → 4.15.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: 60097ddd8ee68f3625128a8e6aa69f1192e9967bb50a62fbef007a99e1098f65
4
- data.tar.gz: 80985ad1c0cfaa65d4849caa30830f1fe5ca343a5321ccf4d714ea1225230370
3
+ metadata.gz: 1d40707d3a05b63c0ecadcd2a871c769840ebe77182aae281e024167b6f73337
4
+ data.tar.gz: 89ce86fbbeacdaa4236d00c5a4c2d24926ece3fb1c71b4504b10a6efd1a55f95
5
5
  SHA512:
6
- metadata.gz: 9de9ae516248fab40be9a6e5c7c3c121047ddc86cb73dca4aea6918900d9c14ec6e50c045a2d31dc703e22a68e4adf2705a2287b3c1b1b8964682664947a0688
7
- data.tar.gz: 6185d768c0966c6792c9462750ca9ba113d4bd494e4de36aa12e405d7662d1bb2dbf1422bffe1e19d0baed128ee507ea900259817a138840ddfe91bc0982834a
6
+ metadata.gz: 77f1fd6beaea8d60c4b4eb2a83a10fadb39ad67886a8a893340644de2864a56900e598a99a97b81b6700c465b8a201d320b5406b73bf86e470307fa80d771cde
7
+ data.tar.gz: f34020017620ea6d47992fef1a74db9863929cc98c6ebf3fc5f57206779de1e4f756ab39402af88704b39077873f878336dafc0bc677f48f7157023e1b36923f
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+ cd "$CLAUDE_PROJECT_DIR" || exit 0
3
+
4
+ INPUT=$(cat)
5
+ FILE=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
6
+
7
+ # Only track .rb files, skip vendored/generated paths
8
+ if [[ "$FILE" == *.rb ]] && [[ "$FILE" != */vendor/* ]] && [[ "$FILE" != */coverage/* ]]; then
9
+ TRACKER="${TMPDIR:-/tmp}/claude-edited-rb-files-${CLAUDE_HOOK_SESSION_ID:-default}"
10
+ echo "$FILE" >> "$TRACKER"
11
+ sort -u "$TRACKER" -o "$TRACKER"
12
+ fi
13
+
14
+ exit 0
@@ -0,0 +1,44 @@
1
+ #!/bin/bash
2
+ cd "$CLAUDE_PROJECT_DIR" || exit 0
3
+
4
+ TRACKER="${TMPDIR:-/tmp}/claude-edited-rb-files-${CLAUDE_HOOK_SESSION_ID:-default}"
5
+
6
+ ctx=""
7
+ had_edits=false
8
+
9
+ # Batch rubocop autocorrect on tracked files (if any were edited)
10
+ if [[ -f "$TRACKER" ]]; then
11
+ files=$(cat "$TRACKER")
12
+ rm -f "$TRACKER"
13
+
14
+ if [[ -n "$files" ]]; then
15
+ had_edits=true
16
+ rubocop_out=$(echo "$files" | xargs bundle exec rubocop -a 2>&1) || true
17
+ offenses=$(echo "$rubocop_out" | grep -E "^.+:[0-9]+:[0-9]+:" | head -20)
18
+ if [[ -n "$offenses" ]]; then
19
+ ctx+="rubocop offenses remaining after autocorrect:\n$offenses\n"
20
+ fi
21
+ fi
22
+ fi
23
+
24
+ # Only run rspec if files were edited (~1s)
25
+ if [[ "$had_edits" == true ]]; then
26
+ rspec_out=$(bundle exec rspec 2>&1)
27
+ rspec_exit=$?
28
+ if [[ $rspec_exit -ne 0 ]]; then
29
+ summary=$(echo "$rspec_out" | grep -E "[0-9]+ examples?, [0-9]+ failures?" | tail -1)
30
+ failed=$(echo "$rspec_out" | grep -E "^rspec .+" | head -10)
31
+ ctx+="rspec failed ($summary):\n$failed\n"
32
+ fi
33
+ fi
34
+
35
+ if [[ -n "$ctx" ]]; then
36
+ jq -n --arg ctx "$ctx" '{
37
+ "hookSpecificOutput": {
38
+ "hookEventName": "Stop",
39
+ "additionalContext": $ctx
40
+ }
41
+ }'
42
+ fi
43
+
44
+ exit 0
@@ -0,0 +1,42 @@
1
+ #!/bin/bash
2
+ cd "$CLAUDE_PROJECT_DIR" || exit 0
3
+
4
+ # Read session_id from hook input and persist via CLAUDE_ENV_FILE
5
+ # so the edit tracker and stop hook share the same file path
6
+ INPUT=$(cat)
7
+ SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // empty')
8
+ if [[ -n "$SESSION_ID" ]] && [[ -n "$CLAUDE_ENV_FILE" ]]; then
9
+ echo "export CLAUDE_HOOK_SESSION_ID='$SESSION_ID'" >> "$CLAUDE_ENV_FILE"
10
+ fi
11
+
12
+ ctx=""
13
+
14
+ # Warn if Gemfile.lock is missing or stale
15
+ if [[ ! -f Gemfile.lock ]]; then
16
+ ctx+="Gemfile.lock missing - run bundle install.\n"
17
+ elif [[ Gemfile -nt Gemfile.lock ]]; then
18
+ ctx+="Gemfile.lock is stale - run bundle install before testing.\n"
19
+ fi
20
+
21
+ # Warn about uncommitted changes
22
+ dirty=$(git diff --name-only 2>/dev/null | head -5)
23
+ if [[ -n "$dirty" ]]; then
24
+ ctx+="Uncommitted changes:\n$dirty\n"
25
+ fi
26
+
27
+ # Report current branch
28
+ branch=$(git branch --show-current 2>/dev/null)
29
+ if [[ -n "$branch" ]]; then
30
+ ctx+="Branch: $branch\n"
31
+ fi
32
+
33
+ if [[ -n "$ctx" ]]; then
34
+ jq -n --arg ctx "$ctx" '{
35
+ "hookSpecificOutput": {
36
+ "hookEventName": "SessionStart",
37
+ "additionalContext": $ctx
38
+ }
39
+ }'
40
+ fi
41
+
42
+ exit 0
@@ -0,0 +1,74 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(bundle install)",
5
+ "Bash(bundle exec rspec:*)",
6
+ "Bash(bundle exec rubocop:*)",
7
+ "Bash(gem build:*)",
8
+ "Bash(ruby --version)",
9
+ "Bash(git status:*)",
10
+ "Bash(git log:*)",
11
+ "Bash(git diff:*)",
12
+ "Bash(git branch:*)",
13
+ "Bash(git fetch:*)",
14
+ "Bash(git stash:*)",
15
+ "Bash(git checkout:*)",
16
+ "Bash(git add:*)",
17
+ "Bash(git commit:*)",
18
+ "Bash(git push:*)",
19
+ "Bash(git pull:*)",
20
+ "Bash(git cherry-pick:*)",
21
+ "Bash(git reset:*)",
22
+ "Bash(gh pr view:*)",
23
+ "Bash(gh pr list:*)",
24
+ "Bash(gh pr diff:*)",
25
+ "Bash(gh pr checks:*)",
26
+ "Bash(gh pr status:*)",
27
+ "Bash(gh run view:*)",
28
+ "Bash(gh run list:*)",
29
+ "Bash(gh run watch:*)",
30
+ "Bash(gh issue view:*)",
31
+ "Bash(gh issue list:*)",
32
+ "Bash(gh release view:*)",
33
+ "Bash(gh release list:*)",
34
+ "Bash(gh repo view:*)",
35
+ "Bash(gh search:*)"
36
+ ],
37
+ "deny": [
38
+ "Read(./.env*)"
39
+ ]
40
+ },
41
+ "hooks": {
42
+ "SessionStart": [
43
+ {
44
+ "hooks": [
45
+ {
46
+ "type": "command",
47
+ "command": "./.claude/hooks/session-start-setup.sh"
48
+ }
49
+ ]
50
+ }
51
+ ],
52
+ "PostToolUse": [
53
+ {
54
+ "matcher": "Edit|Write|MultiEdit",
55
+ "hooks": [
56
+ {
57
+ "type": "command",
58
+ "command": "./.claude/hooks/post-edit-lint.sh"
59
+ }
60
+ ]
61
+ }
62
+ ],
63
+ "Stop": [
64
+ {
65
+ "hooks": [
66
+ {
67
+ "type": "command",
68
+ "command": "./.claude/hooks/post-stop-validate.sh"
69
+ }
70
+ ]
71
+ }
72
+ ]
73
+ }
74
+ }
data/.gitignore CHANGED
@@ -8,6 +8,25 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  *.swp
11
+ *.gem
11
12
  vendor/bundle
12
13
  /.idea
13
14
  .DS_Store
15
+
16
+ # AI agent local/ephemeral data
17
+ .claude/plans/
18
+ .claude/memory/
19
+ .claude/worktrees/
20
+ .claude/scheduled-tasks/
21
+ .claude/settings.local.json
22
+ .claude/todos/
23
+ .claude/credentials.json
24
+ CLAUDE.local.md
25
+ .cursor/chat/
26
+ .cursor/composer/
27
+ .cursor/mcp.json
28
+ .windsurf/
29
+ .cline/
30
+ .continue/
31
+ .junie/
32
+ .aider*
data/README.md CHANGED
@@ -24,6 +24,8 @@
24
24
  |
25
25
  <b><a href="#contributing">Contributing</a></b>
26
26
  |
27
+ <b><a href="#security">Security</a></b>
28
+ |
27
29
  <b><a href="#license">License</a></b>
28
30
  </p>
29
31
 
@@ -113,12 +115,26 @@ Set it to 0 to disable it.
113
115
 
114
116
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
115
117
 
116
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
118
+ To install this gem onto your local machine, run `bundle exec rake install`.
119
+
120
+ ## Releasing
121
+
122
+ See [RELEASING.md](RELEASING.md) for the full release process.
117
123
 
118
124
  ## Contributing
119
125
 
120
126
  Bug reports and pull requests are welcome on GitHub at https://github.com/chartmogul/chartmogul-ruby.
121
127
 
128
+ ## Security
129
+
130
+ ### Verifying Releases
131
+
132
+ All releases of this library are published as [immutable GitHub Releases](https://github.com/chartmogul/chartmogul-ruby/releases) with protected tags and as a gem on [RubyGems.org](https://rubygems.org/gems/chartmogul-ruby).
133
+
134
+ To maximize supply chain security:
135
+ - **Commit your `Gemfile.lock`** to version control — it records integrity hashes for all dependencies, ensuring reproducible and tamper-evident installs
136
+ - **Verify gem checksums** with `bundle install` (Bundler 2.x+ records checksums automatically)
137
+
122
138
  ## License
123
139
 
124
140
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/changelog.md CHANGED
@@ -1,151 +1,3 @@
1
- # chartmogul-ruby Change Log
1
+ # Changelog
2
2
 
3
- ## Version 4.12.0 - Mar 16, 2026
4
- - Add `external_id` key to Contact model
5
-
6
- ## Version 4.11.0 - Jan 6, 2026
7
- - Add new API usage for Customer Subscriptions connect and disconnect
8
- - Update retrieve to accept query params
9
-
10
- ## Version 4.10.0 - Dec 22, 2025
11
- - Add fetching additional DataSource fields
12
-
13
- ## Version 4.9.0 - Nov 25, 2025
14
- - Add field subscription-set-external-id to /activities, drop support for eol rubies
15
-
16
- ## Version 4.7.1 - July 25, 2025
17
- - Fix create! and update! methods for Task (customer_uuid was omitted from payload)
18
-
19
- ## Version 4.7.0 - April 25, 2025
20
- - Adds support for Tasks (https://dev.chartmogul.com/reference/tasks)
21
-
22
- ## Version 4.6.0 - March 14, 2025
23
- - Adds support for disconnecting subscriptions
24
- - Adds support for `transaction_fees_in_cents` attribute on transactions
25
-
26
- ## Version 4.5.0 - February 19, 2025
27
- - Adds support for proration type support for LineItems Subscription
28
-
29
- ## Version 4.4.0 - October 24, 2024
30
- - Adds support for unmerging customers
31
-
32
- ## Version 4.3.0 - March 25, 2024
33
- - Adds support for Opportunities (https://dev.chartmogul.com/reference/opportunities)
34
-
35
- ## Version 4.2.0 - February 8, 2024
36
- - Add support for customer's `website_url` attribute
37
- - Add support for customer's subscription `uuid` attribute
38
-
39
- ## Version 4.1.0 - December 20, 2023
40
- - Adds support for Customer Notes
41
-
42
- ## Version 4.0.1 - November 7 2023
43
- - Add upgrade guide from v3.x to v4.x
44
-
45
- ## Version 4.0.0 - November 1 2023
46
- - Remove support for old pagination using `page` parameter.
47
- - Drop support for Ruby versions below 2.7.
48
-
49
- ## Version 3.3.1 - October 27 2023
50
- - Add support for cursor based pagination to `.all` endpoints.
51
- - Add `.next` pagination method for all supported cursor based endpoints.
52
- - Move `fixtures/` folder inside the `spec/` folder.
53
- - Update `.merge!` methods to always return `true` when successful.
54
- - Add new attributes to `ChartMogul::Customer` resource.
55
- - Do not error when the server returns an empty body from `.custom!` methods.
56
-
57
- ## Version 3.3.0 - August 14 2023
58
- - Fix an issue with creating using `SubscriptionEvents.create!(attrs)`.
59
-
60
- ## Version 3.2.0 - June 14 2023
61
- - Adds support for Faraday 2.7
62
- - Removes support for Ruby 2.3, 2.4, and 2.5
63
-
64
- ## Version 3.1.0 - Mar 30 2023
65
- - Adds support for Contacts (https://dev.chartmogul.com/reference/contacts)
66
-
67
- ## Version 3.0.2 - 22 Jun 2022
68
- - Adds percentage change support
69
-
70
- ## Version 3.0.1 - 30 May 2022
71
- - Add Subscription Events support
72
-
73
- ## Version 3.0.0 - 29 October 2021
74
- - Update ChartMogul::Configuration to use `api_key` instead of `account_token`& `secret_key` combo for authentication
75
- - Send library version as part of `User-Agent` header
76
-
77
- ## Version 2.9.0 - 3 Nov 2021
78
- - Adds post install message informing about authentication changes *& deprecation warning.
79
-
80
- ## Version 2.1.0 - 9 July 2021
81
- - Adds ChartMogul::Metrics::ActivitiesExport class to support async activities export endpoint
82
-
83
- ## Version 2.0.0 - 25 June 2021
84
- - Moves customer scoped Metrics::Activities and Metrics::Subscriptions under Metrics::Customers namespace
85
- - Adds unscoped activities API endpoint
86
-
87
- ## Version 1.7.2 - 16 March 2021
88
- - Fix bug preventing instantiating attributes on ChartMogul::Customers objects
89
-
90
- ## Version 1.7.1 - 8 March 2021
91
- - Adds amount_in_cents to payment for partial payments
92
- - Adds account API endpoint
93
-
94
- ## Version 1.6.9 - 10 December 2020
95
- - Fix ChartMogul::Customers class
96
-
97
- ## Version 1.6.8 - 1 November 2020
98
- - Add support for subscription_external_id when listing Activities
99
-
100
- ## Version 1.6.7 - 8 September 2020
101
- - Allow adding Customer custom attributes in camel case
102
-
103
- ## Version 1.5.0 - 20 February 2020
104
- - Add support for plan groups API
105
-
106
- ## Version 1.4.0 - 20 September 2019
107
- - Add support for subscription sets
108
-
109
- ## Version 1.3.1 - 6 May 2019
110
- - Add #last method to Entries
111
-
112
- ## Version 1.3.0 - 5 March 2019
113
- - Method #update_cancellation_dates added to allow users to update the cancellation dates on subscription.
114
-
115
- ## Version 1.2.2 - 21 December 2018
116
- - Added connect subscriptions method
117
-
118
- ## Version 1.2.1 - 11 September 2018
119
- - Update Faraday dependency version
120
-
121
- ## Version 1.2.0 - 15 August 2018
122
- - Rertry requests on certain statuses and allow config
123
-
124
- ## Version 1.1.8 - 22 June 2018
125
- - Fix ChartMogul::ChartMogulError class
126
-
127
- ## Version 1.0.2 - 6 March 2017
128
- - Consolidated Customer, Enrichment/Customer now deprecated
129
-
130
- ## Version 1.0.1 - 21 February 2017
131
- - Fixed all() in Customer, now returns Customers with paging
132
-
133
- ## Version 1.0.0 - 14 February 2017
134
- - Add support for new plan and data source endpoints
135
- - Remove deprecated Import namespace
136
-
137
- ## Version 0.1.4 - 10 November 2016
138
- - Add support for merging customers
139
- - Add support for updating customers
140
-
141
- ## Version 0.1.3 - 8 November 2016
142
- - Add support for lead_created_at and free_trial_started_at fields to work with Leads and Trials charts
143
-
144
- ## Version 0.1.2 - 13 July 2016
145
- - Fix bug preventing cancellation of subscriptions [#22]
146
-
147
- ## Version 0.1.1 - 4 July 2016
148
- - Version bump after 0.1.0 pushed to RubyGems under incorrect account.
149
-
150
- ## Version 0.1.0 - 4 July 2016
151
- - Initial release with support for our Import, Enrichment and Metrics APIs.
3
+ Release notes are auto-generated from merged pull request titles and published on the [GitHub Releases page](https://github.com/chartmogul/chartmogul-ruby/releases).
@@ -16,13 +16,11 @@ Gem::Specification.new do |spec|
16
16
  spec.license = 'MIT'
17
17
  spec.required_ruby_version = '>= 3.2'
18
18
 
19
- spec.post_install_message = %q{
20
- Starting October 29 2021, we are updating our developer libraries to support the enhanced API Access Management. Please use the same API Key for both API Token and Secret Key.
21
- [Deprecation] - account_token/secret_key combo is deprecated. Please use API key for both fields.
22
- Version 3.x will introduce a breaking change in authentication configuration. For more details, please visit: https://dev.chartmogul.com/docs/authentication
23
- }
24
-
25
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features|\.github)/}) ||
21
+ f.match(/\A(AGENTS|CLAUDE|RELEASING)\.md\z/) ||
22
+ f == 'bin/release.sh'
23
+ end
26
24
  spec.bindir = 'exe'
27
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
26
  spec.require_paths = ['lib']
@@ -5,15 +5,28 @@ module ChartMogul
5
5
  set_resource_name 'Account'
6
6
  set_resource_path '/v1/account'
7
7
 
8
+ readonly_attr :id
8
9
  readonly_attr :name
9
10
  readonly_attr :currency
10
11
  readonly_attr :time_zone
11
12
  readonly_attr :week_start_on
12
13
 
14
+ # Optional attributes returned when using the include parameter
15
+ readonly_attr :churn_recognition
16
+ readonly_attr :churn_when_zero_mrr
17
+ readonly_attr :auto_churn_subscription
18
+ readonly_attr :refund_handling
19
+ readonly_attr :proximate_movement_reclassification
20
+
13
21
  include API::Actions::Custom
14
22
 
15
- def self.retrieve
16
- custom!(:get, '/v1/account')
23
+ def self.retrieve(include: nil)
24
+ path = '/v1/account'
25
+ if include
26
+ fields = Array(include).map { |f| CGI.escape(f) }.join(',')
27
+ path += "?include=#{fields}"
28
+ end
29
+ custom!(:get, path)
17
30
  end
18
31
  end
19
32
  end
@@ -16,7 +16,8 @@ module ChartMogul
16
16
  end
17
17
  end
18
18
 
19
- json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: self.class.immutable_keys)
19
+ parsed_body = resp.body.empty? ? '{}' : resp.body
20
+ json = ChartMogul::Utils::JSONParser.parse(parsed_body, immutable_keys: self.class.immutable_keys)
20
21
 
21
22
  assign_all_attributes(json)
22
23
  end
@@ -31,7 +32,8 @@ module ChartMogul
31
32
  req.body = JSON.dump(resource.serialize_for_write)
32
33
  end
33
34
  end
34
- json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: immutable_keys)
35
+ parsed_body = resp.body.empty? ? '{}' : resp.body
36
+ json = ChartMogul::Utils::JSONParser.parse(parsed_body, immutable_keys: immutable_keys)
35
37
 
36
38
  new_from_json(json)
37
39
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "cgi"
4
+ require "uri"
3
5
  require "forwardable"
4
6
  require "set"
5
7
 
@@ -162,6 +164,39 @@ module ChartMogul
162
164
  custom!(http_method, path, attrs)
163
165
  end
164
166
 
167
+ # Build a URL path with query parameters, handling ? vs & correctly
168
+ def self.build_query_path(base_path, **params)
169
+ filtered = params.compact
170
+ return base_path if filtered.empty?
171
+
172
+ separator = base_path.include?("?") ? "&" : "?"
173
+ "#{base_path}#{separator}#{URI.encode_www_form(filtered)}"
174
+ end
175
+
176
+ # Convenience for JSON PATCH requests
177
+ def self.json_patch(path, body)
178
+ connection.patch(path) do |req|
179
+ req.headers["Content-Type"] = "application/json"
180
+ req.body = JSON.dump(body)
181
+ end
182
+ end
183
+
184
+ # Convenience for JSON PUT requests
185
+ def self.json_put(path, body)
186
+ connection.put(path) do |req|
187
+ req.headers["Content-Type"] = "application/json"
188
+ req.body = JSON.dump(body)
189
+ end
190
+ end
191
+
192
+ # Convenience for JSON POST requests
193
+ def self.json_post(path, body)
194
+ connection.post(path) do |req|
195
+ req.headers["Content-Type"] = "application/json"
196
+ req.body = JSON.dump(body)
197
+ end
198
+ end
199
+
165
200
  def self.build_connection
166
201
  Faraday.new(url: ChartMogul.api_base,
167
202
  headers: { "User-Agent" => "chartmogul-ruby/#{ChartMogul::VERSION}" }) do |faraday|
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChartMogul
4
+ module Concerns
5
+ # Shared class methods for resources that support CRUD by data_source_uuid + external_id.
6
+ # These resources use query-parameter-based lookups (not path-based).
7
+ module ExternalIdOperations
8
+ def self.included(base)
9
+ base.extend ClassMethods
10
+ end
11
+
12
+ module ClassMethods
13
+ # Retrieve a resource by data_source_uuid and external_id
14
+ def retrieve_by_external_id(data_source_uuid:, external_id:)
15
+ path = build_query_path(
16
+ resource_path.path,
17
+ data_source_uuid: data_source_uuid,
18
+ external_id: external_id
19
+ )
20
+ resp = handling_errors { connection.get(path) }
21
+ json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: immutable_keys)
22
+ new_from_json(json)
23
+ end
24
+
25
+ # Update a resource by data_source_uuid and external_id
26
+ # @param handle_as_user_edit [Boolean] If true, the change is treated as a user edit
27
+ def update_by_external_id!(data_source_uuid:, external_id:, handle_as_user_edit: nil, **attributes)
28
+ path = build_query_path(
29
+ resource_path.path,
30
+ data_source_uuid: data_source_uuid,
31
+ external_id: external_id,
32
+ handle_as_user_edit: handle_as_user_edit
33
+ )
34
+ resp = handling_errors { json_patch(path, attributes) }
35
+ json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: immutable_keys)
36
+ new_from_json(json)
37
+ end
38
+
39
+ # Delete a resource by data_source_uuid and external_id
40
+ # @param handle_as_user_edit [Boolean] If true, the change is treated as a user edit
41
+ def destroy_by_external_id!(data_source_uuid:, external_id:, handle_as_user_edit: nil)
42
+ path = build_query_path(
43
+ resource_path.path,
44
+ data_source_uuid: data_source_uuid,
45
+ external_id: external_id,
46
+ handle_as_user_edit: handle_as_user_edit
47
+ )
48
+ handling_errors { connection.delete(path) }
49
+ true
50
+ end
51
+
52
+ # Toggle disabled state of a resource by data_source_uuid and external_id
53
+ # @param handle_as_user_edit [Boolean] If true, the change is treated as a user edit
54
+ def toggle_disabled_by_external_id!(data_source_uuid:, external_id:, disabled:, handle_as_user_edit: nil)
55
+ path = build_query_path(
56
+ "#{resource_path.path}/disabled_state",
57
+ data_source_uuid: data_source_uuid,
58
+ external_id: external_id,
59
+ handle_as_user_edit: handle_as_user_edit
60
+ )
61
+ resp = handling_errors { json_patch(path, { disabled: disabled }) }
62
+ json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: immutable_keys)
63
+ new_from_json(json)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChartMogul
4
+ module Concerns
5
+ # Shared toggle_disabled! instance method for resources that support disabling.
6
+ # Expects the including class to have a `uuid` attribute.
7
+ module ToggleDisabled
8
+ # Toggle the disabled state of the resource
9
+ # @param disabled [Boolean] Whether to disable the resource
10
+ # @param handle_as_user_edit [Boolean] If true, the change is treated as a user edit
11
+ # @return [self] the updated resource
12
+ def toggle_disabled!(disabled:, handle_as_user_edit: nil)
13
+ path = "#{resource_path.path}/#{uuid}/disabled_state"
14
+ path = self.class.build_query_path(path, handle_as_user_edit: handle_as_user_edit)
15
+ resp = handling_errors do
16
+ self.class.json_patch(path, { disabled: disabled })
17
+ end
18
+ json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: self.class.immutable_keys)
19
+ assign_all_attributes(json)
20
+ self
21
+ end
22
+ end
23
+ end
24
+ end