<commit_before># DigitSend

DigitSend is a secure email and file sharing service with a streamlined two-factor registration process.  This gem allows you to send email and upload files to share programmatically.

## Usage

### 1. API Key

You must set the API key before performing any operations.  API keys are granted on a per-user basis using the administration portal.  All operations are done on behalf of the user to which the API key belongs.

```ruby
DigitSend::Config.api_token = 'bdf6a88dcb7e3ff3df18afda99591360'
```
 
### 2. Sending Messages

The general approach:

```ruby
DigitSend::Message.send do |m|
  m.to "<EMAIL>", "3125551234"
  m.to "<EMAIL>", "7731112222"
  m.cc "<EMAIL>"
  m.subject "Hello Bob, Tom, and Fred"
  m.body "Here's a message, hope you enjoy!"
  m.attach "report.xls"
  m.attach "notes.txt", "here's the contents of notes.txt"
end
```

A few things to note:

* Call to or cc multiple times to add multiple recipients.
* The second (optional) argument to the to and cc methods is that user's phone number.  The phone number is required if this is the first message being sent to the user.

### 3. DigitSend::MissingPhoneNumbers

This exception is thrown whenever an attempt is made to send a message to a new user without providing a phone number:

```ruby
begin
  DigitSend::Message.send do |m|
    m.to "<EMAIL>"
    m.subject "Testing"
    m.body "Here's a test mesage"
  end
rescue DigitSend::MissingPhoneNumbers => ex
  puts "need phone numbers for: #{ex.email_addresses}"
end
```

### 4. Message File Attachments

The attach method can be called a number of ways:

```ruby
DigitSend::Message.send do |m|
  m.to "<EMAIL>"
  m.subject "Here's some attachments"

  # Attach the report.xls file on disk.
  m.attach "/path/to/report.xls"

  # Attach a file with its contents specified as a string.
  m.attach "reports.txt", "contents of the file"

  # Attach a file with its contents specified as any object
  # that can be passed to UploadIO.new. 
  m.attach "picture.jpg", File.open("picture.jpg")
end
```

### 5. Uploading Files to Repositories

Repositories are referenced by name and must be created in using the admin portal.

```ruby
DigitSend::Repository.upload "Reports", "/Internal/#{Date.today}", "activity.csv"
```

* The first parameter is the name of the repository.
* The second parameter identifies the folder to which the file should belong.  Folders are created on the fly, mkdir_p style.
* The third parameter is the name of the file.
* The optional fourth parameter can be the string contents of the file or an object just like when attaching a file to a message.  (Above.)<commit_msg>documentation<commit_after># DigitSend

DigitSend is a secure email and file sharing service with a streamlined
two-factor registration process.  This gem allows you to send email and upload
files to share programmatically.

## Usage

### 1. API Key

You must set the API key before performing any operations.  API keys are
granted on a per-user basis using the administration portal.  All operations
are done on behalf of the user to which the API key belongs.

```ruby
DigitSend::Config.api_token = 'bdf6a88dcb7e3ff3df18afda99591360'
```
 
### 2. Sending Messages

The general approach:

```ruby
DigitSend::Message.send do |m|
  m.to "<EMAIL>", "3125551234"
  m.to "<EMAIL>", "7731112222"
  m.cc "<EMAIL>"
  m.subject "Hello Bob, Tom, and Fred"
  m.body "Here's a message, hope you enjoy!"
  m.attach "report.xls"
  m.attach "notes.txt", "here's the contents of notes.txt"
end
```

A few things to note:

* Call to or cc multiple times to add multiple recipients.
* The second (optional) argument to the to and cc methods is that user's phone
  number.  The phone number is required if this is the first message being sent
  to the user.

### 3. DigitSend::MissingPhoneNumbers

This exception is thrown whenever an attempt is made to send a message to a new
user without providing a phone number:

```ruby
begin
  DigitSend::Message.send do |m|
    m.to "<EMAIL>"
    m.subject "Testing"
    m.body "Here's a test mesage"
  end
rescue DigitSend::MissingPhoneNumbers => ex
  puts "need phone numbers for: #{ex.email_addresses}"
end
```

### 4. Message File Attachments

The attach method can be called a number of ways:

```ruby
DigitSend::Message.send do |m|
  m.to "<EMAIL>"
  m.subject "Here's some attachments"

  # Attach the report.xls file on disk.
  m.attach "/path/to/report.xls"

  # Attach a file with its contents specified as a string.
  m.attach "reports.txt", "contents of the file"

  # Attach a file with its contents specified as any object
  # that can be passed to UploadIO.new. 
  m.attach "picture.jpg", File.open("picture.jpg")
end
```

### 5. Uploading Files to Repositories

Repositories are referenced by name and must be created in using the admin
portal.

```ruby
DigitSend::Repository.upload "Reports", "/Internal/#{Date.today}", "activity.csv"
```

* The first parameter is the name of the repository.
* The second parameter identifies the folder to which the file should belong.  Folders are created on the fly, mkdir_p style.
* The third parameter is the name of the file.
* The optional fourth parameter can can be the string contents of the file or
  an object; it has the same behavior as with message attachments described
  above.
{'fraction_non_alphanumeric': 0.09041250706347712, 'fraction_numerical': 0.01544546995667734, 'mean_word_length': 3.957983193277311, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '1475737', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1584, 'n_words': 731}