class Glass::TimelineItem

Each item in the user’s timeline is represented as a TimelineItem JSON structure, described below.

Constants

DISPLAY_TIME
WRITE_TIME

Attributes

kind[R]

The type of resource. This is always mirror#timelineItem.

attachments[RW]

A list of media attachments associated with this item.

bundleId[RW]

The bundle ID for this item. Services can specify a bundleId to group many items together. They appear under a single top-level item on the device.

canonicalUrl[RW]

A canonical URL pointing to the canonical/high quality version of the data represented by the timeline item.

client[R]

The Client

created[R]

The time at which this item was created, formatted according to RFC 3339.

creator[RW]

The user or group that created this item.

displayTime[R]

The time that should be displayed when this item is viewed in the timeline, formatted according to RFC 3339. This user’s timeline is sorted chronologically on display time, so this will also determine where the item is displayed in the timeline. If not set by the service, the display time defaults to the updated time.

etag[R]

ETag for this item.

html[RW]

HTML content for this item. If both text and html are provided for an item, the html will be rendered in the timeline.

htmlPages[RW]

Additional pages of HTML content associated with this item. If this field is specified, the item will be displayed as a bundle, with the html field as the cover. It is an error to specify this field without specifying the html field.

id[RW]

The ID of the timeline item. This is unique within a user’s timeline.

inReplyTo[RW]

If this item was generated as a reply to another item, this field will be set to the ID of the item being replied to. This can be used to attach a reply to the appropriate conversation or post.

isBundleCover[RW]

Whether this item is a bundle cover.

If an item is marked as a bundle cover, it will be the entry point to the bundle of items that have the same bundleId as that item. It will be shown only on the main timeline — not within the opened bundle.

On the main timeline, items that are shown are:

Items that have isBundleCover set to true
Items that do not have a bundleId

Items that do not have a bundleId

In a bundle sub-timeline, items that are shown are:
Items that have the bundleId in question AND isBundleCover set to false
isDeleted[RW]

When true, indicates this item is deleted, and only the ID property is set.

isPinned[RW]

When true, indicates this item is pinned, which means it’s grouped alongside “active” items like navigation and hangouts, on the opposite side of the home screen from historical (non-pinned) timeline items.

location[RW]

The geographic location associated with this item.

menuItems[RW]

A list of menu items that will be presented to the user when this item is selected in the timeline.

notification[RW]

Controls how notifications for this item are presented on the device. If this is missing, no notification will be generated.

pinScore[RW]

For pinned items, this determines the order in which the item is displayed in the timeline, with a higher score appearing closer to the clock. Note: setting this field is currently not supported.

recipients[RW]

A list of contacts or groups that this item has been shared with.

sourceItemId[RW]

Opaque string you can use to map a timeline item to data in your own service.

speakableText[RW]

The speakable version of the content of this item. Along with the READ_ALOUD menu item, use this field to provide text that would be clearer when read aloud, or to provide extended information to what is displayed visually on Glass.

text[RW]

Text content of this item.

title[RW]

The title of this item.

updated[RW]

The time at which this item was last modified, formatted according to RFC 3339.

Public Class Methods

get(client, id) click to toggle source
# File lib/glass/timeline/timeline_item.rb, line 21
def get(client, id)
  client.exexute(
      :api_method => client.timeline.get,
      :parameters => {:id => id}
  )
end
list(client, params={}) click to toggle source

Retrieves a list of timeline items for the authenticated user. @param [string] bundleId

If true, tombstone records for deleted items will be returned.

@param [boolean] includeDeleted

If true, tombstone records for deleted items will be returned.

@param [integer] maxResults

The maximum number of items to include in the response, used for paging.

@param [string] orderBy

Controls the order in which timeline items are returned.
Acceptable values are:
  "displayTime": Results will be ordered by displayTime (default). This is the same ordering as is used in the timeline on the device.
  "writeTime": Results will be ordered by the time at which they were last written to the data store.

@param [string] pageToken

Token for the page of results to return.

@param [boolean] pinnedOnly

If true, only pinned items will be returned.

@param [string] sourceItemId

If provided, only items with the given sourceItemId will be returned.
# File lib/glass/timeline/timeline_item.rb, line 50
def list(client, params={})
  result=[]
  parameters = params
  api_result = client.execute(
      :api_method => mirror.timeline.list,
      :parameters => parameters)
  if api_result.success?
    data = api_result.data
    unless data.items.empty?
      result << data.items
      parameters[:pageToken]= data.next_page_token
      result << list(client, parameters)
    end
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
  result
end
new(client=nil) click to toggle source
# File lib/glass/timeline/timeline_item.rb, line 10
def initialize(client=nil)
  @client = client
end

Public Instance Methods

file_to_upload() click to toggle source
# File lib/glass/timeline/timeline_item.rb, line 389
def file_to_upload
  file_to_upload=[]
  @attachments.each { |attachment|
    file_to_upload << attachment unless attachment.id
  }
  file_to_upload
end
file_upload?() click to toggle source
# File lib/glass/timeline/timeline_item.rb, line 381
def file_upload?
  flag=false
  @attachments.each { |attachment|
    flag = true unless attachment.id
  }
  return flag
end
insert!(mirror=@client) click to toggle source

Insert a new Timeline Item in the user’s glass.

@param [Google::APIClient::API] client

Authorized client instance.

@return Array

Timeline item instance if successful, nil otherwise.
# File lib/glass/timeline/timeline_item.rb, line 359
def insert!(mirror=@client)
  timeline_item = self
  result = []
  if file_upload?
    for file in file_to_upload
      media = Google::APIClient::UploadIO.new(file.contentUrl, file.content_type)
      result << client.execute!(
          :api_method => mirror.timeline.insert,
          :body_object => timeline_item,
          :media => media,
          :parameters => {
              :uploadType => 'multipart',
              :alt => 'json'})
    end
  else
    result << client.execute(
        :api_method => mirror.timeline.insert,
        :body_object => timeline_item)
  end
  return result.data
end