baxter/twilio_recordings — pull request #5 by baxter (2014-03-10 16:14:38+00:00)
Title: Use Tempfiles instead of Files

This PR alters the TwilioRecordings gem so that it creates Tempfiles rather than regular files.

The interface is unchanged, so it should not affect existing users, but the files will now be cleaned up after the ruby process ends.

* All downloaded files be Tempfiles instead of regular Files
* The output file will be a Tempfile if no filename is passed in to `join`

## REPRO :rooster:

Aside from the specs you can test this in irb by doing the following:

```ruby
require './lib/twilio_recordings'
@account_sid = "ACeb4e7b38952d70a91bc4a4acea8dc9e0"
@recording_sids = [
"RE93fcf1c3912aea0db664914147789e10",
"REcd5c5bec7ff667d5c3f1502d04ccb79e",
"REf7b24375cdbbbb42f58828f2fdf7b5a9",
"RE23c45b6262e256a455b1ee296af53fbb"
]
t = TwilioRecordings.new(@account_sid, @recording_sids)
t.download
```

Now *without closing irb*, check the contents of your `/tmp` directory.

```bash
> ls /tmp
...
RE23c45b6262e256a455b1ee296af53fbb20140310-55220-utxtth.mp3
RE93fcf1c3912aea0db664914147789e1020140310-55220-oqk8n1.mp3
REcd5c5bec7ff667d5c3f1502d04ccb79e20140310-55220-1sd75hv.mp3
REf7b24375cdbbbb42f58828f2fdf7b5a920140310-55220-18hhwin.mp3
```

Now run `t.join` in irb. You should no longer see the temporarily downloaded files, but you should see a file with a name beginning `joined_recording`

```bash
ls /tmp/
...
joined_recording20140310-55220-p5l3ev.mp3
```

You should be able to play this file in Quicktime or VLC.

Now close irb and the `joined_recording` file should also be deleted.