0.0
No commit activity in last 3 years
No release in over 3 years
Short implementation of a client rest API for the Context.IO Lite API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

~> 1.7
~> 0
~> 10.0

Runtime

 Project Readme

Contextio::Lite

This is API client for the Context.IO Lite version based on Context.IO Ruby for the 2.0 version. It works in the same way as the official, calling first a user object and then working with the collections...

Installation

Add this line to your application's Gemfile:

gem 'contextio-lite', :require => 'contextio'

And then execute:

$ bundle

Or install it yourself as:

$ gem install contextio-lite

Usage

Get a client

require 'contextio'

client = ContextIO.lite(API_KEY, API_SECRET)

Dealing with users

List all the registered lite users IDs

p client.users.map(&:id)

CRUD

user = client.users.create email: 'bob@gmail.com', first_name: 'Bob', server: 'imap.gmail.com' username: 'bob', use_sll:true, port: 993, type: 'IMAP'

user_id = user.id

client.users[user_id].update :hash_attrs

client.users[user_id].delete

Retrieving messages

To access the emails, first you need to select an email_account and the folder containing your email

So if you want to list the user email accounts or folders you can do like this

p client[user_id].email_accounts.map(&:label)
p client[user_id].email_accounts[label].folders.map(&:name) # can access email_accounts by number => email_accounts[0]

Listing all the email subjects inside a folder (limited by context IO to 100)

client[user_id].email_accounts[0].folders['INBOX'].messages do
    p messages.subject
end

And if you want to filter the emails

client[user_id].email_accounts[0].folder['INBOX'].messages.where(limit: 3)

You also may want to access the content of one message

client[user_id].email_accounts[0].folder['INBOX'].messages['<message_id>'].body_plain # or body_html

client[user_id].email_accounts[0].folder['INBOX'].messages['<message_id>'].with(include_body:true).body_plain

The first one calls https://api.context.io/lite/users/id/email_accounts/label/folders/folder/messages/message_id/body and the second calls https://api.context.io/lite/users/id/email_accounts/label/folders/folder/messages/message_id?include_body=1 but they return the same.

And the above should works also with 'flags' or 'headers'.

Webhooks

One of the main feature that this version has and 2.0 doesn't is the real-time webhooks. So in order to work with them we can do

client[user_id].webhooks.map(&:webhook_id) # listing all the webhooks an user has

client[user_id].create callback_url, failure_url, filter_folder_added: 'INBOX', include_body: true

So it will call the callback_url every time there is a new message on the user INBOX folder, posting the message info and body included.

Attachments

To get the list of attachments metadata of a message :

client[user_id].email_accounts[account_label].folders[folder_name].messages[message_id].attachments

To get metadata on a specific attachment :

client[user_id].email_accounts[account_label].folders[folder_name].messages[message_id].attachments[attachment_id]

To get a specific attachment file :

attachment= client[user_id].email_accounts[account_label].folders[folder_name].messages[message_id].attachment_files[attachment_id]

attachment.content # => The file body
attachment.headers # => The response headers

Contributing

  1. Fork it ( https://github.com/javijuol/contextio-lite/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Copyright

This gem is distributed under the MIT License. See LICENSE.md for details.