SlicingDice API Docs

SlicingDice API Docs

Welcome to the SlicingDice API documentation. You'll find comprehensive guides and documentation to help you start working with SlicingDice as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Documentation

Ruby

Ruby client/SDK for SlicingDice

You can use the SlicingDice's Ruby client/SDK to rapidly start inserting and querying your data, without having to handle with all the API HTTP requests yourself.

Installing the client

In order to install the Ruby client, you only need to install our gem or visit this page .

$ curl -s https://packagecloud.io/install/repositories/slicingdice/clients/script.gem.sh | bash
$ gem install rbslicer

Source code

SlicingDice's Ruby client/SDK source code is available on Github .

Build Status: CircleCI


Tests and Examples

At the Ruby client/SDK Github repository, you will find examples of data insertion and queries with their respective expected result messages. You take advantage of all these examples to test the client and also learn how to use it.


Using the client

SlicingDice class encapsulates logic for sending requests to the API. Its methods are thin layers around the API endpoints, so their parameters and return values are JSON-like Hash objects with the same syntax as the API endpoints.

require 'rbslicer'

# Configure the client
client = SlicingDice.new(master_key: "API_KEY")

# Creating a column
column_data = {
    "name" => "Age",
    "api-name" => "age",
    "description" => "User age",
    "type" => "integer",
    "storage" => "latest-value"
}
client.create_column(column_data)

# Inserting data
insert_data = {
    "user1@slicingdice.com" => {
        "age" => 22
    }
}
client.insert(insert_data)

# Querying data
query_data = {
    "query-name" => "users-between-20-and-40",
    "query" => [
        {
            "age" => {
                "range": [
                    20,
                    40
                ]
            }
        }
    ]
}
puts client.count_entity(query_data)

API Keys

API keys are configured with the client constructor, as presented in the example below.

require 'rbslicer'

