Provides a Ruby interface to the Context.IO API
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

The 2.0 version of the API will be partially deprecated on June 15, 2018, and fully deprecated on December 15, 2018


Context.IO 2.0 API Ruby Library


This library is meant to serve as a way to connect to the 2.0 version of the Context.IO API. All classes contained in the library are name spaced under the ContextIO module and accept keyword arguments.



gem install context_io


First you need to instantiate a ContextIO class.

cio = your_cio_key, secret: your_cio_secret)

Each class has it's own methods that are endpoints to the API. ContextIO endpoints. From here you can fetch any accounts associated with your ContextIO Developer key.


This will return an array of all of the accounts. Each element of the array is an instantiated Account object with the data parsed from the API returned as instance variables.

acc = cio.get_accounts[0].id  #=> "this_account_id"

An object can be created as long as it is given a valid identifier and an instantiated parent. Every class, except for ContextIO, requires a parent and an identifier To make it easier on a user of this library you do not need to know what we call each identifier.

message = acc, identifier: "some id")

A class instantiation will not call the API. In order to retrieve the data CIO has on an object you will need to call get on it.

message.subject #=> nil

message = message.get
message.subject  #=> "This message subject"

If an API call was not succesful, defined as not returning a status of 2XX, the library will throw a standard error with the message given in response.

valid_length_id = "0" * 24 cio, identifier: "valid_length_id").get
#=> StandardError: HTTP code 404. Response {"type"=>"error", "value"=>"account #{valid_length_id} is invalid"}

Some classes have methods that can only be called if it has the proper parent. For example a Message could have valid parents of Account, Contact, or Folder. If you attempt to call a method on a class without the proper parent you will receive a standard error.

account_message = account, identifier: "some id")
#=> <ContextIO::Message:0x007fabc ...

contact_message = contact, identifier: "some id")
#=> StandardError: "This method can only be called from '2.0/accounts/:account/message/:message_id'"

Example of an API call return

#=> #<ContextIO::Message:0x007fabc4dd9380
 @addresses={"from"=>{"email"=>"from_address", "name"=>"from_name"}, "to"=>[{"email"=>"to_email"}]},
  #<struct ContextIO::APICallMade::CALL_MADE_STRUCT
 @connection=#<ContextIO::Connection:0x007fabc61e3998 @key=api_key, @secret=api_secret">,
 @date=Uniux timestamp,
 @date_indexed=Unix timestamp,
 @date_received=Unix timestamp,
 @folders=["\\Important", "INBOX", "\\Inbox", "[Gmail]/Important"],
   @api_call_made=#<struct ContextIO::APICallMade::CALL_MADE_STRUCT url=#<URI::HTTPS>, method=:get, allowed_params=[], rejected_params=[]>,
   @connection=#<ContextIO::Connection:0x007fabc61e3998 @key="key", @secret="secret">,
   @created=Unix timestamp,
   @email_addresses=["first_email_address", "second_email_address"],
   @parent=#<ContextIO::ContextIO:0x007fabc61e39e8 @call_url="/2.0", @connection=#<ContextIO::Connection:0x007fabc61e3998 @key="key", @secret="secret">>,
 @sources=[{"label"=>"source_label", "resource_url"=>""}],
 @subject="Email Subject",

Two notes about API returns.

  1. Each return will have an attached struct called api_call_made. This will contain the URL of the endpoint hit, the HTTP method, paramaters submitted with the call, and parameters rejected by the API.

  2. The above listing shows the parent, and grand parent, of this object. Those are private attrs on each class and are not accessible outside of that class's code.


There are unit tests for this library. If you would like to submit a pull request against this project please ensure that you include the appropriate unit tests.


If you have any questions, don't hesitate to contact