teamsnap_rb 2.0.0.beta4 → 2.0.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/teamsnap.rb +15 -4
- data/lib/teamsnap/api.rb +2 -0
- data/lib/teamsnap/item.rb +10 -3
- data/lib/teamsnap/response.rb +1 -1
- data/lib/teamsnap/version.rb +1 -1
- data/spec/teamsnap/apiv_spec.rb +30 -0
- data/spec/teamsnap/item_spec.rb +11 -3
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f52464e6a2e0dcb607c8cb48f44da22fcb99088c
|
4
|
+
data.tar.gz: e7a00559a594e50b8e2681cae0ca9f17f37d68fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdd9bd671fea6da070c628d12d2423b6a9bd88c2990e357755f2e23e87dd2a4a63bddd11c6b309739803505207396a5a2ae4a770dcc2d181a8b9800e1eed49cf
|
7
|
+
data.tar.gz: 7e1d60b58f8ea299f5a16284ad90f51095c333b3602d9a61ad9a974beeabde7bcb11ce12ed96c1408098c2ca42ebf5fc3f27039d81734ffba3a2900784978971
|
data/CHANGELOG.md
CHANGED
data/lib/teamsnap.rb
CHANGED
@@ -15,6 +15,7 @@ module TeamSnap
|
|
15
15
|
DEFAULT_URL = "https://apiv3.teamsnap.com"
|
16
16
|
Error = Class.new(StandardError)
|
17
17
|
NotFound = Class.new(TeamSnap::Error)
|
18
|
+
InitializationError = Class.new(TeamSnap::Error)
|
18
19
|
|
19
20
|
class << self
|
20
21
|
attr_accessor :client_id, :client_secret, :root_client, :token, :url
|
@@ -34,7 +35,10 @@ module TeamSnap
|
|
34
35
|
self.root_client = TeamSnap::Client.new(:token => token)
|
35
36
|
|
36
37
|
## Make the apiv3 root call. collection is parsed JSON
|
37
|
-
collection = TeamSnap.run(root_client, :get, self.url, {})
|
38
|
+
collection = TeamSnap.run(root_client, :get, self.url, {}) do
|
39
|
+
self.root_client = nil
|
40
|
+
raise TeamSnap::InitializationError
|
41
|
+
end
|
38
42
|
|
39
43
|
## Setup Dynamic Classes from the collection
|
40
44
|
TeamSnap::Structure.init(root_client, collection)
|
@@ -43,12 +47,19 @@ module TeamSnap
|
|
43
47
|
TeamSnap::Collection.apply_endpoints(self, collection) && true
|
44
48
|
end
|
45
49
|
|
46
|
-
def run(client, via, href, args = {})
|
50
|
+
def run(client, via, href, args = {}, &block)
|
51
|
+
timeout_error = block || default_timeout_error
|
47
52
|
resp = client_send(client, via, href, args)
|
48
53
|
return TeamSnap::Response.load_collection(resp)
|
49
54
|
rescue Faraday::TimeoutError
|
50
|
-
|
51
|
-
|
55
|
+
timeout_error.call
|
56
|
+
end
|
57
|
+
|
58
|
+
def default_timeout_error
|
59
|
+
-> {
|
60
|
+
warn("Connection to API failed with TimeoutError")
|
61
|
+
{:links => []}
|
62
|
+
}
|
52
63
|
end
|
53
64
|
|
54
65
|
def client_send(client, via, href, args)
|
data/lib/teamsnap/api.rb
CHANGED
data/lib/teamsnap/item.rb
CHANGED
@@ -6,7 +6,9 @@ module TeamSnap
|
|
6
6
|
collection
|
7
7
|
.fetch(:items) { [] }
|
8
8
|
.map { |item|
|
9
|
-
data = parse_data(item)
|
9
|
+
data = parse_data(item)
|
10
|
+
.merge(:href => item[:href])
|
11
|
+
.merge(url_attributes(item))
|
10
12
|
type = type_of(item)
|
11
13
|
cls = load_class(type, data)
|
12
14
|
|
@@ -53,12 +55,18 @@ module TeamSnap
|
|
53
55
|
}
|
54
56
|
end
|
55
57
|
|
58
|
+
def url_attributes(item)
|
59
|
+
links = item
|
60
|
+
.fetch(:links) { [] }
|
61
|
+
.map { |link| ["#{link.fetch(:rel)}_url", link.fetch(:href)] }
|
62
|
+
hashify(links)
|
63
|
+
end
|
64
|
+
|
56
65
|
def hashify(arr)
|
57
66
|
Hash[*arr.flatten]
|
58
67
|
rescue NoMethodError
|
59
68
|
arr.inject({}) { |hash, (key, value)| hash[key] = value; hash }
|
60
69
|
end
|
61
|
-
|
62
70
|
end
|
63
71
|
|
64
72
|
private
|
@@ -71,7 +79,6 @@ module TeamSnap
|
|
71
79
|
href = link.fetch(:href)
|
72
80
|
is_singular = rel == Inflecto.singularize(rel)
|
73
81
|
|
74
|
-
define_singleton_method("#{rel}_url") { href }
|
75
82
|
define_singleton_method(rel) {
|
76
83
|
instance_variable_get("@#{rel}") || instance_variable_set(
|
77
84
|
"@#{rel}", -> {
|
data/lib/teamsnap/response.rb
CHANGED
@@ -84,7 +84,7 @@ module TeamSnap
|
|
84
84
|
|
85
85
|
def process_error
|
86
86
|
if @resp.headers["content-type"].match("json")
|
87
|
-
body = Oj.load(@resp.body)
|
87
|
+
body = Oj.load(@resp.body) || {}
|
88
88
|
@collection = body.fetch(:collection) { {} }
|
89
89
|
@message = TeamSnap::Api.parse_error(@resp)
|
90
90
|
@objects = TeamSnap::Item.load_items(@client, @collection)
|
data/lib/teamsnap/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "teamsnap"
|
3
|
+
|
4
|
+
RSpec.describe "teamsnap__api", :vcr => true do
|
5
|
+
context ".parse_error" do
|
6
|
+
it "returns error message on a 403 and an empty body" do
|
7
|
+
response = Faraday::Response.new(
|
8
|
+
:status => 403,
|
9
|
+
:body => ""
|
10
|
+
)
|
11
|
+
expect(TeamSnap::Api.parse_error(response)).to eq("Forbidden (403)")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns error message on a 404" do
|
15
|
+
response = Faraday::Response.new(
|
16
|
+
:status => 404,
|
17
|
+
:body => ""
|
18
|
+
)
|
19
|
+
expect(TeamSnap::Api.parse_error(response)).to eq("Object Not Found (404)")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns a proper error message" do
|
23
|
+
response = Faraday::Response.new(
|
24
|
+
:status => 403,
|
25
|
+
:body => Oj.dump("collection" => { :error => { :message => "Error Message"}})
|
26
|
+
)
|
27
|
+
expect(TeamSnap::Api.parse_error(response)).to eq("Error Message")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/teamsnap/item_spec.rb
CHANGED
@@ -142,14 +142,22 @@ RSpec.describe "teamsnap__item", :vcr => true do
|
|
142
142
|
:name => "humanized_media_storage_used",
|
143
143
|
:value => "0 B"
|
144
144
|
}
|
145
|
+
],
|
146
|
+
:links => [
|
147
|
+
{
|
148
|
+
:rel => "logo",
|
149
|
+
:href => "http://example.com/logo.png"
|
150
|
+
}
|
145
151
|
]
|
146
152
|
}
|
147
153
|
]
|
148
154
|
}
|
149
155
|
|
150
|
-
|
151
|
-
|
152
|
-
).to eq(TeamSnap::Team)
|
156
|
+
item = TeamSnap::Item.load_items(TeamSnap.root_client, collection)[0]
|
157
|
+
|
158
|
+
expect(item.class).to eq(TeamSnap::Team)
|
159
|
+
expect(item.logo_url).to eq("http://example.com/logo.png")
|
160
|
+
expect(item.attributes[:logo_url]).to eq("http://example.com/logo.png")
|
153
161
|
end
|
154
162
|
end
|
155
163
|
end
|
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: 2.0.0.
|
4
|
+
version: 2.0.0.beta6
|
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: 2016-
|
12
|
+
date: 2016-05-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -193,6 +193,7 @@ files:
|
|
193
193
|
- spec/cassettes/teamsnap_rb/_run/processes_the_response.yml
|
194
194
|
- spec/cassettes/teamsnap_rb/_server_error/Specifies_call_and_endpoint_that_was_unsuccessful.yml
|
195
195
|
- spec/spec_helper.rb
|
196
|
+
- spec/teamsnap/apiv_spec.rb
|
196
197
|
- spec/teamsnap/client_spec.rb
|
197
198
|
- spec/teamsnap/collection_spec.rb
|
198
199
|
- spec/teamsnap/item_spec.rb
|
@@ -220,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
221
|
version: 1.3.1
|
221
222
|
requirements: []
|
222
223
|
rubyforge_project:
|
223
|
-
rubygems_version: 2.
|
224
|
+
rubygems_version: 2.6.3
|
224
225
|
signing_key:
|
225
226
|
specification_version: 4
|
226
227
|
summary: A gem to interact with TeamSnap's API
|
@@ -256,6 +257,7 @@ test_files:
|
|
256
257
|
- spec/cassettes/teamsnap_rb/_run/processes_the_response.yml
|
257
258
|
- spec/cassettes/teamsnap_rb/_server_error/Specifies_call_and_endpoint_that_was_unsuccessful.yml
|
258
259
|
- spec/spec_helper.rb
|
260
|
+
- spec/teamsnap/apiv_spec.rb
|
259
261
|
- spec/teamsnap/client_spec.rb
|
260
262
|
- spec/teamsnap/collection_spec.rb
|
261
263
|
- spec/teamsnap/item_spec.rb
|