Class: ChartMogul::SubscriptionEvent

Inherits:
APIResource show all
Includes:
API::Actions::Custom, API::Actions::DestroyWithParams
Defined in:
lib/chartmogul/subscription_event.rb

Constant Summary

Constants inherited from APIResource

APIResource::BACKOFF_FACTOR, APIResource::INTERVAL, APIResource::INTERVAL_RANDOMNESS, APIResource::MAX_INTERVAL, APIResource::RETRY_EXCEPTIONS, APIResource::RETRY_STATUSES, APIResource::THREAD_CONNECTION_KEY

Class Method Summary collapse

Instance Method Summary collapse

Methods included from API::Actions::DestroyWithParams

#destroy_with_params!, included

Methods included from API::Actions::Custom

#custom!, #custom_without_assign!, included

Methods inherited from APIResource

connection, handle_other_error, handle_request_error, handling_errors, immutable_keys, set_immutable_keys, set_resource_name, set_resource_path, set_resource_root_key

Methods inherited from Object

#allowed_for_write?, #assign_all_attributes, #assign_writeable_attributes, attributes, define_private_writer, define_reader, define_writer, #initialize, #instance_attributes, new_from_json, readonly_attr, #serialize_for_write, #serialized_value_for_attr, writeable_attr, writeable_attributes

Constructor Details

This class inherits a constructor from ChartMogul::Object

Class Method Details

.all(options = {}) ⇒ Object



30
31
32
# File 'lib/chartmogul/subscription_event.rb', line 30

def self.all(options = {})
  SubscriptionEvents.all(options)
end

.create!(attributes) ⇒ Object

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.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chartmogul/subscription_event.rb', line 42

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

Instance Method Details

#create!Object



34
35
36
# File 'lib/chartmogul/subscription_event.rb', line 34

def create!
  custom!(:post, resource_path.path, subscription_event: instance_attributes)
end

#destroy!Object



58
59
60
61
62
# File 'lib/chartmogul/subscription_event.rb', line 58

def destroy!
  handling_errors do
    connection.delete(resource_path.path, subscription_event: { id: instance_attributes[:id] })
  end
end

#update!(attrs) ⇒ Object



54
55
56
# File 'lib/chartmogul/subscription_event.rb', line 54

def update!(attrs)
  custom!(:patch, resource_path.path, subscription_event: attrs.merge(id: instance_attributes[:id]))
end