Class: Fulcrum::Photo

Inherits:
Api
  • Object
show all
Defined in:
lib/fulcrum/photo.rb

Constant Summary collapse

ALLOWED_FORMATS =
%w(jpg json)

Constants inherited from Api

Api::VALID_METHODS

Instance Attribute Summary

Attributes inherited from Api

#configuration, #connection, #response

Class Method Summary collapse

Methods inherited from Api

call, configuration, configure, connection, get_key, key, parse_opts, response, uri

Class Method Details

.create(file, content_type, id, label = '') ⇒ Object



18
19
20
21
# File 'lib/fulcrum/photo.rb', line 18

def create(file, content_type, id, label = '')
  photo = Faraday::UploadIO.new(file, content_type)
  call(:post, 'photos.json', { photo: { file: photo, access_key: id, label: label}})
end

.delete(id) ⇒ Object



23
24
25
# File 'lib/fulcrum/photo.rb', line 23

def delete(id)
  call(:delete, "photos/#{id}.json")
end

.find(id, opts = {}) ⇒ Object



8
9
10
11
# File 'lib/fulcrum/photo.rb', line 8

def find(id, opts = {})
  format = image_opts(opts)
  call(:get, "photos/#{id}.#{format}")
end

.image_opts(opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
32
# File 'lib/fulcrum/photo.rb', line 27

def image_opts(opts = {})
  opts = opts.with_indifferent_access
  format = opts.delete(:format) || 'json'
  raise ArgumentError, "#{format} is not an allowed format, use either 'json' or 'jpg'" unless ALLOWED_FORMATS.include?(format)
  format
end

.thumbnail(id, opts = {}) ⇒ Object



13
14
15
16
# File 'lib/fulcrum/photo.rb', line 13

def thumbnail(id, opts = {})
  format = image_opts(opts)
  call(:get, "photos/#{id}/thumbnail.#{format}")
end