glass-rails 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/lib/glass/client.rb +50 -5
- data/lib/glass/rails/version.rb +1 -1
- data/lib/glass/timeline_item.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -175,7 +175,7 @@ could instantiate a new instance of the class and assign it
|
|
175
175
|
an associated google account like so
|
176
176
|
|
177
177
|
```ruby
|
178
|
-
gt = Glass::Tweet.new(google_account_id: GoogleAccount.first)
|
178
|
+
gt = Glass::Tweet.new(google_account_id: GoogleAccount.first.id)
|
179
179
|
```
|
180
180
|
Then, you can populate an erb template with instance variables by
|
181
181
|
using the `serialize` method which is available to all subclasses
|
@@ -196,8 +196,8 @@ For example, let's say you have the following erb template:
|
|
196
196
|
You can serialize the template for a glass::tweet instance like so:
|
197
197
|
|
198
198
|
```ruby
|
199
|
-
gt = Glass::Tweet.new(google_account_id: GoogleAccount.first)
|
200
|
-
gt.serialize({template_variables: {content: "
|
199
|
+
gt = Glass::Tweet.new(google_account_id: GoogleAccount.first.id)
|
200
|
+
gt.serialize({template_variables: {content: "random stuff", title: "title"}})
|
201
201
|
```
|
202
202
|
|
203
203
|
which will basically populate the `@content` and `@title` instance variables
|
data/lib/glass/client.rb
CHANGED
@@ -5,7 +5,8 @@ module Glass
|
|
5
5
|
class Client
|
6
6
|
attr_accessor :access_token, :google_client, :mirror_api,
|
7
7
|
:google_account, :refresh_token, :content,
|
8
|
-
:mirror_content_type, :timeline_item, :has_expired_token
|
8
|
+
:mirror_content_type, :timeline_item, :has_expired_token,
|
9
|
+
:api_keys, :timeline_list
|
9
10
|
|
10
11
|
|
11
12
|
|
@@ -18,6 +19,7 @@ module Glass
|
|
18
19
|
|
19
20
|
|
20
21
|
def initialize(opts)
|
22
|
+
self.api_keys = opts[:api_keys] || ::Glass::ApiKeys.new
|
21
23
|
self.google_client = ::Google::APIClient.new
|
22
24
|
self.mirror_api = google_client.discovered_api("mirror", "v1")
|
23
25
|
self.google_account = opts[:google_account]
|
@@ -56,7 +58,15 @@ module Glass
|
|
56
58
|
end
|
57
59
|
|
58
60
|
def json_content(options)
|
59
|
-
|
61
|
+
if c = options[:content]
|
62
|
+
data = c.is_a?(String) ? {text: c} : c
|
63
|
+
else
|
64
|
+
data = self.timeline_item.to_json.merge(options)
|
65
|
+
end
|
66
|
+
mirror_api.timeline.insert.request_schema.new(data)
|
67
|
+
end
|
68
|
+
def text_content(text)
|
69
|
+
mirror_api.timeline.insert.request_schema.new({text: text})
|
60
70
|
end
|
61
71
|
|
62
72
|
## optional parameter is merged into the content hash
|
@@ -64,12 +74,48 @@ module Glass
|
|
64
74
|
## specific stuff like speakableText parameters.
|
65
75
|
|
66
76
|
def insert(options={})
|
67
|
-
body_object =
|
77
|
+
body_object = json_content(options)
|
68
78
|
inserting_content = { api_method: mirror_api.timeline.insert,
|
69
79
|
body_object: body_object }
|
70
80
|
google_client.execute(inserting_content)
|
71
81
|
end
|
72
82
|
|
83
|
+
|
84
|
+
def timeline_list(opts={as_hash: true})
|
85
|
+
retval = @timeline_list.nil? ? self.list(opts) : @timeline_list
|
86
|
+
opts[:as_hash] ? retval.map(&:to_hash) : retval
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
### this method is pretty much extracted directly from
|
92
|
+
### the mirror API code samples in ruby
|
93
|
+
###
|
94
|
+
### https://developers.google.com/glass/v1/reference/timeline/list
|
95
|
+
|
96
|
+
def list(opts={as_hash: true})
|
97
|
+
page_token = nil
|
98
|
+
parameters = {}
|
99
|
+
self.timeline_list = []
|
100
|
+
begin
|
101
|
+
parameters = {}
|
102
|
+
parameters['pageToken'] = page_token if page_token.present?
|
103
|
+
api_result = google_client.execute(api_method: mirror_api.timeline.list,
|
104
|
+
parameters: parameters)
|
105
|
+
if api_result.success?
|
106
|
+
timeline_items = api_result.data
|
107
|
+
page_token = nil if timeline_items.items.empty?
|
108
|
+
if timeline_items.items.any?
|
109
|
+
@timeline_list.concat(timeline_items.items)
|
110
|
+
page_token = timeline_items.next_page_token
|
111
|
+
end
|
112
|
+
else
|
113
|
+
puts "An error occurred: #{result.data['error']['message']}"
|
114
|
+
page_token = nil
|
115
|
+
end
|
116
|
+
end while page_token.to_s != ''
|
117
|
+
timeline_list(opts)
|
118
|
+
end
|
73
119
|
def delete(options={})
|
74
120
|
deleting_content = { api_method: mirror_api.timeline.delete,
|
75
121
|
parameters: options }
|
@@ -83,9 +129,8 @@ module Glass
|
|
83
129
|
private
|
84
130
|
|
85
131
|
def setup_with_our_access_tokens
|
86
|
-
api_keys = Glass::ApiKeys.new
|
87
132
|
["client_id", "client_secret"].each do |meth|
|
88
|
-
google_client.authorization.send("#{meth}=", api_keys.send(meth))
|
133
|
+
google_client.authorization.send("#{meth}=", self.api_keys.send(meth))
|
89
134
|
end
|
90
135
|
end
|
91
136
|
|
data/lib/glass/rails/version.rb
CHANGED
data/lib/glass/timeline_item.rb
CHANGED
@@ -179,7 +179,7 @@ module Glass
|
|
179
179
|
|
180
180
|
## For example,
|
181
181
|
## @google_account = GoogleAccount.first
|
182
|
-
## @timeline_object =
|
182
|
+
## @timeline_object = Glass::TimelineItem.new(google_account_id: @google_account.id)
|
183
183
|
## @timeline_object.serialize({template_variables: {content: "this is the content
|
184
184
|
## i've pushed to glass"}})
|
185
185
|
##
|
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.0.
|
4
|
+
version: 0.0.8
|
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-05-
|
13
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|