Module: Kippt::CollectionResource

Includes:
ReadCollectionResource
Included in:
Clips, Comments, Favorites, Likes, Lists, UserLists
Defined in:
lib/kippt/collection_resource.rb

Defined Under Namespace

Classes: SaveResponse

Instance Method Summary collapse

Methods included from ReadCollectionResource

#[], #fetch

Instance Method Details

#build(attributes = {}) ⇒ Object



30
31
32
# File 'lib/kippt/collection_resource.rb', line 30

def build(attributes = {})
  object_class.new(attributes, client)
end

#create(attributes = {}) ⇒ Object



34
35
36
# File 'lib/kippt/collection_resource.rb', line 34

def create(attributes = {})
  build(attributes).save
end

#destroy_resource(resource) ⇒ Object



48
49
50
51
52
# File 'lib/kippt/collection_resource.rb', line 48

def destroy_resource(resource)
  if resource.id
    client.delete("#{base_uri}/#{resource.id}").success?
  end
end

#save_resource(object) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/kippt/collection_resource.rb', line 38

def save_resource(object)
  if object.id
    response = client.put("#{base_uri}/#{object.id}", :data => writable_parameters_from(object))
  else
    response = client.post("#{base_uri}", :data => writable_parameters_from(object))
  end

  SaveResponse.new(response)
end