Ruby Wrapper for Stitch Data's Import API
The Stitch Import API is a REST API that allows you to push arbitrary data into your data warehouse. Once the data enters the Import API, it’ll be processed and sent through Stitch like data from any other integration.
Rails:
gem 'stitch_data', github: 'theminijohn/mini_stitch'Authentication with the Import API is done with a single API access token placed in the Authorization header of your request and your client ID, which will be used in the request body.
# initializers/mini_stitch.rb
MiniStitch.configure do |config|
config.token = "your-api-token"
config.client_id = "your-client-id"
endThis gem also supports a second configuration (for a separate Stitch account) should you want to import data to two different accounts. While secondary_token and secondary_client_id are optional, token and client_id are not.
# initializers/mini_stitch.rb
MiniStitch.configure do |config|
config.token = "your-api-token"
config.client_id = "your-client-id"
config.secondary_token = "your-api-token"
config.secondary_client_id = "your-client-id"
endI recommend you take a look at the Stitch Data Import Api Doc to get the gist of what the upsert, validate & status methods do. Yes, this gem has only 3 methods ☀️
!! For the Wrapper to successfully accept and process your data, your call must contain all of the request fields listed below:
-
table_name |
StringThis field contains the name of the destination table -
sequence |
StringThis property tells the Import API the order in which data points in the request body should be considered. See Defining Sequence for more info. The most straightforward way is to useTime.now.to_ito get the current time in posix format. -
key_names |
Array| 🔑 This field defines the Primary Key and will contain an array of field names that uniquely identify the row that the record belongs to. Primary Keys identify unique rows within a table and ensure that only the most recently updated version of that record appears in your data warehouse. -
data |
Array of HashesThis field contains the data to be upserted into your data warehouse.
The status endpoint can be used to determine if the Import API is operating correctly.
MiniStitch.statusThe validate endpoint can be used to validate requests but will not persist them to Stitch
MiniStitch::Api.new(table_name, sequence, [key_names], [data]).validate!The upsert endpoint is used to push data into your data warehouse.
MiniStitch::Api.new(table_name, sequence, [key_names], [data]).upsert!