0.01
No commit activity in last 3 years
No release in over 3 years
A Ruby wrapper for the Etherios Device Cloud
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
>= 0
 Project Readme

DeviceCloud

Gem Version

wercker status

#####TODO:

  • Add code for maintaining devices
  • Add code for maintaining alarms

Installation

Add this line to your application's Gemfile:

gem 'device_cloud'

And then execute:

$ bundle

Or install it yourself as:

$ gem install device_cloud

Usage

Configuration

DeviceCloud.configure do |config|
  config.username = 'your idigi username'
  config.password = 'your idigi password'
end
# =>
# {
#   username: 'your idigi username,
#   password: 'your idigi password',
#   root_url: 'https://my.idigi.com',
#   host: 'my.idigi.com',
#   alert_notification_handler: nil,
#   empty_alert_notification_handler: nil,
#   data_notification_handler: nil,
#   empty_data_notification_handler: nil,
#   event_notification_handler: nil,
#   empty_event_notification_handler: nil,
#   logger: Logger.new(STDOUT) # default
# }

Push Notifications

device_cloud is currently only able to handle JSON push notifications via http, so your monitor must be set up accordingly. Read more about Monitors below.

When your application receives an HTTP push notification, it can be passed to the DeviceCloud gem using the following:

push_notification = DeviceCloud::PushNotification( http_response_body )
# where http_response_body is a hash of the parsed JSON body content sent by DeviceCloud
  
push_notification.handle_each!

The event will then be handled by one of your defined Notification Handlers.

Notification Handlers

Notification handlers take a Proc, and are called with a relevant alert or event object. A list of supported topic handlers are listed as follows:

alert_notification_handler
data_notification_handler
event_notification_handler

The following empty notification handlers are also available:

empty_alert_notification_handler
empty_data_notification_handler
empty_event_notification_handler

An example definition may look like the following

DeviceCloud.alert_notification_handler = Proc.new do |alert|
  puts "#{alert.type} Alert: for device #{alert.device_id}"
  puts "Base 64 encoded data #{alert.raw_data}"
end

Example Push Notification

{
  "Document": {
    "Msg": {
      "timestamp": "2013-10-21T19:34:56Z",
      "topic": "device/event/event.json",
      "FileData": {
        "id": {
          "fdPath": "/device/event/",
          "fdName": "event.json"
        },
        "fdLastModifiedDate": "2013-10-21T19:34:56Z",
        "fdSize": 545,
        "fdContentType": "application/json",
        "fdData": "eW91IGhhdmUgdG9vIG11Y2ggZnJlZSB0aW1l\n",
        "fdArchive": false,
        "cstId": 4044,
        "fdType": "event",
        "fdCreatedDate": "2013-06-24T14:52:55.421Z"
      },
      "operation": "INSERTION",
      "replay": true,
      "group": "*"
    }
  }
}

Monitors

TODO: write about Monitor class

Contributing

  1. Fork it
  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 new Pull Request

Development

You can get a pry console by using the :console Rake task

$ rake console

You can also optionally pass your Device Cloud username and password like so

$ IDIGI_USERNAME=youruser IDIGI_PASSWORD=yourpass rake console