Coder Social home page Coder Social logo

peeps3's Introduction

Peeps 3

Overview

This is a simple test app for testing JSONAPI::Resources.

It supports the three different resource retrieval strategies under different namespaces, V09, V10, V11.

It is currently setup to use JR from a local directory that is a sibling of where this is checked out, but this can of course be changed in the Gemfile.

The app provides access to a contacts database with the following features for testing and demonstrating the JR v0.11 release (currently in development). The database will be seeded with a fairly large set of realistic data using the seeds script and the Faker gem.

Models

User

Users of the application. These can be admins or regular users, set by an admin boolean.

Requests to Peeps3 can be authenticated or not. Pass in a username as the content of an Authorization header.

Relationships:

  • has_many :images, as: :imageable - Images of the user using a polymorphic type
  • has_many :contacts, foreign_key: "created_by_user_id" - Contacts created by the User

Contact

Contacts managed by Peeps3. Contacts have email, names, and a public boolean setting. The public setting is used to determine if a contact can be accessed without authorization.

Relationships:

  • belongs_to :creator, foreign_key: "created_by_user_id", class_name: "User" - The user that created the contact
  • has_many :phone_numbers
  • has_many :images, as: :imageable - Images of the contact using a polymorphic type

Image

Images of Contacts or Users, using a polymorphic relationship. No real images are stored, just filenames to keep it simple.

Relationships:

  • belongs_to :imageable, polymorphic: true
  • belongs_to :user,-> { left_joins(:images).where(images: {imageable_type: 'User'}) }, foreign_key: 'imageable_id', optional: true
  • belongs_to :contact,-> { left_joins(:images).where(images: {imageable_type: 'Contact'}) }, foreign_key: 'imageable_id', optional: true

PhoneNumber

A Phone Number record associated with contacts.

Relationship:

  • belongs_to :contact

Setup

docker compose for running postgres and redis

The app contains a docker compose environment if you wish to use it to run postgres and redis. Make a copy of docker-compose.override.yml for the example file as set the ports to expose and any other needed changes.

Start the databases with docker compose up

Setup the peeps database

bundle exec rails db:setup

This should create and seed the database with some data using faker.

Run the app

bundle exec rails s

Access the API with curl

The controllers support authentication by specifying the user name in an authentication header. For example:

curl "http://localhost:4000/v11/images?include=imageable&page%5Bsize%5D=1000" \
     -H 'Accept: application/vnd.api+json' \
     -H 'Authorization: admin1'
curl "http://localhost:4000/v11/contacts?include=phone-numbers&include=images&page%5Bsize%5D=15" \
     -H 'Accept: application/vnd.api+json'

There are some additional curl commands to access the api in the Wiki.

Differences by resource retrieval strategy

Currently using 'JSONAPI::ActiveRelationRetrievalV09' does not apply permissions filtering to the included resources

peeps3's People

Contributors

lgebhardt avatar

Watchers

Dan Gebhardt avatar  avatar  avatar

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.