Skip to content

Commit

Permalink
fix creating SubscriptionEvent through .create!(attrs) (#140)
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Vieira <bruno@chartmogul.com>
  • Loading branch information
Bruno Vieira authored Aug 14, 2023
1 parent 5a80acd commit 89e78b9
Show file tree
Hide file tree
Showing 4 changed files with 383 additions and 2 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions lib/chartmogul/subscription_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ def create!
custom!(:post, resource_path.path, subscription_event: instance_attributes)
end

# This endpoint requires we send the attributes as:
# { subscription_event: { key: value }}
# So we do not include the API::Actions::Create module here and rather use a
# variation of the method there to accommodate this difference in behaviour.
def self.create!(attributes)
resp = handling_errors do
connection.post(resource_path.path) do |req|
req.headers['Content-Type'] = 'application/json'
req.body = JSON.dump({ subscription_event: attributes })
end
end
json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: immutable_keys)

new_from_json(json)
end

def update!(attrs)
custom!(:patch, resource_path.path, subscription_event: attrs.merge(id: instance_attributes[:id]))
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chartmogul/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ChartMogul
VERSION = '3.2.0'
VERSION = '3.3.0'
end
Loading

0 comments on commit 89e78b9

Please sign in to comment.