apiculture 0.0.18 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0376c2d819d808e7c8857d3eb6eeea9bc057c7d
4
- data.tar.gz: 52015f4360aa39a19c0a037f978568ac793a00c7
3
+ metadata.gz: b6f0c8bf33ab6d850b0e5ebe4137248b2eece90b
4
+ data.tar.gz: ff2545d4a6b2d335670722f52052b3081976afb6
5
5
  SHA512:
6
- metadata.gz: '09068eb0cca7bb8d66806bd501220921418d8a7dc02d5e82f8570f18e3014f6b1c0c929bab30c15118b90b7c3534f4226e66c1eb36ebd6b415208d93cfefbead'
7
- data.tar.gz: f6d7f01b4d95527ca815e1eeaccfbc4e19d28ae6dc8aeaa1281fe50f14166d66bb7895081bb2f4c993d75483dcd5ff8e914f72756b4691f1a2e82b0bcd36f1b6
6
+ metadata.gz: 0cd7c2561d5d0139893fbfc78c58e46ee889c84e91756f51773d1000ce4a94b8c5e1af3d2cf0c997835dfc35d6de2fdbaff9b65cece17c3c9835f31915349126
7
+ data.tar.gz: 2870ec784e365047cf7c737bec1510b98e19fb3efa1d5fbb6c3b3cecabdf78aaa09fea584d3a83abca63ffd99d190831a46867b1ee36c397a9eb275bc3b85bf4
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+ Gemfile.lock
15
+
16
+ # jeweler generated
17
+ pkg
18
+
19
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
20
+ #
21
+ # * Create a file at ~/.gitignore
22
+ # * Include files you want ignored
23
+ # * Run: git config --global core.excludesfile ~/.gitignore
24
+ #
25
+ # After doing this, these files will be ignored in all your git projects,
26
+ # saving you from having to 'pollute' every project you touch with them
27
+ #
28
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
29
+ #
30
+ # For MacOS:
31
+ #
32
+ #.DS_Store
33
+
34
+ # For TextMate
35
+ #*.tmproj
36
+ #tmtags
37
+
38
+ # For emacs:
39
+ #*~
40
+ #\#*
41
+ #.\#*
42
+
43
+ # For vim:
44
+ #*.swp
45
+
46
+ # For redcar:
47
+ #.redcar
48
+
49
+ # For rubinius:
50
+ #*.rbc
data/.travis.yml CHANGED
@@ -1,6 +1,10 @@
1
1
  rvm:
2
2
  - 2.1.5
3
3
  - 2.2.2
4
- - 2.3.0
4
+ - 2.3.3
5
+ - 2.4.1
5
6
  sudo: false
6
7
  cache: bundler
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: 2.1.5 # incompatible with the new jeweler version
data/Gemfile CHANGED
@@ -1,15 +1,4 @@
1
- source "http://rubygems.org"
2
- gem 'sinatra', '~> 1.4', :require => 'sinatra/base'
3
- gem 'builder', '~> 3'
4
- gem 'rdiscount', '~> 2.1'
5
- gem 'github-markup', '~> 1'
6
- gem "mustache", '~> 1'
1
+ source 'https://rubygems.org'
7
2
 
8
- group :development do
9
- gem 'rack-test', '~> 0.6'
10
- gem "rspec", "~> 3.1", '< 3.2'
11
- gem "rdoc", "~> 3.12"
12
- gem "bundler", "~> 1.0"
13
- gem "jeweler", "~> 2"
14
- gem "simplecov", ">= 0"
15
- end
3
+ # Source from the gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -1,45 +1,5 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require_relative 'lib/apiculture/version'
15
- require 'jeweler'
16
- Jeweler::Tasks.new do |gem|
17
- gem.name = "apiculture"
18
- gem.version = Apiculture::VERSION
19
- gem.homepage = "https://github.com/WeTransfer/apiculture"
20
- gem.license = "MIT"
21
- gem.description = %Q{A toolkit for building REST APIs on top of Sinatra}
22
- gem.summary = %Q{Sweet API sauce on top of Sintra}
23
- gem.email = "me@julik.nl"
24
- gem.authors = ["Julik Tarkhanov", "WeTransfer"]
25
- # dependencies defined in Gemfile
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
28
-
29
- require 'rspec/core'
1
+ require 'bundler/gem_tasks'
30
2
  require 'rspec/core/rake_task'
