# Mode Ruby SDK [![Build Status](https://travis-ci.org/mode/mode-ruby-sdk.svg)](https://travis-ci.org/mode/mode-ruby-sdk) [![Code Climate](https://codeclimate.com/repos/53ea7f57e30ba007c500a24a/badges/44f08215be76ea780d56/gpa.svg)](https://codeclimate.com/repos/53ea7f57e30ba007c500a24a/feed) [![Gem Version](https://badge.fury.io/rb/mode-sdk.svg)](http://badge.fury.io/rb/mode-sdk) This SDK provides a wrapper for the [Mode Analytics](https://modeanalytics.com) API. ## Installation Add this line to your application's Gemfile: gem 'mode-sdk' And then execute: $ bundle Or install it yourself as: $ gem install mode-sdk ## Usage ### Setup ```ruby Mode::Sdk.configure do |config| config.token = 'token' config.secret = 'secret' end ``` You can manage your Mode API tokens here: [https://modeanalytics.com/settings/access_tokens] (https://modeanalytics.com/settings/access_tokens) ### 1. Upload CSV to Mode Before importing a table, you will need to upload the raw CSV (with no header) using the `Upload` class. The first argument can be either a string or an IO-like object. ```ruby csv = File.open('sf_film_locations.csv', 'r') { |f| f.read } upload = Mode::Sdk::Upload.new(csv) upload.create upload.token # => '5b68f4b6a3c6' save this token for step 2 ``` Full Upload API documentation: [http://developer.modeanalytics.com/#page:uploads,header:uploads-upload] (http://developer.modeanalytics.com/#page:uploads,header:uploads-upload) ### 2. Import the table Next, initialize a `Table` instance with a name: ```ruby table = Mode::Sdk::Table.new('sf_film_locations') table.exists? # => true, false ``` Assign a column schema (required) and description (optional): ```ruby table.columns = [ { name: 'movie_title', type: 'string' }, { name: 'release_year', type: 'integer' }, { name: 'location', type: 'string' } ] table.description = 'Famous film locations in San Francisco' ``` Then use the upload token from Step 1 to create or replace the table: ```ruby table.upload_token = '5b68f4b6a3c6' table.create table.replace ``` ### 3. Check the status of your import The response from `Table#create` or `Table#replace` will indicate the status of your import, including: * `enqueued` * `running` * `succeeded` * `failed` You can poll this response until your import has completed. ## Documentation [http://rubydoc.info/github/mode/mode-ruby-sdk/master/frames] (http://rubydoc.info/github/mode/mode-ruby-sdk/master/frames) ## Examples A collection of examples can be found in the [mode/mode-ruby-examples](https://github.com/mode/mode-ruby-examples) repository. ## 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