27. Signup API
Feature: Signup API
As a MCDO developer
In order to develop apps
I want to register new users
Scenario: Succesful signup
When I call "/users.json" in POST with:
"""
{
"user": {
"email": "hello@abc.org",
"password": "abcde",
"password_confirmation": "abcde"
}
}
"""
Then the JSON should be:
"""
{
"id": 1,
"email": "hello@abc.org"
}
"""
28. Signup API
Scenario: signup fails with a wrong password_confirmation
When I call "/users.json" in POST with:
"""
{
"user": {
"email": "hello@abc.org",
"password": "abcde",
"password_confirmation": "abcde1"
}
}
"""
Then the JSON should be:
"""
{
"errors": { "password": ["doesn't match confirmation"] }
}
"""
33. Login API
Feature: Login API
As a MCDO developer
In order to develop apps
I want to login with an existing user
Background:
Given there is the following user:
| email | password | password_confirmation |
| abcd@org.it | aa | aa |
Scenario: Succesful login
When I call "/session.json" in POST with:
"""
{
"email": "abcd@org.it",
"password": "aa"
}
"""
Then the JSON should be:
"""
{
"status": "authenticated"
}
"""
34. Login API
Scenario: Failed login
When I call "/session.json" in POST with:
"""
{
"email": "abcd@org.it",
"password": "bb"
}
"""
Then the JSON should be:
"""
{
"status": "not authenticated"
}
"""
35. Login API
Scenario: Validating an active session
Given I call "/session.json" in POST with:
"""
{
"email": "abcd@org.it",
"password": "aa"
}
"""
When I call "/session.json" in GET
Then the JSON should be:
"""
{
"status": "authenticated"
}
"""
36. Login API
Scenario: Validating an active session
Given I call "/session.json" in POST with:
"""
{
"email": "abcd@org.it",
"password": "aa"
}
Let’s see some code!
"""
When I call "/session.json" in GET
Then the JSON should be:
"""
{
"status": "authenticated"
}
"""
38. Lists API
Feature: Lists API
As a MCDO developer
In order to develop apps
I want to manage a user's lists
Background:
Given I login succesfully with user "aaa@abc.org"
Scenario: Default lists
When I call "/lists.json" in GET
Then the JSON should be:
"""
{
"lists": [{
"id": 1,
"name": "Personal",
"link": "http://www.example.com/lists/1",
"items_link": "http://www.example.com/lists/1/items"
}]
}
"""
39. Lists API
Scenario: Creating a list
When I call "/lists.json" in POST with:
"""
{
"list": {
"name": "foobar"
}
}
"""
Then the JSON should be:
"""
{
"name": "foobar",
"items_link": "http://www.example.com/lists/1/items"
}
"""
40. Lists API
Scenario: Creating a list should add it to the index
Given I call "/lists.json" in POST with:
"""
{
"list": {
"name": "foobar"
}
}
"""
When I call "/lists.json" in GET
Then the JSON should be:
"""
{
"lists": [{
"id": 2,
"name": "foobar",
"link": "http://www.example.com/lists/2",
"items_link": "http://www.example.com/lists/2/items"
}, {
"id": 1,
"name": "Personal",
"link": "http://www.example.com/lists/1",
"items_link": "http://www.example.com/lists/1/items"
}]
}
"""
41. Lists API
Scenario: Removing a list (and the index is empty)
Given I call "/lists/1.json" in DELETE
When I call "/lists.json"
Then the JSON should be:
"""
{
"lists": []
}
"""
Scenario: Updating a list's name
When I call "/lists/1.json" in PUT with:
"""
{
"list": {
"name": "foobar"
}
}
"""
Then the JSON should be:
"""
{
"name": "foobar",
"items_link": "http://www.example.com/lists/1/items"
}
"""
42. Lists API
Scenario: Removing a list (and the index is empty)
Given I call "/lists/1.json" in DELETE
When I call "/lists.json"
Then the JSON should be:
"""
{
"lists": []
}
"""
Let’s see some code!
Scenario: Updating a list's name
When I call "/lists/1.json" in PUT with:
"""
{
"list": {
"name": "foobar"
}
}
"""
Then the JSON should be:
"""
{
"name": "foobar",
"items_link": "http://www.example.com/lists/1/items"
}
"""
44. Items API
Feature: Manage a list's items
As a developer
In order to manipulate the list's item
I want to access them through APIs
Background:
Given I login succesfully with user "aaa@abc.org"
Scenario: Default items
When I call "/lists/1/items.json" in GET
Then the JSON should be:
"""
{
"items": [{
"name": "Insert your items!",
"position": 0
}],
"list_link": "http://www.example.com/lists/1"
}
"""
45. Items API
Scenario: Moving an element to the top
Given I call "/lists/1/items.json" in POST with:
...
And I call "/lists/1/items.json" in POST with:
...
When I call "/lists/1/items/2/move.json" in PUT with:
"""
{
"position": 0
}
"""
Then the JSON should be:
"""
{
"items": [{
"name": "b",
"position": 0
}, {
"name": "Insert your items!",
"position": 1
}, {
"name": "c",
"position": 2
}],
"list_link": "http://www.example.com/lists/1"
}
"""
46. Items API
Scenario: Moving an element to the top
Given I call "/lists/1/items.json" in POST with:
...
And I call "/lists/1/items.json" in POST with:
...
When I call "/lists/1/items/2/move.json" in PUT with:
"""
{
"position": 0
}
Let’s see some code!
"""
Then the JSON should be:
"""
{
"items": [{
"name": "b",
"position": 0
}, {
"name": "Insert your items!",
"position": 1
}, {
"name": "c",
"position": 2
}],
"list_link": "http://www.example.com/lists/1"
}
"""
49. Do we need
an admin panel?
Put in your Gemfile:
gem 'activeadmin'
gem 'meta_search', '>= 1.1.0.pre'
Then run:
$ bundle install
$ rails g active_admin:install
$ rails g active_admin:resource users
$ rails g active_admin:resource lists
$ rails g active_admin:resource items
$ rake db:migrate
50. Do we need
an admin panel?
Put in your Gemfile:
Let’s see some code!
gem 'activeadmin'
gem 'meta_search', '>= 1.1.0.pre'
Then run:
$ bundle install
$ rails g active_admin:install
$ rails g active_admin:resource users
$ rails g active_admin:resource lists
$ rails g active_admin:resource items
$ rake db:migrate
52. Build a JS App!
Backbone.js: MVC in the browser
Rails asset pipeline concatenate
and minifies our JS automatically
We can even write our app in
CoffeeScript: it works out of the box.
53. Build a JS App!
Backbone.js: MVC in the browser
to Rails asset pipeline concatenate
the code.. again?
and minifies our JS automatically
We can even write our app in
CoffeeScript: it works out of the box.
57. TL;DR
Mobile Apps need an API
Ruby on Rails is good for writing APIs
You can build nice admin interfaces
with ActiveAdmin
You can craft Javascript Apps easily
using the asset pipeline.