teamsnap_rb 0.0.8 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -0
  3. data/Gemfile +2 -1
  4. data/LICENSE +1 -1
  5. data/README.md +31 -79
  6. data/Rakefile +19 -1
  7. data/lib/teamsnap/version.rb +3 -0
  8. data/lib/teamsnap.rb +270 -0
  9. data/spec/cassettes/apiv3-init.yml +1963 -0
  10. data/spec/cassettes/teamsnap_rb/adds_find_if_search_is_available.yml +56 -0
  11. data/spec/cassettes/teamsnap_rb/can_follow_plural_links.yml +111 -0
  12. data/spec/cassettes/teamsnap_rb/can_follow_singular_links.yml +105 -0
  13. data/spec/cassettes/teamsnap_rb/can_handle_an_empty_bulk_load.yml +52 -0
  14. data/spec/cassettes/teamsnap_rb/can_handle_an_error_with_bulk_load.yml +50 -0
  15. data/spec/cassettes/teamsnap_rb/can_handle_errors_generated_by_command.yml +50 -0
  16. data/spec/cassettes/teamsnap_rb/can_handle_links_with_no_data.yml +101 -0
  17. data/spec/cassettes/teamsnap_rb/can_use_bulk_load.yml +61 -0
  18. data/spec/cassettes/teamsnap_rb/handles_executing_an_action_via_commands.yml +54 -0
  19. data/spec/cassettes/teamsnap_rb/handles_fetching_data_via_queries.yml +56 -0
  20. data/spec/cassettes/teamsnap_rb/handles_queries_with_no_data.yml +53 -0
  21. data/spec/cassettes/teamsnap_rb/raises_an_exception_if_find_returns_nothing.yml +53 -0
  22. data/spec/spec_helper.rb +18 -13
  23. data/spec/teamsnap_spec.rb +125 -0
  24. data/teamsnap_rb.gemspec +17 -15
  25. metadata +100 -84
  26. data/lib/teamsnap_rb/client.rb +0 -8
  27. data/lib/teamsnap_rb/collection.rb +0 -179
  28. data/lib/teamsnap_rb/command.rb +0 -39
  29. data/lib/teamsnap_rb/commands.rb +0 -40
  30. data/lib/teamsnap_rb/config.rb +0 -14
  31. data/lib/teamsnap_rb/exceptions.rb +0 -3
  32. data/lib/teamsnap_rb/item.rb +0 -136
  33. data/lib/teamsnap_rb/link.rb +0 -24
  34. data/lib/teamsnap_rb/links_proxy.rb +0 -40
  35. data/lib/teamsnap_rb/models/event.rb +0 -4
  36. data/lib/teamsnap_rb/models/user.rb +0 -4
  37. data/lib/teamsnap_rb/queries_proxy.rb +0 -68
  38. data/lib/teamsnap_rb/request_builder.rb +0 -67
  39. data/lib/teamsnap_rb/template.rb +0 -37
  40. data/lib/teamsnap_rb/version.rb +0 -3
  41. data/lib/teamsnap_rb.rb +0 -22
  42. data/spec/client_spec.rb +0 -39
  43. data/spec/collection_spec.rb +0 -175
  44. data/spec/command_spec.rb +0 -60
  45. data/spec/commands_spec.rb +0 -35
  46. data/spec/config_spec.rb +0 -16
  47. data/spec/fixtures/cassettes/production_root.yml +0 -59
  48. data/spec/fixtures/cassettes/root.yml +0 -573
  49. data/spec/fixtures/cassettes/team.yml +0 -4858
  50. data/spec/fixtures/cassettes/teams.yml +0 -160
  51. data/spec/item_spec.rb +0 -133
  52. data/spec/link_spec.rb +0 -43
  53. data/spec/links_proxy_spec.rb +0 -32
  54. data/spec/queries_proxy_spec.rb +0 -31
  55. data/spec/template_spec.rb +0 -57
