mirror-api 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.
@@ -21,6 +21,10 @@ module Mirror
21
21
  def subscriptions
22
22
  @subscriptions ||= Resource.new(@credentials, Request::SUBSCRIPTIONS)
23
23
  end
24
+
25
+ def locations
26
+ @locations ||= Resource.new(@credentials, Request::LOCATIONS)
27
+ end
24
28
  end
25
29
  end
26
30
  end
@@ -7,6 +7,7 @@ module Mirror
7
7
  class Request < Mirror::Api::Base
8
8
  TIMELINE = "timeline"
9
9
  SUBSCRIPTIONS = "subscriptions"
10
+ LOCATIONS = "locations"
10
11
 
11
12
  def initialize(creds, options={})
12
13
  @resource = options[:resource] || TIMELINE
@@ -16,8 +16,9 @@ module Mirror
16
16
  end
17
17
 
18
18
  def create(params)
19
- Request.new(@credentials, make_options(params, 201)).post
19
+ Request.new(@credentials, make_options(params, 200)).post
20
20
  end
21
+ alias insert create
21
22
 
22
23
  def get(id, params=nil)
23
24
  Request.new(@credentials, item_options(id, params)).get
@@ -1,5 +1,5 @@
1
1
  module Mirror
2
2
  module Api
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
data/lib/mirror-api.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require "mirror-api/version"
2
- require "mirror-api/timeline"
2
+ require "mirror-api/base"
3
+ require "mirror-api/client"
3
4
 
data/mirror-api.gemspec CHANGED
@@ -25,4 +25,8 @@ Gem::Specification.new do |gem|
25
25
  gem.add_development_dependency "rspec"
26
26
  gem.add_development_dependency "webmock"
27
27
  gem.add_development_dependency "simplecov"
28
+ gem.add_development_dependency "pry"
29
+ gem.add_development_dependency "pry-nav"
30
+ gem.add_development_dependency "pry-remote"
31
+ gem.add_development_dependency "pry-awesome_print"
28
32
  end
data/spec/client_spec.rb CHANGED
@@ -17,7 +17,7 @@ describe Mirror::Api::Client do
17
17
  stub_request(:post, "https://www.googleapis.com/mirror/v1/timeline/").
18
18
  with(body: {text: @msg},
19
19
  headers: json_post_request_headers).
20
- to_return(status: 201,
20
+ to_return(status: 200,
21
21
  body: fixture("timeline_item.json", true),
22
22
  headers: JSON.parse(fixture("timeline_item_response_headers.json", true)))
23
23
  end
@@ -37,7 +37,7 @@ describe Mirror::Api::Client do
37
37
  # TODO: Verify error code is 422
38
38
  stub_request(:post, "https://www.googleapis.com/mirror/v1/timeline/").
39
39
  with(body: {random: "123"},
40
- headers: json_post_request_headers).
40
+ headers: json_get_request_headers).
41
41
  to_return(status: 422, body: {}.to_json,
42
42
  headers: {})
43
43
  end
@@ -47,19 +47,94 @@ describe Mirror::Api::Client do
47
47
  item = @api.timeline.create({random: "123"})
48
48
  item.should be_nil
49
49
  end
50
+
50
51
  end
52
+
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "locations" do
58
+
59
+ describe "get" do
60
+
61
+ context "with valid params" do
62
+ before do
63
+ @id = "0987"
64
+
65
+ stub_request(:get, "https://www.googleapis.com/mirror/v1/locations/#{@id}").
66
+ with(headers: json_get_request_headers).
67
+ to_return(status: 200,
68
+ body: fixture("locations_item.json", true),
69
+ headers: {})
70
+ end
71
+
72
+ it "should get the location for @id", :focus => true do
73
+ location = @api.locations.get(@id)
74
+ location.should_not be_nil
75
+ location.displayName.should == "Home" # see fixture
76
+ end
77
+ end
78
+
79
+ context "with invalid params" do
80
+ before do
81
+ @id = "0987asdasds"
82
+
83
+ # TODO: Verify error code is 422
84
+ stub_request(:get, "https://www.googleapis.com/mirror/v1/locations/").
85
+ with(headers: json_post_request_headers).
86
+ to_return(status: 422, body: {}.to_json,
87
+ headers: {})
88
+ end
89
+
90
+ it "should not get the item" do
91
+
92
+ item = @api.timeline.create({random: "123"})
93
+ item.should be_nil
94
+ end
51
95
  end
96
+ end
97
+ describe "list" do
98
+
99
+ context "with valid params" do
100
+ before do
101
+
102
+ stub_request(:get, "https://www.googleapis.com/mirror/v1/locations/").
103
+ with(headers: json_get_request_headers).
104
+ to_return(status: 200,
105
+ body: fixture("locations_list.json", true),
106
+ headers: {})
107
+ end
52
108
 
