Method: ClientSuccess::Subscription#create

Defined in:
lib/client_success/subscription.rb

#create(attributes:, connection:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/client_success/subscription.rb', line 12

def create(attributes:, connection:)
  body = Schema::Subscription::Create[attributes]
    .deep_transform_keys { |k| k.to_s.camelize(:lower) }
    .to_json

  response = connection.post(
    "/v1/subscriptions", body)

  if response.body.blank?
    raise InvalidAttributes, "subscription has invalid attributes"
  else
    payload = response.body
    DomainModel::Subscription.new(
      payload.deep_transform_keys(&:underscore))
  end
end