mashery_rails

A Rails library for the Mashery API.

Includes:

Installation

Add the following to your Gemfile

gem "mashery_rails", require: "mashery"

Then run the installer to create config/mashery.yml

$ rails g mashery:install

Configuration

Edit config/mashery.yml with your site_key, key and secret options.

---
site_id: '123'
key: "abc"
secret: "xyz"
host: "api.mashery.com"

Note this doesn't distinguish between development, testing, production, etc. If you really need that functionality, open a new issue.

JSON-RPC API

The central data objects are all listed on the RPC API documentation page, and should be supported. However, fetching objects are the main & typically only supported method for each of these objects. If you would like more API methods, don't be shy! Create a pull request and it'll probably get merged within a day.

all

Fetch the first 100 objects of a particular type. The 100 objects constraint is caused by Mashery:

Query results are always paginated. There is a limit of fetching 100 records at one time. By default, only the first 100 records are returned.

Mashery::Member.all #=>

find_each

Much like ActiveRecord::Base.find_each, this will take a block and auto-paginate the object set, working around the 100 items per page limitation stated above.

Mashery::Member.find_each {|m| m.do_something! }

first

Fetch the first object of a particular type. This is effectively setting “ITEMS 1” and reifying that object.

Mashery::Member.first #=>

count

The total number of objects.

Mashery::Member.count #=>

Query Language

Mashery has a basic SQL-like Query Language. This library provides basic AREL-like functionality to build those queries. One small, but important difference is lack of lazy loading. These methods produce queries, but you have to call all in order to retrieve the objects.

select

Change the SELECT fragment of the query.

Mashery::Member.select("name") #=>

where

Change the WHERE fragment of the query.

Mashery::Member.where(name: "User Name")

#=> SELECT * FROM members WHERE name = 'User Name' ITEMS 100

items

Change the ITEMS fragment of the query.

Mashery::Member.items(10)

#=> => SELECT * FROM members ITEMS 10

page

Change the PAGE fragment of the query.

Mashery::Member.page(10)

#=> SELECT * FROM members PAGE 10 ITEMS 100

REST API

Mashery's REST API are pulling statistics about Services. As such, these calls are invoked via the Service API object

Service#activity

Maps to the CallsDeveloperActivityForService call.

service = Mashery::Service.where(key: "my_service_id")
service.activity #=>

Service#errorcodes

Maps to the CallsErrorcodesForService call.

service = Mashery::Service.where(key: "my_service_id")
service.errorcodes #=>

Service#errorcount

Maps to the CallsErrorcountByMethodForService call.

service = Mashery::Service.where(key: "my_service_id")
service.errorcount #=>

Service#latency

Maps to the CallsLatencyForService call.

service = Mashery::Service.where(key: "my_service_id")
service.latency #=>

Service#latency_by_method

Maps to the CallsLatencyByMethodForService call.

service = Mashery::Service.where(key: "my_service_id")
service.latency_by_method #=>

Service#methods

Maps to the CallsMethodsForService call.

service = Mashery::Service.where(key: "my_service_id")
service.methods #=>

Service#volume_by_hour

Maps to the CallsMedianVolumeByHourForService call.

service = Mashery::Service.where(key: "my_service_id")
service.volume_by_hour #=>