Module: Catch::Comment

Included in:
Client
Defined in:
lib/catch/comment.rb

Instance Method Summary collapse

Instance Method Details

#add_comment(note_id, params = {}) ⇒ Object

Adds a new comment to a note.

Parameters:

  • note_id (Integer)

    Note ID

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :source (String)

    Source (application) which created the comment.

  • :text (String)

    The text of the comment

  • :created_at (DateTime)

    Date at which the comment was created.

  • :modified_at (DateTime)

    Date of last modification

  • :server_modified_at (DateTime)

    Providing the server_modified_at timestamp will ensure that the object being modified is not out of date.



33
34
35
36
37
# File 'lib/catch/comment.rb', line 33

def add_comment(note_id, params={})
  payload = params.map {|k,v| "#{k}=#{v}"}.join("&")
  response = connection.post "comments/#{note_id}", payload
  response.body.notes.first
end

#comment(note_id, comment_id) ⇒ Object

Retrieves a single comment from the server.

Parameters:

  • note_id (Integer)

    Note ID

  • comment_id (Integer)

    Comment ID



17
18
19
20
21
22
23
# File 'lib/catch/comment.rb', line 17

def comment(note_id, comment_id)
  params = {:comment => comment_id}
  connection.get do |req|
    req.url("comment/#{note_id}")
    req.params.merge!(params)
  end.body.notes.first
end

#comments(note_id) ⇒ Object

Retrieve a list of all comments for a note.

Parameters:

  • note_id (Integer)

    Note ID



7
8
9
10
11
# File 'lib/catch/comment.rb', line 7

def comments(note_id)
  connection.get do |req|
    req.url("comments/#{note_id}")
  end.body.notes
end

#delete_comment(note_id, comment_id) ⇒ Object

Remove a single comment from a note.

Parameters:

  • note_id (Integer)

    Note ID

  • comment_id (Integer)

    Comment ID



62
63
64
# File 'lib/catch/comment.rb', line 62

def delete_comment(note_id, comment_id)
  connection.delete("comments/#{note_id}?comment=#{comment_id}").body.status == 'ok'
end

#modify_comment(note_id, comment_id, params = {}) ⇒ Object

Edits an existing comment.

Parameters:

  • note_id (Integer)

    Note ID

  • comment_id (Integer)

    Comment ID

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :source (String)

    Source (application) which created the comment.

  • :text (String)

    The text of the comment

  • :created_at (DateTime)

    Date at which the comment was created.

  • :modified_at (DateTime)

    Date of last modification

  • :server_modified_at (DateTime)

    Providing the server_modified_at timestamp will ensure that the object being modified is not out of date.



48
49
50
51
52
53
54
55
56
# File 'lib/catch/comment.rb', line 48

def modify_comment(note_id, comment_id, params={})
  payload = {:comment => comment_id }
  payload.merge! params

  response = connection.post do |req|
    req.url("comments/#{note_id}")
    req.params.merge!(payload)
  end.body.notes.first
end