Module: Catch::Media

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

Instance Method Summary collapse

Instance Method Details

#add_media(id, filepath, params = {}) ⇒ Object

Adds a file to a note.

Parameters:

  • note_id (Integer)

    Note ID

  • filepath (String)

    The full path to the file to add to the note

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

    a customizable set of options

Options Hash (params):

  • :content_type (String)

    The content type

  • :content_type (String)

    The content type

  • :voicenote_hunt (Boolean)

    If this media is a voicenote

  • :created_at (DateTime)

    Date at which the comment was created.

  • :server_modified_at (DateTime)

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



13
14
15
16
17
# File 'lib/catch/media.rb', line 13

def add_media(id, filepath, params={})
  params.merge!({:data => Faraday::UploadIO.new(filepath, 'image/jpeg')})

  connection.put("media/#{id}", params).body
end

#delete_media(note_id, media_id) ⇒ Object

Deletes a file attachment from a note

Parameters:

  • note_id (Integer)

    Note ID

  • media_id (String)

    Media ID



39
40
41
# File 'lib/catch/media.rb', line 39

def delete_media(note_id, media_id)
  connection.delete("media/#{note_id}/#{media_id}").body.status == 'ok'
end

#media(note_id, media_id, params = {}) ⇒ Object

Return the media file

small images are at most 128 pixels in the longer dimension. medium images are at most 800 pixels in the longer dimension. large images are at most 9999 pixels in the longer dimension.

Parameters:

  • note_id (Integer)

    Note ID

  • media_id (String)

    Media ID

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

    a customizable set of options

Options Hash (params):

  • :size (String)

    For images, the size to which to scale the image.

  • :original (boolean)

    For images whether or not to return the original unscaled image. The scaling process removes all additional metadata, including EXIF geocoding. You must use this flag if you want to retain such data.



28
29
30
31
32
33
# File 'lib/catch/media.rb', line 28

def media(note_id, media_id, params={})
  media_connection.get do |req|
    req.url("media/#{note_id}/#{media_id}")
    req.params.merge!(params)
  end.body
end