Class: Glass::TimelineItem

Inherits:
Object
  • Object
show all
Defined in:
lib/glass/timeline/timeline_item.rb

Overview

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

Defined Under Namespace

Classes: Attachment, MenuItems, Notification

Constant Summary collapse

DISPLAY_TIME =
"displayTime"
WRITE_TIME =
"writeTime"
@@kind =
MIRROR+"#"+TIMELINE_ITEM

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client = nil) ⇒ TimelineItem

Returns a new instance of TimelineItem.



10
11
12
# File 'lib/glass/timeline/timeline_item.rb', line 10

def initialize(client=nil)
  @client = client
end

Class Attribute Details

.kindObject (readonly)

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



18
19
20
# File 'lib/glass/timeline/timeline_item.rb', line 18

def kind
  @kind
end

Instance Attribute Details

#attachmentsObject

A list of media attachments associated with this item.



131
132
133
# File 'lib/glass/timeline/timeline_item.rb', line 131

def attachments
  @attachments
end

#bundleIdObject

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.



165
166
167
# File 'lib/glass/timeline/timeline_item.rb', line 165

def bundleId
  @bundleId
end

#canonicalUrlObject

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



179
180
181
# File 'lib/glass/timeline/timeline_item.rb', line 179

def canonicalUrl
  @canonicalUrl
end

#clientObject (readonly)

The Client



74
75
76
# File 'lib/glass/timeline/timeline_item.rb', line 74

def client
  @client
end

#createdObject (readonly)

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



87
88
89
# File 'lib/glass/timeline/timeline_item.rb', line 87

def created
  @created
end

#creatorObject

The user or group that created this item.



110
111
112
# File 'lib/glass/timeline/timeline_item.rb', line 110

def creator
  @creator
end

#displayTimeObject (readonly)

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.



98
99
100
# File 'lib/glass/timeline/timeline_item.rb', line 98

def displayTime
  @displayTime
end

#etagObject (readonly)

ETag for this item.



106
107
108
# File 'lib/glass/timeline/timeline_item.rb', line 106

def etag
  @etag
end

#htmlObject

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



160
161
162
# File 'lib/glass/timeline/timeline_item.rb', line 160

def html
  @html
end

#htmlPagesObject

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.



171
172
173
# File 'lib/glass/timeline/timeline_item.rb', line 171

def htmlPages
  @htmlPages
end

#idObject

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



79
80
81
# File 'lib/glass/timeline/timeline_item.rb', line 79

def id
  @id
end

#inReplyToObject

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.



116
117
118
# File 'lib/glass/timeline/timeline_item.rb', line 116

def inReplyTo
  @inReplyTo
end

#isBundleCoverObject

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


195
196
197
# File 'lib/glass/timeline/timeline_item.rb', line 195

def isBundleCover
  @isBundleCover
end

#isDeletedObject

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



102
103
104
# File 'lib/glass/timeline/timeline_item.rb', line 102

def isDeleted
  @isDeleted
end

#isPinnedObject

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.



151
152
153
# File 'lib/glass/timeline/timeline_item.rb', line 151

def isPinned
  @isPinned
end

#locationObject

The geographic location associated with this item.



135
136
137
# File 'lib/glass/timeline/timeline_item.rb', line 135

def location
  @location
end

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



139
140
141
# File 'lib/glass/timeline/timeline_item.rb', line 139

def menuItems
  @menuItems
end

#notificationObject

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



144
145
146
# File 'lib/glass/timeline/timeline_item.rb', line 144

def notification
  @notification
end

#pinScoreObject

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.



200
201
202
# File 'lib/glass/timeline/timeline_item.rb', line 200

def pinScore
  @pinScore
end

#recipientsObject

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



204
205
206
# File 'lib/glass/timeline/timeline_item.rb', line 204

def recipients
  @recipients
end

A URL that can be used to retrieve this item.



83
84
85
# File 'lib/glass/timeline/timeline_item.rb', line 83

def selfLink
  @selfLink
end

#sourceItemIdObject

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



175
176
177
# File 'lib/glass/timeline/timeline_item.rb', line 175

def sourceItemId
  @sourceItemId
end

#speakableTextObject

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.



127
128
129
# File 'lib/glass/timeline/timeline_item.rb', line 127

def speakableText
  @speakableText
end

#textObject

Text content of this item.



120
121
122
# File 'lib/glass/timeline/timeline_item.rb', line 120

def text
  @text
end

#titleObject

The title of this item.



155
156
157
# File 'lib/glass/timeline/timeline_item.rb', line 155

def title
  @title
end

#updatedObject

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



91
92
93
# File 'lib/glass/timeline/timeline_item.rb', line 91

def updated
  @updated
end

Class Method Details

.get(client, id) ⇒ Object



21
22
23
24
25
26
# 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 = {}) ⇒ Object

Retrieves a list of timeline items for the authenticated user.

Parameters:

  • bundleId (string)

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

  • includeDeleted (boolean)

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

  • maxResults (integer)

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

  • orderBy (string)

    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.
    
  • pageToken (string)

    Token for the page of results to return.

  • pinnedOnly (boolean)

    If true, only pinned items will be returned.

  • sourceItemId (string)

    If provided, only items with the given sourceItemId will be returned.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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

Instance Method Details

#file_to_uploadObject



389
390
391
392
393
394
395
# 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?Boolean

Returns:

  • (Boolean)


381
382
383
384
385
386
387
# 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) ⇒ Object

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

Parameters:

  • client (Google::APIClient::API)

    Authorized client instance.



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# 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