31
- RSpec::Core::RakeTask.new(:spec) do |spec|
32
- spec.pattern = FileList['spec/**/*_spec.rb']
33
- end
34
-
35
- task :default => :spec
36
-
37
- require 'rdoc/task'
38
- Rake::RDocTask.new do |rdoc|
39
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
3
 
41
- rdoc.rdoc_dir = 'rdoc'
42
- rdoc.title = "apiculture #{version}"
43
- rdoc.rdoc_files.include('README*')
44
- rdoc.rdoc_files.include('lib/**/*.rb')
45
- end
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
data/apiculture.gemspec CHANGED
@@ -1,91 +1,48 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
- # stub: apiculture 0.0.18 ruby lib
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'apiculture/version'
6
5
 
7
6
  Gem::Specification.new do |s|
8
7
  s.name = "apiculture"
9
- s.version = "0.0.18"
8
+ s.version = Apiculture::VERSION
10
9
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
10
  s.require_paths = ["lib"]
13
11
  s.authors = ["Julik Tarkhanov", "WeTransfer"]
14
- s.date = "2016-11-25"
12
+ s.homepage = 'http://github.com/wetransfer/zip_tricks'
15
13
  s.description = "A toolkit for building REST APIs on top of Sinatra"
16
14
  s.email = "me@julik.nl"
15
+
16
+ # Prevent pushing this gem to RubyGems.org.
17
+ # To allow pushes either set the 'allowed_push_host'
18
+ # To allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if s.respond_to?(:metadata)
20
+ s.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
23
+ 'public gem pushes.'
24
+ end
25
+
26
+ s.files = `git ls-files -z`.split("\x0")
17
27
  s.extra_rdoc_files = [
18
28
  "LICENSE.txt",
19
29
  "README.md"
20
30
  ]
21
- s.files = [
22
- ".travis.yml",
23
- "Gemfile",
24
- "LICENSE.txt",
25
- "README.md",
26
- "Rakefile",
27
- "apiculture.gemspec",
28
- "lib/apiculture.rb",
29
- "lib/apiculture/action.rb",
30
- "lib/apiculture/action_definition.rb",
31
- "lib/apiculture/app_documentation.rb",
32
- "lib/apiculture/app_documentation_tpl.mustache",
33
- "lib/apiculture/markdown_segment.rb",
34
- "lib/apiculture/method_documentation.rb",
35
- "lib/apiculture/sinatra_instance_methods.rb",
36
- "lib/apiculture/timestamp_promise.rb",
37
- "lib/apiculture/version.rb",
38
- "spec/apiculture/action_spec.rb",
39
- "spec/apiculture/app_documentation_spec.rb",
40
- "spec/apiculture/method_documentation_spec.rb",
41
- "spec/apiculture_spec.rb",
42
- "spec/spec_helper.rb"
43
- ]
44
31
  s.homepage = "https://github.com/WeTransfer/apiculture"
45
32
  s.licenses = ["MIT"]
46
33
  s.rubygems_version = "2.4.5.1"
47
34
  s.summary = "Sweet API sauce on top of Sintra"
48
35
 
49
- if s.respond_to? :specification_version then
50
- s.specification_version = 4
36
+ s.add_runtime_dependency 'sinatra', '~> 1'
37
+ s.add_runtime_dependency 'builder', '~> 3'
38
+ s.add_runtime_dependency 'rdiscount', '~> 2'
39
+ s.add_runtime_dependency 'github-markup', '~> 1'
40
+ s.add_runtime_dependency "mustache", '~> 1'
51
41
 
