Class: Clubhouse::Comment

Inherits:
BaseResource show all
Defined in:
lib/clubhouse/comment.rb

Instance Attribute Summary

Attributes inherited from BaseResource

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseResource

attributes, attributes_for_create, attributes_for_update, client, #initialize, resource, #update_object_from_payload

Constructor Details

This class inherits a constructor from Clubhouse::BaseResource

Class Method Details

.allObject



39
40
41
42
# File 'lib/clubhouse/comment.rb', line 39

def all
  raise NotSupportedByAPIError,
    "You can get all comments associated directly from the story model"
end

.delete(story_id, comment_id) ⇒ Object



35
36
37
# File 'lib/clubhouse/comment.rb', line 35

def delete(story_id, comment_id)
  client.delete("stories/#{story_id}/#{endpoint}/#{comment_id}")
end

.find(story_id, comment_id) ⇒ Object



30
31
32
33
# File 'lib/clubhouse/comment.rb', line 30

def find(story_id, comment_id)
  payload = client.get("stories/#{story_id}/#{endpoint}/#{comment_id}")
  new.update_object_from_payload(payload)
end

Instance Method Details

#reloadObject



24
25
26
27
# File 'lib/clubhouse/comment.rb', line 24

def reload
  payload = client.get("stories/#{story_id}/#{self.class.endpoint}/#{id}")
  update_object_from_payload(payload)
end

#saveObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/clubhouse/comment.rb', line 11

def save
  raise MissingStoryIDError, 'story_id is required to create/update comments' unless story_id
  raise ClientNotSetup, "A default client or instance client is not setup" unless client

  payload = if id
              client.put("stories/#{story_id}/#{self.class.endpoint}/#{id}", update_attributes)
            else
              client.post("stories/#{story_id}/#{self.class.endpoint}", create_attributes)
            end

  update_object_from_payload(payload)
end