Find file
Fetching contributors…
Cannot retrieve contributors at this time
164 lines (119 sloc) 4.55 KB


Usergrid_ironhorse is based on Usergrid_iron and enables Ruby or Rails applications native Rails-style access to Apigee's App Services (aka Usergrid) REST API.


Add this line to your application's Gemfile:

gem 'usergrid_ironhorse'

And then execute:

$ bundle

Or install it yourself as:

$ gem install usergrid_ironhorse


Not familiar with Usergrid / Apigee's App Services?

It's great stuff! Check it out, here:

Open source:

Getting started with the Usergrid_ironhorse SDK is super simple!


  • Add 'gem usergrid_ironhorse' to your Gemfile
  • Create a 'config/usergrid.yml' file that looks something like this (the auth_token is your application admin token):
    application_url: http://localhost:8080/my-organization/my-application
    auth_token: YWMtc4WjqhcbEeK6UhQQn9SVgQAAATpryjMnLy9oFaPbP-0qIxoUx_4vtaOmpmE

development: application_url: http://localhost:8080/my-organization/my-application auth_token: YWMtc4WjqhcbEeK6UhQQn9SVgQAAATpryjMnLy9oFaPbP-0qIxoUx_4vtaOmpmE

production: application_url: auth_token: YWMtc4WjqhcbEeK6UhQQn9SVgQAAATpryjMnLy9oFaPbP-0qIxoUx_4vtaOmpmE

  • Your User model should subclass Usergrid::Ironhorse::Base and extend Usergrid::Ironhorse::UserContext like so:
    class User < Usergrid::Ironhorse::Base
    extend Usergrid::Ironhorse::UserContext


  • Set up your authentication
    • Use User.authenticate(username, password, session) to login.
    • Use User.clear_authentication(session) to log out.
  • Propogate the authentication in your ApplicationController:
    before_filter :set_thread_context
    def set_thread_context
    User.set_thread_context session
  • Optionally, if you need to access the User from your view, you may add something like the following to your ApplicationController:
    helper_method :current_user
    def current_user

Get going!

  • Subclass Usergrid::Ironhorse::Base for your models. Your models will automatically be stored in a collection according to the name of your class as defined by Rails' ActiveModel::Naming module. (Which you may override by implementing model_name if desired.)
class Developer < Usergrid::Ironhorse::Base
  validates :name, :presence => true  # Yes, of course you can use validation

  • Now just use the Rails methods you're already familiar with:

    dev = language: 'Ruby'
    dev.valid? # nope!
    dev.errors # {:name=>["can't be blank"]} = 'Scott'!
    dev = Developer.find_or_create_by_name 'Scott'
    dev.favorite_color = 'green' # assign new attributes automatically
    dev = Developer.find_by_name 'Scott'
  • BTW: If you need to do management tasks, wrapping the work in an as_admin block will use the auth_token from your settings:
User.as_admin do
  # do protected task


We welcome your enhancements!

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write some broken rspecs.
  4. Fix the rspecs with your new code.
  5. Commit your changes (git commit -am 'Added some feature')
  6. Push your changes to the upstream branch (git push origin my-new-feature)
  7. Create new Pull Request

We're shooting for 100% rspec coverage, so keep that in mind!

In order to run the tests, check out the Usergrid open source project (, build, and launch it locally.

(Note: If you change your local Usergrid settings from the default, be sure to update usergrid_ironhorse/spec/spec_settings.yaml to match.)

Release notes


  • Internal
    1. Improve authentication and user propagation


  • New Features
    1. Authentication and user propagation features


  • Initial commit
    1. Support for most ActiveModel stuff including Validations
    2. No scoping support


Copyright (c) 2012 Scott Ganyo

Licensed under the Apache License, Version 2.0 (the "License"); you may not use the included files except in compliance with the License.

You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.