52
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
- s.add_runtime_dependency(%q<sinatra>, ["~> 1.4"])
54
- s.add_runtime_dependency(%q<builder>, ["~> 3"])
55
- s.add_runtime_dependency(%q<rdiscount>, ["~> 2.1"])
56
- s.add_runtime_dependency(%q<github-markup>, ["~> 1"])
57
- s.add_runtime_dependency(%q<mustache>, ["~> 1"])
58
- s.add_development_dependency(%q<rack-test>, ["~> 0.6"])
59
- s.add_development_dependency(%q<rspec>, ["< 3.2", "~> 3.1"])
60
- s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
61
- s.add_development_dependency(%q<bundler>, ["~> 1.0"])
62
- s.add_development_dependency(%q<jeweler>, ["~> 2"])
63
- s.add_development_dependency(%q<simplecov>, [">= 0"])
64
- else
65
- s.add_dependency(%q<sinatra>, ["~> 1.4"])
66
- s.add_dependency(%q<builder>, ["~> 3"])
67
- s.add_dependency(%q<rdiscount>, ["~> 2.1"])
68
- s.add_dependency(%q<github-markup>, ["~> 1"])
69
- s.add_dependency(%q<mustache>, ["~> 1"])
70
- s.add_dependency(%q<rack-test>, ["~> 0.6"])
71
- s.add_dependency(%q<rspec>, ["< 3.2", "~> 3.1"])
72
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
73
- s.add_dependency(%q<bundler>, ["~> 1.0"])
74
- s.add_dependency(%q<jeweler>, ["~> 2"])
75
- s.add_dependency(%q<simplecov>, [">= 0"])
76
- end
77
- else
78
- s.add_dependency(%q<sinatra>, ["~> 1.4"])
79
- s.add_dependency(%q<builder>, ["~> 3"])
80
- s.add_dependency(%q<rdiscount>, ["~> 2.1"])
81
- s.add_dependency(%q<github-markup>, ["~> 1"])
82
- s.add_dependency(%q<mustache>, ["~> 1"])
83
- s.add_dependency(%q<rack-test>, ["~> 0.6"])
84
- s.add_dependency(%q<rspec>, ["< 3.2", "~> 3.1"])
85
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
86
- s.add_dependency(%q<bundler>, ["~> 1.0"])
87
- s.add_dependency(%q<jeweler>, ["~> 2"])
88
- s.add_dependency(%q<simplecov>, [">= 0"])
89
- end
42
+ s.add_development_dependency 'rack-test'
43
+ s.add_development_dependency "rspec", "~> 3.1", '< 3.2'
44
+ s.add_development_dependency "rdoc", "~> 3.12"
45
+ s.add_development_dependency "rake", "~> 10"
46
+ s.add_development_dependency "bundler", "~> 1.0"
47
+ s.add_development_dependency "simplecov", ">= 0"
90
48
  end
91
-
@@ -28,11 +28,11 @@ module Apiculture::SinatraInstanceMethods
28
28
  # given in the keyword arguments
29
29
  def action_result(action_class, **action_ivars)
30
30
  call_result = action_class.new(self, **action_ivars).perform
31
-
32
- unless call_result.is_a?(Array) || call_result.is_a?(Hash)
33
- raise "Action result should be an Array or a Hash, but was a #{call_result.class}"
31
+
32
+ unless call_result.is_a?(Array) || call_result.is_a?(Hash) || (call_result.nil? && status == 204)
33
+ raise "Action result should be an Array, a Hash or it can be nil but only if status is 204, instead it was a #{call_result.class}"
34
34
  end
35
35
 
36
- json_response call_result
36
+ json_response call_result if call_result
37
37
  end
38
38
  end
@@ -1,3 +1,3 @@
1
1
  module Apiculture
