8000 GitHub - hs414h/ports: Ports management app.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

hs414h/ports

Repository files navigation

Ports

CircleCI

An API which allows you to manage ports with CRUD operations and also you can create batch ports at once from a CSV file

Setting up the project

  • clone the repo: git clone git@github.com:Heshamsalah/ports.git
  • Goto ports directory cd ports.
  • Run bundle install.
  • Change Database related [Evnironment Variables] in the .env file to match your PostgreSQL Database configuration.
  • Run rails db:create && rails db:migrate.
  • Start rails server using: rails s.

Postman

  • Use Postman app to interact with the deployed api.

Run in Postman

Steps and App Usage Explaination

  • To perform actions in this application you need to be an authorized user

  • First you need to login through /login:

    • Request:
      curl -d '{"email": "user@example.com", "password": "123456789"}' \
           -H 'Content-Type: application/json' http://localhost:3000/login
      
    • Response
      {
        "token":"eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxNywiZXhwIjoxNTU4OTMyOTExfQ.OWVJmUYFgU0uen_Apjhpp5eA6qXC0qo7dXWWZS3lHLE",
        "exp":"05-27-2019 06:55"
      }
      
  • If you don't have an account you may register /signup:

    • Request:
      curl -d '{"email": "user@example.com", "password": "123456789", "password_confirmation": "123456789"}' \
           -H 'Content-Type: application/json' http://localhost:3000/signup
      
    • Response:
      {
        "token":"eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxNywiZXhwIjoxNTU4OTMyODEwfQ.IrlCt_ytyXM9ZBPbKK_1AOt2Uer2s3dTM2g5BODw3sA",
        "exp":"05-27-2019 06:53"
      }
      
  • Then you need to copy the token that came back with the response and add it to any coming request.

  • You can get list of all ports through: /ports

    • Request:
      curl -X GET -d '{"page": 1, "per": 20}' \
          -H "Authorization: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxNywiZXhwIjoxNTU4OTMyODEwfQ.IrlCt_ytyXM9ZBPbKK_1AOt2Uer2s3dTM2g5BODw3sA" \
          http://localhost:3000/ports
      
  • To create multiple ports from CSV file you should provide csv_string in the json body with a base64 encoded csv string:

    • Request:
      curl -d '{ "csv_string": <base64 encoded csv file string>}' \ 
          -H "Authorization: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE1NTg5MjgxMTF9.YjhAAVEnnwWg2Wgldhgq0xabH1H5zOQZfNa_HkT3CxI" \ 
        http://localhost:3000/ports/batch_create_csv
      
  • You can perform the rest of the CRUD Operations in the same way.

  • You can provide search params to the index action to search by any of the port's fields.

Running Tests

  • Tests run automatically on master branch using CircleCI.
  • Run tests locally using: rspec

Rake Tasks

  • rake create_demo_data

    • this rake task will generate and puts in the console:
      • User with email and password
      • '3' newly created port records
      • Base64 encoded string of a small test csv file.
  • rake convert_csv_to_base64'[/path/to/file]'

    • this rake task is for converting any csv file into base64 string.
    • it will put out a base64 string of the file in console.

Used Gems:

About

Ports management app.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
0