Skip to content
Find file
Latest commit 6c40705 @fsaravia fsaravia Bump version to 2.4.0

AT&T M2X Ruby Client

AT&T M2X is a cloud-based fully managed time-series data storage service for network connected machine-to-machine (M2M) devices and the Internet of Things (IoT).

The AT&T M2X API provides all the needed operations and methods to connect your devices to AT&T's M2X service. This library aims to provide a simple wrapper to interact with the AT&T M2X API for Ruby. Refer to the Glossary of Terms to understand the nomenclature used throughout this documentation.

Getting Started

  1. Signup for an M2X Account.
  2. Obtain your Master Key from the Master Keys tab of your Account Settings screen.
  3. Create your first Device and copy its Device ID.
  4. Review the M2X API Documentation.


$ gem install m2x


In order to communicate with the M2X API, you need an instance of M2X::Client. You need to pass your API key in the constructor to access your data.

m2x =<YOUR-API-KEY>)

This provides an interface to your data in M2X

  • Distribution

    distribution = m2x.distribution("<DISTRIBUTION-ID>")
    distributions = m2x.distributions
  • Device

    device = m2x.device("<DEVICE-ID>")
    devices = m2x.devices
  • Collection

    collection = m2x.collection("<COLLECTION-ID>")
    collections = m2x.collections
  • Key

    key = m2x.key("<KEY-TOKEN>")
    keys = m2x.keys
  • Job

    job = m2x.job("<JOB-ID>")

Refer to the documentation on each class for further usage instructions.


For devices that do not have a Real Time Clock, M2X provides a set of endpoints that returns the server's time.

=> {"seconds"=>1435970368, "millis"=>1435970368451, "iso8601"=>"2015-07-04T00:39:28.451Z"}

=> "1435970400"

=> "1435970418134"

=> "2015-07-04T00:40:37.504Z"


In order to run this example, you will need a Device ID and API Key. If you don't have any, access your M2X account, create a new Device, and copy the Device ID and API Key values. The following script will send your CPU load average to three different streams named load_1m, load_5m and load_15. Check that there's no need to create a stream in order to write values into it.

In order to execute this script, run:

#! /usr/bin/env ruby

# See for instructions

require "time"
require "m2x"

API_KEY = ENV.fetch("API_KEY")

puts "M2X::Client/#{M2X::Client::VERSION} example"

@run = true

stop = { @run = false }

trap(:INT,  &stop)
trap(:TERM, &stop)

# Match `uptime` load averages output for both Linux and OSX
UPTIME_RE = /(\d+\.\d+),? (\d+\.\d+),? (\d+\.\d+)$/

def load_avg

m2x =

# Get the device
device = m2x.device(DEVICE)

# Create the streams if they don't exist

while @run
  load_1m, load_5m, load_15m = load_avg

  # Write the different values into AT&T M2X
  now =

  values = {
    load_1m:  [ { value: load_1m,  timestamp: now } ],
    load_5m:  [ { value: load_5m,  timestamp: now } ],
    load_15m: [ { value: load_15m, timestamp: now } ]

  res = device.post_updates(values: values)

  abort res.json["message"] unless res.success?

  sleep 1


You can find this script in examples/m2x-uptime.rb.


This gem aims to adhere to Semantic Versioning 2.0.0. As a summary, given a version number MAJOR.MINOR.PATCH:

  1. MAJOR will increment when backwards-incompatible changes are introduced to the client.
  2. MINOR will increment when backwards-compatible functionality is added.
  3. PATCH will increment with backwards-compatible bug fixes.

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

Note: the client version does not necessarily reflect the version used in the AT&T M2X API.


This gem is provided under the MIT license. See LICENSE for applicable terms.

Something went wrong with that request. Please try again.