apiculture 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/apiculture.gemspec +2 -2
 - data/lib/apiculture/sinatra_instance_methods.rb +3 -2
 - data/lib/apiculture/version.rb +1 -1
 - data/spec/apiculture_spec.rb +20 -0
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: d0376c2d819d808e7c8857d3eb6eeea9bc057c7d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 52015f4360aa39a19c0a037f978568ac793a00c7
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: '09068eb0cca7bb8d66806bd501220921418d8a7dc02d5e82f8570f18e3014f6b1c0c929bab30c15118b90b7c3534f4226e66c1eb36ebd6b415208d93cfefbead'
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: f6d7f01b4d95527ca815e1eeaccfbc4e19d28ae6dc8aeaa1281fe50f14166d66bb7895081bb2f4c993d75483dcd5ff8e914f72756b4691f1a2e82b0bcd36f1b6
         
     | 
    
        data/apiculture.gemspec
    CHANGED
    
    | 
         @@ -2,11 +2,11 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            # DO NOT EDIT THIS FILE DIRECTLY
         
     | 
| 
       3 
3 
     | 
    
         
             
            # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
         
     | 
| 
       4 
4 
     | 
    
         
             
            # -*- encoding: utf-8 -*-
         
     | 
| 
       5 
     | 
    
         
            -
            # stub: apiculture 0.0. 
     | 
| 
      
 5 
     | 
    
         
            +
            # stub: apiculture 0.0.18 ruby lib
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       8 
8 
     | 
    
         
             
              s.name = "apiculture"
         
     | 
| 
       9 
     | 
    
         
            -
              s.version = "0.0. 
     | 
| 
      
 9 
     | 
    
         
            +
              s.version = "0.0.18"
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       12 
12 
     | 
    
         
             
              s.require_paths = ["lib"]
         
     | 
| 
         @@ -3,12 +3,13 @@ require 'json' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            # Some sugary methods for use within Sinatra, when responding to a request/rendering JSON
         
     | 
| 
       4 
4 
     | 
    
         
             
            module Apiculture::SinatraInstanceMethods
         
     | 
| 
       5 
5 
     | 
    
         
             
              NEWLINE = "\n"
         
     | 
| 
      
 6 
     | 
    
         
            +
              DEFAULT = :__default__
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
8 
     | 
    
         
             
              # Convert the given structure to JSON, set the content-type and
         
     | 
| 
       8 
9 
     | 
    
         
             
              # return the JSON string
         
     | 
| 
       9 
     | 
    
         
            -
              def json_response(structure, status:  
     | 
| 
      
 10 
     | 
    
         
            +
              def json_response(structure, status: DEFAULT)
         
     | 
| 
       10 
11 
     | 
    
         
             
                content_type :json
         
     | 
| 
       11 
     | 
    
         
            -
                status status
         
     | 
| 
      
 12 
     | 
    
         
            +
                status(status) unless status == DEFAULT
         
     | 
| 
       12 
13 
     | 
    
         
             
                JSON.pretty_generate(structure)
         
     | 
| 
       13 
14 
     | 
    
         
             
              end
         
     | 
| 
       14 
15 
     | 
    
         | 
    
        data/lib/apiculture/version.rb
    CHANGED
    
    
    
        data/spec/apiculture_spec.rb
    CHANGED
    
    | 
         @@ -201,12 +201,16 @@ describe "Apiculture" do 
     | 
|
| 
       201 
201 
     | 
    
         
             
                    api_method :post, '/api-thing/:id_of_thing' do |id|
         
     | 
| 
       202 
202 
     | 
    
         
             
                      raise 'id_of_thing must be passed' unless id == '123456'
         
     | 
| 
       203 
203 
     | 
    
         
             
                      raise "id_of_thing must be present in params, but they were #{params.inspect}" unless params.keys.include?('id_of_thing')
         
     | 
| 
      
 204 
     | 
    
         
            +
                      raise "id_of_thing must be string-accessible in params" unless params['id_of_thing'] == '123456'
         
     | 
| 
      
 205 
     | 
    
         
            +
                      raise "id_of_thing must be symbol-accessible in params" unless params[:id_of_thing] == '123456'
         
     | 
| 
       204 
206 
     | 
    
         
             
                      'All is well'
         
     | 
| 
       205 
207 
     | 
    
         
             
                    end
         
     | 
| 
       206 
208 
     | 
    
         | 
| 
       207 
209 
     | 
    
         
             
                    post '/vanilla-thing/:id_of_thing' do |id|
         
     | 
| 
       208 
210 
     | 
    
         
             
                      raise 'id_of_thing must be passed' unless id == '123456'
         
     | 
| 
       209 
211 
     | 
    
         
             
                      raise "id_of_thing must be present in params, but they were #{params.inspect}" unless params.keys.include?('id_of_thing')
         
     | 
| 
      
 212 
     | 
    
         
            +
                      raise "id_of_thing must be string-accessible in params" unless params['id_of_thing'] == '123456'
         
     | 
| 
      
 213 
     | 
    
         
            +
                      raise "id_of_thing must be symbol-accessible in params" unless params[:id_of_thing] == '123456'
         
     | 
| 
       210 
214 
     | 
    
         
             
                      'All is well'
         
     | 
| 
       211 
215 
     | 
    
         
             
                    end
         
     | 
| 
       212 
216 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -218,6 +222,22 @@ describe "Apiculture" do 
     | 
|
| 
       218 
222 
     | 
    
         
             
                  expect(last_response).to be_ok
         
     | 
| 
       219 
223 
     | 
    
         
             
                end
         
     | 
| 
       220 
224 
     | 
    
         | 
| 
      
 225 
     | 
    
         
            +
                it 'does not clobber the status set in a separate mutating call when using json_response' do
         
     | 
| 
      
 226 
     | 
    
         
            +
                  @app_class = Class.new(Sinatra::Base) do
         
     | 
| 
      
 227 
     | 
    
         
            +
                    settings.show_exceptions = false
         
     | 
| 
      
 228 
     | 
    
         
            +
                    settings.raise_errors = true
         
     | 
| 
      
 229 
     | 
    
         
            +
                    extend Apiculture
         
     | 
| 
      
 230 
     | 
    
         
            +
             
     | 
| 
      
 231 
     | 
    
         
            +
                    api_method :post, '/api/:id' do
         
     | 
| 
      
 232 
     | 
    
         
            +
                      status 201
         
     | 
| 
      
 233 
     | 
    
         
            +
                      json_response({was_created: true})
         
     | 
| 
      
 234 
     | 
    
         
            +
                    end
         
     | 
| 
      
 235 
     | 
    
         
            +
                  end
         
     | 
| 
      
 236 
     | 
    
         
            +
                  
         
     | 
| 
      
 237 
     | 
    
         
            +
                  post '/api/123'
         
     | 
| 
      
 238 
     | 
    
         
            +
                  expect(last_response.status).to eq(201)
         
     | 
| 
      
 239 
     | 
    
         
            +
                end
         
     | 
| 
      
 240 
     | 
    
         
            +
                
         
     | 
| 
       221 
241 
     | 
    
         
             
                it 'raises when describing a route parameter that is not included in the path' do
         
     | 
| 
       222 
242 
     | 
    
         
             
                  expect {
         
     | 
| 
       223 
243 
     | 
    
         
             
                    Class.new(Sinatra::Base) do
         
     |