interfax 1.0.0.beta.1 → 1.0.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ca2a92fceee202dd5447d835b0dddeafa67c009
4
- data.tar.gz: a867d88f73fa55d5d6718f004b5c2b434fa2e746
3
+ metadata.gz: a1e9c472700ce6e06a0b6e73c8404177ff8798ce
4
+ data.tar.gz: e4d2321131a15cfdbf3a7a35f25260bbf72877b3
5
5
  SHA512:
6
- metadata.gz: 0252390bb07c553572fcefd0138789eac6bc515fcf975983ad1cf96d0ad97522a19c7b4a43b0cac1172f816d3d48a90638781a013d8fd0cef615b1bc89f7ff9c
7
- data.tar.gz: c6a052dbed6f1b6832349b01858061d9946138e8ccdfb72cbcd13f4e6a9c487583f31fc385abbfc86c5d06a361e25aa4c321b7f144fc3a5b28fef331d5e6a8e0
6
+ metadata.gz: c8e357151a090187121cadfec40d95604b1b5e45f2b8ea44347be9a26935526a203ccb2623c7af26441f23c07cb76da5927baa19dc31e5d2555528effff54cc1
7
+ data.tar.gz: c92ba400dc2def9cca50d94eb27f3d8471e9d2d3b79eed7aae34f7299e7f4c6ef7787208da649f4acd5c5811dffbfa1ba3a8adbec0f8efb54d6f19222a36698c
data/README.md CHANGED
@@ -8,7 +8,7 @@ Send and receive faxes in Ruby with the [InterFAX](https://www.interfax.net/en/d
8
8
 
9
9
  ## Installation
10
10
 
11
- Either install directly or via bundler.
11
+ This gem requires 2.1+. You can install install it directly or via bundler.
12
12
 
13
13
  ```ruby
14
14
  gem 'interfax', '~> 1.0.0'
@@ -22,27 +22,31 @@ To send a fax from a PDF file:
22
22
  require 'interfax'
23
23
 
24
24
  interfax = InterFAX::Client.new(username: 'username', password: 'password')
25
- interfax.deliver(faxNumber: "+11111111112", file: 'folder/fax.pdf')
25
+ fax = interfax.deliver(faxNumber: "+11111111112", file: 'folder/fax.pdf')
26
+ fax = fax.reload # resync with API to get latest status
27
+ fax.status # Success if 0. Pending if < 0. Error if > 0
26
28
  ```
27
29
 
28
30
  # Usage
29
31
 
30
- [Client](#client) | [Account](#account) | [Outbound](#outbound) | [Inbound](#inbound) | [Helper Classes](#helper-classes)
32
+ [Client](#client) | [Account](#account) | [Outbound](#outbound) | [Inbound](#inbound) | [Documents](#documents) | [Helper Classes](#helper-classes)
31
33
 
32
34
  ## Client
33
35
 
34
36
  The client follows the [12-factor](12factor.net/config) apps principle and can be either set directly or via environment variables.
35
37
 
36
38
  ```ruby
37
- # using parameters
39
+ # Initialize using parameters
38
40
  interfax = InterFAX::Client.new(username: '...', password: '...')
39
41
 
40
- # using environment variables:
42
+ # Alternatice: Initialize using environment variables
41
43
  # * INTERFAX_USERNAME
42
44
  # * INTERFAX_PASSWORD
43
45
  interfax = InterFAX::Client.new
44
46
  ```
45
47
 
48
+ All connections are established over HTTPS.
49
+
46
50
  ## Account
47
51
 
48
52
  ### Balance
@@ -54,7 +58,7 @@ interfax.account.balance
54
58
  => 9.86
55
59
  ```
56
60
 
57
- **Documentation:** [`GET /accounts/self/ppcards/balance`](https://www.interfax.net/en/dev/rest/reference/3001)
61
+ **More:** [documentation](https://www.interfax.net/en/dev/rest/reference/3001)
58
62
 
59
63
  ## Outbound
60
64
 
@@ -69,16 +73,22 @@ Submit a fax to a single destination number.
69
73
  There are a few ways to send a fax. One way is to directly provide a file path or url.
70
74
 
71
75
  ```ruby
72
- interfax.outbound.deliver(faxNumber: "+11111111112", file: 'file://fax.pdf')
76
+ # with a path
77
+ interfax.outbound.deliver(faxNumber: "+11111111112", file: 'folder/fax.txt')
78
+ # with a URL
73
79
  interfax.outbound.deliver(faxNumber: "+11111111112", file: 'https://s3.aws.com/example/fax.pdf')
74
80
  ```
75
81
 
82
+ InterFAX supports over 20 file types including HTML, PDF, TXT, Word, and many more. For a full list see the [Supported File Types](https://www.interfax.net/en/help/supported_file_types) documentation.
83
+
76
84
  The returned object is a `InterFAX::Outbound::Fax` with just an `id`. You can use this object to load more information, get the image, or cancel the sending of the fax.
77
85
 
78
86
  ```rb
79
87
  fax = interfax.outbound.deliver(faxNumber: "+11111111112", file: 'file://fax.pdf')
80
- fax = fax.reload # load more information about this fax
81
- fax.image # load the image sent to the faxNumber
88
+ fax = fax.reload # Reload fax, allowing you to inspect the status and more
89
+
90
+ fax.id # the ID of the fax that can be used in some of the other API calls
91
+ fax.image # returns an image representing the fax sent to the faxNumber
82
92
  fax.cancel # cancel the sending of the fax
83
93
  ```
84
94
 
@@ -86,7 +96,7 @@ Alternatively you can create an `InterFAX::File` with binary data and pass this
86
96
 
87
97
  ```ruby
88
98
  data = File.open('file://fax.pdf').read
89
- file = InterFAX::File.new(data, mime_type: 'application/pdf')
99
+ file = interfax.files.create(data, mime_type: 'application/pdf')
90
100
  interfax.outbound.deliver(faxNumber: "+11111111112", file: file)
91
101
  ```
92
102
 
@@ -98,9 +108,7 @@ interfax.outbound.deliver(faxNumber: "+11111111112", files: ['file://fax.pdf', '
98
108
 
99
109
  Under the hood every path and string is turned into a [InterFAX::File](#InterFax::File) object. For more information see [the documentation](#InterFax::File) for this class.
100
110
 
101
- **Documentation:** [`POST /outbound/faxes`](https://www.interfax.net/en/dev/rest/reference/2918)
102
-
103
- [**Additional options:**](https://www.interfax.net/en/dev/rest/reference/2918) `contact`, `postponeTime`, `retriesToPerform`, `csid`, `pageHeader`, `reference`, `pageSize`, `fitToPage`, `pageOrientation`, `resolution`, `rendering`
111
+ **Options:** [`contact`, `postponeTime`, `retriesToPerform`, `csid`, `pageHeader`, `reference`, `pageSize`, `fitToPage`, `pageOrientation`, `resolution`, `rendering`](https://www.interfax.net/en/dev/rest/reference/2918)
104
112
 
105
113
  **Alias**: `interfax.deliver`
106
114
 
@@ -115,11 +123,11 @@ Get a list of recent outbound faxes (which does not include batch faxes).
115
123
  ```ruby
116
124
  interfax.outbound.all
117
125
  => [#<InterFAX::Outbound::Fax>, ...]
126
+ interfax.outbound.all(limit: 1)
127
+ => [#<InterFAX::Outbound::Fax>]
118
128
  ```
119
129
 
120
- **Documentation:** [`GET /outbound/faxes`](https://www.interfax.net/en/dev/rest/reference/2920)
121
-
122
- [**Options:**](https://www.interfax.net/en/dev/rest/reference/2920) `limit`, `lastId`, `sortOrder`, `userId`
130
+ **Options:** [`limit`, `lastId`, `sortOrder`, `userId`](https://www.interfax.net/en/dev/rest/reference/2920)
123
131
 
124
132
  ----
125
133
 
@@ -134,7 +142,7 @@ interfax.outbound.completed(123, 234)
134
142
  => [#<InterFAX::Outbound::Fax>, ...]
135
143
  ```
136
144
 
137
- **Documentation:** [`GET /outbound/faxes/completed`](https://www.interfax.net/en/dev/rest/reference/2972)
145
+ **More:** [none](https://www.interfax.net/en/dev/rest/reference/2972)
138
146
 
139
147
  ----
140
148
 
@@ -149,7 +157,7 @@ interfax.outbound.find(123456)
149
157
  => #<InterFAX::Outbound::Fax>
150
158
  ```
151
159
 
152
- **Documentation:** [`GET /outbound/faxes/:id`](https://www.interfax.net/en/dev/rest/reference/2921)
160
+ **More:** [none](https://www.interfax.net/en/dev/rest/reference/2921)
153
161
 
154
162
  ----
155
163
 
@@ -168,7 +176,7 @@ image.save('fax.tiff')
168
176
  => # saves image to file
169
177
  ```
170
178
 
171
- **Documentation:** [`GET /outbound/faxes/:id/image`](https://www.interfax.net/en/dev/rest/reference/2941)
179
+ **More:** [none](https://www.interfax.net/en/dev/rest/reference/2941)
172
180
 
173
181
  ----
174
182
 
@@ -183,7 +191,7 @@ interfax.outbound.cancel(123456)
183
191
  => #<InterFAX::Outbound::Fax>
184
192
  ```
185
193
 
186
- **Documentation:** [`GET /outbound/faxes/:id/cancel`](https://www.interfax.net/en/dev/rest/reference/2939)
194
+ **More:** [none](https://www.interfax.net/en/dev/rest/reference/2939)
187
195
 
188
196
  ----
189
197
 
@@ -198,9 +206,7 @@ interfax.outbound.search(faxNumber: '+1230002305555')
198
206
  => [#<InterFAX::Outbound::Fax>, ...]
199
207
  ```
200
208
 
201
- **Documentation:** [`GET /outbound/search`](https://www.interfax.net/en/dev/rest/reference/2959)
202
-
203
- [**Options:**](https://www.interfax.net/en/dev/rest/reference/2959) `ids`, `reference`, `dateFrom`, `dateTo`, `status`, `userId`, `faxNumber`, `limit`, `offset`
209
+ **Options:** [`ids`, `reference`, `dateFrom`, `dateTo`, `status`, `userId`, `faxNumber`, `limit`, `offset`](https://www.interfax.net/en/dev/rest/reference/2959)
204
210
 
205
211
  ## Inbound
206
212
 
@@ -215,11 +221,11 @@ Retrieves a user's list of inbound faxes. (Sort order is always in descending ID
215
221
  ```ruby
216
222
  interfax.inbound.all
217
223
  => [#<InterFAX::Inbound::Fax>, ...]
224
+ interfax.inbound.all(limit: 1)
225
+ => [#<InterFAX::Inbound::Fax>]
218
226
  ```
219
227
 
220
- **Documentation:** [`GET /inbound/faxes`](https://www.interfax.net/en/dev/rest/reference/2935)
221
-
222
- [**Options:**](https://www.interfax.net/en/dev/rest/reference/2935) `unreadOnly`, `limit`, `lastId`, `allUsers`
228
+ **Options:** [`unreadOnly`, `limit`, `lastId`, `allUsers`](https://www.interfax.net/en/dev/rest/reference/2935)
223
229
 
224
230
  ---
225
231
 
@@ -234,7 +240,7 @@ interfax.inbound.find(123456)
234
240
  => #<InterFAX::Inbound::Fax>
235
241
  ```
236
242
 
237
- **Documentation:** [`GET /inbound/faxes/:id`](https://www.interfax.net/en/dev/rest/reference/2938)
243
+ **More:** [none](https://www.interfax.net/en/dev/rest/reference/2938)
238
244
 
239
245
  ---
240
246
 
@@ -253,7 +259,7 @@ image.save('fax.tiff')
253
259
  => # saves image to file
254
260
  ```
255
261
 
256
- **Documentation:** [`GET /inbound/faxes/:id/image`](https://www.interfax.net/en/dev/rest/reference/2937)
262
+ **More:** [none](https://www.interfax.net/en/dev/rest/reference/2937)
257
263
 
258
264
  ---
259
265
 
@@ -268,7 +274,7 @@ interfax.inbound.email(123456)
268
274
  => [#<InterFAX::Email>]
269
275
  ```
270
276
 
271
- **Documentation:** [`GET /inbound/faxes/:id/emails`](https://www.interfax.net/en/dev/rest/reference/2930)
277
+ **More:** [none](https://www.interfax.net/en/dev/rest/reference/2930)
272
278
 
273
279
  ---
274
280
 
@@ -285,7 +291,9 @@ interfax.inbound.mark(123456, read: false) # mark unread
285
291
  => true
286
292
  ```
287
293
 
288
- **Documentation:** [`POST /inbound/faxes/:id/mark`](https://www.interfax.net/en/dev/rest/reference/2936)
294
+ **More:** [none](https://www.interfax.net/en/dev/rest/reference/2936)
295
+
296
+ ---
289
297
 
290
298
  ### Resend inbound fax
291
299
 
@@ -302,6 +310,105 @@ interfax.inbound.resend(123456, email: 'test@example.com')
302
310
  => true
303
311
  ```
304
312
 
313
+ **More:** [none](https://www.interfax.net/en/dev/rest/reference/2929)
314
+
315
+ ---
316
+
317
+ ## Documents
318
+
319
+ [Create](#create-document) | [Upload chunk](#upload-chunk) | [Get list](#get-document-list) | [Status](#get-document-status) | [Cancel](#cancel-document)
320
+
321
+ Document allow for uploading of large files up to 20MB in 200kb chunks. The `InterFAX::File` format automatically uses this if needed but a sample implementation would look as followed.
322
+
323
+ ```ruby
324
+ file = File.open('test.pdf', 'rb')
325
+
326
+ document = interfax.documents.create('test.pdf', file.size)
327
+
328
+ cursor = 0
329
+ while !file.eof?
330
+ chunk = file.read(500)
331
+ next_cursor = cursor + chunk.length
332
+ document.upload(cursor, next_cursor-1, chunk)
333
+ cursor = next_cursor
334
+ end
335
+ ```
336
+
337
+ ### Create Documents
338
+
339
+ `interfax.documents.create(name, size, options = {})`
340
+
341
+ Create a document upload session, allowing you to upload large files in chunks.
342
+
343
+ ```ruby
344
+ interfax.documents.create('large_file.pdf', '231234')
345
+ => #<InterFAX::Document uri="https://rest.interfax.net/outbound/documents/123456">
346
+ ```
347
+
348
+ **Options:** [`disposition`, `sharing`](https://www.interfax.net/en/dev/rest/reference/2967)
349
+
350
+ ---
351
+
352
+ ### Upload chunk
353
+
354
+ `interfax.documents.upload(id, range_start, range_end, chunk)`
355
+
356
+ Upload a chunk to an existing document upload session.
357
+
358
+ ```ruby
359
+ interfax.documents.upload(123456, 0, 999, "....binary-data....")
360
+ => true
361
+ ```
362
+
363
+ **More:** [none](https://www.interfax.net/en/dev/rest/reference/2966)
364
+
365
+ ---
366
+
367
+ ### Get document list
368
+
369
+ `interfax.documents.all(options = {})`
370
+
371
+ Get a list of previous document uploads which are currently available.
372
+
373
+ ```ruby
374
+ interfax.documents.all
375
+ => #[#<InterFAX::Document>, ...]
376
+ interfax.documents.all(offset: 10)
377
+ => #[#<InterFAX::Document>, ...]
378
+ ```
379
+
380
+ **Options:** [`limit`, `offset`](https://www.interfax.net/en/dev/rest/reference/2968)
381
+
382
+ ---
383
+
384
+ ### Get document status
385
+
386
+ `interfax.documents.find(id)`
387
+
388
+ Get the current status of a specific document upload.
389
+
390
+ ```ruby
391
+ interfax.documents.find(123456)
392
+ => #<InterFAX::Document ... >
393
+ ```
394
+
395
+ **More:** [documentation](https://www.interfax.net/en/dev/rest/reference/2965)
396
+
397
+ ---
398
+
399
+ ### Cancel document
400
+
401
+ `interfax.documents.cancel(id)`
402
+
403
+ Cancel a document upload and tear down the upload session, or delete a previous upload.
404
+
405
+ ```ruby
406
+ interfax.documents.cancel(123456)
407
+ => true
408
+ ```
409
+
410
+ **More:** [none](https://www.interfax.net/en/dev/rest/reference/2964)
411
+
305
412
  ---
306
413
 
307
414
  ## Helper Classes
@@ -344,15 +451,21 @@ image.save('folder/fax.tiff') # Saves the TIFF to the path provided
344
451
 
345
452
  ### InterFAX::File
346
453
 
347
- This class is used by `interfax.outbound.deliver` to turn every URL, path and binary data into a uniform format, ready to be sent out to the InterFAX API.
454
+ This class is used by `interfax.outbound.deliver` and `interfax.files` to turn every URL, path and binary data into a uniform format, ready to be sent out to the InterFAX API.
348
455
 
349
456
  It is most useful for sending binary data to the `.deliver` method.
350
457
 
351
458
  ```rb
352
459
  # binary data
353
- file = InterFAX::File.new('....binary data.....', mime_type: 'application/pdf')
354
- file.header #=> "Content-Type: application/pdf"
355
- file.body #=> '....binary data.....'
460
+ file = InterFAX::File.new(interfax, '....binary data.....', mime_type: 'application/pdf')
461
+ => #<InterFAX::File>
462
+
463
+ # Alternatively
464
+ file = interfax.files.create('....binary data.....', mime_type: 'application/pdf')
465
+ file.header
466
+ => "Content-Type: application/pdf"
467
+ file.body
468
+ => '....binary data.....'
356
469
 
357
470
  interfax.outbound.deliver(faxNumber: '+1111111111112', file: file)
358
471
  ```
@@ -361,12 +474,12 @@ Additionally it can be used to turn a URL or path into a valid object as well, t
361
474
 
362
475
  ```rb
363
476
  # a file by path
364
- file = InterFAX::File.new('foo/bar.pdf')
477
+ file = interfax.files.create('foo/bar.pdf')
365
478
  file.header #=> "Content-Type: application/pdf"
366
479
  file.body #=> '....binary data.....'
367
480
 
368
481
  # a file by url
369
- file = InterFAX::File.new('https://foo.com/bar.html')
482
+ file = interfax.files.create('https://foo.com/bar.html')
370
483
  file.header #=> "Content-Location: https://foo.com/bar.html"
371
484
  file.body #=> nil
372
485
  ```
@@ -383,6 +496,18 @@ email.messageStatus # 0 = OK; number smaller than zero = in progress; number gre
383
496
  email.completionTime # Completion timestamp.
384
497
  ```
385
498
 
499
+ ### InterFAX::Document
500
+
501
+ The `InterFAX::Document` is returned in most of the Document APIs. As a convenience the following methods are available.
502
+
503
+ ```ruby
504
+ document = interfax.documents.find(123)
505
+ document = document.reload # Loads or reloads object
506
+ document.upload(0, 999, '.....binary data....' # Maps to the interfax.documents.upload method
507
+ document.cancel # Maps to the interfax.documents.upload method
508
+ document.id # Extracts the ID from the URI (the API does not return the ID)
509
+ ```
510
+
386
511
  ## Contributing
387
512
 
388
513
  1. **Fork** the repo on GitHub
data/lib/interfax.rb CHANGED
@@ -3,6 +3,7 @@ require 'interfax/client'
3
3
  require 'interfax/account'
4
4
  require 'interfax/object'
5
5
  require 'interfax/file'
6
+ require 'interfax/files'
6
7
  require 'interfax/forwarding_email'
7
8
  require 'interfax/outbound'
8
9
  require 'interfax/outbound/fax'
@@ -10,5 +11,7 @@ require 'interfax/outbound/delivery'
10
11
  require 'interfax/inbound'
11
12
  require 'interfax/inbound/fax'
12
13
  require 'interfax/image'
14
+ require 'interfax/document'
15
+ require 'interfax/documents'
13
16
 
14
17
  require 'mimemagic'
@@ -10,7 +10,7 @@ module InterFAX
10
10
  class UnauthorizedError < StandardError; end
11
11
 
12
12
  attr_accessor :username, :password, :http
13
- attr_writer :outbound, :inbound, :account
13
+ attr_writer :outbound, :inbound, :account, :documents, :files
14
14
 
15
15
  DOMAIN = "rest.interfax.net".freeze
16
16
  USER_AGENT = "InterFAX Ruby #{InterFAX::VERSION}".freeze
@@ -45,6 +45,14 @@ module InterFAX
45
45
  @inbound ||= InterFAX::Inbound.new(self)
46
46
  end
47
47
 
48
+ def documents
49
+ @documents ||= InterFAX::Documents.new(self)
50
+ end
51
+
52
+ def files
53
+ @files ||= InterFAX::Files.new(self)
54
+ end
55
+
48
56
  def get path, params = {}, valid_keys = {}
49
57
  uri = uri_for(path, params, valid_keys)
50
58
  request = Net::HTTP::Get.new(uri.request_uri)
@@ -61,6 +69,12 @@ module InterFAX
61
69
  transmit(request)
62
70
  end
63
71
 
72
+ def delete path
73
+ uri = uri_for(path)
74
+ request = Net::HTTP::Delete.new(uri.request_uri)
75
+ transmit(request)
76
+ end
77
+
64
78
  private
65
79
 
66
80
  def uri_for(path, params = {}, keys = {})
@@ -0,0 +1,17 @@
1
+ class InterFAX::Document < InterFAX::Object
2
+ def upload range_start, range_end, chunk
3
+ client.documents.upload(id, range_start, range_end, chunk)
4
+ end
5
+
6
+ def cancel
7
+ client.documents.cancel(id)
8
+ end
9
+
10
+ def reload
11
+ client.documents.find(id)
12
+ end
13
+
14
+ def id
15
+ uri.split("/").last
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ class InterFAX::Documents
2
+
3
+ def initialize client
4
+ @client = client
5
+ end
6
+
7
+ def create name, size, options = {}
8
+ options[:name] = name
9
+ options[:size] = size
10
+
11
+ valid_keys = [:name, :size, :disposition, :shared]
12
+
13
+ uri = @client.post("/outbound/documents", options, valid_keys)
14
+ InterFAX::Document.new(uri: uri, client: @client)
15
+ end
16
+
17
+ def upload document_id, range_start, range_end, chunk
18
+ headers = { 'Range' => "bytes=#{range_start}-#{range_end}" }
19
+ @client.post("/outbound/documents/#{document_id}", {}, {}, headers, chunk)
20
+ true
21
+ end
22
+
23
+ def all options = {}
24
+ valid_keys = [:limit, :offset]
25
+ @client.get("/outbound/documents", options, valid_keys).map do |document|
26
+ document[:client] = @client
27
+ InterFAX::Document.new(document)
28
+ end
29
+ end
30
+
31
+ def find document_id
32
+ document = @client.get("/outbound/documents/#{document_id}")
33
+ document[:client] = @client
34
+ InterFAX::Document.new(document)
35
+ end
36
+
37
+ def cancel document_id
38
+ @client.delete("/outbound/documents/#{document_id}")
39
+ true
40
+ end
41
+
42
+ end
data/lib/interfax/file.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  class InterFAX::File
2
- attr_accessor :header, :body
2
+ attr_accessor :header, :body, :client, :chunk_size
3
+
4
+ def initialize client, location, options = {}
5
+ self.client = client
6
+ self.chunk_size = options[:chunk_size] || 1024*1024
3
7
 
4
- def initialize location, options = {}
5
8
  if options[:mime_type]
6
9
  initialize_binary(location, options[:mime_type])
7
10
  elsif location.start_with?('http://') || location.start_with?('https://')
@@ -12,6 +15,7 @@ class InterFAX::File
12
15
  end
13
16
 
14
17
  def initialize_binary(data, mime_type)
18
+ return initialize_document(data, mime_type) if data.length > chunk_size
15
19
  self.header = "Content-Type: #{mime_type}"
16
20
  self.body = data
17
21
  end
@@ -23,9 +27,30 @@ class InterFAX::File
23
27
 
24
28
  def initialize_path(path)
25
29
  file = File.open(path)
26
- mime_type = MimeMagic.by_magic(file)
30
+ mime_type = MimeMagic.by_magic(file) || MimeMagic.by_path(file)
31
+ data = File.open(path, 'rb').read
27
32
 
28
- self.header = "Content-Type: #{mime_type}"
29
- self.body = File.open(path, 'rb').read
33
+ initialize_binary(data, mime_type)
34
+ end
35
+
36
+ def initialize_document(data, mime_type)
37
+ document = create_document(data, mime_type)
38
+ upload(document, data)
39
+ initialize_url(document.uri)
40
+ end
41
+
42
+ def upload document, data
43
+ cursor = 0
44
+ data.bytes.each_slice(chunk_size) do |slice|
45
+ chunk = slice.pack("C*")
46
+ next_cursor = cursor + chunk.length
47
+ document.upload(cursor, next_cursor - 1, chunk)
48
+ cursor = next_cursor
49
+ end
50
+ end
51
+
52
+ def create_document data, mime_type
53
+ extension = MimeMagic::EXTENSIONS.select {|k,v| v == mime_type.to_s}.keys.first
54
+ client.documents.create("upload-#{Time.now.to_i}.#{extension}", data.length)
30
55
  end
31
56
  end
@@ -0,0 +1,9 @@
1
+ class InterFAX::Files
2
+ def initialize client
3
+ @client = client
4
+ end
5
+
6
+ def create data, options = {}
7
+ InterFAX::File.new(@client, data, options)
8
+ end
9
+ end
@@ -37,7 +37,7 @@ class InterFAX::Outbound::Delivery
37
37
  def generate_file_objects files
38
38
  files.map do |file|
39
39
  if file.kind_of?(String)
40
- InterFAX::File.new(file)
40
+ InterFAX::File.new(client, file)
41
41
  elsif file.kind_of?(InterFAX::File)
42
42
  file
43
43
  end
@@ -1,3 +1,3 @@
1
1
  module InterFAX
2
- VERSION = '1.0.0.beta.1'
2
+ VERSION = '1.0.0.beta.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interfax
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta.1
4
+ version: 1.0.0.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - InterFAX
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-01 00:00:00.000000000 Z
12
+ date: 2016-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mimemagic
@@ -95,7 +95,10 @@ files:
95
95
  - lib/interfax.rb
96
96
  - lib/interfax/account.rb
97
97
  - lib/interfax/client.rb
98
+ - lib/interfax/document.rb
99
+ - lib/interfax/documents.rb
98
100
  - lib/interfax/file.rb
101
+ - lib/interfax/files.rb
99
102
  - lib/interfax/forwarding_email.rb
100
103
  - lib/interfax/image.rb
101
104
  - lib/interfax/inbound.rb