Class: Pinterest::Pin

Inherits:
Entity
  • Object
show all
Defined in:
lib/pinterest/models/pin.rb

Overview

A object representing a Pinterest pin.

Constant Summary collapse

FIELDS =

The list of fields of the object.

["id", "link", "url", "creator", "board", "created_at", "note", "color", "counts", "media", "attribution", "image"].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#initialize, parse_timestamp

Constructor Details

This class inherits a constructor from Pinterest::Entity

Class Method Details

.create(data) ⇒ Pinterest::Board

Creates a new pin object.

Parameters:

  • data (Hash)

    The data of the new object. For a list of valid fields, see Pinterest::Pin::FIELDS.

Returns:



18
19
20
21
22
# File 'lib/pinterest/models/pin.rb', line 18

def self.create(data)
  data["created_at"] = Pinterest::Entity.parse_timestamp(data["created_at"]) if data["created_at"]
  data = create_relationships(data)
  new(data)
end

.create_relationships(data) ⇒ Hash

Converts the relationships (user, board, images) of the pin to a gem object.

Parameters:

  • data (Hash)

    The raw data.

Returns:

  • (Hash)

    The input data where relationships are gem objects.



28
29
30
31
32
33
# File 'lib/pinterest/models/pin.rb', line 28

def self.create_relationships(data)
  data["creator"] = Pinterest::User.create(data["creator"]) if data["creator"]
  data["board"] = Pinterest::Board.create(data["board"]) if data["board"]
  data["image"] = Pinterest::Image.new(data["image"]) if data["image"]
  data
end

Instance Method Details

#as_json(options = {}) ⇒ Hash

Serialize the object as a Hash that can be serialized as JSON.

Parameters:

  • options (Hash) (defaults to: {})

    The options to use to serialize.

Returns:

  • (Hash)

    The serialized object.



39
40
41
# File 'lib/pinterest/models/pin.rb', line 39

def as_json(options = {})
  super(::Pinterest::Pin::FIELDS, options)
end