teamsnap_rb 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/teamsnap/version.rb +1 -1
- data/lib/teamsnap.rb +38 -6
- data/spec/teamsnap_spec.rb +69 -1
- data/tmp/.gitignore +4 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c81581a206de0d99dea75777830a764ba63b965
|
4
|
+
data.tar.gz: 284dc197b286c7bfa8041b5810332fe5717ccfc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf8b9e6b81e6fc05ffaa5270d9a5bc6b0ae32cd98106abe1e4af8029e9327111f59588acc007967343636c19e8d5636624058e4f39cf016101e8f31bed3e68dd
|
7
|
+
data.tar.gz: 9bd33d443efa7a176dda48c92227f3a8cf60c71292e9d54b7c0a1347f3e93348f7decb54ccf4f5f9d628524ea7b24838fc2598ff21e4538255195e535beea3e1
|
data/README.md
CHANGED
@@ -29,6 +29,18 @@ _Note: You'll need an OAuth2 Token from TeamSnap. Checkout our API docs
|
|
29
29
|
=> "Andrew"
|
30
30
|
```
|
31
31
|
|
32
|
+
## Backup Cache
|
33
|
+
|
34
|
+
By default when calling TeamSnap.init(...), there is a backup cache of the API root response used
|
35
|
+
to setup all relevant classes. This is primarily used so CI testing and deploy jobs do not have to
|
36
|
+
connect to the API to complete.
|
37
|
+
|
38
|
+
This creates a .teamsnap\_rb file in your ./tmp directory (./tmp/.teamsnap_rb). If you would like to turn this functionality
|
39
|
+
off, just set ```:backup_cache => false``` in your init options. Alternatively, you can set the location
|
40
|
+
of the backup by passing a string location of where to store the file. e.g.
|
41
|
+
```:backup_cache => "./another/location/.teamsnap_rb_file"```
|
42
|
+
|
43
|
+
|
32
44
|
## Todo
|
33
45
|
|
34
46
|
- Literate style docs?
|
data/lib/teamsnap/version.rb
CHANGED
data/lib/teamsnap.rb
CHANGED
@@ -104,6 +104,11 @@ module TeamSnap
|
|
104
104
|
)
|
105
105
|
end
|
106
106
|
|
107
|
+
opts[:backup_cache] = opts.fetch(:backup_cache) { true }
|
108
|
+
if opts[:backup_cache]
|
109
|
+
opts[:backup_cache_file] = TeamSnap.backup_file_for(opts[:backup_cache])
|
110
|
+
end
|
111
|
+
|
107
112
|
self.client = Faraday.new(
|
108
113
|
:url => opts.fetch(:url),
|
109
114
|
:parallel_manager => Typhoeus::Hydra.new
|
@@ -116,7 +121,7 @@ module TeamSnap
|
|
116
121
|
c.adapter :typhoeus
|
117
122
|
end
|
118
123
|
|
119
|
-
collection = TeamSnap.run(:get, "/")
|
124
|
+
collection = TeamSnap.run(:get, "/", {}, opts)
|
120
125
|
|
121
126
|
classes = []
|
122
127
|
client.in_parallel do
|
@@ -131,18 +136,45 @@ module TeamSnap
|
|
131
136
|
apply_endpoints(self, collection) && true
|
132
137
|
end
|
133
138
|
|
134
|
-
def run(via, href, args = {})
|
139
|
+
def run(via, href, args = {}, opts = {})
|
135
140
|
resp = client.send(via, href, args)
|
136
141
|
|
137
142
|
if resp.status == 200
|
138
|
-
Oj.load(resp.body)
|
139
|
-
|
143
|
+
collection = Oj.load(resp.body).fetch(:collection)
|
144
|
+
TeamSnap.write_backup_file(opts[:backup_cache_file], collection)
|
145
|
+
collection
|
140
146
|
else
|
141
|
-
|
142
|
-
|
147
|
+
if TeamSnap.backup_file_exists?(opts[:backup_cache_file])
|
148
|
+
warn("Connection to API failed.. using backup cache file to initialize endpoints")
|
149
|
+
Oj.load(IO.read(opts[:backup_cache_file]))
|
150
|
+
else
|
151
|
+
error_message = parse_error(resp)
|
152
|
+
raise TeamSnap::Error.new(error_message)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def backup_file_for(backup_cache)
|
158
|
+
backup_cache == true ? "./tmp/.teamsnap_rb" : backup_cache
|
159
|
+
end
|
160
|
+
|
161
|
+
def write_backup_file(file_location, collection)
|
162
|
+
return unless file_location
|
163
|
+
dir_location = File.dirname(file_location)
|
164
|
+
if Dir.exist?(dir_location)
|
165
|
+
File.open(file_location, "w+") { |f| f.write Oj.dump(collection) }
|
166
|
+
else
|
167
|
+
warn(
|
168
|
+
"WARNING: Directory '#{dir_location}' does not exist. " +
|
169
|
+
"Backup cache functionality will not work until this is resolved."
|
170
|
+
)
|
143
171
|
end
|
144
172
|
end
|
145
173
|
|
174
|
+
def backup_file_exists?(backup_cache_file)
|
175
|
+
!!backup_cache_file && File.exist?(backup_cache_file)
|
176
|
+
end
|
177
|
+
|
146
178
|
def parse_error(resp)
|
147
179
|
Oj.load(resp.body)
|
148
180
|
.fetch(:collection)
|
data/spec/teamsnap_spec.rb
CHANGED
@@ -6,7 +6,8 @@ RSpec.describe "teamsnap_rb", :vcr => true do
|
|
6
6
|
VCR.use_cassette("apiv3-init") do
|
7
7
|
TeamSnap.init(
|
8
8
|
:url => "http://localhost:3000",
|
9
|
-
:token => "1-classic-dont_tell_the_cops"
|
9
|
+
:token => "1-classic-dont_tell_the_cops",
|
10
|
+
:backup_cache => false
|
10
11
|
)
|
11
12
|
end
|
12
13
|
end
|
@@ -161,4 +162,71 @@ RSpec.describe "teamsnap_rb", :vcr => true do
|
|
161
162
|
end
|
162
163
|
end
|
163
164
|
end
|
165
|
+
|
166
|
+
context "supports using a backup file on init for when API cannot be reached" do
|
167
|
+
context ".backup_file_for" do
|
168
|
+
let(:default_file_location) { "./tmp/.teamsnap_rb" }
|
169
|
+
|
170
|
+
it "responds with the given file location if provided" do
|
171
|
+
file_location = "./some_dir/some_file.testing"
|
172
|
+
expect(TeamSnap.backup_file_for(file_location)).to eq(file_location)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "responds with the default file location if set to true" do
|
176
|
+
expect(TeamSnap.backup_file_for(true)).to eq(default_file_location)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context ".write_backup_file" do
|
181
|
+
let(:collection) { {:one => 1} }
|
182
|
+
|
183
|
+
context "when the given directory exists" do
|
184
|
+
let(:test_file_location) { "./tmp/.teamsnap_rb" }
|
185
|
+
let(:file_contents) { Oj.dump(collection) }
|
186
|
+
|
187
|
+
it "returns the number of characters written to the file" do
|
188
|
+
expect(TeamSnap.write_backup_file(test_file_location, collection)).to eq(file_contents.length)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "writes the file inside the directory provided" do
|
192
|
+
expect(File).to receive(:open).with(test_file_location, "w+")
|
193
|
+
TeamSnap.write_backup_file(test_file_location, collection)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "writes the file with the correct information" do
|
197
|
+
TeamSnap.write_backup_file(test_file_location, collection)
|
198
|
+
file_contents = Oj.load(IO.read(test_file_location))
|
199
|
+
expect(file_contents).to eq(collection)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context "when the given directory does NOT exist" do
|
204
|
+
let(:test_file_location) { "./directory_doesnt_exist/file" }
|
205
|
+
let(:test_dir_location) { File.dirname(test_file_location) }
|
206
|
+
let(:warning_message) {
|
207
|
+
"WARNING: Directory '#{test_dir_location}' does not exist. " +
|
208
|
+
"Backup cache functionality will not work until this is resolved."
|
209
|
+
}
|
210
|
+
|
211
|
+
it "issues a warning that the directory does not exist" do
|
212
|
+
expect(TeamSnap).to receive(:warn).with(warning_message)
|
213
|
+
TeamSnap.write_backup_file(test_file_location, collection)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
context ".backup_file_exists?" do
|
219
|
+
it "returns false if backup_cache_file is NOT set" do
|
220
|
+
expect(TeamSnap.backup_file_exists?(nil)).to eq(false)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "returns false if the file does NOT exist" do
|
224
|
+
expect(TeamSnap.backup_file_exists?("./some_file_that_does_not_exist")).to eq(false)
|
225
|
+
end
|
226
|
+
|
227
|
+
it "returns true is the file exists" do
|
228
|
+
expect(TeamSnap.backup_file_exists?("./Gemfile")).to eq(true)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
164
232
|
end
|
data/tmp/.gitignore
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teamsnap_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -174,6 +174,7 @@ files:
|
|
174
174
|
- spec/spec_helper.rb
|
175
175
|
- spec/teamsnap_spec.rb
|
176
176
|
- teamsnap_rb.gemspec
|
177
|
+
- tmp/.gitignore
|
177
178
|
homepage: http://developer.teamsnap.com/
|
178
179
|
licenses:
|
179
180
|
- MIT
|
@@ -194,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
195
|
version: '0'
|
195
196
|
requirements: []
|
196
197
|
rubyforge_project:
|
197
|
-
rubygems_version: 2.
|
198
|
+
rubygems_version: 2.2.2
|
198
199
|
signing_key:
|
199
200
|
specification_version: 4
|
200
201
|
summary: A gem to interact with TeamSnap's API
|