apify 0.4.5 → 0.5.0
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.
- data/README.md +3 -0
- data/VERSION +1 -1
- data/apify.gemspec +3 -2
- data/lib/apify.rb +1 -0
- data/lib/apify/patterns.rb +10 -0
- data/lib/apify/schema_helper.rb +8 -3
- data/spec/app_root/app/models/api.rb +24 -0
- data/spec/controllers/api_controller_spec.rb +77 -8
- metadata +5 -4
    
        data/README.md
    CHANGED
    
    | @@ -136,12 +136,15 @@ Here is another example for a more complex schema: | |
| 136 136 | 
             
                        'phone' => integer,
         | 
| 137 137 | 
             
                        'phone_type' => enum(string, 'home', 'office'),
         | 
| 138 138 | 
             
                        'email' => optional(email),
         | 
| 139 | 
            +
                        'website' => optional(url),
         | 
| 139 140 | 
             
                        'favorite' => boolean
         | 
| 140 141 | 
             
                      )
         | 
| 141 142 | 
             
                    )
         | 
| 142 143 | 
             
                  end
         | 
| 143 144 | 
             
                end
         | 
| 144 145 |  | 
| 146 | 
            +
            Note that the schema considers an key/value pair to be "present" when the key is present, even if the value is `nil`. That means if an object entry is optional and you want to omit that entry, you need to leave out the entire key/value pair.
         | 
| 147 | 
            +
             | 
| 145 148 |  | 
| 146 149 | 
             
            Auto-generated API documentation
         | 
| 147 150 | 
             
            --------------------------------
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.5.0
         | 
    
        data/apify.gemspec
    CHANGED
    
    | @@ -5,11 +5,11 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = %q{apify}
         | 
| 8 | 
            -
              s.version = "0. | 
| 8 | 
            +
              s.version = "0.5.0"
         | 
| 9 9 |  | 
| 10 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 11 | 
             
              s.authors = ["Henning Koch"]
         | 
