glass-rails 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/glass/install/templates/initializer.rb +0 -3
- data/lib/glass.rb +1 -1
- data/lib/glass/client.rb +19 -1
- data/lib/glass/rails/version.rb +1 -1
- data/lib/glass/subscription.rb +4 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37b56305c29a9db73a5ada1a75300f60068973ac
|
4
|
+
data.tar.gz: bf7de7f146ee006b4b127b7b6d481c4ed4d3247b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e1d1e03191e5d4d4137559d6d33e8aa7f2a1cb9cfbb40aa6a54ecdab737376cf89a2098db99f71e002a47c5a8bc630cacec14a0df339c26c36b58556e73f25d
|
7
|
+
data.tar.gz: 46f57ec672c8d5470e399bacafae9d9273aab99d430808fccd4023ec6f745406e696cb16ebf03898e9d463a737a4f667be923d2381e92429381b53381cbac62f
|
@@ -14,12 +14,10 @@ Glass.setup do |config|
|
|
14
14
|
## config.application_name = "SomeGlassApp"
|
15
15
|
|
16
16
|
|
17
|
-
|
18
17
|
# modify this to change the application version of your glass app
|
19
18
|
## config.application_version = "0.0.1"
|
20
19
|
|
21
20
|
|
22
|
-
|
23
21
|
# if you don't want to use a yaml file to load your api
|
24
22
|
# keys, then you can use these config vars to force load
|
25
23
|
# your keys from enviroment variables, or whatever method
|
@@ -29,7 +27,6 @@ Glass.setup do |config|
|
|
29
27
|
## config.client_secret = ENV["GOOGLE_CLIENT_SECRET"]
|
30
28
|
|
31
29
|
|
32
|
-
|
33
30
|
## manually override your glass views path here.
|
34
31
|
config.glass_template_path = "app/views/glass"
|
35
32
|
end
|
data/lib/glass.rb
CHANGED
@@ -4,7 +4,7 @@ require 'active_support/dependencies'
|
|
4
4
|
require 'glass/rails/version'
|
5
5
|
|
6
6
|
module Glass
|
7
|
-
|
7
|
+
DEVELOPMENT_PROXY_URL = "https://mirrornotifications.appspot.com/forward?url="
|
8
8
|
mattr_accessor :application_name
|
9
9
|
application_name = (defined?(::Rails) && ::Rails.application) ? ::Rails.application.class.name.split('::').first : "SomeGlassApp"
|
10
10
|
@@application_name = application_name
|
data/lib/glass/client.rb
CHANGED
@@ -7,6 +7,7 @@ module Glass
|
|
7
7
|
:google_account, :refresh_token, :content,
|
8
8
|
:mirror_content_type, :timeline_item, :has_expired_token,
|
9
9
|
:api_keys, :timeline_list
|
10
|
+
attr_writer :callback_url
|
10
11
|
|
11
12
|
def self.create(timeline_item, opts={})
|
12
13
|
client = new(opts.merge({google_account: timeline_item.google_account}))
|
@@ -18,6 +19,11 @@ module Glass
|
|
18
19
|
setup_google_api_keys
|
19
20
|
initialize_google_client
|
20
21
|
self.google_account = opts[:google_account]
|
22
|
+
|
23
|
+
self.access_token = opts[:access_token] || google_account.try(:token)
|
24
|
+
self.refresh_token = opts[:refresh_token] || google_account.try(:refresh_token)
|
25
|
+
self.has_expired_token = opts[:has_expired_token] || google_account.has_expired_token?
|
26
|
+
|
21
27
|
setup_with_our_access_tokens
|
22
28
|
setup_with_user_access_token
|
23
29
|
self
|
@@ -35,6 +41,18 @@ module Glass
|
|
35
41
|
}
|
36
42
|
end
|
37
43
|
|
44
|
+
def callback_url
|
45
|
+
if ::Rails.env.production?
|
46
|
+
::Rails.application.routes.url_helpers.glass_notifications_callback_url(protocol: 'https')
|
47
|
+
else
|
48
|
+
::Glass::DEVELOPMENT_PROXY_URL + @callback_url + "/glass/notifications"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
38
56
|
def set_timeline_item(timeline_object)
|
39
57
|
self.timeline_item = timeline_object
|
40
58
|
self
|
@@ -185,7 +203,7 @@ module Glass
|
|
185
203
|
|
186
204
|
def initialize_google_client
|
187
205
|
application_name = ::Glass.application_name
|
188
|
-
application_version = ::Glass.
|
206
|
+
application_version = ::Glass.application_version
|
189
207
|
self.google_client = ::Google::APIClient.new(application_name: application_name,
|
190
208
|
application_version: application_version)
|
191
209
|
self.mirror_api = google_client.discovered_api("mirror", "v1")
|
data/lib/glass/rails/version.rb
CHANGED
data/lib/glass/subscription.rb
CHANGED
@@ -17,21 +17,20 @@ module Glass
|
|
17
17
|
## collection can be :timeline or :locations
|
18
18
|
## operation is an array of operations subscribed to. Valid values are 'UPDATE', 'INSERT', 'DELETE'
|
19
19
|
def insert(opts={})
|
20
|
+
mirror_api_method = opts[:mirror_api_method] || :subscriptions
|
20
21
|
subscription = mirror_api.subscriptions.insert.request_schema.new(
|
21
22
|
collection: opts[:collection] || DEFAULT_COLLECTION,
|
22
23
|
userToken: user_token,
|
23
24
|
verifyToken: verification_secret,
|
24
|
-
callbackUrl: opts[:callback_url] || callback_url,
|
25
|
+
callbackUrl: opts[:callback_url] || google_client.callback_url,
|
25
26
|
operation: opts[:operations] || DEFAULT_OPERATIONS)
|
26
|
-
result = google_client.execute(api_method: mirror_api.
|
27
|
+
result = google_client.execute(api_method: mirror_api.send(mirror_api_method).insert,
|
27
28
|
body_object: subscription)
|
28
29
|
result
|
29
30
|
end
|
30
31
|
|
31
32
|
## Must be HTTPS
|
32
|
-
|
33
|
-
::Rails.application.routes.url_helpers.glass_notifications_callback_url(protocol: 'https')
|
34
|
-
end
|
33
|
+
|
35
34
|
|
36
35
|
## Token string used to identify user in the callback
|
37
36
|
def user_token
|