Ruby API Example

In the Ruby programming language, a gem called OAuth2 encapsulates much of the functionality necessary to speak to an OAuth 2 compliant API. Here is an example of using the OAuth2 gem to interact with NationBuilder.

First you need to build a client object that represents your application. Make sure to plug in your applicable values for the nation slug, application client id, application secret key, and redirect_uri.

The client will build the authorization url for you, just have the resource owner visit the page it builds.

Once you get the authorization code, you can request an access token.

With the token object you receive, you can start consuming resources.

This response will have a JSON body which can be interpreted into a native hash object.

To refresh the current token, do this:

Visit OAuth2 gem for more information

NationBuilder
520 S. Grand Ave., 2nd Floor, Los Angeles, CA 90071
· ·
Los Angeles: 1-213-394-4623 · New York: 1-646-350-1508
Vancouver: 1-604-256-8419 · London: +44 20-3807-0849
Created with NationBuilder