glass-rails 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/generators/glass/model/templates/model.rb +3 -1
- data/lib/glass/client.rb +52 -14
- data/lib/glass/menu_item.rb +11 -6
- data/lib/glass/rails/version.rb +1 -1
- data/lib/glass/timeline_item.rb +54 -22
- metadata +2 -2
@@ -14,9 +14,11 @@ class Glass::<%= model_name.camelize %> < Glass::TimelineItem
|
|
14
14
|
#### for the timeline object.
|
15
15
|
####
|
16
16
|
|
17
|
+
|
17
18
|
has_menu_item :custom_action_name, display_name: "this is displayed",
|
18
19
|
icon_url: "http://icons.iconarchive.com/icons/enhancedlabs/lha-objects/128/Filetype-URL-icon.png",
|
19
|
-
handles_with: :custom_action_handler
|
20
|
+
handles_with: :custom_action_handler,
|
21
|
+
remove_when_selected: false
|
20
22
|
|
21
23
|
|
22
24
|
|
data/lib/glass/client.rb
CHANGED
@@ -55,32 +55,62 @@ module Glass
|
|
55
55
|
end
|
56
56
|
|
57
57
|
|
58
|
-
def json_content(options)
|
58
|
+
def json_content(options, api_method="insert")
|
59
59
|
if c = options[:content]
|
60
60
|
data = c.is_a?(String) ? {text: c} : c
|
61
61
|
else
|
62
62
|
data = self.timeline_item.to_json.merge(options)
|
63
63
|
end
|
64
64
|
data = format_hash_properly(data)
|
65
|
-
mirror_api.timeline.
|
65
|
+
mirror_api.timeline.send(api_method).request_schema.new(data)
|
66
66
|
end
|
67
|
-
|
68
|
-
|
67
|
+
|
68
|
+
def text_content(text, api_method="insert")
|
69
|
+
mirror_api.timeline.send(api_method).request_schema.new({text: text})
|
69
70
|
end
|
70
71
|
|
71
72
|
## optional parameter is merged into the content hash
|
72
73
|
## before sending. good for specifying more application
|
73
74
|
## specific stuff like speakableText parameters.
|
75
|
+
def rest_action(options, action="insert")
|
76
|
+
body_object = json_content(options, action)
|
77
|
+
inserting_content = { api_method: mirror_api.timeline.send(action),
|
78
|
+
body_object: body_object}
|
79
|
+
end
|
80
|
+
def get(id)
|
81
|
+
self.google_client.execute(get_timeline_item_parameters(id))
|
82
|
+
end
|
74
83
|
|
75
84
|
def insert(options={})
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
85
|
+
google_client.execute(rest_action(options, "insert"))
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def patch(options={})
|
90
|
+
glass_item_id = options.delete(:glass_item_id)
|
91
|
+
patch_action = rest_action(options, "patch").merge(parameters: {id: glass_item_id})
|
92
|
+
puts patch_action
|
93
|
+
google_client.execute(patch_action)
|
94
|
+
end
|
95
|
+
|
96
|
+
def update(timeline_item, options={})
|
97
|
+
glass_item_id = options.delete(:glass_item_id)
|
98
|
+
update_content = { api_method: mirror_api.timeline.update,
|
99
|
+
body_object: timeline_item,
|
100
|
+
parameters: {id: glass_item_id}}
|
101
|
+
google_client.execute update_content
|
80
102
|
end
|
81
103
|
|
82
|
-
|
83
|
-
|
104
|
+
|
105
|
+
|
106
|
+
## deprecated: please use cached_list instead
|
107
|
+
def timeline_list
|
108
|
+
puts "DEPRECATION WARNING: timeline_list is now deprecated, please use cached_list instead"
|
109
|
+
cached_list
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def cached_list(opts={as_hash: true})
|
84
114
|
retval = @timeline_list.nil? ? self.list(opts) : @timeline_list
|
85
115
|
opts[:as_hash] ? retval.map(&:to_hash).map(&:with_indifferent_access) : retval
|
86
116
|
end
|
@@ -115,6 +145,10 @@ module Glass
|
|
115
145
|
end while page_token.to_s != ''
|
116
146
|
timeline_list(opts)
|
117
147
|
end
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
118
152
|
def delete(options={})
|
119
153
|
deleting_content = { api_method: mirror_api.timeline.delete,
|
120
154
|
parameters: options }
|
@@ -125,6 +159,8 @@ module Glass
|
|
125
159
|
def response_hash(google_response)
|
126
160
|
JSON.parse(google_response.body).with_indifferent_access
|
127
161
|
end
|
162
|
+
|
163
|
+
|
128
164
|
private
|
129
165
|
|
130
166
|
def setup_with_our_access_tokens
|
@@ -145,10 +181,6 @@ module Glass
|
|
145
181
|
end
|
146
182
|
end
|
147
183
|
|
148
|
-
def to_google_time(time)
|
149
|
-
Time.now.to_i + time
|
150
|
-
end
|
151
|
-
|
152
184
|
def convert_user_data(google_data_hash)
|
153
185
|
ea_data_hash = {}
|
154
186
|
ea_data_hash["token"] = google_data_hash["access_token"]
|
@@ -156,12 +188,18 @@ module Glass
|
|
156
188
|
ea_data_hash["id_token"] = google_data_hash["id_token"]
|
157
189
|
ea_data_hash
|
158
190
|
end
|
191
|
+
|
192
|
+
|
193
|
+
private
|
159
194
|
def format_hash_properly(data_hash)
|
160
195
|
data_hash.inject({}) do |acc, (key, value)|
|
161
196
|
new_key = key.to_s.camelize(:lower)
|
162
197
|
acc[new_key]= (new_key == "displayTime") ? format_date(value) : value
|
163
198
|
acc
|
164
199
|
end.with_indifferent_access
|
200
|
+
end
|
201
|
+
def to_google_time(time)
|
202
|
+
Time.now.to_i + time
|
165
203
|
end
|
166
204
|
def format_date(time)
|
167
205
|
time.to_time.utc.iso8601.gsub("Z", ".000Z") # fucking google has a weird format
|
data/lib/glass/menu_item.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module Glass
|
2
2
|
class MenuItem
|
3
|
-
attr_accessor :action,
|
3
|
+
attr_accessor :action, :id, :display_name,
|
4
|
+
:icon_url, :remove_when_selected
|
5
|
+
|
6
|
+
|
4
7
|
BUILT_IN_ACTIONS = [:reply, :reply_all, :delete,
|
5
8
|
:share, :read_aloud, :voice_call,
|
6
9
|
:navigate, :toggle_pinned]
|
@@ -12,10 +15,11 @@ module Glass
|
|
12
15
|
end
|
13
16
|
|
14
17
|
def initialize(opts={})
|
15
|
-
self.action
|
16
|
-
self.id
|
17
|
-
self.display_name
|
18
|
-
self.icon_url
|
18
|
+
self.action = opts[:action] || "CUSTOM"
|
19
|
+
self.id = opts[:id]
|
20
|
+
self.display_name = opts[:display_name]
|
21
|
+
self.icon_url = opts[:icon_url]
|
22
|
+
self.remove_when_selected = opts[:remove_when_selected] || false
|
19
23
|
end
|
20
24
|
|
21
25
|
def action
|
@@ -24,7 +28,8 @@ module Glass
|
|
24
28
|
|
25
29
|
def serialize
|
26
30
|
hash = {action: action}
|
27
|
-
hash.merge!({id: id,
|
31
|
+
hash.merge!({id: id,
|
32
|
+
removeWhenSelected: remove_when_selected,
|
28
33
|
values: [{ displayName: display_name,
|
29
34
|
iconUrl: icon_url}]}) if action == "CUSTOM"
|
30
35
|
hash
|
data/lib/glass/rails/version.rb
CHANGED
data/lib/glass/timeline_item.rb
CHANGED
@@ -212,33 +212,60 @@ module Glass
|
|
212
212
|
return self
|
213
213
|
end
|
214
214
|
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
215
219
|
def insert(opts={})
|
220
|
+
puts "DEPRECATION WARNING: insert is now deprecated, please use mirror_insert instead"
|
221
|
+
mirror_insert(opts)
|
222
|
+
end
|
223
|
+
|
224
|
+
|
225
|
+
def mirror_insert(opts={})
|
216
226
|
result = client.insert(opts)
|
217
|
-
if result.error?
|
218
|
-
|
219
|
-
else
|
220
|
-
data = result.data
|
221
|
-
result_data_type = :html #default
|
222
|
-
[:html, :text].each do |result_type|
|
223
|
-
result_data_type = result_type if data.send(result_type).present?
|
224
|
-
end
|
225
|
-
self.update_attributes(glass_item_id: data.id,
|
226
|
-
glass_etag: data.etag,
|
227
|
-
glass_self_link: data.self_link,
|
228
|
-
glass_kind: data.kind,
|
229
|
-
glass_created_at: data.created,
|
230
|
-
glass_updated_at: data.updated,
|
231
|
-
glass_content_type: result_data_type,
|
232
|
-
glass_content: data.send(result_data_type))
|
233
|
-
end
|
227
|
+
raise TimelineInsertionError if result.error?
|
228
|
+
save_data(result)
|
234
229
|
end
|
235
|
-
def
|
236
|
-
|
230
|
+
def mirror_get(opts={})
|
231
|
+
self.client = Glass::Client.create(self)
|
232
|
+
result = client.get(self.glass_item_id)
|
233
|
+
save_data(result)
|
234
|
+
end
|
235
|
+
def mirror_patch(opts={})
|
236
|
+
opts.merge!(glass_item_id: self.glass_item_id)
|
237
|
+
self.client = Glass::Client.create(self)
|
238
|
+
result = client.patch(opts)
|
239
|
+
save_data(result)
|
240
|
+
end
|
241
|
+
def mirror_update(timeline_item, opts={})
|
242
|
+
opts.merge!(glass_item_id: self.glass_item_id)
|
243
|
+
self.client = Glass::Client.create(self)
|
244
|
+
result = client.update(timeline_item, opts)
|
245
|
+
save_data(result)
|
246
|
+
end
|
247
|
+
def mirror_delete
|
248
|
+
self.client = Glass::Client.create(self)
|
249
|
+
client.delete(id: self.glass_item_id)
|
250
|
+
self.update_attributes(is_deleted: true)
|
237
251
|
end
|
238
|
-
# def update(opts={})
|
239
|
-
|
240
|
-
# end
|
241
252
|
|
253
|
+
def save_data(result)
|
254
|
+
data = result.data
|
255
|
+
result_data_type = :html #default
|
256
|
+
[:html, :text].each do |result_type|
|
257
|
+
result_data_type = result_type if data.send(result_type).present?
|
258
|
+
end
|
259
|
+
self.update_attributes(glass_item_id: data.id,
|
260
|
+
glass_etag: data.etag,
|
261
|
+
glass_self_link: data.self_link,
|
262
|
+
glass_kind: data.kind,
|
263
|
+
glass_created_at: data.created,
|
264
|
+
glass_updated_at: data.updated,
|
265
|
+
glass_content_type: result_data_type,
|
266
|
+
glass_content: data.send(result_data_type))
|
267
|
+
to_indifferent_json_hash(result)
|
268
|
+
end
|
242
269
|
|
243
270
|
|
244
271
|
## this is not intended to be a part of the public api
|
@@ -256,5 +283,10 @@ module Glass
|
|
256
283
|
def has_default_template?
|
257
284
|
self.class.default_template
|
258
285
|
end
|
286
|
+
private
|
287
|
+
def to_indifferent_json_hash(obj)
|
288
|
+
JSON.parse(obj.body).with_indifferent_access
|
289
|
+
end
|
290
|
+
|
259
291
|
end
|
260
292
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glass-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-06-
|
13
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|