glass-rails 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/glass/client.rb +24 -2
- data/lib/glass/rails/version.rb +1 -1
- data/lib/glass/subscription_notification.rb +24 -16
- data/lib/glass/timeline_item.rb +6 -5
- metadata +38 -21
- checksums.yaml +0 -15
data/lib/glass/client.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require "glass/api_keys"
|
2
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
2
3
|
require "google/api_client"
|
3
4
|
module Glass
|
4
5
|
class Client
|
5
6
|
attr_accessor :access_token, :google_client, :mirror_api,
|
6
|
-
:google_account, :refresh_token,
|
7
|
+
:google_account, :refresh_token, :content,
|
7
8
|
:mirror_content_type, :timeline_item, :has_expired_token
|
8
9
|
|
9
10
|
|
@@ -25,6 +26,7 @@ module Glass
|
|
25
26
|
### an api for those who wish to opt out of passing in a
|
26
27
|
### google account, by passing in a hash of options
|
27
28
|
###
|
29
|
+
###
|
28
30
|
### the tricky aspect of this is how to handle the update
|
29
31
|
### of the token information if the token is expired.
|
30
32
|
|
@@ -32,15 +34,27 @@ module Glass
|
|
32
34
|
self.refresh_token = opts[:refresh_token] || google_account.try(:refresh_token)
|
33
35
|
self.has_expired_token = opts[:has_expired_token] || google_account.has_expired_token?
|
34
36
|
|
35
|
-
|
36
37
|
setup_with_our_access_tokens
|
37
38
|
setup_with_user_access_token
|
38
39
|
self
|
39
40
|
end
|
41
|
+
|
42
|
+
def get_timeline_item(id)
|
43
|
+
response_hash(self.google_client.execute(get_timeline_item_parameters(id)).response)
|
44
|
+
end
|
45
|
+
def get_timeline_item_parameters(id)
|
46
|
+
{ api_method: self.mirror_api.timeline.get,
|
47
|
+
parameters: {
|
48
|
+
"id" => id
|
49
|
+
}
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
40
53
|
def set_timeline_item(timeline_object)
|
41
54
|
self.timeline_item = timeline_object
|
42
55
|
self
|
43
56
|
end
|
57
|
+
|
44
58
|
def json_content(options)
|
45
59
|
mirror_api.timeline.insert.request_schema.new(self.timeline_item.to_json.merge(options))
|
46
60
|
end
|
@@ -62,13 +76,19 @@ module Glass
|
|
62
76
|
google_client.execute(deleting_content)
|
63
77
|
end
|
64
78
|
|
79
|
+
|
80
|
+
def response_hash(google_response)
|
81
|
+
JSON.parse(google_response.body).with_indifferent_access
|
82
|
+
end
|
65
83
|
private
|
84
|
+
|
66
85
|
def setup_with_our_access_tokens
|
67
86
|
api_keys = Glass::ApiKeys.new
|
68
87
|
["client_id", "client_secret"].each do |meth|
|
69
88
|
google_client.authorization.send("#{meth}=", api_keys.send(meth))
|
70
89
|
end
|
71
90
|
end
|
91
|
+
|
72
92
|
def setup_with_user_access_token
|
73
93
|
google_client.authorization.update_token!(access_token: access_token,
|
74
94
|
refresh_token: refresh_token)
|
@@ -84,6 +104,7 @@ module Glass
|
|
84
104
|
def to_google_time(time)
|
85
105
|
Time.now.to_i + time
|
86
106
|
end
|
107
|
+
|
87
108
|
def convert_user_data(google_data_hash)
|
88
109
|
ea_data_hash = {}
|
89
110
|
ea_data_hash["token"] = google_data_hash["access_token"]
|
@@ -91,5 +112,6 @@ module Glass
|
|
91
112
|
ea_data_hash["id_token"] = google_data_hash["id_token"]
|
92
113
|
ea_data_hash
|
93
114
|
end
|
115
|
+
|
94
116
|
end
|
95
117
|
end
|
data/lib/glass/rails/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Glass
|
2
2
|
class SubscriptionNotification
|
3
|
-
attr_accessor :google_account, :params,
|
4
|
-
:user_actions
|
3
|
+
attr_accessor :google_account, :params, :collection,
|
4
|
+
:user_actions, :reply_request_hash, :glass_item_id
|
5
5
|
|
6
6
|
class VerificationError < StandardError; end
|
7
7
|
|
@@ -17,6 +17,13 @@ module Glass
|
|
17
17
|
verify_authenticity!
|
18
18
|
end
|
19
19
|
|
20
|
+
|
21
|
+
## things required to handle the notification properly
|
22
|
+
##
|
23
|
+
## 1. depending on the type of notification, we're going
|
24
|
+
## to need to get access to a timeline item
|
25
|
+
|
26
|
+
|
20
27
|
## Perform the corresponding notification actions
|
21
28
|
def handle!
|
22
29
|
if collection == "locations"
|
@@ -24,34 +31,35 @@ module Glass
|
|
24
31
|
# When your Glassware receives a location update, send a request to the glass.locations.get endpoint to retrieve the latest known location.
|
25
32
|
# Something like: google_account.handle_location_update
|
26
33
|
else
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# Something like google_account.handle_shared_item(params)
|
31
|
-
elsif has_user_action? :reply
|
32
|
-
# TODO: Someone replied to a card.
|
33
|
-
# itemId => TimelineItem which contains at least: inReplyTo (original item),
|
34
|
-
# text (text transcription of reply), and attachments
|
35
|
-
else # Custom Action or DELETE
|
36
|
-
handle_action(params[:itemId])
|
37
|
-
end
|
34
|
+
self.glass_item_id = params[:itemId]
|
35
|
+
handle_reply(params)
|
36
|
+
handle_action
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
40
|
private
|
41
|
+
def handle_reply(params)
|
42
|
+
return unless has_user_action? :reply
|
43
|
+
google_client = ::Glass::Client.new(google_account: self.google_account)
|
44
|
+
self.reply_request_hash = google_client.get_timeline_item(params[:itemId])
|
45
|
+
self.glass_item_id = reply_request_hash[:inReplyTo]
|
46
|
+
end
|
47
|
+
|
48
|
+
|
42
49
|
def has_user_action?(action)
|
43
50
|
user_actions.select{|user_action| user_action["type"].downcase == action.to_s}.first
|
44
51
|
end
|
45
52
|
|
46
53
|
## Handle actions on a timeline_item with a given id (custom actions, delete, etc.)
|
47
|
-
def handle_action
|
48
|
-
timeline_item = find_timeline_item(
|
54
|
+
def handle_action
|
55
|
+
timeline_item = find_timeline_item(self.glass_item_id)
|
49
56
|
|
50
57
|
# TODO: Should we uniq these? When glass doesn't have connection, it will queue up
|
51
58
|
# actions, so users might press the same one multiple times.
|
52
59
|
user_actions.uniq.each do |user_action|
|
53
60
|
type = user_action[:type] == "CUSTOM" ? user_action[:payload] : user_action[:type]
|
54
|
-
|
61
|
+
json_to_return = self.reply_request_hash ? self.reply_request_hash : self.params
|
62
|
+
timeline_item.send("handles_#{type.downcase}", json_to_return)
|
55
63
|
end if user_actions
|
56
64
|
end
|
57
65
|
|
data/lib/glass/timeline_item.rb
CHANGED
@@ -100,7 +100,6 @@ module Glass
|
|
100
100
|
## for this class. this will override
|
101
101
|
## defaults_template path if it is
|
102
102
|
## defined.
|
103
|
-
|
104
103
|
## end
|
105
104
|
def self.manages_templates(opts={})
|
106
105
|
self.template_manager = opts[:with] if opts[:with]
|
@@ -147,9 +146,9 @@ module Glass
|
|
147
146
|
## there in the model.
|
148
147
|
|
149
148
|
def self.defines_callback_methods(action, opts)
|
150
|
-
self.send(:define_method, "handles_#{action.to_s.underscore}") do
|
151
|
-
if self.respond_to?(opts[:
|
152
|
-
self.send(opts[:
|
149
|
+
self.send(:define_method, "handles_#{action.to_s.underscore}") do |json|
|
150
|
+
if self.respond_to?(opts[:handles_with])
|
151
|
+
self.method(opts[:handles_with]).arity > 0 ? self.send(opts[:handles_with], json) : self.send(opts[:handles_with])
|
153
152
|
else
|
154
153
|
raise MenuItemHandlerIsNotDefinedError
|
155
154
|
end
|
@@ -158,11 +157,13 @@ module Glass
|
|
158
157
|
|
159
158
|
|
160
159
|
|
161
|
-
##
|
160
|
+
## convert the menu items into hash form
|
161
|
+
## not a part of the public api.
|
162
162
|
def self.menu_items_hash
|
163
163
|
{menuItems: self.menu_items.map(&:serialize) }
|
164
164
|
end
|
165
165
|
|
166
|
+
## convert class to instance method.
|
166
167
|
## not meant to be a part of the public api.
|
167
168
|
def menu_items_hash
|
168
169
|
self.class.menu_items_hash
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glass-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Kunal Modi
|
@@ -9,39 +10,44 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
13
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: railties
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
|
-
- -
|
20
|
+
- - '>='
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: '3.1'
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
|
-
- -
|
28
|
+
- - '>='
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: '3.1'
|
28
31
|
- !ruby/object:Gem::Dependency
|
29
32
|
name: google-api-client
|
30
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
31
35
|
requirements:
|
32
|
-
- -
|
36
|
+
- - '>='
|
33
37
|
- !ruby/object:Gem::Version
|
34
38
|
version: '0'
|
35
39
|
type: :runtime
|
36
40
|
prerelease: false
|
37
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
38
43
|
requirements:
|
39
|
-
- -
|
44
|
+
- - '>='
|
40
45
|
- !ruby/object:Gem::Version
|
41
46
|
version: '0'
|
42
47
|
- !ruby/object:Gem::Dependency
|
43
48
|
name: bundler
|
44
49
|
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
45
51
|
requirements:
|
46
52
|
- - ~>
|
47
53
|
- !ruby/object:Gem::Version
|
@@ -49,6 +55,7 @@ dependencies:
|
|
49
55
|
type: :development
|
50
56
|
prerelease: false
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
52
59
|
requirements:
|
53
60
|
- - ~>
|
54
61
|
- !ruby/object:Gem::Version
|
@@ -56,62 +63,71 @@ dependencies:
|
|
56
63
|
- !ruby/object:Gem::Dependency
|
57
64
|
name: rake
|
58
65
|
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
59
67
|
requirements:
|
60
|
-
- -
|
68
|
+
- - '>='
|
61
69
|
- !ruby/object:Gem::Version
|
62
70
|
version: '0'
|
63
71
|
type: :development
|
64
72
|
prerelease: false
|
65
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
66
75
|
requirements:
|
67
|
-
- -
|
76
|
+
- - '>='
|
68
77
|
- !ruby/object:Gem::Version
|
69
78
|
version: '0'
|
70
79
|
- !ruby/object:Gem::Dependency
|
71
80
|
name: pry
|
72
81
|
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
73
83
|
requirements:
|
74
|
-
- -
|
84
|
+
- - '>='
|
75
85
|
- !ruby/object:Gem::Version
|
76
86
|
version: '0'
|
77
87
|
type: :development
|
78
88
|
prerelease: false
|
79
89
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
80
91
|
requirements:
|
81
|
-
- -
|
92
|
+
- - '>='
|
82
93
|
- !ruby/object:Gem::Version
|
83
94
|
version: '0'
|
84
95
|
- !ruby/object:Gem::Dependency
|
85
96
|
name: pry-rails
|
86
97
|
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
87
99
|
requirements:
|
88
|
-
- -
|
100
|
+
- - '>='
|
89
101
|
- !ruby/object:Gem::Version
|
90
102
|
version: '0'
|
91
103
|
type: :development
|
92
104
|
prerelease: false
|
93
105
|
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
94
107
|
requirements:
|
95
|
-
- -
|
108
|
+
- - '>='
|
96
109
|
- !ruby/object:Gem::Version
|
97
110
|
version: '0'
|
98
111
|
- !ruby/object:Gem::Dependency
|
99
112
|
name: rspec
|
100
113
|
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
101
115
|
requirements:
|
102
|
-
- -
|
116
|
+
- - '>='
|
103
117
|
- !ruby/object:Gem::Version
|
104
118
|
version: 1.5.2
|
105
119
|
type: :development
|
106
120
|
prerelease: false
|
107
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
108
123
|
requirements:
|
109
|
-
- -
|
124
|
+
- - '>='
|
110
125
|
- !ruby/object:Gem::Version
|
111
126
|
version: 1.5.2
|
112
127
|
- !ruby/object:Gem::Dependency
|
113
128
|
name: rspec-rails
|
114
129
|
requirement: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
115
131
|
requirements:
|
116
132
|
- - ~>
|
117
133
|
- !ruby/object:Gem::Version
|
@@ -119,12 +135,12 @@ dependencies:
|
|
119
135
|
type: :development
|
120
136
|
prerelease: false
|
121
137
|
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
122
139
|
requirements:
|
123
140
|
- - ~>
|
124
141
|
- !ruby/object:Gem::Version
|
125
142
|
version: 2.11.0
|
126
|
-
description:
|
127
|
-
rails. '
|
143
|
+
description: ' A framework for creating google glass applications using ruby on rails. '
|
128
144
|
email:
|
129
145
|
- kunal@thirstlabs.com
|
130
146
|
- han@therubyists.org
|
@@ -180,26 +196,27 @@ files:
|
|
180
196
|
homepage: http://thirst.github.io/glass-rails/
|
181
197
|
licenses:
|
182
198
|
- MIT
|
183
|
-
metadata: {}
|
184
199
|
post_install_message:
|
185
200
|
rdoc_options: []
|
186
201
|
require_paths:
|
187
202
|
- lib
|
188
203
|
required_ruby_version: !ruby/object:Gem::Requirement
|
204
|
+
none: false
|
189
205
|
requirements:
|
190
|
-
- -
|
206
|
+
- - '>='
|
191
207
|
- !ruby/object:Gem::Version
|
192
208
|
version: '0'
|
193
209
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
|
+
none: false
|
194
211
|
requirements:
|
195
|
-
- -
|
212
|
+
- - '>='
|
196
213
|
- !ruby/object:Gem::Version
|
197
214
|
version: '0'
|
198
215
|
requirements: []
|
199
216
|
rubyforge_project:
|
200
|
-
rubygems_version:
|
217
|
+
rubygems_version: 1.8.25
|
201
218
|
signing_key:
|
202
|
-
specification_version:
|
219
|
+
specification_version: 3
|
203
220
|
summary: A framework for creating google glass applications using ruby on rails. This
|
204
221
|
probably isn't for everyone, but we did our best to make it suitable for as many
|
205
222
|
cases as possible.
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
NzkzNjIyMWI2MTc4ZGM0M2I3NDc1NzZmNDIyNTQ4ZmMxYTc3NWVjZQ==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MTJkMmM4MzhhMTc3YmE3ZTU1YTY1NDE4YzgxZjQyN2QzMzU2NGFhZQ==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
NGM1MmYyOGMzNTMwZjIxNjExODQzMjhlNDdiYmI0NjQxMGYyNTA4YTAwN2Nh
|
10
|
-
NTI2YWJjZWQ1MjY2ZjlmYjYwNTY0Zjc3NDIyNGY1MjMxYTY0MTU3ZDliZWU3
|
11
|
-
NzViNDFmOTQyMWVmMTM5MDEyNDU2ZjMyZDNhMmU5YTQzZDU1ODQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NzM1YWUzOTRhMjA3N2M1MGJlYzU0ZWVhNzc0MjZiNzAyYmJlZDliZDNiNzE1
|
14
|
-
ZjJmNmIyMjMzNWM0YzY3MDMzMmY4OTg0MDljZmFlYWZkMDhiYjNiODYwZDlm
|
15
|
-
YzAwNDU1N2M2ZmUxYjFlMDMyYjE1MDg2ZTJhMGJlYzdkOWE5M2U=
|