2
- VERSION = '0.0.18'
2
+ VERSION = '0.0.19'
3
3
  end
@@ -29,7 +29,7 @@ describe "Apiculture.api_documentation" do
29
29
  end
30
30
 
31
31
  desc 'Pancake ingredients are in the URL'
32
- route_param :topping_id, 'Pancake topping ID', Fixnum, cast: :to_i
32
+ route_param :topping_id, 'Pancake topping ID', Integer, cast: :to_i
33
33
  api_method :get, '/pancake/with/:topping_id' do |topping_id|
34
34
  end
35
35
  end
@@ -68,7 +68,7 @@ describe Apiculture::MethodDocumentation do
68
68
 
69
69
  definition.description = "This adds a topping to a pancake"
70
70
 
71
- definition.route_parameters << Apiculture::RouteParameter.new(:topping_id, 'ID of the pancake topping', Fixnum, cast: :to_i)
71
+ definition.route_parameters << Apiculture::RouteParameter.new(:topping_id, 'ID of the pancake topping', Integer, cast: :to_i)
72
72
  definition.http_verb = 'get'
73
73
  definition.path = '/pancake/:topping_id'
74
74
 
@@ -319,9 +319,9 @@ describe "Apiculture" do
319
319
  settings.raise_errors = true
320
320
  extend Apiculture
321
321
 
322
- route_param :number, "Number of the thing", Fixnum, :cast => :to_i
322
+ route_param :number, "Number of the thing", Integer, :cast => :to_i
323
323
  api_method :post, '/thing/:number' do |number|
324
- raise "Not cast" unless number.class == Fixnum
324
+ raise "Not cast" unless number.class == Integer
325
325
  'Total success'
326
326
  end
327
327
  end
@@ -337,7 +337,7 @@ describe "Apiculture" do
337
337
  extend Apiculture
338
338
 
339
339
  param :number, "Number of the thing", Integer, :cast => :to_i
340
- route_param :id, "Id of the thingy", Fixnum, :cast => :to_i
340
+ route_param :id, "Id of the thingy", Integer, :cast => :to_i
341
341
  route_param :awesome, "Hash of the thingy"
342
342
 
343
343
  api_method :post, '/thing/:id/:awesome' do |id|
@@ -386,6 +386,7 @@ describe "Apiculture" do
386
386
  parsed_body = JSON.load(last_response.body)
387
387
  expect(parsed_body['foo']).to eq('bar')
388
388
  end
389
+
389
390
  it 'adds support for json_response to set http status code', run: true do
390
391
  @app_class = Class.new(Sinatra::Base) do
391
392
  extend Apiculture
@@ -399,6 +400,7 @@ describe "Apiculture" do
399
400
  post '/some-json'
400
401
  expect(last_response.status).to eq(201)
401
402
  end
403
+
402
404
  it 'adds support for json_halt' do
403
405
  @app_class = Class.new(Sinatra::Base) do
404
406
  extend Apiculture
@@ -430,5 +432,44 @@ describe "Apiculture" do
430
432
  parsed_body = JSON.load(last_response.body)
431
433
  expect(parsed_body).to eq({"error"=>"Nein.", "teapot"=>true})
432
434
  end
