class Pinterest::Entity

Base class for entity objects.

Public Class Methods

new(data) click to toggle source

Creates a new object.

@param data [Hash] The data of the new object. @return [Pinterest::Board] The new object.

# File lib/pinterest/models/entity.rb, line 22
def initialize(data)
  data.each do |field, value|
    send("#{field}=", value) if respond_to?(field)
  end
end
parse_timestamp(timestamp) click to toggle source

Parses a timestamps.

@param timestamp [String] The string to parse. @return [DateTime] The parsed timestamp.

# File lib/pinterest/models/entity.rb, line 13
def self.parse_timestamp(timestamp)
  return nil if !timestamp || timestamp.empty?
  DateTime.parse(timestamp + "+00:00")
end

Public Instance Methods

as_json(fields, options = {}) click to toggle source

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

@param options [Hash] The options to use to serialize. @return [Hash] The serialized object.

# File lib/pinterest/models/entity.rb, line 32
def as_json(fields, options = {})
  fields.reduce({}) do |accu, field|
    value = send(field)
    value = value.as_json(options) if value.respond_to?(:as_json)

    accu[field.to_sym] = value
    accu
  end
end