glass-rails 0.0.8 → 0.0.9
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 +14 -6
- data/lib/glass/rails/version.rb +1 -1
- metadata +2 -2
data/lib/glass/client.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "glass/api_keys"
|
2
2
|
require 'active_support/core_ext/hash/indifferent_access'
|
3
3
|
require "google/api_client"
|
4
|
+
|
4
5
|
module Glass
|
5
6
|
class Client
|
6
7
|
attr_accessor :access_token, :google_client, :mirror_api,
|
@@ -8,16 +9,12 @@ module Glass
|
|
8
9
|
:mirror_content_type, :timeline_item, :has_expired_token,
|
9
10
|
:api_keys, :timeline_list
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
12
|
def self.create(timeline_item, opts={})
|
15
13
|
client = new(opts.merge({google_account: timeline_item.google_account}))
|
16
14
|
client.set_timeline_item(timeline_item)
|
17
15
|
client
|
18
16
|
end
|
19
17
|
|
20
|
-
|
21
18
|
def initialize(opts)
|
22
19
|
self.api_keys = opts[:api_keys] || ::Glass::ApiKeys.new
|
23
20
|
self.google_client = ::Google::APIClient.new
|
@@ -57,12 +54,14 @@ module Glass
|
|
57
54
|
self
|
58
55
|
end
|
59
56
|
|
57
|
+
|
60
58
|
def json_content(options)
|
61
59
|
if c = options[:content]
|
62
60
|
data = c.is_a?(String) ? {text: c} : c
|
63
61
|
else
|
64
62
|
data = self.timeline_item.to_json.merge(options)
|
65
63
|
end
|
64
|
+
data = format_hash_properly(data)
|
66
65
|
mirror_api.timeline.insert.request_schema.new(data)
|
67
66
|
end
|
68
67
|
def text_content(text)
|
@@ -83,7 +82,7 @@ module Glass
|
|
83
82
|
|
84
83
|
def timeline_list(opts={as_hash: true})
|
85
84
|
retval = @timeline_list.nil? ? self.list(opts) : @timeline_list
|
86
|
-
opts[:as_hash] ? retval.map(&:to_hash) : retval
|
85
|
+
opts[:as_hash] ? retval.map(&:to_hash).map(&:with_indifferent_access) : retval
|
87
86
|
end
|
88
87
|
|
89
88
|
|
@@ -157,6 +156,15 @@ module Glass
|
|
157
156
|
ea_data_hash["id_token"] = google_data_hash["id_token"]
|
158
157
|
ea_data_hash
|
159
158
|
end
|
160
|
-
|
159
|
+
def format_hash_properly(data_hash)
|
160
|
+
data_hash.inject({}) do |acc, (key, value)|
|
161
|
+
new_key = key.to_s.camelize(:lower)
|
162
|
+
acc[new_key]= (new_key == "displayTime") ? format_date(value) : value
|
163
|
+
acc
|
164
|
+
end.with_indifferent_access
|
165
|
+
end
|
166
|
+
def format_date(time)
|
167
|
+
time.to_time.utc.iso8601.gsub("Z", ".000Z") # fucking google has a weird format
|
168
|
+
end
|
161
169
|
end
|
162
170
|
end
|
data/lib/glass/rails/version.rb
CHANGED
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.9
|
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-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|