435
+
436
+ # Mocks didn't play well with setting the status in a sinatra action
437
+ class NilTestAction < Apiculture::Action
438
+ def perform
439
+ status 204
440
+ nil
441
+ end
442
+ end
443
+ it 'allows returning an empty body when the status is 204' do
444
+ @app_class = Class.new(Sinatra::Base) do
445
+ extend Apiculture
446
+ settings.show_exceptions = false
447
+ settings.raise_errors = true
448
+ api_method :get, '/nil204' do
449
+ action_result NilTestAction
450
+ end
451
+ end
452
+
453
+ get '/nil204'
454
+ expect(last_response.status).to eq(204)
455
+ expect(last_response.body).to be_empty
456
+ end
457
+
458
+ it "does not allow returning an empty body when the status isn't 204" do
459
+ # Mock out the perform call so that status doesn't change from the default of 200
460
+ expect_any_instance_of(NilTestAction).to receive(:perform).with(any_args).and_return(nil)
461
+ @app_class = Class.new(Sinatra::Base) do
462
+ extend Apiculture
463
+ settings.show_exceptions = false
464
+ settings.raise_errors = true
465
+ api_method :get, '/nil200' do
466
+ action_result NilTestAction
467
+ end
468
+ end
469
+
470
+ expect{
471
+ get '/nil200'
472
+ }.to raise_error(RuntimeError)
473
+ end
433
474
  end
434
475
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiculture
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-25 00:00:00.000000000 Z
12
+ date: 2017-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.4'
20
+ version: '1'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '1.4'
27
+ version: '1'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: builder
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '2.1'
48
+ version: '2'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '2.1'
55
+ version: '2'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: github-markup
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -85,36 +85,36 @@ dependencies:
85
85
  name: rack-test
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - "~>"
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: '0.6'
90
+ version: '0'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - "~>"
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
- version: '0.6'
97
+ version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rspec
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - "<"
103
- - !ruby/object:Gem::Version
104
- version: '3.2'
105
102
  - - "~>"
106
103
  - !ruby/object:Gem::Version
107
104
  version: '3.1'
105
+ - - "<"
106
+ - !ruby/object:Gem::Version
107
+ version: '3.2'
108
108
  type: :development
109
109
  prerelease: false
110
110
  version_requirements: !ruby/object:Gem::Requirement
111
111
  requirements:
112
- - - "<"
113
- - !ruby/object:Gem::Version
114
- version: '3.2'
115
112
  - - "~>"
116
113
  - !ruby/object:Gem::Version
117
114
  version: '3.1'
115
+ - - "<"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.2'
118
118
  - !ruby/object:Gem::Dependency
119
119
  name: rdoc
120
120
  requirement: !ruby/object:Gem::Requirement
@@ -130,33 +130,33 @@ dependencies:
130
130
  - !ruby/object:Gem::Version
131
131
  version: '3.12'
132
132
  - !ruby/object:Gem::Dependency
133
- name: bundler
133
+ name: rake
134
134
  requirement: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '1.0'
138
+ version: '10'
139
139
  type: :development
140
140
  prerelease: false
141
141
  version_requirements: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '1.0'
145
+ version: '10'
146
146
  - !ruby/object:Gem::Dependency
147
- name: jeweler
147
+ name: bundler
148
148
  requirement: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '2'
152
+ version: '1.0'
153
153
  type: :development
154
154
  prerelease: false
155
155
  version_requirements: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '2'
159
+ version: '1.0'
160
160
  - !ruby/object:Gem::Dependency
161
161
  name: simplecov
162
162
  requirement: !ruby/object:Gem::Requirement
@@ -179,6 +179,7 @@ extra_rdoc_files:
179
179
  - LICENSE.txt
180
180
  - README.md
181
181
  files:
182
+ - ".gitignore"
182
183
  - ".travis.yml"
183
184
  - Gemfile
184
185
  - LICENSE.txt
@@ -203,7 +204,8 @@ files:
203
204
  homepage: https://github.com/WeTransfer/apiculture
204
205
  licenses:
205
206
  - MIT
206
- metadata: {}
207
+ metadata:
208
+ allowed_push_host: https://rubygems.org
207
209
  post_install_message:
208
210
  rdoc_options: []
209
211
  require_paths:
@@ -220,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
222
  version: '0'
221
223
  requirements: []
222
224
  rubyforge_project:
223
- rubygems_version: 2.4.5.1
225
+ rubygems_version: 2.6.11
224
226
  signing_key:
225
227
  specification_version: 4
226
228
  summary: Sweet API sauce on top of Sintra