53
- def json_post_request_headers
54
- {
55
- 'Accept'=>'application/json',
56
- 'Accept-Encoding'=>'gzip, deflate',
57
- 'Authorization'=>"Bearer #{@token}",
58
- 'Content-Length'=>/\d+/,
59
- 'Content-Type'=>'application/x-www-form-urlencoded',
60
- 'User-Agent'=>'Ruby'
61
- }
109
+ it "should return a list of ids", :focus => true do
110
+ locations = @api.locations.list()
111
+ locations.should_not be_nil
112
+ locations.items.count.should == 2 # see fixture
113
+ end
62
114
  end
63
115
  end
64
116
  end
117
+
118
+
119
+ def json_post_request_headers
120
+ {
121
+ 'Accept'=>'application/json',
122
+ 'Accept-Encoding'=>'gzip, deflate',
123
+ 'Authorization'=>"Bearer #{@token}",
124
+ 'Content-Length'=>/\d+/,
125
+ 'Content-Type'=>'application/x-www-form-urlencoded',
126
+ 'User-Agent'=>'Ruby'
127
+ }
128
+ end
129
+
130
+ def json_get_request_headers
131
+ {
132
+ 'Accept'=>'application/json',
133
+ 'Accept-Encoding'=>'gzip, deflate',
134
+ 'Authorization'=>"Bearer #{@token}",
135
+ 'Content-Type'=>'application/json',
136
+ 'User-Agent'=>'Ruby'
137
+ }
138
+ end
139
+
65
140
  end
@@ -0,0 +1,10 @@
1
+ {
2
+ "kind": "mirror#location",
3
+ "id": "0987",
4
+ "timestamp": "2013-04-23T04:38:18.124Z",
5
+ "latitude": "34.026628",
6
+ "longitude": "-118.481884",
7
+ "accuracy": "1.0000",
8
+ "displayName": "Home",
9
+ "address": "1718 Santa Monica blvd."
10
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "kind": "mirror#locationsList",
3
+ "items": [
4
+ {
5
+ "kind": "mirror#location",
6
+ "id": "0987",
7
+ "timestamp": "2013-04-23T04:38:18.124Z",
8
+ "latitude": "34.026628",
9
+ "longitude": "-118.481884",
10
+ "accuracy": "1.0000",
11
+ "displayName": "Home",
12
+ "address": "1718 Santa Monica blvd."
13
+ },
14
+ {
15
+ "kind": "mirror#location",
16
+ "id": "1234",
17
+ "timestamp": "2013-04-23T04:38:18.124Z",
18
+ "latitude": "42.486372",
19
+ "longitude": "-90.681539",
20
+ "accuracy": "2.01231",
21
+ "displayName": "Country Club",
22
+ "address": "446 Bradley St."
23
+ }
24
+ ]
25
+ }
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ SimpleCov.start
3
3
  require "rspec"
4
4
  require 'webmock/rspec'
5
5
  require 'webmock'
6
+ require 'pry'
6
7
 
7
8
  require_relative "../lib/mirror-api/client.rb"
8
9
 
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.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -124,6 +124,70 @@ dependencies:
124
124
  - - ! '>='
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: pry
129
+ requirement: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: pry-nav
145
+ requirement: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: pry-remote
161
+ requirement: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ type: :development
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ - !ruby/object:Gem::Dependency
176
+ name: pry-awesome_print
177
+ requirement: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ type: :development
184
+ prerelease: false
185
+ version_requirements: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ! '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
127
191
  description: Wrapper for Google Glass Mirror API v1
128
192
  email:
129
193
  - monica@crushpath.com
@@ -147,6 +211,8 @@ files:
147
211
  - lib/mirror-api/version.rb
148
212
  - mirror-api.gemspec
149
213
  - spec/client_spec.rb
214
+ - spec/fixtures/locations_item.json
215
+ - spec/fixtures/locations_list.json
150
216
  - spec/fixtures/timeline_item.json
151
217
  - spec/fixtures/timeline_item_response_headers.json
152
218
  - spec/spec_helper.rb
@@ -176,6 +242,8 @@ specification_version: 3
176
242
  summary: https://developers.google.com/glass/v1/reference/
177
243
  test_files:
178
244
  - spec/client_spec.rb
245
+ - spec/fixtures/locations_item.json
246
+ - spec/fixtures/locations_list.json
179
247
  - spec/fixtures/timeline_item.json
180
248
  - spec/fixtures/timeline_item_response_headers.json
181
249
  - spec/spec_helper.rb