Module: Supercast::Operations::Save

Included in:
Channel, Creator, Episode, Role, Subscriber
Defined in:
lib/supercast/operations/save.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



57
58
59
# File 'lib/supercast/operations/save.rb', line 57

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#save(params = {}, opts = {}) ⇒ Object

Creates or updates an API resource.

If the resource doesn’t yet have an assigned ID and the resource is one that can be created, then the method attempts to create the resource. The resource is updated otherwise.

Attributes

  • params - Overrides any parameters in the resource’s serialized data and includes them in the create or update. If :req_url: is included in the list, it overrides the update URL used for the create or update.

  • opts - A Hash of additional options (separate from the params / object values) to be added to the request.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/supercast/operations/save.rb', line 41

def save(params = {}, opts = {})
  update_attributes(params)

  # Now remove any parameters that look like object attributes.
  params = params.reject { |k, _| respond_to?(k) }

  values = serialize_params(self).merge(params)

  # note that id gets removed here our call to #url above has already
  # generated a uri for this object with an identifier baked in
  values.delete(:id)

  resp, opts = request(save_verb, save_url, Hash[object_name => values], opts)
  initialize_from(resp.data, opts)
end