mirror-api 0.0.9 → 0.1.0

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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mirror-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
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-04-26 00:00:00.000000000 Z
13
+ date: 2013-05-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -195,6 +195,7 @@ executables: []
195
195
  extensions: []
196
196
  extra_rdoc_files: []
197
197
  files:
198
+ - .coveralls.yml
198
199
  - .gitignore
199
200
  - .rspec
200
201
  - .travis.yml
@@ -204,26 +205,38 @@ files:
204
205
  - Rakefile
205
206
  - example/.gitkeep
206
207
  - lib/mirror-api.rb
207
- - lib/mirror-api/base.rb
208
208
  - lib/mirror-api/client.rb
209
+ - lib/mirror-api/errors.rb
209
210
  - lib/mirror-api/oauth.rb
210
211
  - lib/mirror-api/request.rb
212
+ - lib/mirror-api/request_data.rb
211
213
  - lib/mirror-api/resource.rb
214
+ - lib/mirror-api/response_data.rb
212
215
  - lib/mirror-api/version.rb
213
216
  - mirror-api.gemspec
214
217
  - spec/client_spec.rb
218
+ - spec/contacts_spec.rb
215
219
  - spec/fixtures/contacts_item.json
216
220
  - spec/fixtures/contacts_list.json
217
221
  - spec/fixtures/files/fry.png
218
222
  - spec/fixtures/locations_item.json
219
223
  - spec/fixtures/locations_list.json
220
224
  - spec/fixtures/oauth_response.json
225
+ - spec/fixtures/subscriptions_item.json
226
+ - spec/fixtures/subscriptions_list.json
221
227
  - spec/fixtures/timeline_item.json
222
228
  - spec/fixtures/timeline_item_attachments_item.json
223
229
  - spec/fixtures/timeline_item_attachments_list.json
224
230
  - spec/fixtures/timeline_item_response_headers.json
231
+ - spec/fixtures/timeline_list.json
232
+ - spec/locations_spec.rb
225
233
  - spec/oauth_spec.rb
234
+ - spec/request_data_spec.rb
235
+ - spec/request_spec.rb
226
236
  - spec/spec_helper.rb
237
+ - spec/subscriptions_spec.rb
238
+ - spec/timeline_attachments_spec.rb
239
+ - spec/timeline_spec.rb
227
240
  homepage: https://github.com/ciberch/mirror-api
228
241
  licenses: []
229
242
  post_install_message:
@@ -250,15 +263,25 @@ specification_version: 3
250
263
  summary: https://developers.google.com/glass/v1/reference/
251
264
  test_files:
252
265
  - spec/client_spec.rb
266
+ - spec/contacts_spec.rb
253
267
  - spec/fixtures/contacts_item.json
254
268
  - spec/fixtures/contacts_list.json
255
269
  - spec/fixtures/files/fry.png
256
270
  - spec/fixtures/locations_item.json
257
271
  - spec/fixtures/locations_list.json
258
272
  - spec/fixtures/oauth_response.json
273
+ - spec/fixtures/subscriptions_item.json
274
+ - spec/fixtures/subscriptions_list.json
259
275
  - spec/fixtures/timeline_item.json
260
276
  - spec/fixtures/timeline_item_attachments_item.json
261
277
  - spec/fixtures/timeline_item_attachments_list.json
262
278
  - spec/fixtures/timeline_item_response_headers.json
279
+ - spec/fixtures/timeline_list.json
280
+ - spec/locations_spec.rb
263
281
  - spec/oauth_spec.rb
282
+ - spec/request_data_spec.rb
283
+ - spec/request_spec.rb
264
284
  - spec/spec_helper.rb
