Class: HangoutsJsonParser::Attachment::Photo

Inherits:
Attachment
  • Object
show all
Defined in:
lib/hangouts_json_parser/attachment/photo.rb

Overview

A photo attachment

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, album, photo_link, thumbnail, url) ⇒ Photo

Returns a new instance of Photo.



16
17
18
19
20
21
22
# File 'lib/hangouts_json_parser/attachment/photo.rb', line 16

def initialize id, album, photo_link, thumbnail, url
	@album = album
	@id = id
	@photo_link = photo_link
	@thumbnail = thumbnail
	@url = url
end

Instance Attribute Details

#albumString (readonly)

Returns album ID that the photo is in.

Returns:

  • (String)

    album ID that the photo is in



8
9
10
# File 'lib/hangouts_json_parser/attachment/photo.rb', line 8

def album
  @album
end

#idString (readonly)

Returns photo ID.

Returns:

  • (String)

    photo ID



6
7
8
# File 'lib/hangouts_json_parser/attachment/photo.rb', line 6

def id
  @id
end

Returns link to the photo on Google+.

Returns:

  • (String)

    link to the photo on Google+



10
11
12
# File 'lib/hangouts_json_parser/attachment/photo.rb', line 10

def photo_link
  @photo_link
end

#thumbnailString (readonly)

Returns URL to thumbnail of the image.

Returns:

  • (String)

    URL to thumbnail of the image



12
13
14
# File 'lib/hangouts_json_parser/attachment/photo.rb', line 12

def thumbnail
  @thumbnail
end

#urlString (readonly)

Returns URL of the image.

Returns:

  • (String)

    URL of the image



14
15
16
# File 'lib/hangouts_json_parser/attachment/photo.rb', line 14

def url
  @url
end

Class Method Details

.from_message_attachment(data) ⇒ Photo

Creates a Photo from message data

Parameters:

  • data (Hash)

    attachment data

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hangouts_json_parser/attachment/photo.rb', line 27

def self.from_message_attachment data
	raise "Attachment passed is not a photo" unless data.dig("embed_item", "type").eql? Photo.type

	photo = data.dig("embed_item", "embeds.PlusPhoto.plus_photo")
	raise "Photo data not found" if photo.nil?

	Photo.new photo["photo_id"],
				photo["album_id"],
				photo.dig("thumbnail", "url"),
				photo.dig("thumbnail", "image_url"),
				photo["url"]
end

.typeArray

Returns type identifier of this attachment.

Returns:

  • (Array)

    type identifier of this attachment



41
42
43
# File 'lib/hangouts_json_parser/attachment/photo.rb', line 41

def self.type
	["PLUS_PHOTO"]
end