csv2api 0.0.1 → 0.1.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.
- checksums.yaml +4 -4
- data/Changelog.md +7 -1
- data/README.md +8 -3
- data/csv2api.gemspec +4 -2
- data/lib/csv2api/server.rb +22 -13
- data/lib/csv2api/version.rb +1 -1
- data/lib/csv2api.rb +1 -0
- data/spec/csv2api/server_spec.rb +40 -9
- data/spec/spec_helper.rb +8 -0
- metadata +32 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 245ac997c6252b30230fedf04586ccae04b2eeb1
         | 
| 4 | 
            +
              data.tar.gz: 3b886a7ad499db858d87ed66d3aa0463a0b3f358
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7ce4141c440da7152fb6001c324c906ad4d09f87e4c586ba1ffeadc14401d275adfcff45cdbc4c9088eb3203b007fa72a54439d75af83fc72aa5caab8dc59962
         | 
| 7 | 
            +
              data.tar.gz: dc99410e6be1d4f1d9c076d40584bf79f508385213d3908555a07c32e0296b4572ca69a659fce2a5df52d6ad4b84d1f475bbc075aff26f047c7295b050df063c
         | 
    
        data/Changelog.md
    CHANGED
    
    | @@ -1,7 +1,13 @@ | |
| 1 1 | 
             
            # CSV2API Changelog
         | 
