A Ruby library for the Mashery API.
Prerequisites
Install the gem dependencies (see gembundler.com if you aren’t familiar with Bundler):
$ bundle install
Calling methods from the command line
A set of Thor tasks are provided so that you can call API methods from the command line (read more about Thor at http://github.com/wycats/thor).
The following examples assume you have Thor installed system-wide. If it’s local to your bundle, then replace
thor with bundle exec thor.
You can see all available Mashery tasks with this command:
$ thor list mashery
Environment
Before you can successfully call an API method, you must set these environment variables:
$ export MASHERY_SITE_ID=666
$ export MASHERY_API_KEY=cafebebedeadbeefcafebebedeadbeef
$ export MASHERY_SHARED_SECRET=blahblahblah
By default, the thor tasks call methods in the Mashery sandbox. If you want them to access the production environment instead, set the {MASHERY_PRODUCTION_MODE} environment variable to any value:
$ export MASHERY_PRODUCTION_MODE=hi
Querying objects
The Mashery API supports querying the following types of objects: members, applications, keys, services, and roles.
To perform a query, construct a Query object for the type of object you want to query:
query = Mashery::Query.new('members')
members = query.fetch_all
The fetch_all method will automatically paginate through the results for you. You can also control this yourself with the page parameter and execute:
query = Mashery::Query.new('members', :page => 2)
result = query.execute
items = result['items']
(Or, use the items method, which combines execute and result['items'] — however, this does not return result set metadata, like current page and total pages.)
The default will return all fields (e.g., SELECT * FROM members). To control this, specify the :fields parameter.
To control which records are returned, specify the :where parameter.
query = Mashery::Query.new('members', :where => 'username = "Jeff"'