== README
#YHANBL :D
Une API simple.
##Installation
Pré requis :
- Ruby 2.2.1
- Rails 4.2.6
Installation :
git clone https://github.com/haterecoil/yhanbl_api.git
cd yhanbl_api
bundle install
Database :
bin/rake db:setup
bin/rake db:seed
Lancer le serveur :
rails s
##Structure
Deux ressources : Message et User
Message :
- string :title
- text :text
- datetime :sent_on
- datetime :read_on
- datetime :answered_on
- belongs_to :user, :sender
- belongs_to :user, :recipient
- timestamps null: false
User :
- string :username
- has_many :message, :sent_messages
- has_many :message, :received_messages
Routes :
Prefix Verb URI Pattern Controller#Action
GET /users/:id/friends(.:format) users#get_friends
sign_in POST /sign_in(.:format) sessions#create
users GET /users(.:format) users#index
POST /users(.:format) users#create
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
messages GET /messages(.:format) messages#index
POST /messages(.:format) messages#create
message GET /messages/:id(.:format) messages#show
PATCH /messages/:id(.:format) messages#update
PUT /messages/:id(.:format) messages#update
DELETE /messages/:id(.:format) messages#destroy
Authentification / Authorization
L'authentification se fait en envoyant :
# POST /sign_in
{
"user" : {
"username" : "User0",
"password" : "aa"
}
}
Ce qui renvoie
{
"id": 1,
"username": "User0",
"authentication_token": "vz/z64WkBYqzgnhIoJl2voqz2eqk4D+wgs4VpA8RTCrKIHyL0Z+dMjX2b1YJd9ga457bfbyPAPkuJZDJVH8Q6w=="
}
Authorization ?
On se sert de l'authentication token pour chaque requête, en ajoutant dans le header des requêtes:
Authorization: Token token="{le token sans les accolades la}", username="{le user name sans les accolades)"
##Todo
- /users/:id/friends ( sent to user ) : utilisateurs avec les quels :user a échangé
- /users/:id/all_messages : tous les messages de :user
- /users/:id/received_messages/since/:timestamp tous les messages reçus depuis un :timestamp
- /oauth/ Password Credentials Flow oAuth rails
- [ ]