data/spec/client_spec.rb DELETED
@@ -1,39 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe TeamsnapRb::Client do
4
- describe "#new (GET production root/)" do
5
- use_vcr_cassette "production_root"
6
-
7
- it "raises an HttpError for unauthorized access" do
8
- expect{TeamsnapRb::Client.new}.to raise_exception(TeamsnapRb::HttpError)
9
- end
10
- end
11
-
12
- context "#new (GET local root/)" do
13
- use_vcr_cassette "root"
14
-
15
- it "does not raise an error when authorized" do
16
- expect{TeamsnapRb::Client.new("http://localhost:3003/")}.to_not raise_exception
17
- end
18
-
19
- it "return a TeamsnapRb::Collection" do
20
- expect(TeamsnapRb::Client.new("http://localhost:3003/")).to be_a(TeamsnapRb::Collection)
21
- end
22
- end
23
-
24
- context "#teams (GET local teams/)" do
25
- use_vcr_cassette "root"
26
- let(:client) { TeamsnapRb::Client.new("http://localhost:3003") }
27
-
28
- describe "client navigation of the api" do
29
- it "responds to links in the root collection, returning the appropriate collection" do
30
- expect(client.teams).to be_a(TeamsnapRb::Collection)
31
- end
32
-
33
- it "enables access to collections and items directly from the client" do
34
- team = client.teams.search(:id => 1).first
35
- expect(team.id).to eq(1)
36
- end
37
- end
38
- end
39
- end
@@ -1,175 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe TeamsnapRb::Collection do
4
- describe "default attributes" do
5
- it "includes Enumerable" do
6
- expect(TeamsnapRb::Collection).to include(Enumerable)
7
- end
8
- end
9
-
10
- context "GET root", :vcr, record: :once do
11
- use_vcr_cassette "root"
12
- let(:root_collection) { TeamsnapRb::Collection.new("http://localhost:3003", {}, TeamsnapRb::Config.new) }
13
-
14
- describe "#href" do
15
- it "responds to href with the correct value" do
16
- expect(root_collection.href).to eq("http://localhost:3003/")
17
- end
18
- end
19
-
20
- describe "#links" do
21
- it "returns a LinksProxy object" do
22
- expect(root_collection.links).to be_a(TeamsnapRb::LinksProxy)
23
- end
24
- end
25
-
26
- describe "#[]" do
27
- it "returns nil when the collection does not have any data elements" do
28
- expect(root_collection[0]).to be_nil
29
- end
30
- end
31
-
32
- describe "#queries" do
33
- it "returns a QueriesProxy object" do
34
- expect(root_collection.queries).to be_a(TeamsnapRb::QueriesProxy)
35
- end
36
-
37
- it "contains a set of Query objects" do
38
- expect(root_collection.queries.first).to be_a(TeamsnapRb::Query)
39
- end
40
- end
41
-
42
- describe "#each" do
43
- it "returns an empty array when there are not data elements" do
44
- expect(root_collection.each).to eq([])
45
- end
46
- end
47
-
48
- describe "#where" do
49
- it "returns a CollectionWhereProxy" do
50
- expect(root_collection.where({})).to be_a(TeamsnapRb::Collection::CollectionWhereProxy)
51
- end
52
-
53
- it "returns nil when trying to access an empty collection" do
54
- expect(root_collection.where({})[0]).to be_nil
55
- end
56
- end
57
-
58
- describe "#error" do
59
- it "returns an empty array if there are no errors" do
60
- expect(root_collection.error).to be_empty
61
- end
62
- end
63
-
64
- describe "#error?" do
65
- it "returns false if there are no errors" do
66
- expect(root_collection.error?).to eq(false)
67
- end
68
- end
69
-
70
- describe "size" do
71
- it "returns zero when there are no items" do
72
- expect(root_collection.size).to eq(0)
73
- end
74
- end
75
-
76
- describe "present?" do
77
- it "returns false when there are no iteams" do
78
- expect(root_collection.present?).to eq(false)
79
- end
80
- end
81
-
82
- describe "blank?" do
83
- it "returns true when there are no iteams" do
84
- expect(root_collection.blank?).to eq(true)
85
- end
86
- end
87
- end
88
-
89
- context "GET /teams/1", :vcr, record: :once do
90
- use_vcr_cassette "team"
91
- let(:team_collection) { TeamsnapRb::Collection.new("http://localhost:3003/teams/1", {}, TeamsnapRb::Config.new) }
92
-
93
- describe "#href" do
94
- it "responds to href with the correct value" do
95
- expect(team_collection.href).to eq("http://localhost:3003/teams")
96
- end
97
- end
98
-
99
- describe "#links" do
100
- it "returns a LinksProxy object" do
101
- expect(team_collection.links).to be_a(TeamsnapRb::LinksProxy)
102
- end
103
- end
104
-
105
- describe "#[]" do
106
- it "returns an Item when the collection has data elements" do
107
- expect(team_collection[0]).to be_a(TeamsnapRb::Item)
108
- end
109
- end
110
-
111
- describe "#queries" do
112
- it "returns a QueriesProxy object" do
113
- expect(team_collection.queries).to be_a(TeamsnapRb::QueriesProxy)
114
- end
115
-
116
- it "contains a set of Query objects" do
117
- expect(team_collection.queries.first).to be_a(TeamsnapRb::Query)
118
- end
119
- end
120
-
121
- describe "#each" do
122
- it "returns an array of items" do
123
- expect(team_collection.each {|item|}).to_not be_empty
124
- end
125
- end
126
-
127
- describe "size" do
128
- it "returns zero when there are no items" do
129
- expect(team_collection.size).to eq(1)
130
- end
131
- end
132
-
133
- describe "present?" do
134
- it "returns true when there are no iteams" do
135
- expect(team_collection.present?).to eq(true)
136
- end
137
- end
138
-
139
- describe "blank?" do
140
- it "returns false when there are no iteams" do
141
- expect(team_collection.blank?).to eq(false)
142
- end
143
- end
144
-
145
- describe "#where" do
146
- it "returns a CollectionWhereProxy" do
147
- expect(team_collection.where({})).to be_a(TeamsnapRb::Collection::CollectionWhereProxy)
148
- end
149
-
150
- it "returns nil when trying to access a type that doesn't exist in the collection" do
151
- expect(team_collection.where({type: "division"})[0]).to be_nil
152
- end
153
-
154
- it "returns an array of items that match the type passed in" do
155
- expect(team_collection.where({type: "team"})[0]).to be_a(TeamsnapRb::Item)
156
- end
157
-
158
- it "the item selected has the expected data" do
159
- expect(team_collection.where({type: "team"})[0].name).to eq("Test Mania")
160
- end
161
- end
162
-
163
- describe "#error" do
164
- it "returns an empty array if there are no errors" do
165
- expect(team_collection.error).to be_empty
166
- end
167
- end
168
-
169
- describe "#error?" do
170
- it "returns false if there are no errors" do
171
- expect(team_collection.error?).to eq(false)
172
- end
173
- end
174
- end
175
- end
data/spec/command_spec.rb DELETED
@@ -1,60 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe TeamsnapRb::Command do
4
- use_vcr_cassette "team", :match_requests_on => [:host, :path, :body], :record => :new_episodes
5
-
6
- let(:client) { TeamsnapRb::Client.new("http://localhost:3003/teams/1") }
7
- let(:command) { client.commands.first }
8
-
9
- describe "#new" do
10
- it "is built from a TeamsnapRb::Collection" do
11
- expect{command}.to_not raise_exception
12
- end
13
- end
14
-
15
- describe "#execute" do
16
- it "returns a Faraday::Response" do
17
- expect(
18
- command.execute(
19
- [:team_id => 1, :member_id => 8, :notify_as_member_id => 1]
20
- )
21
- ).to be_a(Faraday::Response)
22
- end
23
-
24
- it "returns an appropriate status code" do
25
- expect(
26
- command.execute(
27
- [:team_id => 1, :member_id => 8, :notify_as_member_id => 1]
28
- ).status
29
- ).to eq(202)
30
- end
31
- end
32
-
33
- describe "#href" do
34
- it "returns the href for the command" do
35
- expect(command.href).to eq("http://localhost:3003/teams/invite")
36
- end
37
- end
38
-
39
- describe "#rel" do
40
- it "returns the name of the command" do
41
- expect(command.rel).to eq("invite")
42
- end
43
- end
44
-
45
- describe "#prompt" do
46
- it "returns the prompt for the command" do
47
- expect(command.prompt).to eq("invite team members or contacts to join TeamSnap.")
48
- end
49
- end
50
-
51
- describe "#data" do
52
- it "returns the data for the command" do
53
- expect(command.data).to include("team_id", "member_id")
54
- end
55
-
56
- it "returns the data for the command" do
57
- expect(command.data).to be_a(Array)
58
- end
59
- end
60
- end
@@ -1,35 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe TeamsnapRb::CommandsProxy do
4
- use_vcr_cassette "team", :match_requests_on => [:host, :path, :body]
5
-
6
- let(:commands_proxy) { TeamsnapRb::Collection.new(
7
- "http://localhost:3003/teams/1", {}, TeamsnapRb::Config.new
8
- ).commands }
9
-
10
- describe "#new" do
11
- it "accepts an array of commands from a collection+json response and a config" do
12
- expect(commands_proxy).to be_a(TeamsnapRb::CommandsProxy)
13
- end
14
- end
15
-
16
- describe "#rels" do
17
- it "returns an array of the different commands available for the collection" do
18
- expect(commands_proxy.rels).to eq([:invite])
19
- end
20
- end
21
-
22
- describe "executing a command" do
23
- it "with valid data, it posts to the invite href when a match is found" do
24
- expect(
25
- commands_proxy.invite(
26
- :team_id => 1, :member_id => 8, :notify_as_member_id => 1
27
- ).status
28
- ).to eq(202)
29
- end
30
-
31
- it "with invalid data, it returns a 400" do
32
- expect(commands_proxy.invite.status).to eq(400)
33
- end
34
- end
35
- end
data/spec/config_spec.rb DELETED
@@ -1,16 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe TeamsnapRb::Config do
4
- let(:config) { TeamsnapRb::Config.new }
5
-
6
- describe "#new" do
7
- it "uses sensible defaults when no options are passed in" do
8
- expect(config.authorization).to be_nil
9
- expect(config.access_token).to be_nil
10
- expect(config.client_secret).to be_nil
11
- expect(config.client_id).to be_nil
12
- expect(config.response_middleware).to eq([])
13
- expect(config.request_middleware).to eq([])
14
- end
15
- end
16
- end
@@ -1,59 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://api.teamsnap.com/v3/
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- User-Agent:
11
- - Faraday v0.9.0
12
- Accept-Encoding:
13
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
- Accept:
15
- - "*/*"
16
- response:
17
- status:
18
- code: 401
19
- message: Unauthorized
20
- headers:
21
- Content-Type:
22
- - text/html;charset=utf-8
23
- Content-Length:
24
- - '138'
25
- Connection:
26
- - keep-alive
27
- Status:
28
- - 401 Unauthorized
29
- X-Xss-Protection:
30
- - 1; mode=block
31
- X-Content-Type-Options:
32
- - nosniff
33
- X-Frame-Options:
34
- - SAMEORIGIN
35
- X-Ratelimit-Limit:
36
- - '5000'
37
- X-Ratelimit-Remaining:
38
- - '4997'
39
- X-Ratelimit-Reset:
40
- - '1415731203'
41
- Cache-Control:
42
- - no-cache
43
- X-Request-Id:
44
- - 16f9d410-b994-472a-a2ef-097357c11915
45
- X-Runtime:
46
- - '0.004984'
47
- X-Powered-By:
48
- - Phusion Passenger 4.0.48
49
- Date:
50
- - Tue, 11 Nov 2014 17:46:29 GMT
51
- Server:
52
- - nginx/1.4.5 + Phusion Passenger 4.0.48
53
- body:
54
- encoding: UTF-8
55
- string: '{"collection":{"error":{"message":"You are not authorized to access
56
- this resource. Please ensure you''ve provided a valid access token."}}}'
57
- http_version:
58
- recorded_at: Tue, 11 Nov 2014 17:46:29 GMT
59
- recorded_with: VCR 2.9.3