Class: Snapfish::Asset

Inherits:
Base
  • Object
show all
Defined in:
lib/snapfish/asset.rb

Instance Attribute Summary

Attributes inherited from Base

#json

Instance Method Summary collapse

Methods inherited from Base

connection, connection=, #created_at, #initialize, #updated_at

Constructor Details

This class inherits a constructor from Snapfish::Base

Instance Method Details

#as_json(options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/snapfish/asset.rb', line 42

def as_json(options = {})
  {
    id: id,
    ref: snapfish_ref,
    filename: filename,
    file_extension: file_extension,
    width: width,
    height: height,
    size: size,
    caption: caption,
    url: hires_url
  }
end

#captionObject



30
31
32
# File 'lib/snapfish/asset.rb', line 30

def caption
  extract_tag('userTags', 'caption')
end

#file_extensionObject



34
35
36
# File 'lib/snapfish/asset.rb', line 34

def file_extension
  File.extname(hires_url).downcase.gsub(/^\./, '')
end

#filenameObject



11
12
13
14
15
16
# File 'lib/snapfish/asset.rb', line 11

def filename
   = extract_tag('systemTags', 'OS_METADATA')
  if  &&  = ['value']
    .match(/os.fn=(\S+)/)[1]
  end
end

#heightObject



26
27
28
# File 'lib/snapfish/asset.rb', line 26

def height
  find_file('HIRES')['height']
end

#hires_urlObject



38
39
40
# File 'lib/snapfish/asset.rb', line 38

def hires_url
  find_file('HIRES')['url']
end

#idObject



3
4
5
# File 'lib/snapfish/asset.rb', line 3

def id
  json['_id']
end

#sizeObject



18
19
20
# File 'lib/snapfish/asset.rb', line 18

def size
  json['files'].first['size']
end

#snapfish_refObject



7
8
9
# File 'lib/snapfish/asset.rb', line 7

def snapfish_ref
  find_file('THUMBNAIL')['url']
end

#widthObject



22
23
24
# File 'lib/snapfish/asset.rb', line 22

def width
  find_file('HIRES')['width']
end