strutta-api 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Strutta API Wrapper' do
4
+
5
+ before { WebMock.disable_net_connect!(allow_localhost: true, allow: /codeclimate/) }
6
+ after { WebMock.allow_net_connect! }
7
+
8
+ let(:token) { 'dc1479c52801fbfa0975947de092a1e7' }
9
+ let(:host) { 'http://api.strutta.dev:4000' }
10
+ let(:path) { '/v2/' }
11
+ let(:strutta) { Strutta::API.new token, host, path }
12
+
13
+ let(:point_params) do
14
+ {
15
+ round_id: POINTS_ROUND[:id],
16
+ entry_id: ENTRY_01[:id],
17
+ participant: PARTICIPANT_01[:id],
18
+ weight: 5
19
+ }
20
+ end
21
+
22
+ let(:new_game) { strutta.games.create }
23
+ let(:game) { strutta.games(VALID_GAME_01[:id]) }
24
+
25
+ describe 'games(:id).points' do
26
+ context 'when no id is given' do
27
+
28
+ context '.create' do
29
+ context 'with valid parameters' do
30
+ before do
31
+ stub_request(:post, /.*points/)
32
+ .to_return(status: 201, body: POINTS_RESPONSE.to_json, headers: {})
33
+ end
34
+ it 'should return a new flow hash' do
35
+ points = strutta.games(333).points.create(point_params)
36
+ expect(points['id'].is_a? Integer).to be true
37
+ expect(points['weight']).to eq point_params[:weight]
38
+ end
39
+ end
40
+ end
41
+
42
+ context '.all' do
43
+ it 'should throw disabled endpoint error' do
44
+ expect { game.points.all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
45
+ end
46
+ end
47
+
48
+ context '.get' do
49
+ it 'should throw disabled endpoint error' do
50
+ expect { game.points.get({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
51
+ end
52
+ end
53
+
54
+ context '.update' do
55
+ it 'should throw disabled endpoint error' do
56
+ expect { game.points.update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
57
+ end
58
+ end
59
+
60
+ context '.delete' do
61
+ it 'should throw disabled endpoint error' do
62
+ expect { game.points.delete({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
63
+ end
64
+ end
65
+ end
66
+
67
+ context 'when id is given' do
68
+ context '.all' do
69
+ it 'should throw disabled endpoint error' do
70
+ expect { game.points(1).all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
71
+ end
72
+ end
73
+
74
+ context '.get' do
75
+ it 'should throw disabled endpoint error' do
76
+ expect { game.points(1).get({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
77
+ end
78
+ end
79
+
80
+ context '.update' do
81
+ it 'should throw disabled endpoint error' do
82
+ expect { game.points(1).update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
83
+ end
84
+ end
85
+
86
+ context '.delete' do
87
+ it 'should throw disabled endpoint error' do
88
+ expect { game.points(1).delete({}) }.to raise_error(Strutta::Errors::DisabledEndpointError)
89
+ end
90
+ end
91
+
92
+ context '.create' do
93
+ it 'should throw error' do
94
+ expect { game.flow(1).create }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Strutta API Wrapper' do
4
+
5
+ before { WebMock.disable_net_connect!(allow_localhost: true, allow: /codeclimate/) }
6
+ after { WebMock.allow_net_connect! }
7
+
8
+ let(:token) { 'dc1479c52801fbfa0975947de092a1e7' }
9
+ let(:host) { 'http://api.strutta.dev:4000' }
10
+ let(:path) { '/v2/' }
11
+ let(:strutta) { Strutta::API.new token, host, path }
12
+
13
+ let(:new_game) { strutta.games.create }
14
+ let(:round_params) do
15
+ {
16
+ title: 'my round',
17
+ type: 'submission',
18
+ start_date: Time.now.to_i,
19
+ end_date: Time.now.to_i + 3600,
20
+ rules: {
21
+ num_entries: 100,
22
+ interval: 'day'
23
+ }
24
+ }
25
+ end
26
+
27
+ before do
28
+ stub_request(:post, /.*games/)
29
+ .to_return(status: 201, body: VALID_GAME_02.to_json, headers: {})
30
+ end
31
+
32
+ describe 'games(:id).rounds' do
33
+ context 'when no id is given' do
34
+ context '.get' do
35
+ it 'should throw error' do
36
+ expect { strutta.games.rounds.get }.to raise_error(Strutta::Errors::ObjectIDRequired)
37
+ end
38
+ end
39
+
40
+ context '.update' do
41
+ it 'should throw error' do
42
+ expect { strutta.games.rounds.update(title: 'title') }.to raise_error(Strutta::Errors::ObjectIDRequired)
43
+ end
44
+ end
45
+
46
+ context '.delete' do
47
+ it 'should throw error' do
48
+ expect { strutta.games.rounds.delete }.to raise_error(Strutta::Errors::ObjectIDRequired)
49
+ end
50
+ end
51
+
52
+ context '.all' do
53
+ before do
54
+ stub_request(:get, /.*rounds/)
55
+ .to_return(status: 200, body: ROUND_INDEX.to_json, headers: {})
56
+ end
57
+ it 'should return array of rounds' do
58
+ round_list = strutta.games(VALID_GAME_02[:id]).rounds.all
59
+ expect(round_list.is_a? Array).to be true
60
+ end
61
+ end
62
+
63
+ context '.create' do
64
+ before do
65
+ stub_request(:post, /.*rounds/)
66
+ .to_return(status: 201, body: SUBMISSION_ROUND.to_json, headers: {})
67
+ end
68
+ context 'with valid parameters' do
69
+ it 'should return a new round hash' do
70
+ round = strutta.games(VALID_GAME_02[:id]).rounds.create(round_params)
71
+ expect(round['id']).to_not be nil
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ context 'when id is given' do
78
+ before do
79
+ stub_request(:get, /.*rounds\/\d+/)
80
+ .to_return(status: 200, body: RANDOM_DRAW_ROUND.to_json, headers: {})
81
+ end
82
+ context '.get' do
83
+ it 'should return round hash' do
84
+ r = strutta.games(VALID_GAME_01[:id]).rounds(RANDOM_DRAW_ROUND[:id]).get
85
+ expect(r['id']).to_not be nil
86
+ end
87
+ end
88
+
89
+ context '.update' do
90
+ before do
91
+ stub_request(:patch, /.*rounds\/\d+/)
92
+ .to_return(status: 200, body: SUBMISSION_ROUND_UPDATED.to_json, headers: {})
93
+ end
94
+ it 'should return updated round hash' do
95
+ updated = strutta.games(VALID_GAME_01[:id]).rounds(SUBMISSION_ROUND[:id]).update(title: 'updated')
96
+ expect(updated['title']).to eq('updated')
97
+ end
98
+ end
99
+
100
+ context '.delete' do
101
+ before do
102
+ stub_request(:delete, /.*rounds\/\d+/)
103
+ .to_return(status: 204, body: '', headers: {})
104
+ end
105
+ it 'should delete round' do
106
+ expect(strutta.games(VALID_GAME_01[:id]).rounds(SUBMISSION_ROUND[:id]).delete).to be true
107
+ end
108
+ end
109
+
110
+ context '.all' do
111
+ it 'should throw error' do
112
+ expect { strutta.games(VALID_GAME_01[:id]).rounds(PRIZE_FULFILLMENT_ROUND[:id]).all }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
113
+ end
114
+ end
115
+
116
+ context '.create' do
117
+ it 'should throw error' do
118
+ expect { strutta.games(VALID_GAME_01[:id]).rounds(PRIZE_FULFILLMENT_ROUND[:id]).create(round_params) }.to raise_error(Strutta::Errors::ObjectIDNotAllowed)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,16 @@
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
3
+
4
+ require 'strutta-api'
5
+ require 'webmock/rspec'
6
+ require 'fixtures/games_fixtures.rb'
7
+ require 'fixtures/rounds_fixtures.rb'
8
+ require 'fixtures/entries_fixtures.rb'
9
+ require 'fixtures/participants_fixtures.rb'
10
+ require 'fixtures/flow_fixtures.rb'
11
+ require 'fixtures/points_fixtures.rb'
12
+ require 'fixtures/moderation_fixtures.rb'
13
+ require 'fixtures/judging_fixtures.rb'
14
+
15
+ require 'simplecov'
16
+ SimpleCov.start
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'strutta-api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'strutta-api'
8
+ spec.version = Strutta::Version::VERSION
9
+ spec.authors = ['BlakeTurner']
10
+ spec.email = ['blake@strutta.com']
11
+ spec.summary = %q( Official Strutta API wrapper )
12
+ spec.description = %q()
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ # spec.files = ['lib/strutta-api.rb', 'lib/strutta-api/*']
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "excon"
27
+ spec.add_development_dependency "webmock"
28
+ spec.add_development_dependency "simplecov"
29
+ spec.add_development_dependency 'codeclimate-test-reporter'
30
+ spec.add_development_dependency 'yard'
31
+ end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strutta-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - BlakeTurner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: excon
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: ''
126
+ email:
127
+ - blake@strutta.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - Gemfile
134
+ - LICENSE.txt
135
+ - README.md
136
+ - Rakefile
137
+ - lib/strutta-api.rb
138
+ - lib/strutta-api/api_object.rb
139
+ - lib/strutta-api/entries.rb
140
+ - lib/strutta-api/errors.rb
141
+ - lib/strutta-api/flow.rb
142
+ - lib/strutta-api/games.rb
143
+ - lib/strutta-api/judging.rb
144
+ - lib/strutta-api/moderation.rb
145
+ - lib/strutta-api/participants.rb
146
+ - lib/strutta-api/points.rb
147
+ - lib/strutta-api/rounds.rb
148
+ - lib/strutta-api/version.rb
149
+ - spec/entries_spec.rb
150
+ - spec/errors_spec.rb
151
+ - spec/fixtures/entries_fixtures.rb
152
+ - spec/fixtures/flow_fixtures.rb
153
+ - spec/fixtures/games_fixtures.rb
154
+ - spec/fixtures/judging_fixtures.rb
155
+ - spec/fixtures/moderation_fixtures.rb
156
+ - spec/fixtures/participants_fixtures.rb
157
+ - spec/fixtures/points_fixtures.rb
158
+ - spec/fixtures/rounds_fixtures.rb
159
+ - spec/flow_spec.rb
160
+ - spec/games_spec.rb
161
+ - spec/judging_spec.rb
162
+ - spec/moderation_spec.rb
163
+ - spec/participants_spec.rb
164
+ - spec/points_spec.rb
165
+ - spec/rounds_spec.rb
166
+ - spec/spec_helper.rb
167
+ - strutta-api.gemspec
168
+ homepage: ''
169
+ licenses:
170
+ - MIT
171
+ metadata: {}
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubyforge_project:
188
+ rubygems_version: 2.2.2
189
+ signing_key:
190
+ specification_version: 4
191
+ summary: Official Strutta API wrapper
192
+ test_files:
193
+ - spec/entries_spec.rb
194
+ - spec/errors_spec.rb
195
+ - spec/fixtures/entries_fixtures.rb
196
+ - spec/fixtures/flow_fixtures.rb
197
+ - spec/fixtures/games_fixtures.rb
198
+ - spec/fixtures/judging_fixtures.rb
199
+ - spec/fixtures/moderation_fixtures.rb
200
+ - spec/fixtures/participants_fixtures.rb
201
+ - spec/fixtures/points_fixtures.rb
202
+ - spec/fixtures/rounds_fixtures.rb
203
+ - spec/flow_spec.rb
204
+ - spec/games_spec.rb
205
+ - spec/judging_spec.rb
206
+ - spec/moderation_spec.rb
207
+ - spec/participants_spec.rb
208
+ - spec/points_spec.rb
209
+ - spec/rounds_spec.rb
210
+ - spec/spec_helper.rb
211
+ has_rdoc: