Giter Club home page Giter Club logo

devise-ios-rails-example's Introduction

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": "[email protected]", "password": "1234" } }' \
https://devise-ios-rails-example.herokuapp.com/users

in return you will get a newly created user

{
  "id": 2,
  "email": "[email protected]",
  "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": "[email protected]", "password": "1234" } }' \
https://devise-ios-rails-example.herokuapp.com/users/sign_in

you will get again the same data:

{
  "id": 2,
  "email": "[email protected]",
  "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: [email protected]' \
-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": "[email protected]" } }' \
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-example.git ./devise-ios-rails-example

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

devise-ios-rails-example's People

Contributors

ghilead avatar lubieniebieski avatar matdobek avatar pharmaceutics avatar testbrian avatar

Watchers

 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.