# Configure client with master API key
client = Rbslicer::Client.new((master_key = "MASTER_API_KEY")

# Configure client with read API key
client = Rbslicer::Client.new((read_key = "READ_API_KEY")

# Configure client with write API key
client = Rbslicer::Client.new((write_key = "WRITE_API_KEY")

# Configure client with custom API key
client = Rbslicer::Client.new((custom_key = "CUSTOM_API_KEY")

Constructor

initialize(master_key = nil, 
       custom_key = nil, 
       read_key = nil, 
       write_key = nil, 
       timeout = 60, 
       use_ssl = true)
  • master_key (String) - Master API Key to used to authenticate requests on SlicingDice API.
  • custom_key (String) - Custom API Key to used to authenticate requests on SlicingDice API.
  • read_key (String) - Read API Key to used to authenticate requests on SlicingDice API.
  • write_key (String) - Write API Key to used to authenticate requests on SlicingDice API.
  • use_ssl (Bool) - Define if it should verify SSL for HTTPS requests. (when set to false, all operations but insert() become unavailable)
  • timeout (Fixnum) - Amount of time, in seconds, to wait for results for each request.

Methods

  • get_database() - Get current database, identified by the given API key. This method corresponds to a GET request at /database.
require 'rbslicer'
client = SlicingDice.new(master_key: "MASTER_API_KEY")

puts client.get_database()
  • get_columns() - Get all created columns, both active and inactive ones organized by table. This method corresponds to a GET request at /column.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

puts slicingdice.get_columns()
  • create_column(json_data) - Create a new column. This method corresponds to a POST request at /column.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

insert_data = [
    {
        "type" => "string",
        "storage" => "latest-value",
        "api-name" => "state",
        "name" => "User State",
        "description" => "State where the user lives"
    }, 
    {
        "type" => "integer",
        "storage" => "latest-value",
        "api-name" => "age",
        "name" => "User Age"
    }
]
puts slicingdice.create_column(insert_data)
  • insert(json_data) - Insert data to existing entities or create new entities, if necessary. This method corresponds to a POST request at /insert.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

insert_data = {
    "UUID-01" => {
        "table" => "users",
        "age" => 25,
        "name" => "Jeff",
        "clicks" => [
            {
                "date" => "2017-05-26T12:54:12Z",
                "value" => "Add to Cart"
            }, 
            {
                "date" => "2017-05-31T10:22:10Z",
                "value" => "Pay Now"
            }, 
            {
                "date" => "2017-06-03T17:05:25Z",
                "value" => "Support"
            }
        ]
    },
    "auto-create" => [
        "table", 
        "column"
    ]
}

puts slicingdice.insert(insert_data)
  • exists_entity(ids, table=nil) - Verify which entities exist in a table (uses default table if not provided) given a list of entity IDs. This method corresponds to a POST request at /query/exists/entity.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

table = "users"
query_data = [
        "user1@slicingdice.com", 
        "user2@slicingdice.com", 
        "user3@slicingdice.com", 
        "user4@slicingdice.com", 
        "user5@slicingdice.com"
]

puts slicingdice.exists_entity(query_data, table=table)
  • count_entity_total(tables=[]) - Count the number of stored entities in given tables (or in all tables by default). This method corresponds to a POST request at /query/count/entity/total.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

puts slicingdice.count_entity_total()
  • count_entity(json_data) - Count the number of entities satisfying the given query. This method corresponds to a POST request at /query/count/entity.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = [
    {
        "table" => "users",
        "query-name" => "jeff-user-clicked-to-pay",
        "bypass-cache" => true,
        "query" => [
            {
                "name" => {
                    "equals" => "Jeff"
                }
            }, 
            "and", 
            {
                "clicks" => {
                    "equals" => "Pay Now",
                    "between" => [
                        "2017-05-21T00:00:00Z", 
                        "2017-06-04T00:00:00Z"
                    ]
                }
            }
        ]
    }
]

puts slicingdice.count_entity(query_data)
  • count_event(json_data) - Count the number of occurrences for events satisfying the given query. This method corresponds to a POST request at /query/count/event.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = [
    {
        "query" => [
            {
                "actions" => {
                    "equals" => "visited-page",
                    "between" => [
                        "2017-05-21T00:00:00Z", 
                        "2017-06-04T00:00:00Z"
                    ]
                }
            }
        ],
        "query-name" => "visited-page-events"
    }
]

puts slicingdice.count_event(query_data)
  • top_values(json_data) - Return the top values for entities satisfying the given query. This method corresponds to a POST request at /query/top_values.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = {
    "name-contains-eff" => {
        "table" => "users",
        "contains" => [
            "eff"
        ],
        "name" => 3
    }
}

puts slicingdice.top_values(query_data)
  • aggregation(json_data) - Return the aggregation of all columns in the given query. This method corresponds to a POST request at /query/aggregation.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = {
    "filter" => [
        {
            "country" => {
                "equals" => "USA"
            }
        }
    ],
    "query" => [
        {
            "purchased-products" => 2,
            "between" => [
                "2017-05-16T00:00:00Z", 
                "2017-06-04T00:00:00Z"
            ]
        }
    ]
}

puts slicingdice.aggregation(query_data)
  • get_saved_queries(test) - Get all saved queries. This method corresponds to a GET request at /query/saved.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

puts slicingdice.get_saved_queries()
  • create_saved_query(json_data) - Create a saved query at SlicingDice. This method corresponds to a POST request at /query/saved.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = {
    "query" => [
        {
            "state" => {
                "equals" => "NY"
            }
        }, 
        "or", 
        {
            "state" => {
                "equals" => "CA"
            }
        }
    ],
    "type" => "count/entity",
    "name" => "my-saved-query",
    "table" => "users"
}

puts slicingdice.create_saved_query(query_data)
  • update_saved_query(query_name, json_data) - Update an existing saved query at SlicingDice. This method corresponds to a PUT request at /query/saved/:query_name.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = {
    "query" => [
        {
            "state" => {
                "equals" => "NY"
            }
        }, 
        "or", 
        {
            "state" => {
                "equals" => "CA"
            }
        }
    ],
    "type" => "count/entity",
    "table" => "users"
}

puts slicingdice.update_saved_query("my-saved-query", query_data)
  • get_saved_query(query_name) - Executed a saved query at SlicingDice. This method corresponds to a GET request at /query/saved/:query_name.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

puts slicingdice.get_saved_query("my-saved-query")
  • delete_saved_query(query_name) - Delete a saved query at SlicingDice. This method corresponds to a DELETE request at /query/saved/:query_name.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

puts slicingdice.delete_saved_query("my-saved-query")
  • result(json_data) - Retrieve stored values for entities satisfying the given query. This method corresponds to a POST request at /data_extraction/result.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = {
    "query" => [
        {
            "state" => {
                "equals" => "NY"
            }
        }, 
        "or", 
        {
            "state" => {
                "equals" => "CA"
            }
        }
    ],
    "limit" => 3,
    "columns" => [
        "city", 
        "state"
    ]
}

puts slicingdice.result(query_data)
  • score(json_data) - Retrieve stored values as well as their relevance for entities satisfying the given query. This method corresponds to a POST request at /data_extraction/score.
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = {
    "query" => [
        {
            "state" => {
                "equals" => "NY"
            }
        }, 
        "or", 
        {
            "state" => {
                "equals" => "CA"
            }
        }, 
        "or", 
        {
            "gender" => {
                "equals" => "male"
            }
        }, 
        "or", 
        {
            "age" => {
                "range" => [
                    18, 
                    25
                ]
            }
        }
    ],
    "limit" => 3,
    "columns" => [
        "city", 
        "state"
    ]
}

puts slicingdice.score(query_data)
  • sql(statement) - Retrieve inserted values using a SQL syntax. This method corresponds to a POST request at /query/sql.

Query Statement

require 'rbslicer'
client = SlicingDice.new(master_key: "API_KEY")
query = "SELECT COUNT(*) FROM default WHERE age BETWEEN 0 AND 49"

puts client.sql(query)

Insert statement

require 'rbslicer'
client = SlicingDice.new(master_key: "API_KEY")
query = "INSERT INTO default([entity-id], name, age) VALUES(1, 'john', 10)"

puts client.sql(query)

Ruby

Ruby client/SDK for SlicingDice