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...
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
require 'contextio'
client = ContextIO.lite(API_KEY, API_SECRET)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].deleteTo 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
endAnd 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_plainThe 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'.
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: trueSo 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.
To get the list of attachments metadata of a message :
client[user_id].email_accounts[account_label].folders[folder_name].messages[message_id].attachmentsTo 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- Fork it ( https://github.com/javijuol/contextio-lite/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
This gem is distributed under the MIT License. See LICENSE.md for details.