opushon 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -5
  3. data/.travis.yml +12 -3
  4. data/.yardopts +1 -0
  5. data/CODE_OF_CONDUCT.md +13 -0
  6. data/Gemfile +1 -0
  7. data/LICENSE.md +17 -18
  8. data/README.md +36 -3
  9. data/Rakefile +3 -2
  10. data/VERSION.semver +1 -1
  11. data/bin/console +7 -0
  12. data/bin/setup +5 -0
  13. data/lib/opushon/body.rb +35 -0
  14. data/lib/opushon/option.rb +22 -0
  15. data/lib/opushon/parameter.rb +52 -6
  16. data/lib/opushon/request.rb +19 -0
  17. data/lib/opushon/response.rb +17 -0
  18. data/lib/opushon/restricted_value.rb +4 -22
  19. data/lib/opushon.rb +23 -9
  20. data/opushon.gemspec +10 -6
  21. metadata +65 -68
  22. data/.coveralls.yml +0 -1
  23. data/.ruby-version +0 -1
  24. data/lib/opushon/error/base_error.rb +0 -6
  25. data/lib/opushon/error/min_is_greater_than_max_error.rb +0 -8
  26. data/lib/opushon/error/minlen_is_longer_than_maxlen_error.rb +0 -8
  27. data/lib/opushon/error/syntax_error.rb +0 -8
  28. data/lib/opushon/error/verb_error.rb +0 -8
  29. data/lib/opushon/error.rb +0 -3
  30. data/lib/opushon/instance.rb +0 -34
  31. data/lib/opushon/option_object.rb +0 -36
  32. data/lib/opushon/parameter/base.rb +0 -47
  33. data/lib/opushon/parameter/input.rb +0 -34
  34. data/lib/opushon/parameter/output.rb +0 -10
  35. data/lib/opushon/type/array.rb +0 -10
  36. data/lib/opushon/type/base.rb +0 -25
  37. data/lib/opushon/type/boolean.rb +0 -10
  38. data/lib/opushon/type/hash.rb +0 -10
  39. data/lib/opushon/type/number.rb +0 -29
  40. data/lib/opushon/type/string.rb +0 -32
  41. data/lib/opushon/type.rb +0 -10
  42. data/lib/opushon/verb/base.rb +0 -7
  43. data/lib/opushon/verb/delete.rb +0 -9
  44. data/lib/opushon/verb/get.rb +0 -9
  45. data/lib/opushon/verb/head.rb +0 -9
  46. data/lib/opushon/verb/patch.rb +0 -9
  47. data/lib/opushon/verb/post.rb +0 -9
  48. data/lib/opushon/verb/put.rb +0 -9
  49. data/lib/opushon/verb.rb +0 -9
  50. data/lib/opushon/version.rb +0 -9
  51. data/spec/opushon/parameter/input_spec.rb +0 -161
  52. data/spec/opushon/parameter/output_spec.rb +0 -108
  53. data/spec/opushon/parameter/spec_helper.rb +0 -1
  54. data/spec/opushon/restricted_value_spec.rb +0 -42
  55. data/spec/opushon/spec_helper.rb +0 -1
  56. data/spec/opushon/version_spec.rb +0 -9
  57. data/spec/opushon_spec.rb +0 -343
  58. data/spec/spec_helper.rb +0 -4
  59. data/spec/support/coverage.rb +0 -9
  60. data/spec/support/env.rb +0 -1
  61. data/spec/support/immutable.rb +0 -15
  62. data/spec/support.rb +0 -3
