/devise-ios-rails-example

Open Source Devise iOS Rails Backend

Primary LanguageRubyBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Open Source Devise iOS Rails Backend

Circle CI Code Climate Test Coverage Dependency

A rails backend for demonstrating how Devise for iOS works.

How to use

After a successfull installation you can use localhost:3000/doc to trigger a request at some particular endpoints.

Demo App

We've setup for you a demo of this server at https://devise-ios-rails-example.herokuapp.com. You can test how it works with either using dynamically generated swagger docs or by using some old school curl commands:

register a user

$ curl \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-X POST -d '{ "user": { "email": "user@example.com", "password": "1234" } }' \
https://devise-ios-rails-example.herokuapp.com/users

in return you will get a newly created user

{
  "id": 2,
  "email": "user@example.com",
  "created_at": "2014-12-09T16:17:46.170Z",
  "updated_at": "2014-12-09T16:17:46.170Z",
  "authentication_token": "2-D9jBtnAPcP8fppzJAL"
}

login a user

$ curl \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-X POST -d '{ "user": { "email": "user@example.com", "password": "1234" } }' \
https://devise-ios-rails-example.herokuapp.com/users/sign_in

you will get again the same data:

{
  "id": 2,
  "email": "user@example.com",
  "created_at": "2014-12-09T16:17:46.170Z",
  "updated_at": "2014-12-09T16:17:46.170Z",
  "authentication_token": "2-D9jBtnAPcP8fppzJAL"
}

to make a request to resources that are only available for registered users, you need to pass email and authentication token in your headers all the time:

$ curl \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'X-User-Email: user@example.com' \
-H 'X-User-Token: 2-D9jBtnAPcP8fppzJAL' \
-X GET https://devise-ios-rails-example.herokuapp.com/secret_spaces/new

response: { "id": null, "text": null, "created_at": null, "updated_at": null }

in order to check how password reset works:

$ curl \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-X POST -d '{ "user": { "email": "user@example.com" } }' \
https://devise-ios-rails-example.herokuapp.com/users/password

you receive response status 204 (no content). In the meantime, server sends instructions on how to reset the password, which you should follow. On heroku we use letter_opener_web gem therefore those emails are stored at https://devise-ios-rails-example.herokuapp.com/letter_opener. Therefore mails are NOT send to users.

Here is a complete list of paths:

  • Useful Devise paths
               login - POST   /users/sign_in
               login - GET    /users/sign_in
            register - POST   /users
         update user - PUT    /users
         delete user - DELETE /users
change user password - PUT    /users/password
      password reset - POST   /users/password
  • Secret Spaces for demonstration purposes
               index - GET    /secret_spaces
                show - GET    /secret_spaces/:id
                 new - GET    /secret_spaces/new
              create - POST   /secret_spaces
                edit - GET    /secret_spaces/:id/edit
              update - PUT    /secret_spaces/:id
              delete - DELETE /secret_spaces/password/:id

Requirements

Name Version
Ruby 2.1.5
Ruby on Rails 4.1.8

You can find some guidelines on how to install above on mac and on ubuntu.

Optional (recommended)

  • git (mac - brew install git, ubuntu - apt-get install git)

Setup

  • clone repo to your local machine git clone https://github.com/netguru/devise-ios-rails.git ./devise-ios-rails

Environment config

  • copy .env.sample to .env cp .env.sample .env
  • fill in your domain name and url - in the local environment it's normally localhost and http://localhost:3000 respectively.
  • you will need to generate your own SECRET_KEY_BASE by running rake secret and pasting the output into .env file.
  • you can omit Rollbar config in the development environment.

Database config

  • copy config/database.yml.sample to config/database.yml cp config/database.yml.sample config/database.yml
  • fill in your appropriate details in your database.yml config file, example:
development:
  adapter: sqlite3
  host: localhost
  database: devise_ios_rails_development.sqlite3
  username: devise_ios_rails
  • and create a database:
rake db:create
rake db:schema:load
rake db:test:prepare
  • create seed data with:
rake db:seed

this will create:

Start Server

Before you start the app be sure that PostgreSQL is already running. Then start a Rails server on default port with: rails server.

Tests

  • run tests with spring rspec

Other tools

Spring

You can use Spring to speed up specs, rake tasks and rails commands.

Just add spring before commands like rspec, rake, rails.

Contribution

First, thank you for contributing!

Here's a few guidelines to follow:

  • we follow Ruby Style Guide.
  • you can use rubocop which can be easily integrated with popular editors. (our rubocop config)
  • keep gems up to date - you can use gemsurance to check for outdated gems - simply run bundle exec gemsurance.
  • write tests
  • make sure the entire test suite passes
  • make sure rubocop passes our config
  • open a pull request on GitHub
  • squash your commits after receiving feedback

You can also read our blog post announcing devise-iOS for simplified auth.

Copyright 2014 © Netguru, released under the New BSD License