Giter Club home page Giter Club logo

travelpayouts's Introduction

Travelpayouts test app

1. Build images

docker-compose up -d --build

Now we have puma running on 0.0.0.0:3000 and postgresql configured

2. Load db defaults

docker-compose exec api bundle exec rake db:create
docker-compose exec api bundle exec rake db:migrate
docker-compose exec api bundle exec rake db:seed

Now we have db default values all set

Tasks

1. Create new user

using jsonapi

curl -0 -v -X POST http://localhost:3000/users \
-H "Accept: application/vnd.api+json"          \
-H "Content-Type: application/vnd.api+json"    \
-d @- <<'EOF'
{
  "data": {
    "type": "users",
    "attributes": {
      "email": "[email protected]",
      "name": "Test user 1"
    }
  }
}
EOF

using json

curl -0 -v -X POST http://localhost:3000/users \
-H "Accept: application/json"                  \
-H "Content-Type: application/json"            \
-d '{"user": {"email": "[email protected]", "name": "Test user 2"}}'

4. Get user info

curl -H "Accept: application/json" http://localhost:3000/users/1

5. Get programs list

curl -H "Accept: application/json" http://localhost:3000/programs

Bonus task (term filtering):

curl -H "Accept: application/json" http://localhost:3000/programs?term=Train

6. Create user subscription

You can do it 5 different ways

Using jsonapi

with programs nested url
curl -0 -v -X POST http://localhost:3000/programs/1/subscriptions \
-H "Accept: application/vnd.api+json"                             \
-H "Content-Type: application/vnd.api+json"                       \
-d @- <<'EOF'
{
  "data": {
    "type": "subscriptions",
    "relationships": {
      "user": {
        "data": {
          "type": "users",
          "id": "1"
        }
      }
    }
  }
}
EOF
with users nested url
curl -0 -v -X POST http://localhost:3000/users/1/subscriptions \
-H "Accept: application/vnd.api+json"                          \
-H "Content-Type: application/vnd.api+json"                    \
-d @- <<'EOF'
{
  "data": {
    "type": "subscriptions",
    "relationships": {
      "program": {
        "data": {
          "type": "programs",
          "id": "2"
        }
      }
    }
  }
}
EOF
with root subscriptions url
curl -0 -v -X POST http://localhost:3000/subscriptions \
-H "Accept: application/vnd.api+json"                  \
-H "Content-Type: application/vnd.api+json"            \
-d @- <<'EOF'
{
  "data": {
    "type": "subscriptions",
    "relationships": {
      "user": {
        "data": {
          "type": "users",
          "id": "1"
        }
      },
      "program": {
        "data": {
          "type": "programs",
          "id": "3"
        }
      }
    }
  }
}
EOF

Using json

with users nested url
curl -0 -v -X POST http://localhost:3000/users/1/subscriptions \
-H "Accept: application/json"                                  \
-H "Content-Type: application/json"                            \
-d '{"subscription": {"program_id": 4}}'
with programs nested url
curl -0 -v -X POST http://localhost:3000/programs/5/subscriptions \
-H "Accept: application/json"                                     \
-H "Content-Type: application/json"                               \
-d '{"subscription": {"user_id": 1}}'

Additionally you may set 'banned' attribute to true in every type of subscription creation. Or update subscription with separate request:

curl -0 -v -X PATCH http://localhost:3000/subscriptions/1 \
-H "Accept: application/json"                             \
-H "Content-Type: application/json"                       \
-d '{"subscription": {"banned": true}}'

This will make program hidden in user's programs list:

curl -H "Accept: application/json" http://localhost:3000/users/1/programs

Testing

If you want to run tests or use guard gem for automated testing run

docker-compose exec test bundle exec rake db:create
docker-compose exec test bundle exec rake db:migrate

after test container built and configured find out its id

docker container ls | grep travelpayouts_test

and run

docker attach <your test container id>

Development or test debugging

  1. Get your container id
docker container ls | grep travelpayouts_api
  1. Insert your byebug breakpoint
  2. run
docker attach <your api container id>
  1. ... PROFIT
  2. Press Ctrl+P then Ctrl+Q to detach after debugging is done

travelpayouts's People

Contributors

bombazook avatar

Watchers

 avatar  avatar

travelpayouts's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.