Class: Craigslist::API::ImageInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/craigslist/api/image_info.rb

Overview

Metadata about an image attached to a live posting.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, filename: nil, format: nil, width: nil, height: nil, position: nil) ⇒ ImageInfo

Returns a new instance of ImageInfo.



25
26
27
28
29
30
31
32
33
# File 'lib/craigslist/api/image_info.rb', line 25

def initialize(id:, filename: nil, format: nil, width: nil, height: nil, position: nil)
  @id = id
  @filename = filename
  @format = format
  @width = width
  @height = height
  @position = position
  freeze
end

Instance Attribute Details

#filenameString? (readonly)

Returns:

  • (String, nil)


11
12
13
# File 'lib/craigslist/api/image_info.rb', line 11

def filename
  @filename
end

#formatString? (readonly)

Returns e.g. "JPEG", "GIF", "WEBP".

Returns:

  • (String, nil)

    e.g. "JPEG", "GIF", "WEBP"



14
15
16
# File 'lib/craigslist/api/image_info.rb', line 14

def format
  @format
end

#heightInteger? (readonly)

Returns:

  • (Integer, nil)


20
21
22
# File 'lib/craigslist/api/image_info.rb', line 20

def height
  @height
end

#idString (readonly)

Returns craigslist's image id, e.g. "4:00101_b1ztTgNtBAU".

Returns:

  • (String)

    craigslist's image id, e.g. "4:00101_b1ztTgNtBAU"



8
9
10
# File 'lib/craigslist/api/image_info.rb', line 8

def id
  @id
end

#positionInteger? (readonly)

Returns zero-based position within the posting.

Returns:

  • (Integer, nil)

    zero-based position within the posting



23
24
25
# File 'lib/craigslist/api/image_info.rb', line 23

def position
  @position
end

#widthInteger? (readonly)

Returns:

  • (Integer, nil)


17
18
19
# File 'lib/craigslist/api/image_info.rb', line 17

def width
  @width
end

Class Method Details

.from(hash) ⇒ ImageInfo

Parameters:

  • hash (Hash)

    raw payload

Returns:



37
38
39
40
41
42
43
44
45
46
# File 'lib/craigslist/api/image_info.rb', line 37

def self.from(hash)
  new(
    id: hash["id"],
    filename: hash["filename"],
    format: hash["format"],
    width: hash["width"],
    height: hash["height"],
    position: hash["position"]
  )
end

Instance Method Details

#inspectObject



48
49
50
# File 'lib/craigslist/api/image_info.rb', line 48

def inspect
  "#<#{self.class.name} id=#{id.inspect} position=#{position.inspect} #{width}x#{height} #{format}>"
end