<commit_before>sailthru-ruby-client
====================

A simple client library to remotely access the `Sailthru REST API` as per [http://docs.sailthru.com/api](http://docs.sailthru.com/api)

By default, it will make request in `JSON` format.

It can make requests to following [API calls](http://docs.sailthru.com/api):

* [email](http://docs.sailthru.com/api/email)
* [send](http://docs.sailthru.com/api/send)
* [blast](http://docs.sailthru.com/api/blast)
* [template](http://docs.sailthru.com/api/template)
* [list](http://docs.sailthru.com/api/list)
* [contacts](http://docs.sailthru.com/api/contacts)
* [content](http://docs.sailthru.com/api/content)
* [alert](http://docs.sailthru.com/api/alert)
* [stats](http://docs.sailthru.com/api/stats)
* [purchase](http://docs.sailthru.com/api/purchase)
* [horizon](http://docs.sailthru.com/api/horizon)

### Installing from rubygems.org (Tested with Ruby 1.8.7)
    $ gem install sailthru-client

Examples
--------

``` ruby
require 'sailthru' #if using as gem

api_key = "api_key";
api_secret = 'secret';
api_url = "https://api.sailthru.com";
sailthru = Sailthru::SailthruClient.new(api_key, api_secret, api_url)
```

### [send](http://docs.sailthru.com/api/send)
``` ruby
#send
template_name = 'my-template'
email = '<EMAIL>'
vars = {'name' => '<NAME>', "myvar" => [1111,2,3]}
options = {'test' => 1}
schedule_time = '+3 hours'
response = sailthru.send(template_name, email, vars, options, schedule_time)

#get send
send_id = '6363'<commit_msg>adding user API call examples with native GET and POST<commit_after>sailthru-ruby-client
====================

A simple client library to remotely access the `Sailthru REST API` as per [http://docs.sailthru.com/api](http://docs.sailthru.com/api)

By default, it will make request in `JSON` format.

It can make requests to following [API calls](http://docs.sailthru.com/api):

* [email](http://docs.sailthru.com/api/email)
* [send](http://docs.sailthru.com/api/send)
* [blast](http://docs.sailthru.com/api/blast)
* [template](http://docs.sailthru.com/api/template)
* [list](http://docs.sailthru.com/api/list)
* [contacts](http://docs.sailthru.com/api/contacts)
* [content](http://docs.sailthru.com/api/content)
* [alert](http://docs.sailthru.com/api/alert)
* [stats](http://docs.sailthru.com/api/stats)
* [purchase](http://docs.sailthru.com/api/purchase)
* [horizon](http://docs.sailthru.com/api/horizon)

### Installing from rubygems.org (Tested with Ruby 1.8.7)
    $ gem install sailthru-client

Examples
--------

``` ruby
require 'sailthru' #if using as gem

api_key = "api_key";
api_secret = 'secret';
api_url = "https://api.sailthru.com";
sailthru = Sailthru::SailthruClient.new(api_key, api_secret, api_url)

# GET http://docs.sailthru.com/api/user API call
user_key = 'email'
email = '<EMAIL>'
fields = {'vars' => 1, 'lists' => 1}
data = {
    'id' => email,
    'key' => user_key,
    'fields' => fields
}
response = sailthru.api_get('user', data)

# POST http://docs.sailthru.com/api/user API call
user_sid = '4e2879472d7acd6d97144f9e' #sailthru ID
lists = {
    "list-A" => 1,
    "list-B" => 1,
    "list-C" => 0 #optout of this list
}
vars = {
    'name' => '<NAME>',
    'address' => {
        'city': 'New York',
        'state': 'NY',
        'zipcode': 10011
    }
}
data = {
    'id' => user_sid,
    'lists' => lists,
    'vars' => vars
}
response = sailthru.api_post('user', data)

```

### [send](http://docs.sailthru.com/api/send)
``` ruby
#send
template_name = 'my-template'
email = '<EMAIL>'
vars = {'name' => '<NAME>', "myvar" => [1111,2,3]}
options = {'test' => 1}
schedule_time = '+3 hours'
response = sailthru.send(template_name, email, vars, options, schedule_time)

#get send
send_id = '6363'
{'fraction_non_alphanumeric': 0.20602474448628294, 'fraction_numerical': 0.01506186121570737, 'mean_word_length': 4.252824858757062, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 28, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1476673', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1448, 'n_words': 269}