teamsnap_rb 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/Gemfile.lock +35 -2
- data/README.md +38 -0
- data/Rakefile +3 -0
- data/lib/teamsnap_rb.rb +14 -12
- data/lib/teamsnap_rb/collection.rb +5 -9
- data/lib/teamsnap_rb/command.rb +39 -0
- data/lib/teamsnap_rb/commands.rb +40 -0
- data/lib/teamsnap_rb/item.rb +50 -38
- data/lib/teamsnap_rb/template.rb +1 -1
- data/lib/teamsnap_rb/version.rb +1 -1
- data/spec/client_spec.rb +39 -0
- data/spec/collection_spec.rb +136 -2
- data/spec/command_spec.rb +60 -0
- data/spec/commands_spec.rb +35 -0
- data/spec/config_spec.rb +15 -0
- data/spec/fixtures/cassettes/production_root.yml +59 -0
- data/spec/fixtures/cassettes/root.yml +573 -0
- data/spec/fixtures/cassettes/team.yml +4858 -0
- data/spec/fixtures/cassettes/teams.yml +160 -0
- data/spec/item_spec.rb +112 -2
- data/spec/link_spec.rb +40 -2
- data/spec/links_proxy_spec.rb +32 -0
- data/spec/queries_proxy_spec.rb +31 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/template_spec.rb +57 -0
- data/teamsnap_rb.gemspec +2 -1
- metadata +44 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29904a91fc42a2faba569cde41db6452757595c5
|
4
|
+
data.tar.gz: 2a8c0c3fd6ce5ae221583350285070911f59aa75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8963bb77684586da59b7a8d5727bcca2ce5c70d0d92a2804085918a6f8b0663d13d60a172c9eb4451e36afa42f30b57452a3b6bd6cffc008640ecd8261093ba7
|
7
|
+
data.tar.gz: 45df529d9018566208d00f09cc2ff948db2d03b154530b2f8b82c90e14d58fed7a5c809918bb03686a8da9086309837f06f8911125e20de339f53300eb0aae97
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,25 +1,41 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
teamsnap_rb (0.0.
|
4
|
+
teamsnap_rb (0.0.5)
|
5
5
|
conglomerate (>= 0.15.0)
|
6
6
|
faraday (~> 0.9.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
addressable (2.3.6)
|
11
12
|
coderay (1.1.0)
|
12
|
-
conglomerate (0.
|
13
|
+
conglomerate (0.16.0)
|
14
|
+
coveralls (0.7.1)
|
15
|
+
multi_json (~> 1.3)
|
16
|
+
rest-client
|
17
|
+
simplecov (>= 0.7)
|
18
|
+
term-ansicolor
|
19
|
+
thor
|
20
|
+
crack (0.4.2)
|
21
|
+
safe_yaml (~> 1.0.0)
|
13
22
|
diff-lcs (1.2.5)
|
23
|
+
docile (1.1.5)
|
14
24
|
faraday (0.9.0)
|
15
25
|
multipart-post (>= 1.2, < 3)
|
16
26
|
method_source (0.8.2)
|
27
|
+
mime-types (2.4.3)
|
28
|
+
multi_json (1.10.1)
|
17
29
|
multipart-post (2.0.0)
|
30
|
+
netrc (0.8.0)
|
18
31
|
pry (0.9.12.4)
|
19
32
|
coderay (~> 1.0)
|
20
33
|
method_source (~> 0.8)
|
21
34
|
slop (~> 3.4)
|
22
35
|
rake (10.1.1)
|
36
|
+
rest-client (1.7.2)
|
37
|
+
mime-types (>= 1.16, < 3.0)
|
38
|
+
netrc (~> 0.7)
|
23
39
|
rspec (3.0.0)
|
24
40
|
rspec-core (~> 3.0.0)
|
25
41
|
rspec-expectations (~> 3.0.0)
|
@@ -32,14 +48,31 @@ GEM
|
|
32
48
|
rspec-mocks (3.0.3)
|
33
49
|
rspec-support (~> 3.0.0)
|
34
50
|
rspec-support (3.0.3)
|
51
|
+
safe_yaml (1.0.4)
|
52
|
+
simplecov (0.9.1)
|
53
|
+
docile (~> 1.1.0)
|
54
|
+
multi_json (~> 1.0)
|
55
|
+
simplecov-html (~> 0.8.0)
|
56
|
+
simplecov-html (0.8.0)
|
35
57
|
slop (3.4.7)
|
58
|
+
term-ansicolor (1.3.0)
|
59
|
+
tins (~> 1.0)
|
60
|
+
thor (0.19.1)
|
61
|
+
tins (1.3.3)
|
62
|
+
vcr (2.9.3)
|
63
|
+
webmock (1.20.4)
|
64
|
+
addressable (>= 2.3.6)
|
65
|
+
crack (>= 0.3.2)
|
36
66
|
|
37
67
|
PLATFORMS
|
38
68
|
ruby
|
39
69
|
|
40
70
|
DEPENDENCIES
|
41
71
|
bundler (~> 1.5)
|
72
|
+
coveralls
|
42
73
|
pry
|
43
74
|
rake
|
44
75
|
rspec (>= 3.0.0)
|
45
76
|
teamsnap_rb!
|
77
|
+
vcr
|
78
|
+
webmock
|
data/README.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# TeamSnapRb
|
2
|
+
|
3
|
+
[ ![Codeship Status for teamsnap/teamsnap_rb](https://codeship.com/projects/535cff20-4bf3-0132-5b73-3612ac61d213/status)](https://codeship.com/projects/46910)
|
4
|
+
|
5
|
+
[![Code Climate](https://codeclimate.com/github/teamsnap/teamsnap_rb/badges/gpa.svg)](https://codeclimate.com/github/teamsnap/teamsnap_rb)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/teamsnap/teamsnap_rb/badge.png)](https://coveralls.io/r/teamsnap/teamsnap_rb)
|
7
|
+
|
1
8
|
# EARLY ACCESS
|
2
9
|
|
3
10
|
Please be aware there may be bugs, gremlins, and horrible issues; and you could be eaten by a grue. We are not responsible for any loss of life or limb (especially if you are eaten by a grue).
|
@@ -26,8 +33,39 @@ Needs to be updated; coming soon.
|
|
26
33
|
|
27
34
|
## Contributing
|
28
35
|
|
36
|
+
### Git Workflow
|
37
|
+
|
29
38
|
1. Fork it ( http://github.com/teamsnap/teamsnap_rb/fork )
|
30
39
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
40
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
41
|
4. Push to the branch (`git push origin my-new-feature`)
|
33
42
|
5. Create new Pull Request
|
43
|
+
|
44
|
+
### Testing teamsnap_rb
|
45
|
+
|
46
|
+
`./bin/rspec` will run the test suite.
|
47
|
+
|
48
|
+
### teamsnap_rb in IRB
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
$ irb
|
52
|
+
> require 'teamsnap_rb'
|
53
|
+
=> true
|
54
|
+
> client_config = TeamsnapRb::Config.new(
|
55
|
+
> client_id: "your_client_id_here",
|
56
|
+
> client_secret: "ssshhhhhh!"
|
57
|
+
> )
|
58
|
+
> client = TeamsnapRb::Client.new("http://apiv3.teamsnap.com/", config: client_config)
|
59
|
+
=> # client object
|
60
|
+
> team = client.teams.search(:id => "your_team_id_here").first
|
61
|
+
=> # team object
|
62
|
+
```
|
63
|
+
|
64
|
+
In order to work on teamsnap_rb most effectively and efficiently, it'll he helpful
|
65
|
+
to have a TeamSnap account and teams so you can work with that data. You can
|
66
|
+
create a TeamSnap account [here](https://go.teamsnap.com) and you can then
|
67
|
+
authorize a client application using our [Cogsworth
|
68
|
+
service](https://auth.teamsnap.com).
|
69
|
+
|
70
|
+
With a client ID and secret in hand, you can begin interacting with the gem
|
71
|
+
using real data.
|
data/Rakefile
CHANGED
data/lib/teamsnap_rb.rb
CHANGED
@@ -3,18 +3,20 @@ require "json"
|
|
3
3
|
require "faraday"
|
4
4
|
require "securerandom"
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
require_relative "teamsnap_rb/version"
|
7
|
+
require_relative "teamsnap_rb/exceptions"
|
8
|
+
require_relative "teamsnap_rb/config"
|
9
|
+
require_relative "teamsnap_rb/request_builder"
|
10
|
+
require_relative "teamsnap_rb/link"
|
11
|
+
require_relative "teamsnap_rb/links_proxy"
|
12
|
+
require_relative "teamsnap_rb/queries_proxy"
|
13
|
+
require_relative "teamsnap_rb/item"
|
14
|
+
require_relative "teamsnap_rb/template"
|
15
|
+
require_relative "teamsnap_rb/command"
|
16
|
+
require_relative "teamsnap_rb/commands"
|
17
|
+
require_relative "teamsnap_rb/models/event"
|
18
|
+
require_relative "teamsnap_rb/collection"
|
19
|
+
require_relative "teamsnap_rb/client"
|
18
20
|
|
19
21
|
module TeamsnapRb
|
20
22
|
end
|
@@ -71,14 +71,6 @@ module TeamsnapRb
|
|
71
71
|
links.respond_to?(method) || queries.respond_to?(method)
|
72
72
|
end
|
73
73
|
|
74
|
-
def collection
|
75
|
-
@collection ||= Collection.new(href, {}, config)
|
76
|
-
end
|
77
|
-
|
78
|
-
def this
|
79
|
-
@this ||= Collection.new(this_href, {}, config)
|
80
|
-
end
|
81
|
-
|
82
74
|
def links
|
83
75
|
@links ||= LinksProxy.new(collection_json.links, config)
|
84
76
|
end
|
@@ -88,7 +80,11 @@ module TeamsnapRb
|
|
88
80
|
end
|
89
81
|
|
90
82
|
def template
|
91
|
-
@template ||=
|
83
|
+
@template ||= Template.new(collection_json.template, config, href)
|
84
|
+
end
|
85
|
+
|
86
|
+
def commands
|
87
|
+
@commands ||= CommandsProxy.new(collection_json.commands, config)
|
92
88
|
end
|
93
89
|
|
94
90
|
def error
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module TeamsnapRb
|
2
|
+
class Command
|
3
|
+
def initialize(command, config)
|
4
|
+
self.command = command
|
5
|
+
self.config = config
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute(attrs = {})
|
9
|
+
post(attrs.flatten.first)
|
10
|
+
end
|
11
|
+
|
12
|
+
def rel
|
13
|
+
command.rel
|
14
|
+
end
|
15
|
+
|
16
|
+
def href
|
17
|
+
command.href
|
18
|
+
end
|
19
|
+
|
20
|
+
def prompt
|
21
|
+
command.prompt
|
22
|
+
end
|
23
|
+
|
24
|
+
def data
|
25
|
+
command.data.map(&:name)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def post(attrs = {})
|
31
|
+
RequestBuilder.new(config, href).connection.post do |conn|
|
32
|
+
conn.body = attrs.to_json
|
33
|
+
conn.headers['Content-Type'] = 'application/json'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_accessor :command, :config
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module TeamsnapRb
|
2
|
+
class CommandsProxy
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def initialize(commands, config)
|
6
|
+
self.config = config
|
7
|
+
self.commands = commands.inject({}) do |h, command|
|
8
|
+
h.tap do |hash|
|
9
|
+
hash[command.rel.to_sym] = Command.new(command, config)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method, *args)
|
15
|
+
if command = commands[method.to_sym]
|
16
|
+
command.execute(args)
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def respond_to?(method)
|
23
|
+
commands.include?(method.to_sym) || super
|
24
|
+
end
|
25
|
+
|
26
|
+
def each
|
27
|
+
commands.values.each do |command|
|
28
|
+
yield command
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def rels
|
33
|
+
commands.keys
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_accessor :commands, :config
|
39
|
+
end
|
40
|
+
end
|
data/lib/teamsnap_rb/item.rb
CHANGED
@@ -10,6 +10,39 @@ module TeamsnapRb
|
|
10
10
|
self.item = item
|
11
11
|
end
|
12
12
|
|
13
|
+
def href
|
14
|
+
item.href
|
15
|
+
end
|
16
|
+
|
17
|
+
def data
|
18
|
+
item.data
|
19
|
+
end
|
20
|
+
|
21
|
+
def template
|
22
|
+
self.class.templates[type] ||= fetch_template
|
23
|
+
end
|
24
|
+
|
25
|
+
def this
|
26
|
+
@this ||= Collection.new(href, {}, config)
|
27
|
+
end
|
28
|
+
|
29
|
+
def links
|
30
|
+
@links ||= LinksProxy.new(item.links, config)
|
31
|
+
end
|
32
|
+
|
33
|
+
def commands
|
34
|
+
@commands ||= CommandsProxy.new(item.commands)
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete
|
38
|
+
response = delete_href(href)
|
39
|
+
if response.status == 204
|
40
|
+
true
|
41
|
+
else
|
42
|
+
raise FailedToDelete
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
13
46
|
def with(attrs)
|
14
47
|
attrs = Hash[attrs.map{ |k, v| [k.to_s, v] }]
|
15
48
|
dirtied_attrs = attrs.keys
|
@@ -44,20 +77,8 @@ module TeamsnapRb
|
|
44
77
|
Collection.new(nil, nil, config, :request => request)
|
45
78
|
end
|
46
79
|
|
47
|
-
def attributes
|
48
|
-
@attributes ||= data.inject({}) do |h, datum|
|
49
|
-
h.tap do |hash|
|
50
|
-
hash[datum.name] = datum.value
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def href
|
56
|
-
item.href
|
57
|
-
end
|
58
|
-
|
59
80
|
def method_missing(method, *args)
|
60
|
-
if datum =
|
81
|
+
if datum = data.find { |d| d.name == method.to_s }
|
61
82
|
unless instance_variable_get("@#{method}_datum")
|
62
83
|
instance_variable_set("@#{method}_datum", datum.value)
|
63
84
|
end
|
@@ -65,46 +86,33 @@ module TeamsnapRb
|
|
65
86
|
instance_variable_get("@#{method}_datum")
|
66
87
|
elsif links.respond_to?(method)
|
67
88
|
links.send(method)
|
89
|
+
elsif commands.respond_to?(method)
|
90
|
+
commands.send(method, args)
|
68
91
|
else
|
69
92
|
super
|
70
93
|
end
|
71
94
|
end
|
72
95
|
|
73
96
|
def respond_to?(method)
|
74
|
-
if
|
97
|
+
if data.find { |d| d.name == method.to_s }
|
75
98
|
true
|
76
|
-
|
99
|
+
elsif
|
77
100
|
links.respond_to?(method)
|
101
|
+
elsif
|
102
|
+
commands.respond_to?(method)
|
78
103
|
end
|
79
104
|
end
|
80
105
|
|
81
|
-
|
82
|
-
item.data
|
83
|
-
end
|
84
|
-
|
85
|
-
def template
|
86
|
-
self.class.templates[type] ||= fetch_template
|
87
|
-
end
|
106
|
+
private
|
88
107
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
raise FailedToDelete
|
108
|
+
def attributes
|
109
|
+
@attributes ||= data.inject({}) do |h, datum|
|
110
|
+
h.tap do |hash|
|
111
|
+
hash[datum.name] = datum.value
|
112
|
+
end
|
95
113
|
end
|
96
114
|
end
|
97
115
|
|
98
|
-
def this
|
99
|
-
@this ||= Collection.new(href, {}, config)
|
100
|
-
end
|
101
|
-
|
102
|
-
def links
|
103
|
-
@links ||= LinksProxy.new(item.links, config)
|
104
|
-
end
|
105
|
-
|
106
|
-
private
|
107
|
-
|
108
116
|
def delete_href(href)
|
109
117
|
RequestBuilder.new(config, href).connection.delete
|
110
118
|
end
|
@@ -117,6 +125,10 @@ module TeamsnapRb
|
|
117
125
|
this.template
|
118
126
|
end
|
119
127
|
|
128
|
+
def fetch_commands
|
129
|
+
this.commands
|
130
|
+
end
|
131
|
+
|
120
132
|
attr_accessor :item, :config, :dirty_attributes
|
121
133
|
end
|
122
134
|
|
data/lib/teamsnap_rb/template.rb
CHANGED
data/lib/teamsnap_rb/version.rb
CHANGED
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
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
|