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