| 2 2 |  | 
| 3 | 
            +
            ## 0.1.0
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Released June 3, 2014 ([0.1.0](https://github.com/jonahoffline/csv2api/tree/v0.1.0)).
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            * Add XML `Content-Type` response support
         | 
| 8 | 
            +
             | 
| 3 9 | 
             
            ## 0.0.1
         | 
| 4 10 |  | 
| 5 11 | 
             
            Released May 27, 2014 ([0.0.1](https://github.com/jonahoffline/csv2api/tree/v0.0.1)).
         | 
| 6 12 |  | 
| 7 | 
            -
            * Initial Release.
         | 
| 13 | 
            +
            * Initial Release.
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,12 +1,17 @@ | |
| 1 1 | 
             
            # CSV2API
         | 
| 2 | 
            +
            [](https://travis-ci.org/jonahoffline/csv2api)
         | 
| 3 | 
            +
            [](http://badge.fury.io/rb/csv2api)
         | 
| 4 | 
            +
            [](https://gemnasium.com/jonahoffline/csv2api)
         | 
| 5 | 
            +
            [](https://codeclimate.com/github/jonahoffline/csv2api)
         | 
| 6 | 
            +
            [](http://inch-pages.github.io/github/jonahoffline/csv2api)
         | 
| 2 7 |  | 
| 3 | 
            -
            Auto-create json APIs from csv files. Instant endpoints without any hassle
         | 
| 8 | 
            +
            Auto-create json and xml APIs from csv files. Instant endpoints without any hassle.
         | 
| 4 9 |  | 
| 5 10 | 
             
            ## Why should I use this?
         | 
| 6 11 |  | 
| 7 12 | 
             
            * Your boss/client hates you so they insist on sending you .csv files for their data.
         | 
| 8 13 | 
             
            * You need to do a quick prototype and don't want to waste time importing / converting
         | 
| 9 | 
            -
            * You're bored and want to write an app with pre-historical data you found on a floppy!
         | 
| 14 | 
            +
            * You're bored and want to write an app with pre-historical data that you found on a floppy!
         | 
| 10 15 | 
             
            * Your life depends on it (**Disclaimer:** *Use at your own risk, jk you should be fine!*)
         | 
| 11 16 |  | 
| 12 17 | 
             
            ## Installation
         | 
| @@ -31,7 +36,7 @@ tasks.csv - http://localhost:3000/tasks | |
| 31 36 | 
             
            weather.csv - http://localhost:3000/weather
         | 
| 32 37 | 
             
            ```
         | 
| 33 38 |  | 
| 34 | 
            -
            **Note**: Endpoints can be accessed with  | 
| 39 | 
            +
            **Note**: Endpoints can be accessed with the filename or their `.json`, `.xml` extensions.
         | 
| 35 40 |  | 
| 36 41 | 
             
            ### Load a specific folder
         | 
| 37 42 | 
             
              $csv2api -d office_stuff/sad_csvs/
         | 
    
        data/csv2api.gemspec
    CHANGED
    
    | @@ -8,8 +8,8 @@ Gem::Specification.new do |spec| | |
| 8 8 | 
             
              spec.version       = CSV2API::VERSION
         | 
| 9 9 | 
             
              spec.authors       = ['Jonah Ruiz']
         | 
| 10 10 | 
             
              spec.email         = ['jonah@pixelhipsters.com']
         | 
| 11 | 
            -
              spec. | 
| 12 | 
            -
              spec. | 
| 11 | 
            +
              spec.description   = %q(Auto-create json & xml APIs endpoints from csv files.)
         | 
| 12 | 
            +
              spec.summary       = %q(Auto-create API endpoints from csv files.)
         | 
| 13 13 | 
             
              spec.homepage      = 'https://github.com/jonahoffline/csv2api'
         | 
| 14 14 | 
             
              spec.license       = 'MIT'
         | 
| 15 15 |  | 
| @@ -26,4 +26,6 @@ Gem::Specification.new do |spec| | |
| 26 26 | 
             
              spec.add_development_dependency 'rack-test', '~> 0.6.2'
         | 
| 27 27 |  | 
| 28 28 | 
             
              spec.add_dependency 'sinatra', '~> 1.4.5'
         | 
| 29 | 
            +
              spec.add_dependency 'activesupport', '~> 4.1.1'
         | 
| 30 | 
            +
              spec.add_dependency 'builder', '~> 3.2.2'
         | 
| 29 31 | 
             
            end
         | 
    
        data/lib/csv2api/server.rb
    CHANGED
    
    | @@ -14,25 +14,34 @@ module CSV2API | |
| 14 14 | 
             
                end
         | 
| 15 15 |  | 
| 16 16 | 
             
                # Auto-creates endpoints from filenames
         | 
| 17 | 
            -
                #  | 
| 18 | 
            -
                #   If :files contains 'tasks.csv', it will generate an endpoint like:
         | 
| 17 | 
            +
                #  Endpoints will be reachable at depending on format
         | 
| 19 18 | 
             
                #
         | 
| 20 | 
            -
                # | 
| 21 | 
            -
                # | 
| 22 | 
            -
                # | 
| 23 | 
            -
                #       # (will only return the json version of csv)
         | 
| 24 | 
            -
                #     end
         | 
| 25 | 
            -
                #
         | 
| 26 | 
            -
                #  Endpoint will be reachable at any of the following urls:
         | 
| 27 | 
            -
                #  http://localhost:4567/tasks or http://localhost:4567/tasks.json
         | 
| 19 | 
            +
                #    JSON (the default):
         | 
| 20 | 
            +
                #      http://localhost:4567/tasks
         | 
| 21 | 
            +
                #      http://localhost:4567/tasks.json
         | 
| 28 22 | 
             
                #
         | 
| 23 | 
            +
                #    XML:
         | 
| 24 | 
            +
                #     http://localhost:4567/tasks.xml
         | 
| 29 25 | 
             
                settings.files.each do |endpoint|
         | 
| 30 26 | 
             
                  get "/#{endpoint}.?:format?" do
         | 
| 31 | 
            -
                     | 
| 27 | 
            +
                    csv_data = load_data(endpoint)
         | 
| 32 28 |  | 
| 33 | 
            -
                     | 
| 34 | 
            -
             | 
| 29 | 
            +
                    if params[:format].eql?('xml')
         | 
| 30 | 
            +
                      content_type :xml
         | 
| 31 | 
            +
                      csv_data.to_xml(root: endpoint)
         | 
| 32 | 
            +
                    else
         | 
| 33 | 
            +
                      content_type :json
         | 
| 34 | 
            +
                      generate_json(csv_data)
         | 
| 35 | 
            +
                    end
         | 
| 35 36 | 
             
                  end
         | 
| 36 37 | 
             
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                # Loads data for response
         | 
| 40 | 
            +
                # @param endpoint [String] endpoint name
         | 
| 41 | 
            +
                # @return [Array<Hash>] csv data
         | 
| 42 | 
            +
                def load_data(endpoint)
         | 
| 43 | 
            +
                  csv_file = load_csv(settings.csv_path, endpoint)
         | 
| 44 | 
            +
                  CSV2API::Parser.new(csv_file).all
         | 
| 45 | 
            +
                end
         | 
| 37 46 | 
             
              end
         | 
| 38 47 | 
             
            end
         | 
    
        data/lib/csv2api/version.rb
    CHANGED
    
    
    
        data/lib/csv2api.rb
    CHANGED
    
    
    
        data/spec/csv2api/server_spec.rb
    CHANGED
    
    | @@ -1,5 +1,4 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 | 
            -
            require 'ostruct'
         | 
| 3 2 | 
             
            describe CSV2API::Server do
         | 
| 4 3 | 
             
              include Rack::Test::Methods
         | 
| 5 4 |  | 
| @@ -8,18 +7,50 @@ describe CSV2API::Server do | |
| 8 7 | 
             
              end
         | 
| 9 8 |  | 
| 10 9 | 
             
              describe '/tasks' do
         | 
| 11 | 
            -
                 | 
| 12 | 
            -
                   | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 10 | 
            +
                context 'when called with .json extension' do
         | 
| 11 | 
            +
                  it 'returns tasks.csv in json' do
         | 
| 12 | 
            +
                    get '/tasks'
         | 
| 13 | 
            +
                    expect(last_response.body).not_to be_empty
         | 
| 14 | 
            +
                    expect(last_response).to be_ok
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    parsed_response = json(last_response.body).first
         | 
| 17 | 
            +
                    expect(parsed_response).to be_a(Hash)
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                context 'when called with .xml extension' do
         | 
| 22 | 
            +
                  it 'returns tasks.csv in XML' do
         | 
| 23 | 
            +
                    get '/tasks.xml'
         | 
| 24 | 
            +
                    expect(last_response.body).not_to be_empty
         | 
| 25 | 
            +
                    expect(last_response).to be_ok
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    parsed_response = xml(last_response.body)
         | 
| 28 | 
            +
                    expect(parsed_response).to be_a(Hash)
         | 
| 29 | 
            +
                  end
         | 
| 15 30 | 
             
                end
         | 
| 16 31 | 
             
              end
         | 
| 17 32 |  | 
| 18 33 | 
             
              describe '/transaction' do
         | 
| 19 | 
            -
                 | 
| 20 | 
            -
                   | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 34 | 
            +
                context 'when called without .json extension' do
         | 
| 35 | 
            +
                  it 'returns transaction.csv in json' do
         | 
| 36 | 
            +
                    get '/transaction'
         | 
| 37 | 
            +
                    expect(last_response.body).not_to be_empty
         | 
| 38 | 
            +
                    expect(last_response).to be_ok
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    parsed_response = json(last_response.body).first
         | 
| 41 | 
            +
                    expect(parsed_response).to be_a(Hash)
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                context 'when called with .xml extension' do
         | 
| 46 | 
            +
                  it 'returns transaction.csv in XML' do
         | 
| 47 | 
            +
                    get '/transaction.xml'
         | 
| 48 | 
            +
                    expect(last_response.body).not_to be_empty
         | 
| 49 | 
            +
                    expect(last_response).to be_ok
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                    parsed_response = xml(last_response.body)
         | 
| 52 | 
            +
                    expect(parsed_response).to be_a(Hash)
         | 
| 53 | 
            +
                  end
         | 
| 23 54 | 
             
                end
         | 
| 24 55 | 
             
              end
         | 
| 25 56 | 
             
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: csv2api
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0 | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jonah Ruiz
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-06-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -94,7 +94,35 @@ dependencies: | |
| 94 94 | 
             
                - - "~>"
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 96 | 
             
                    version: 1.4.5
         | 
| 97 | 
            -
             | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: activesupport
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - "~>"
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: 4.1.1
         | 
| 104 | 
            +
              type: :runtime
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - "~>"
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: 4.1.1
         | 
| 111 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 112 | 
            +
              name: builder
         | 
| 113 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - "~>"
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: 3.2.2
         | 
| 118 | 
            +
              type: :runtime
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                requirements:
         | 
| 122 | 
            +
                - - "~>"
         | 
| 123 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            +
                    version: 3.2.2
         | 
| 125 | 
            +
            description: Auto-create json & xml APIs endpoints from csv files.
         | 
| 98 126 | 
             
            email:
         | 
| 99 127 | 
             
            - jonah@pixelhipsters.com
         | 
| 100 128 | 
             
            executables:
         | 
| @@ -152,7 +180,7 @@ rubyforge_project: | |
| 152 180 | 
             
            rubygems_version: 2.2.2
         | 
| 153 181 | 
             
            signing_key: 
         | 
| 154 182 | 
             
            specification_version: 4
         | 
| 155 | 
            -
            summary: Auto-create  | 
| 183 | 
            +
            summary: Auto-create API endpoints from csv files.
         | 
| 156 184 | 
             
            test_files:
         | 
| 157 185 | 
             
            - spec/csv2api/csv2api_spec.rb
         | 
| 158 186 | 
             
            - spec/csv2api/parser_spec.rb
         |