Class: Pexels::Photo

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Photo

Returns a new instance of Photo.


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pexels/photo.rb', line 10

def initialize(attrs)
  @id = attrs.fetch('id')
  @height = attrs.fetch('height')
  @width = attrs.fetch('width')
  @url = attrs.fetch('url')
  @user = Pexels::User.new(
    id: attrs.fetch('photographer_id'),
    name: attrs.fetch('photographer'),
    url: attrs.fetch('photographer_url')
  )
  @src = attrs.fetch('src')
  @avg_color = attrs.fetch('avg_color')

rescue KeyError => exception
  raise Pexels::MalformedAPIResponseError.new(exception)
end

Instance Attribute Details

#avg_colorObject (readonly)

Returns the value of attribute avg_color.


2
3
4
# File 'lib/pexels/photo.rb', line 2

def avg_color
  @avg_color
end

#heightObject (readonly)

Returns the value of attribute height.


2
3
4
# File 'lib/pexels/photo.rb', line 2

def height
  @height
end

#idObject (readonly)

Returns the value of attribute id.


2
3
4
# File 'lib/pexels/photo.rb', line 2

def id
  @id
end

#srcObject (readonly)

Returns the value of attribute src.


2
3
4
# File 'lib/pexels/photo.rb', line 2

def src
  @src
end

#urlObject (readonly)

Returns the value of attribute url.


2
3
4
# File 'lib/pexels/photo.rb', line 2

def url
  @url
end

#userObject (readonly)

Returns the value of attribute user.


2
3
4
# File 'lib/pexels/photo.rb', line 2

def user
  @user
end

#widthObject (readonly)

Returns the value of attribute width.


2
3
4
# File 'lib/pexels/photo.rb', line 2

def width
  @width
end

Instance Method Details

#photo?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/pexels/photo.rb', line 31

def photo?
  true
end

#typeObject


27
28
29
# File 'lib/pexels/photo.rb', line 27

def type
  'Photo'
end

#video?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/pexels/photo.rb', line 35

def video?
  false
end