285
+ - spec/subscriptions_spec.rb
286
+ - spec/timeline_attachments_spec.rb
287
+ - spec/timeline_spec.rb
@@ -1,146 +0,0 @@
1
- require "rest-client"
2
- require "json"
3
- require "hashie/mash"
4
-
5
- module Mirror
6
- module Api
7
-
8
- class Base
9
-
10
- attr_accessor :last_error, :logger, :host, :last_exception, :throw_on_fail, :response, :data, :creds
11
-
12
- def initialize(credentials, throw_on_fail=true, host="https://www.googleapis.com", logger=nil)
13
- @creds = credentials
14
- @last_exception = nil
15
- @throw_on_fail = throw_on_fail
16
- @host = host
17
- @logger = logger
18
- @last_error = nil
19
- end
20
-
21
- public
22
- def post(json=false)
23
- do_verb(:post, json)
24
- end
25
-
26
- def put(json=false)
27
- do_verb(:put, json)
28
- end
29
-
30
- def patch(json=false)
31
- do_verb(:patch, json)
32
- end
33
-
34
- def delete
35
- get_verb(:delete)
36
- end
37
-
38
- def get
39
- get_verb
40
- end
41
-
42
- protected
43
-
44
- def invoke_url; end
45
- def params; end
46
- def send_error
47
- raise "Bad"
48
- end
49
-
50
- def handle_http_response(response, request, result, &block)
51
- @request = request
52
- case response.code
53
- when 400
54
- if @logger
55
- msg = "ERROR - Rejected #{request.inspect} to #{self.invoke_url} with params #{self.params}. Response is #{response.body}"
56
- @logger.error(msg)
57
- end
58
- response
59
- else
60
- response.return!(request, result, &block)
61
- end
62
- end
63
-
64
- def expected_response
65
- 200
66
- end
67
-
68
- def successful_response?
69
- @response and @response.code == expected_response
70
- end
71
-
72
- def ret_val
73
- @data
74
- end
75
-
76
- def headers
77
- {
78
- "Accept" => "application/json",
79
- "Content-type" => "application/json",
80
- "Authorization" => "Bearer #{@creds[:token]}"
81
- }
82
- end
83
-
84
- def handle_response
85
- if successful_response?
86
- ret_val
87
- else
88
- send_error
89
- end
90
- end
91
-
92
- def handle_error(error_desc, msg, errors, validation_error=nil, params={})
93
- @last_error = error_desc.dup
94
- @last_error[:errors] = errors
95
- @last_error[:validation_error] = validation_error if validation_error
96
- msg += " with params #{params}" if params.keys.count > 0
97
- @logger.warn(msg) if @logger
98
- raise error_desc[:message] if throw_on_fail
99
- end
100
-
101
- def handle_exception(error_desc, msg, ex, params={})
102
- @last_exception = ex
103
- @last_error = error_desc
104
- msg += " with params #{params}" if params && params.keys.count > 0
105
- msg += " due to #{ex}.\n" + ex.backtrace.join("\n")
106
- @logger.error(msg) if @logger
107
-
108
- raise ex if throw_on_fail
109
- return nil
110
- end
111
-
112
- def set_data
113
- @data = JSON.parse(@response.body) if @response and @response.body
114
- end
115
-
116
- def handle_http_exception(verb, ex)
117
- handle_exception("INTERNAL_ERROR", "Could not #{verb} to #{self.invoke_url}", ex, self.params)
118
- end
119
-
120
- def do_verb(verb=:post, json=false)
121
- begin
122
- data = json ? self.params : self.params.to_json
123
- @response = RestClient.send(verb, self.invoke_url, data, self.headers) do |response, request, result, &block|
124
- handle_http_response(response, request, result, &block)
125
- end
126
- set_data
127
- handle_response
128
- rescue => ex
129
- return handle_http_exception(verb, ex)
130
- end
131
- end
132
-
133
- def get_verb(verb=:get)
134
- begin
135
- @response = RestClient.send(verb, self.invoke_url, self.headers)
136
- set_data
137
- handle_response
138
- rescue => ex
139
- return handle_http_exception(verb, ex)
140
- end
141
- end
142
- end
143
-
144
-
145
- end
146
- end