| 12 | 
            -
              s.date = %q{2010-10- | 
| 12 | 
            +
              s.date = %q{2010-10-29}
         | 
| 13 13 | 
             
              s.description = %q{Compact definition of JSON APIs for Rails applications. }
         | 
| 14 14 | 
             
              s.email = %q{github@makandra.de}
         | 
| 15 15 | 
             
              s.extra_rdoc_files = [
         | 
| @@ -79,6 +79,7 @@ Gem::Specification.new do |s| | |
| 79 79 | 
             
                 "lib/apify/client.rb",
         | 
| 80 80 | 
             
                 "lib/apify/errors.rb",
         | 
| 81 81 | 
             
                 "lib/apify/exchange.rb",
         | 
| 82 | 
            +
                 "lib/apify/patterns.rb",
         | 
| 82 83 | 
             
                 "lib/apify/schema_helper.rb",
         | 
| 83 84 | 
             
                 "spec/apify/action_spec.rb",
         | 
| 84 85 | 
             
                 "spec/apify/client_spec.rb",
         | 
    
        data/lib/apify.rb
    CHANGED
    
    
| @@ -0,0 +1,10 @@ | |
| 1 | 
            +
            module Apify
         | 
| 2 | 
            +
              class Patterns
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                EMAIL = /\A[a-z0-9\+\-_\.]+@[a-z0-9]+[a-z0-9\-\.]*[a-z0-9]+\z/i
         | 
| 5 | 
            +
                URL = /(http|https):\/\/[\w\-_]+(\.[\w\-_]+)*([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/
         | 
| 6 | 
            +
                SQL_DATE = /\A\d{4}-\d{2}-\d{2}\z/
         | 
| 7 | 
            +
                SQL_DATETIME = /\A\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\z/
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            end
         | 
    
        data/lib/apify/schema_helper.rb
    CHANGED
    
    | @@ -39,17 +39,22 @@ module Apify | |
| 39 39 |  | 
| 40 40 | 
             
                def sql_date
         | 
| 41 41 | 
             
                  { 'type' => 'string',
         | 
| 42 | 
            -
                    'pattern' => Patterns::SQL_DATE.source }
         | 
| 42 | 
            +
                    'pattern' => Apify::Patterns::SQL_DATE.source }
         | 
| 43 43 | 
             
                end
         | 
| 44 44 |  | 
| 45 45 | 
             
                def sql_datetime
         | 
| 46 46 | 
             
                  { 'type' => 'string',
         | 
| 47 | 
            -
                    'pattern' => Patterns::SQL_DATETIME.source }
         | 
| 47 | 
            +
                    'pattern' => Apify::Patterns::SQL_DATETIME.source }
         | 
| 48 48 | 
             
                end
         | 
| 49 49 |  | 
| 50 50 | 
             
                def email
         | 
| 51 51 | 
             
                  { 'type' => 'string',
         | 
| 52 | 
            -
                    'pattern' => Patterns::EMAIL.source }
         | 
| 52 | 
            +
                    'pattern' => Apify::Patterns::EMAIL.source }
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                def url
         | 
| 56 | 
            +
                  { 'type' => 'string',
         | 
| 57 | 
            +
                    'pattern' => Apify::Patterns::URL.source }
         | 
| 53 58 | 
             
                end
         | 
| 54 59 |  | 
| 55 60 | 
             
              end
         | 
| @@ -45,4 +45,28 @@ class Api < Apify::Api | |
| 45 45 | 
             
                end
         | 
| 46 46 | 
             
              end
         | 
| 47 47 |  | 
| 48 | 
            +
              get :schema_with_sql_date do
         | 
| 49 | 
            +
                schema :args do
         | 
| 50 | 
            +
                  object('date' => sql_date)
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
              get :schema_with_sql_datetime do
         | 
| 55 | 
            +
                schema :args do
         | 
| 56 | 
            +
                  object('datetime' => sql_datetime)
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
              get :schema_with_email do
         | 
| 61 | 
            +
                schema :args do
         | 
| 62 | 
            +
                  object('email' => email)
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
              end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
              get :schema_with_url do
         | 
| 67 | 
            +
                schema :args do
         | 
| 68 | 
            +
                  object('url' => url)
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
             | 
| 48 72 | 
             
            end
         | 
| @@ -64,8 +64,11 @@ describe ApiController do | |
| 64 64 |  | 
| 65 65 | 
             
              describe 'argument schemas' do
         | 
| 66 66 |  | 
| 67 | 
            -
                 | 
| 67 | 
            +
                before :each do
         | 
| 68 68 | 
             
                  instance_exec(&authenticate)
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                it "should validate the presence of a property" do
         | 
| 69 72 | 
             
                  post :with_args_schema, :args => {}.to_json
         | 
| 70 73 | 
             
                  response.code.should == '500'
         | 
| 71 74 | 
             
                  response.body.should include('Invalid request args')
         | 
| @@ -73,7 +76,6 @@ describe ApiController do | |
| 73 76 | 
             
                end
         | 
| 74 77 |  | 
| 75 78 | 
             
                it "should validate value types" do
         | 
| 76 | 
            -
                  instance_exec(&authenticate)
         | 
| 77 79 | 
             
                  post :with_args_schema, :args => {'string_arg' => 123}.to_json
         | 
| 78 80 | 
             
                  response.code.should == '500'
         | 
| 79 81 | 
             
                  response.body.should include('Invalid request args')
         | 
| @@ -81,13 +83,11 @@ describe ApiController do | |
| 81 83 | 
             
                end
         | 
| 82 84 |  | 
| 83 85 | 
             
                it "should allow requests that fit the schema" do
         | 
| 84 | 
            -
                  instance_exec(&authenticate)
         | 
| 85 86 | 
             
                  post :with_args_schema, :args => {'string_arg' => 'a string'}.to_json
         | 
| 86 87 | 
             
                  response.code.should == '200'
         | 
| 87 88 | 
             
                end
         | 
| 88 89 |  | 
| 89 90 | 
             
                it "should render the schema if requested" do
         | 
| 90 | 
            -
                  instance_exec(&authenticate)
         | 
| 91 91 | 
             
                  post :with_args_schema, :schema => 'args'
         | 
| 92 92 | 
             
                  response.code.should == '200'
         | 
| 93 93 | 
             
                  JSON.parse(response.body).should == {
         | 
| @@ -101,8 +101,11 @@ describe ApiController do | |
| 101 101 |  | 
| 102 102 | 
             
              describe 'value schemas' do
         | 
| 103 103 |  | 
| 104 | 
            -
                 | 
| 104 | 
            +
                before :each do
         | 
| 105 105 | 
             
                  instance_exec(&authenticate)
         | 
| 106 | 
            +
                end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                it "should validate the presence of a property" do
         | 
| 106 109 | 
             
                  post :with_value_schema, :args => {}.to_json
         | 
| 107 110 | 
             
                  response.code.should == '500'
         | 
| 108 111 | 
             
                  response.body.should include('Invalid response value')
         | 
| @@ -110,7 +113,6 @@ describe ApiController do | |
| 110 113 | 
             
                end
         | 
| 111 114 |  | 
| 112 115 | 
             
                it "should validate value types" do
         | 
| 113 | 
            -
                  instance_exec(&authenticate)
         | 
| 114 116 | 
             
                  post :with_value_schema, :args => {'string_value' => 123}.to_json
         | 
| 115 117 | 
             
                  response.code.should == '500'
         | 
| 116 118 | 
             
                  response.body.should include('Invalid response value')
         | 
| @@ -118,14 +120,12 @@ describe ApiController do | |
| 118 120 | 
             
                end
         | 
| 119 121 |  | 
| 120 122 | 
             
                it "should return responses that fit the schema" do
         | 
| 121 | 
            -
                  instance_exec(&authenticate)
         | 
| 122 123 | 
             
                  post :with_value_schema, :args => {'string_value' => 'a string'}.to_json
         | 
| 123 124 | 
             
                  response.code.should == '200'
         | 
| 124 125 | 
             
                  JSON.parse(response.body).should == {'string_value' => 'a string'}
         | 
| 125 126 | 
             
                end    
         | 
| 126 127 |  | 
| 127 128 | 
             
                it "should render the schema if requested" do
         | 
| 128 | 
            -
                  instance_exec(&authenticate)
         | 
| 129 129 | 
             
                  post :with_value_schema, :schema => 'value'
         | 
| 130 130 | 
             
                  response.code.should == '200'
         | 
| 131 131 | 
             
                  JSON.parse(response.body).should == {
         | 
| @@ -137,6 +137,75 @@ describe ApiController do | |
| 137 137 |  | 
| 138 138 | 
             
              end
         | 
| 139 139 |  | 
| 140 | 
            +
              describe 'schema helpers' do
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                before :each do
         | 
| 143 | 
            +
                  instance_exec(&authenticate)
         | 
| 144 | 
            +
                end
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                describe '#sql_date helper' do
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                  it 'should match a date as seen in SQL' do
         | 
| 149 | 
            +
                    get :schema_with_sql_date, :args => {'date' => '2011-05-01'}.to_json
         | 
| 150 | 
            +
                    response.code.should == '200'
         | 
| 151 | 
            +
                  end
         | 
| 152 | 
            +
             | 
| 153 | 
            +
                  it 'should not match an invalid string' do
         | 
| 154 | 
            +
                    get :schema_with_sql_date, :args => {'date' => '01.05.2011'}.to_json
         | 
| 155 | 
            +
                    response.code.should == '500'
         | 
| 156 | 
            +
                  end
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                end
         | 
| 159 | 
            +
             | 
| 160 | 
            +
                describe '#sql_datetime helper' do
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                  it 'should match a timestamp as seen in SQL' do
         | 
| 163 | 
            +
                    get :schema_with_sql_datetime, :args => {'datetime' => '2011-05-01 12:10:59'}.to_json
         | 
| 164 | 
            +
                    response.code.should == '200'
         | 
| 165 | 
            +
                  end
         | 
| 166 | 
            +
             | 
| 167 | 
            +
                  it 'should not match an invalid string' do
         | 
| 168 | 
            +
                    get :schema_with_sql_datetime, :args => {'datetime' => '2011-05-01'}.to_json
         | 
| 169 | 
            +
                    response.code.should == '500'
         | 
| 170 | 
            +
                  end
         | 
| 171 | 
            +
             | 
| 172 | 
            +
                end
         | 
| 173 | 
            +
             | 
| 174 | 
            +
                describe '#email helper' do
         | 
| 175 | 
            +
             | 
| 176 | 
            +
                  it 'should match an email address' do
         | 
| 177 | 
            +
                    get :schema_with_email, :args => {'email' => 'some.guy@some.domain.tld'}.to_json
         | 
| 178 | 
            +
                    response.code.should == '200'
         | 
| 179 | 
            +
                  end
         | 
| 180 | 
            +
             | 
| 181 | 
            +
                  it 'should not match an invalid string' do
         | 
| 182 | 
            +
                    get :schema_with_email, :args => {'email' => 'some.guy'}.to_json
         | 
| 183 | 
            +
                    response.code.should == '500'
         | 
| 184 | 
            +
                  end
         | 
| 185 | 
            +
             | 
| 186 | 
            +
                end
         | 
| 187 | 
            +
             | 
| 188 | 
            +
                describe '#url_helper' do
         | 
| 189 | 
            +
             | 
| 190 | 
            +
                  it 'should match a http address' do
         | 
| 191 | 
            +
                    get :schema_with_url, :args => {'url' => 'http://some.domain.tld/path/to?query=value'}.to_json
         | 
| 192 | 
            +
                    response.code.should == '200'
         | 
| 193 | 
            +
                  end
         | 
| 194 | 
            +
             | 
| 195 | 
            +
                  it 'should match a https address' do
         | 
| 196 | 
            +
                    get :schema_with_url, :args => {'url' => 'https://some.domain.tld/path/to?query=value'}.to_json
         | 
| 197 | 
            +
                    response.code.should == '200'
         | 
| 198 | 
            +
                  end
         | 
| 199 | 
            +
             | 
| 200 | 
            +
                  it 'should not match an invalid string' do
         | 
| 201 | 
            +
                    get :schema_with_url, :args => {'url' => 'foo:bar:bam'}.to_json
         | 
| 202 | 
            +
                    response.code.should == '500'
         | 
| 203 | 
            +
                  end
         | 
| 204 | 
            +
             | 
| 205 | 
            +
                end
         | 
| 206 | 
            +
             | 
| 207 | 
            +
              end
         | 
| 208 | 
            +
             | 
| 140 209 | 
             
              describe 'auto-generated documentation' do
         | 
| 141 210 | 
             
                integrate_views
         | 
| 142 211 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: apify
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 11
         | 
| 5 5 | 
             
              prerelease: false
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 | 
            -
              - 4
         | 
| 9 8 | 
             
              - 5
         | 
| 10 | 
            -
               | 
| 9 | 
            +
              - 0
         | 
| 10 | 
            +
              version: 0.5.0
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Henning Koch
         | 
| @@ -15,7 +15,7 @@ autorequire: | |
| 15 15 | 
             
            bindir: bin
         | 
| 16 16 | 
             
            cert_chain: []
         | 
| 17 17 |  | 
| 18 | 
            -
            date: 2010-10- | 
| 18 | 
            +
            date: 2010-10-29 00:00:00 +02:00
         | 
| 19 19 | 
             
            default_executable: 
         | 
| 20 20 | 
             
            dependencies: 
         | 
| 21 21 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| @@ -132,6 +132,7 @@ files: | |
| 132 132 | 
             
            - lib/apify/client.rb
         | 
| 133 133 | 
             
            - lib/apify/errors.rb
         | 
| 134 134 | 
             
            - lib/apify/exchange.rb
         | 
| 135 | 
            +
            - lib/apify/patterns.rb
         | 
| 135 136 | 
             
            - lib/apify/schema_helper.rb
         | 
| 136 137 | 
             
            - spec/apify/action_spec.rb
         | 
| 137 138 | 
             
            - spec/apify/client_spec.rb
         |