<commit_before># Mailchimp3

[![Circle CI](https://circleci.com/gh/seven1m/mailchimp3/tree/master.svg?style=svg)](https://circleci.com/gh/seven1m/mailchimp3/tree/master)

`mailchimp3` is a Rubygem that provides a very thin, simple wrapper around the MailChimp RESTful JSON API.

## Installation

```
gem install mailchimp3 (eventually)
```

## Usage

1. Create a new API object, passing in your credentials (either HTTP Basic or OAuth2 access token):

    ```ruby
    # authenticate with HTTP Basic:
    api = Mailchimp3.new(basic_auth_key: 'my key')
    # ...or authenticate with an OAuth2 access token (use the 'oauth2' gem to obtain the token)
    api = Mailchimp3.new(oauth_access_token: 'token')
    ```

2. Call a method on the api object to build the endpoint path.

    ```ruby
    api.lists
    # /lists
    ```

3. For IDs, treat the object like a hash (use square brackets), and chain method calls together.

    ```ruby
    api.lists[1].members
    # /lists/1/members
    ```

4. To execute the request, use `get`, `post`, `patch`, or `delete`, optionally passing arguments.

    ```ruby
    api.lists.get(count: 25)
    # GET /lists?count=25
    api.lists[1].members[2].get
    # GET /lists/1/members/2
    ```

## Example

```ruby
require 'mailchimp3'

api = Mailchimp3.new(basic_auth_key: 'abc123abc123abc123abc123abc123ab-us2')
api.lists.post(
  name: 'Church.IO',
  email_type_option: false,
  permission_reminder: 'signed up on https://church.io'
  contact: {
    company: 'TJRM',
    address1: '123 N. Main',
    city: 'Tulsa',
    state: 'OK',
    zip: '74137',
    country: 'US'
  },
  campaign_defaults: {
    from_name: '<NAME>',
    from_email: '<EMAIL>',
    subject: 'Hello World',
    language: 'English'
  },
)
```

...which returns something like:

```ruby
{
  "id"   => "abc123abc1",
  "name" => "Church.IO",
  "contact" => {
    "company"  => "TJRM",
    "address1" => "123 N. Main",
    "address2" => "",
    "city"     => "Tulsa",
    "state"    => "OK",
    "zip"      => "74137",
    "country"  => "US",
    "phone"    => ""
  },
  "campaign_defaults" => {
    "from_name"  => "<NAME>",
    "from_email" => "<EMAIL>",
    "subject"    => "test",
    "language"   => "English"
  },
  # ...
  "stats" => {
    "member_count" => 0,
    # ...
  },
  "_links" => [
    {
      "rel"          => "self",
      "href"         => "https://us2.api.mailchimp.com/3.0/lists/abc123abc1",
      "method"       => "GET",
      "targetSchema" => "https://us2.api.mailchimp.com/schema/3.0/Lists/Instance.json"
    },
    # ...
  ]
}
```

## get()

`get()` works for a collection (index) and a single resource (show).

```ruby
# collection
api.lists[1].members.get(count: 25)
# => { members: array_of_resources }

# single resource
api.lists[1].members[2].get
# => resource_hash
```

## post()

`post()` sends a POST request to create a new resource.

```ruby
api.lists[1].members.post(...)
# => resource_hash
```

## patch()

`patch()` sends a PATCH request to update an existing resource.

```ruby
api.lists[1].members[2].patch(...)
# => resource_hash
```

## delete()

`delete()` sends a DELETE request to delete an existing resource. This method returns `true` if the delete was successful.

```ruby
api.lists[1].members[2].delete
# => true
```

## Errors

The following errors may be raised by the library, depending on the API response status code.

| HTTP Status Codes   | Error Class                                                                   |
| ------------------- | ----------------------------------------------------------------------------- |
| 400                 | `Mailchimp3::Errors::BadRequest` < `Mailchimp3::Errors::ClientError`          |
| 401                 | `Mailchimp3::Errors::Unauthorized` < `Mailchimp3::Errors::ClientError`        |<commit_msg>Update readme with more realistic ids<commit_after># Mailchimp3

[![Circle CI](https://circleci.com/gh/seven1m/mailchimp3/tree/master.svg?style=svg)](https://circleci.com/gh/seven1m/mailchimp3/tree/master)

`mailchimp3` is a Rubygem that provides a very thin, simple wrapper around the MailChimp RESTful JSON API.

## Installation

```
gem install mailchimp3 (eventually)
```

## Usage

1. Create a new API object, passing in your credentials (either HTTP Basic or OAuth2 access token):

    ```ruby
    # authenticate with HTTP Basic:
    api = Mailchimp3.new(basic_auth_key: 'my key')
    # ...or authenticate with an OAuth2 access token (use the 'oauth2' gem to obtain the token)
    api = Mailchimp3.new(oauth_access_token: 'token')
    ```

2. Call a method on the api object to build the endpoint path.

    ```ruby
    api.lists
    # /lists
    ```

3. For IDs, treat the object like a hash (use square brackets).

    ```ruby
    api.lists['abc123'].members
    # /lists/abc123/members
    ```

4. To execute the request, use `get`, `post`, `patch`, or `delete`, optionally passing arguments.

    ```ruby
    api.lists.get(count: 25)
    # GET /lists?count=25
    api.lists['abc123'].members['cde345'].get
    # GET /lists/abc123/members/cde345
    ```

## Example

```ruby
require 'mailchimp3'

api = Mailchimp3.new(basic_auth_key: 'abc123abc123abc123abc123abc123ab-us2')
api.lists.post(
  name: 'Church.IO',
  email_type_option: false,
  permission_reminder: 'signed up on https://church.io'
  contact: {
    company: 'TJRM',
    address1: '123 N. Main',
    city: 'Tulsa',
    state: 'OK',
    zip: '74137',
    country: 'US'
  },
  campaign_defaults: {
    from_name: '<NAME>',
    from_email: '<EMAIL>',
    subject: 'Hello World',
    language: 'English'
  },
)
```

...which returns something like:

```ruby
{
  "id"   => "abc123abc1",
  "name" => "Church.IO",
  "contact" => {
    "company"  => "TJRM",
    "address1" => "123 N. Main",
    "address2" => "",
    "city"     => "Tulsa",
    "state"    => "OK",
    "zip"      => "74137",
    "country"  => "US",
    "phone"    => ""
  },
  "campaign_defaults" => {
    "from_name"  => "<NAME>",
    "from_email" => "<EMAIL>",
    "subject"    => "test",
    "language"   => "English"
  },
  # ...
  "stats" => {
    "member_count" => 0,
    # ...
  },
  "_links" => [
    {
      "rel"          => "self",
      "href"         => "https://us2.api.mailchimp.com/3.0/lists/abc123abc1",
      "method"       => "GET",
      "targetSchema" => "https://us2.api.mailchimp.com/schema/3.0/Lists/Instance.json"
    },
    # ...
  ]
}
```

## get()

`get()` works for a collection (index) and a single resource (show).

```ruby
# collection
api.lists['abc123'].members.get(count: 25)
# => { members: array_of_resources }

# single resource
api.lists['abc123'].members['cde345'].get
# => resource_hash
```

## post()

`post()` sends a POST request to create a new resource.

```ruby
api.lists['abc123'].members.post(...)
# => resource_hash
```

## patch()

`patch()` sends a PATCH request to update an existing resource.

```ruby
api.lists['abc123'].members['cde345'].patch(...)
# => resource_hash
```

## delete()

`delete()` sends a DELETE request to delete an existing resource. This method returns `true` if the delete was successful.

```ruby
api.lists['abc123'].members['cde345'].delete
# => true
```

## Errors

The following errors may be raised by the library, depending on the API response status code.

| HTTP Status Codes   | Error Class                                                                   |
| ------------------- | ----------------------------------------------------------------------------- |
| 400                 | `Mailchimp3::Errors::BadRequest` < `Mailchimp3::Errors::ClientError`          |
| 401                 | `Mailchimp3::Errors::Unauthorized` < `Mailchimp3::Errors::ClientError`        |
{'fraction_non_alphanumeric': 0.19115159401431359, 'fraction_numerical': 0.0291476903057905, 'mean_word_length': 2.5435684647302903, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 67, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 31, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2780411', 'n_tokens_mistral': 2734, 'n_tokens_neox': 2540, 'n_words': 638}