@@ -1,161 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe Opushon::Parameter::Input do
4
- subject do
5
- Opushon::Parameter::Input
6
- end
7
-
8
- describe '.load' do
9
- it 'MUST return the hash' do
10
- params = {
11
- foo: subject.new(title: 'Foo').to_h,
12
- bar: subject.new(title: 'Bar').to_h
13
- }
14
-
15
- subject.load(params).must_equal({
16
- foo: subject.new(title: 'Foo').to_h,
17
- bar: subject.new(title: 'Bar').to_h
18
- })
19
- end
20
- end
21
-
22
- describe '.new' do
23
- describe '#to_h' do
24
- describe 'default params' do
25
- describe 'default type' do
26
- it 'MUST return the hash' do
27
- o = subject.new
28
-
29
- o.to_h.must_equal(title: '',
30
- description: '',
31
- type: :string,
32
- nullifiable: true,
33
- query_string: true,
34
- restricted_values: nil,
35
- minlen: nil,
36
- maxlen: nil,
37
- pattern: nil)
38
- end
39
- end
40
-
41
- describe 'string type' do
42
- it 'MUST return the hash' do
43
- o = subject.new(type: 'string')
44
-
45
- o.to_h.must_equal(title: '',
46
- description: '',
47
- type: :string,
48
- nullifiable: true,
49
- query_string: true,
50
- restricted_values: nil,
51
- minlen: nil,
52
- maxlen: nil,
53
- pattern: nil)
54
- end
55
- end
56
-
57
- describe 'number type' do
58
- it 'MUST return the hash' do
59
- o = subject.new(type: 'number')
60
-
61
- o.to_h.must_equal(title: '',
62
- description: '',
63
- type: :number,
64
- nullifiable: true,
65
- query_string: true,
66
- restricted_values: nil,
67
- min: nil,
68
- max: nil)
69
- end
70
- end
71
-
72
- describe 'boolean type' do
73
- it 'MUST return the hash' do
74
- o = subject.new(type: 'boolean')
75
-
76
- o.to_h.must_equal(title: '',
77
- description: '',
78
- type: :boolean,
79
- nullifiable: true,
80
- query_string: true,
81
- restricted_values: nil)
82
- end
83
- end
84
-
85
- describe 'array type' do
86
- it 'MUST return the hash' do
87
- o = subject.new(type: 'array')
88
-
89
- o.to_h.must_equal(title: '',
90
- description: '',
91
- type: :array,
92
- nullifiable: true,
93
- query_string: true,
94
- restricted_values: nil)
95
- end
96
- end
97
-
98
- describe 'hash type' do
99
- it 'MUST return the hash' do
100
- o = subject.new(type: 'hash')
101
-
102
- o.to_h.must_equal(title: '',
103
- description: '',
104
- type: :hash,
105
- nullifiable: true,
106
- query_string: true,
107
- restricted_values: nil)
108
- end
109
- end
110
- end
111
- end
112
-
113
- describe 'random example' do
114
- it 'MUST return the hash' do
115
- o = subject.new(
116
- description: 'State of the issues to return.',
117
- type: 'boolean',
118
- query_string: false,
119
- nullifiable: true,
120
- restricted_values: [
121
- {
122
- value: "open",
123
- title: "Open"
124
- },
125
- {
126
- value: "closed",
127
- title: "Closed"
128
- },
129
- {
130
- value: "all",
131
- title: "All"
132
- }
133
- ]
134
- )
135
-
136
- o.to_h.must_equal(title: '',
137
- description: 'State of the issues to return.',
138
- type: :boolean,
139
- nullifiable: true,
140
- query_string: false,
141
- restricted_values: [
142
- {
143
- title: 'Open',
144
- description: '',
145
- value: 'open'
146
- },
147
- {
148
- title: 'Closed',
149
- description: '',
150
- value: 'closed'
151
- },
152
- {
153
- title: 'All',
154
- description: '',
155
- value: 'all'
156
- }
157
- ])
158
- end
159
- end
160
- end
161
- end
@@ -1,108 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe Opushon::Parameter::Output do
4
- subject do
5
- Opushon::Parameter::Output
6
- end
7
-
8
- describe '.load' do
9
- it 'MUST return the hash' do
10
- params = {
11
- foo: subject.new(title: 'Foo').to_h,
12
- bar: subject.new(title: 'Bar').to_h
13
- }
14
-
15
- subject.load(params).must_equal({
16
- foo: subject.new(title: 'Foo').to_h,
17
- bar: subject.new(title: 'Bar').to_h
18
- })
19
- end
20
- end
21
-
22
- describe '.new' do
23
- describe '#to_h' do
24
- describe 'default params' do
25
- describe 'default type' do
26
- it 'MUST return the hash' do
27
- o = subject.new
28
-
29
- o.to_h.must_equal(title: '',
30
- description: '',
31
- type: :string,
32
- nullifiable: true)
33
- end
34
- end
35
-
36
- describe 'string type' do
37
- it 'MUST return the hash' do
38
- o = subject.new(type: 'string')
39
-
40
- o.to_h.must_equal(title: '',
41
- description: '',
42
- type: :string,
43
- nullifiable: true)
44
- end
45
- end
46
-
47
- describe 'number type' do
48
- it 'MUST return the hash' do
49
- o = subject.new(type: 'number')
50
-
51
- o.to_h.must_equal(title: '',
52
- description: '',
53
- type: :number,
54
- nullifiable: true)
55
- end
56
- end
57
-
58
- describe 'boolean type' do
59
- it 'MUST return the hash' do
60
- o = subject.new(type: 'boolean')
61
-
62
- o.to_h.must_equal(title: '',
63
- description: '',
64
- type: :boolean,
65
- nullifiable: true)
66
- end
67
- end
68
-
69
- describe 'array type' do
70
- it 'MUST return the hash' do
71
- o = subject.new(type: 'array')
72
-
73
- o.to_h.must_equal(title: '',
74
- description: '',
75
- type: :array,
76
- nullifiable: true)
77
- end
78
- end
79
-
80
- describe 'hash type' do
81
- it 'MUST return the hash' do
82
- o = subject.new(type: 'hash')
83
-
84
- o.to_h.must_equal(title: '',
85
- description: '',
86
- type: :hash,
87
- nullifiable: true)
88
- end
89
- end
90
- end
91
- end
92
-
93
- describe 'random example' do
94
- it 'MUST return the hash' do
95
- o = subject.new(
96
- description: 'State of the issues to return.',
97
- type: 'boolean',
98
- nullifiable: true
99
- )
100
-
101
- o.to_h.must_equal(title: '',
102
- description: 'State of the issues to return.',
103
- type: :boolean,
104
- nullifiable: true)
105
- end
106
- end
107
- end
108
- end
@@ -1 +0,0 @@
1
- require_relative File.join(*%w(.. spec_helper))
@@ -1,42 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe Opushon::RestrictedValue do
4
- subject do
5
- Opushon::RestrictedValue
6
- end
7
-
8
- describe 'passes' do
9
- describe '#to_h' do
10
- it 'MUST return the hash' do
11
- subject.new(value: :foobar).to_h.must_equal({
12
- title: '',
13
- description: '',
14
- value: :foobar
15
- })
16
- end
17
- end
18
-
19
- describe '#to_h' do
20
- it 'MUST return the hash' do
21
- subject.new(value: :foobar,
22
- description: :foobar).to_h.must_equal({
23
- title: '',
24
- description: 'foobar',
25
- value: :foobar
26
- })
27
- end
28
- end
29
-
30
- describe '#value' do
31
- it 'MUST return the value' do
32
- subject.new(value: :foobar).value.must_equal(:foobar)
33
- end
34
- end
35
- end
36
-
37
- describe 'errors' do
38
- it 'MUST raise without value' do
39
- -> { subject.new(description: :foobar) }.must_raise(ArgumentError)
40
- end
41
- end
42
- end
@@ -1 +0,0 @@
1
- require_relative File.join(*%w(.. spec_helper))
@@ -1,9 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe Opushon::VERSION do
4
- it 'MUST return the version' do
5
- Opushon::VERSION.must_equal File.open(
6
- Pathname.new(__FILE__).join(*%w(.. .. .. VERSION.semver))
7
- ).read.chomp.to_sym
8
- end
9
- end
data/spec/opushon_spec.rb DELETED
@@ -1,343 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe Opushon do
4
- subject { Opushon }
5
-
6
- describe '.load' do
7
- let :opushon_string do
8
- '{
9
- "GET": {
10
- "title": "List issues",
11
- "description": "List all issues across all the authenticated user\'s visible repositories.",
12
- "parameters": {
13
- "input": {
14
- "page": {
15
- "type": "number",
16
- "description": "Identify the page to return.",
17
- "min": 1,
18
- "max": null
19
- },
20
- "per_page": {
21
- "type": "number",
22
- "description": "Indicate the number of issues per page.",
23
- "min": 1,
24
- "max": 100
25
- },
26
- "state": {
27
- "description": "Indicates the state of the issues to return.",
28
- "restricted_values": [
29
- {
30
- "value": "open",
31
- "title": "Open"
32
- },
33
- {
34
- "value": "closed",
35
- "title": "Closed"
36
- },
37
- {
38
- "value": "all",
39
- "title": "All"
40
- }
41
- ],
42
- "nullifiable": true
43
- }
44
- },
45
- "output": {
46
- "created_at": {
47
- "type": "string",
48
- "description": "The datetime that the resource was created at.",
49
- "nullifiable": false
50
- },
51
- "title": {
52
- "type": "string",
53
- "description": "The title of the resource.",
54
- "nullifiable": false
55
- },
56
- "body": {
57
- "type": "string",
58
- "description": "The body of the resource.",
59
- "nullifiable": true
60
- },
61
- "state": {
62
- "type": "string",
63
- "description": "Indicates the state of the issue.",
64
- "nullifiable": false
65
- }
66
- }
67
- },
68
- "examples": {
69
- "input": null,
70
- "output": [
71
- {
72
- "created_at": "2014-01-01T01:01:01Z",
73
- "title": "Found a bug",
74
- "body": "I\'m having a problem with this.",
75
- "state": "open"
76
- }
77
- ]
78
- }
79
- },
80
- "POST": {
81
- "title": "Create an issue",
82
- "description": "Any user with pull access to a repository can create an issue.",
83
- "parameters": {
84
- "input": {
85
- "title": {
86
- "query_string": false,
87
- "type": "string",
88
- "description": "Issue title.",
89
- "maxlen": 255,
90
- "nullifiable": false
91
- },
92
- "body": {
93
- "query_string": false,
94
- "type": "string",
95
- "description": "Issue body.",
96
- "nullifiable": true
97
- },
98
- "labels": {
99
- "query_string": false,
100
- "type": "string",
101
- "description": "Labels to associate with this issue.",
102
- "nullifiable": true,
103
- "restricted_values": [
104
- {
105
- "value": "label_1",
106
- "title": "Java"
107
- },
108
- {
109
- "value": "label_2",
110
- "title": "Ruby"
111
- },
112
- {
113
- "value": "label_3",
114
- "title": "Elixir"
115
- }
116
- ]
117
- }
118
- },
119
- "output": null
120
- },
121
- "examples": {
122
- "input": {
123
- "title": "Found a bug",
124
- "body": "I\'m having a problem with this.",
125
- "labels": [
126
- "label_1",
127
- "label_2"
128
- ]
129
- },
130
- "output": null
131
- }
132
- },
133
- "DELETE": {
134
- "title": "Delete issues",
135
- "description": "Remove every issues.",
136
- "parameters": {
137
- "input": null,
138
- "output": null
139
- },
140
- "examples": {
141
- "input": null,
142
- "output": null
143
- }
144
- }
145
- }'
146
- end
147
-
148
- describe '#to_h' do
149
- it 'MUST load opushon having query_string and parameters' do
150
- subject.load(opushon_string).to_h.must_equal({
151
- :GET=>{
152
- :title=>"List issues",
153
- :description=>"List all issues across all the authenticated user's visible repositories.",
154
- :parameters=>{
155
- :input=>{
156
- :page=>{
157
- :query_string=>true,
158
- :restricted_values=>nil,
159
- :title=>"",
160
- :description=>"Identify the page to return.",
161
- :nullifiable=>true,
162
- :type=>:number,
163
- :min=>1,
164
- :max=>nil
165
- },
166
- :per_page=>{
167
- :query_string=>true,
168
- :restricted_values=>nil,
169
- :title=>"",
170
- :description=>"Indicate the number of issues per page.",
171
- :nullifiable=>true,
172
- :type=>:number,
173
- :min=>1,
174
- :max=>100
175
- },
176
- :state=>{
177
- :query_string=>true,
178
- :restricted_values=>[
179
- {
180
- :title=>"Open",
181
- :description=>"",
182
- :value=>"open"
183
- },
184
- {
185
- :title=>"Closed",
186
- :description=>"",
187
- :value=>"closed"
188
- },
189
- {
190
- :title=>"All",
191
- :description=>"",
192
- :value=>"all"
193
- }
194
- ],
195
- :title=>"",
196
- :description=>"Indicates the state of the issues to return.",
197
- :nullifiable=>true,
198
- :type=>:string,
199
- :minlen=>nil,
200
- :maxlen=>nil,
201
- :pattern=>nil
202
- }
203
- },
204
- :output=>{
205
- :created_at=>{
206
- :title=>"",
207
- :description=>"The datetime that the resource was created at.",
208
- :nullifiable=>false,
209
- :type=>:string
210
- },
211
- :title=>{
212
- :title=>"",
213
- :description=>"The title of the resource.",
214
- :nullifiable=>false,
215
- :type=>:string
216
- },
217
- :body=>{
218
- :title=>"",
219
- :description=>"The body of the resource.",
220
- :nullifiable=>true,
221
- :type=>:string
222
- },
223
- :state=>{
224
- :title=>"",
225
- :description=>"Indicates the state of the issue.",
226
- :nullifiable=>false,
227
- :type=>:string
228
- }
229
- }
230
- },
231
- :examples=>{
232
- :input=>nil,
233
- :output=>[
234
- {
235
- :created_at=>"2014-01-01T01:01:01Z",
236
- :title=>"Found a bug",
237
- :body=>"I'm having a problem with this.",
238
- :state=>"open"
239
- }
240
- ]
241
- }
242
- },
243
- :POST=>{
244
- :title=>"Create an issue",
245
- :description=>"Any user with pull access to a repository can create an issue.",
246
- :parameters=>{
247
- :input=>{
248
- :title=>{
249
- :query_string=>false,
250
- :restricted_values=>nil,
251
- :title=>"",
252
- :description=>"Issue title.",
253
- :nullifiable=>false,
254
- :type=>:string,
255
- :minlen=>nil,
256
- :maxlen=>255,
257
- :pattern=>nil
258
- },
259
- :body=>{
260
- :query_string=>false,
261
- :restricted_values=>nil,
262
- :title=>"",
263
- :description=>"Issue body.",
264
- :nullifiable=>true,
265
- :type=>:string,
266
- :minlen=>nil,
267
- :maxlen=>nil,
268
- :pattern=>nil
269
- },
270
- :labels=>{
271
- :query_string=>false,
272
- :restricted_values=>[
273
- {
274
- :title=>"Java",
275
- :description=>"",
276
- :value=>"label_1"
277
- },
278
- {
279
- :title=>"Ruby",
280
- :description=>"",
281
- :value=>"label_2"
282
- },
283
- {
284
- :title=>"Elixir",
285
- :description=>"",
286
- :value=>"label_3"
287
- }
288
- ],
289
- :title=>"",
290
- :description=>"Labels to associate with this issue.",
291
- :nullifiable=>true,
292
- :type=>:string,
293
- :minlen=>nil,
294
- :maxlen=>nil,
295
- :pattern=>nil
296
- }
297
- },
298
- :output=>nil
299
- },
300
- :examples=>{
301
- :input=>{
302
- :title=>"Found a bug",
303
- :body=>"I'm having a problem with this.",
304
- :labels=>[
305
- "label_1",
306
- "label_2"
307
- ]
308
- },
309
- :output=>nil
310
- }
311
- },
312
- :DELETE=>{
313
- :title=>"Delete issues",
314
- :description=>"Remove every issues.",
315
- :parameters=>{
316
- :input=>nil,
317
- :output=>nil
318
- },
319
- :examples=>{
320
- :input=>nil,
321
- :output=>nil
322
- }
323
- }
324
- })
325
- end
326
- end
327
- end
328
-
329
- describe '.dump' do
330
- it 'MUST dump Ruby object o to a Opushon string' do
331
- JSON.load(
332
- Opushon.dump({
333
- DELETE: {
334
- title: 'Delete issues',
335
- description: 'Remove every issues.'
336
- }
337
- })
338
- ).must_equal(
339
- JSON.load("{\"DELETE\":{\"title\":\"Delete issues\",\"description\":\"Remove every issues.\"}}")
340
- )
341
- end
342
- end
343
- end
data/spec/spec_helper.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'minitest/autorun'
2
-
3
- require_relative 'support'
4
- require_relative File.join(*%w(.. lib opushon))
@@ -1,9 +0,0 @@
1
- require 'simplecov'
2
- require 'coveralls'
3
-
4
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
- SimpleCov::Formatter::HTMLFormatter,
6
- Coveralls::SimpleCov::Formatter
7
- ]
8
-
9
- SimpleCov.start
data/spec/support/env.rb DELETED
@@ -1 +0,0 @@
1
- abort "Needs Ruby 2, you're running: #{RUBY_VERSION}" if RUBY_VERSION < '2'