interfax 0.2.1 → 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ca2a92fceee202dd5447d835b0dddeafa67c009
4
+ data.tar.gz: a867d88f73fa55d5d6718f004b5c2b434fa2e746
5
+ SHA512:
6
+ metadata.gz: 0252390bb07c553572fcefd0138789eac6bc515fcf975983ad1cf96d0ad97522a19c7b4a43b0cac1172f816d3d48a90638781a013d8fd0cef615b1bc89f7ff9c
7
+ data.tar.gz: c6a052dbed6f1b6832349b01858061d9946138e8ccdfb72cbcd13f4e6a9c487583f31fc385abbfc86c5d06a361e25aa4c321b7f144fc3a5b28fef331d5e6a8e0
data/LICENSE CHANGED
@@ -1,20 +1,21 @@
1
- Copyright (c) 2010 Sascha Brink
1
+ MIT License
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
3
+ Copyright (c) 2016 InterFAX
10
4
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
13
11
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,396 @@
1
+ # InterFAX Ruby Gem
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/interfax.svg)](https://badge.fury.io/rb/interfax) [![Build Status](https://travis-ci.org/interfax/interfax-ruby.svg?branch=master)](https://travis-ci.org/interfax/interfax-ruby)
4
+
5
+ [Installation](#installation) | [Getting Started](#getting-started) | [Contributing](#contributing) | [Usage](#usage) | [License](#license)
6
+
7
+ Send and receive faxes in Ruby with the [InterFAX](https://www.interfax.net/en/dev) REST API.
8
+
9
+ ## Installation
10
+
11
+ Either install directly or via bundler.
12
+
13
+ ```ruby
14
+ gem 'interfax', '~> 1.0.0'
15
+ ```
16
+
17
+ ## Getting started
18
+
19
+ To send a fax from a PDF file:
20
+
21
+ ```ruby
22
+ require 'interfax'
23
+
24
+ interfax = InterFAX::Client.new(username: 'username', password: 'password')
25
+ interfax.deliver(faxNumber: "+11111111112", file: 'folder/fax.pdf')
26
+ ```
27
+
28
+ # Usage
29
+
30
+ [Client](#client) | [Account](#account) | [Outbound](#outbound) | [Inbound](#inbound) | [Helper Classes](#helper-classes)
31
+
32
+ ## Client
33
+
34
+ The client follows the [12-factor](12factor.net/config) apps principle and can be either set directly or via environment variables.
35
+
36
+ ```ruby
37
+ # using parameters
38
+ interfax = InterFAX::Client.new(username: '...', password: '...')
39
+
40
+ # using environment variables:
41
+ # * INTERFAX_USERNAME
42
+ # * INTERFAX_PASSWORD
43
+ interfax = InterFAX::Client.new
44
+ ```
45
+
46
+ ## Account
47
+
48
+ ### Balance
49
+
50
+ Determine the remaining faxing credits in your account.
51
+
52
+ ```ruby
53
+ interfax.account.balance
54
+ => 9.86
55
+ ```
56
+
57
+ **Documentation:** [`GET /accounts/self/ppcards/balance`](https://www.interfax.net/en/dev/rest/reference/3001)
58
+
59
+ ## Outbound
60
+
61
+ [Send](#send-fax) | [Get list](#get-outbound-fax-list) | [Get completed list](#get-completed-fax-list) | [Get record](#get-outbound-fax-record) | [Get image](#get-outbound-fax-image) | [Cancel fax](#cancel-a-fax) | [Search](#search-fax-list)
62
+
63
+ ### Send fax
64
+
65
+ `.outbound.deliver(options = {})`
66
+
67
+ Submit a fax to a single destination number.
68
+
69
+ There are a few ways to send a fax. One way is to directly provide a file path or url.
70
+
71
+ ```ruby
72
+ interfax.outbound.deliver(faxNumber: "+11111111112", file: 'file://fax.pdf')
73
+ interfax.outbound.deliver(faxNumber: "+11111111112", file: 'https://s3.aws.com/example/fax.pdf')
74
+ ```
75
+
76
+ 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
+
78
+ ```rb
79
+ 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
82
+ fax.cancel # cancel the sending of the fax
83
+ ```
84
+
85
+ Alternatively you can create an `InterFAX::File` with binary data and pass this in as well.
86
+
87
+ ```ruby
88
+ data = File.open('file://fax.pdf').read
89
+ file = InterFAX::File.new(data, mime_type: 'application/pdf')
90
+ interfax.outbound.deliver(faxNumber: "+11111111112", file: file)
91
+ ```
92
+
93
+ To send multiple files just pass in an array strings and `InterFAX::File` objects.
94
+
95
+ ```rb
96
+ interfax.outbound.deliver(faxNumber: "+11111111112", files: ['file://fax.pdf', 'https://s3.aws.com/example/fax.pdf'])
97
+ ```
98
+
99
+ 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
+
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`
104
+
105
+ **Alias**: `interfax.deliver`
106
+
107
+ ----
108
+
109
+ ### Get outbound fax list
110
+
111
+ `interfax.outbound.all(options = {})`
112
+
113
+ Get a list of recent outbound faxes (which does not include batch faxes).
114
+
115
+ ```ruby
116
+ interfax.outbound.all
117
+ => [#<InterFAX::Outbound::Fax>, ...]
118
+ ```
119
+
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`
123
+
124
+ ----
125
+
126
+ ### Get completed fax list
127
+
128
+ `interfax.outbound.completed(array_of_ids)`
129
+
130
+ Get details for a subset of completed faxes from a submitted list. (Submitted id's which have not completed are ignored).
131
+
132
+ ```ruby
133
+ interfax.outbound.completed(123, 234)
134
+ => [#<InterFAX::Outbound::Fax>, ...]
135
+ ```
136
+
137
+ **Documentation:** [`GET /outbound/faxes/completed`](https://www.interfax.net/en/dev/rest/reference/2972)
138
+
139
+ ----
140
+
141
+ ### Get outbound fax record
142
+
143
+ `interfax.outbound.find(fax_id)`
144
+
145
+ Retrieves information regarding a previously-submitted fax, including its current status.
146
+
147
+ ```ruby
148
+ interfax.outbound.find(123456)
149
+ => #<InterFAX::Outbound::Fax>
150
+ ```
151
+
152
+ **Documentation:** [`GET /outbound/faxes/:id`](https://www.interfax.net/en/dev/rest/reference/2921)
153
+
154
+ ----
155
+
156
+ ### Get oubound fax image
157
+
158
+ `interfax.outbound.image(fax_id)`
159
+
160
+ Retrieve the fax image (TIFF file) of a submitted fax.
161
+
162
+ ```ruby
163
+ image = interfax.outbound.image(123456)
164
+ => #<InterFAX::Image>
165
+ image.data
166
+ => # "....binary data...."
167
+ image.save('fax.tiff')
168
+ => # saves image to file
169
+ ```
170
+
171
+ **Documentation:** [`GET /outbound/faxes/:id/image`](https://www.interfax.net/en/dev/rest/reference/2941)
172
+
173
+ ----
174
+
175
+ ### Cancel a fax
176
+
177
+ `interfax.outbound.cancel(fax_id)`
178
+
179
+ Cancel a fax in progress.
180
+
181
+ ```ruby
182
+ interfax.outbound.cancel(123456)
183
+ => #<InterFAX::Outbound::Fax>
184
+ ```
185
+
186
+ **Documentation:** [`GET /outbound/faxes/:id/cancel`](https://www.interfax.net/en/dev/rest/reference/2939)
187
+
188
+ ----
189
+
190
+ ### Search fax list
191
+
192
+ `interfax.outbound.search(options = {})`
193
+
194
+ Search for outbound faxes.
195
+
196
+ ```ruby
197
+ interfax.outbound.search(faxNumber: '+1230002305555')
198
+ => [#<InterFAX::Outbound::Fax>, ...]
199
+ ```
200
+
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`
204
+
205
+ ## Inbound
206
+
207
+ [Get list](#get-inbound-fax-list) | [Get record](#get-inbound-fax-record) | [Get image](#get-inbound-fax-image) | [Get emails](#get-forwarding-emails) | [Mark as read](#mark-as-readunread) | [Resend to email](#resend-inbound-fax)
208
+
209
+ ### Get inbound fax list
210
+
211
+ `interfax.inbound.all(options = {})`
212
+
213
+ Retrieves a user's list of inbound faxes. (Sort order is always in descending ID).
214
+
215
+ ```ruby
216
+ interfax.inbound.all
217
+ => [#<InterFAX::Inbound::Fax>, ...]
218
+ ```
219
+
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`
223
+
224
+ ---
225
+
226
+ ### Get inbound fax record
227
+
228
+ `interfax.inbound.find(fax_id)`
229
+
230
+ Retrieves a single fax's metadata (receive time, sender number, etc.).
231
+
232
+ ```ruby
233
+ interfax.inbound.find(123456)
234
+ => #<InterFAX::Inbound::Fax>
235
+ ```
236
+
237
+ **Documentation:** [`GET /inbound/faxes/:id`](https://www.interfax.net/en/dev/rest/reference/2938)
238
+
239
+ ---
240
+
241
+ ### Get inbound fax image
242
+
243
+ `interfax.inbound.image(fax_id)`
244
+
245
+ Retrieves a single fax's image.
246
+
247
+ ```ruby
248
+ image = interfax.inbound.image(123456)
249
+ => #<InterFAX::Image>
250
+ image.data
251
+ => # "....binary data...."
252
+ image.save('fax.tiff')
253
+ => # saves image to file
254
+ ```
255
+
256
+ **Documentation:** [`GET /inbound/faxes/:id/image`](https://www.interfax.net/en/dev/rest/reference/2937)
257
+
258
+ ---
259
+
260
+ ### Get forwarding emails
261
+
262
+ `interfax.inbound.emails(fax_id)`
263
+
264
+ Retrieve the list of email addresses to which a fax was forwarded.
265
+
266
+ ```ruby
267
+ interfax.inbound.email(123456)
268
+ => [#<InterFAX::Email>]
269
+ ```
270
+
271
+ **Documentation:** [`GET /inbound/faxes/:id/emails`](https://www.interfax.net/en/dev/rest/reference/2930)
272
+
273
+ ---
274
+
275
+ ### Mark as read/unread
276
+
277
+ `interfax.inbound.mark(fax_id, read: is_read)`
278
+
279
+ Mark a transaction as read/unread.
280
+
281
+ ```ruby
282
+ interfax.inbound.mark(123456, read: true) # mark read
283
+ => true
284
+ interfax.inbound.mark(123456, read: false) # mark unread
285
+ => true
286
+ ```
287
+
288
+ **Documentation:** [`POST /inbound/faxes/:id/mark`](https://www.interfax.net/en/dev/rest/reference/2936)
289
+
290
+ ### Resend inbound fax
291
+
292
+ `interfax.inbound.resend(fax_id, email: to_email)`
293
+
294
+ Resend an inbound fax to a specific email address.
295
+
296
+ ```ruby
297
+ # resend to the email(s) to which the fax was previously forwarded
298
+ interfax.inbound.resend(123456)
299
+ => true
300
+ # resend to a specific address
301
+ interfax.inbound.resend(123456, email: 'test@example.com')
302
+ => true
303
+ ```
304
+
305
+ ---
306
+
307
+ ## Helper Classes
308
+
309
+ ### InterFAX::Outbound::Fax
310
+
311
+ The `InterFAX::Outbound::Fax` is returned in most Outbound APIs. As a convenience the following methods are available.
312
+
313
+ ```rb
314
+ fax = interfax.outbound.find(123)
315
+ fax = fax.reload # Loads or reloads object
316
+ fax.cancel # Cancels the fax
317
+ fax.image # Returns a `InterFAX::Image` for this fax
318
+ fax.attributes # Returns a plain hash with all the attributes
319
+ ```
320
+
321
+ ### InterFAX::Inbound::Fax
322
+
323
+ The `InterFAX::Inbound::Fax` is returned in some of the Inbound APIs. As a convenience the following methods are available.
324
+
325
+ ```rb
326
+ fax = interfax.inbound.find(123)
327
+ fax = fax.reload # Loads or reloads object
328
+ fax.mark(true) # Marks the fax as read/unread
329
+ fax.resend(email) # Resend the fax to a specific email address.
330
+ fax.image # Returns a `InterFAX::Image` for this fax
331
+ fax.emails # Returns a list of InterFAX::ForwardingEmail objects that the fax was forwarded on to
332
+ fax.attributes # Returns a plain hash with all the attributes
333
+ ```
334
+
335
+ ### InterFAX::Image
336
+
337
+ A lightweight wrapper around the image data for a sent or received fax. Provides the following convenience methods.
338
+
339
+ ```rb
340
+ image = interfax.outbound.image(123)
341
+ image.data # Returns the raw binary data for the TIFF image.
342
+ image.save('folder/fax.tiff') # Saves the TIFF to the path provided
343
+ ```
344
+
345
+ ### InterFAX::File
346
+
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.
348
+
349
+ It is most useful for sending binary data to the `.deliver` method.
350
+
351
+ ```rb
352
+ # 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.....'
356
+
357
+ interfax.outbound.deliver(faxNumber: '+1111111111112', file: file)
358
+ ```
359
+
360
+ Additionally it can be used to turn a URL or path into a valid object as well, though the `.deliver` method does this conversion automatically.
361
+
362
+ ```rb
363
+ # a file by path
364
+ file = InterFAX::File.new('foo/bar.pdf')
365
+ file.header #=> "Content-Type: application/pdf"
366
+ file.body #=> '....binary data.....'
367
+
368
+ # a file by url
369
+ file = InterFAX::File.new('https://foo.com/bar.html')
370
+ file.header #=> "Content-Location: https://foo.com/bar.html"
371
+ file.body #=> nil
372
+ ```
373
+
374
+ ### InterFAX::ForwardingEmail
375
+
376
+ A light wrapper around [the response](https://www.interfax.net/en/dev/rest/reference/2930) received by asking for the forwarded emails for a fax.
377
+
378
+ ```ruby
379
+ fax = interfax.inbound.find(123)
380
+ email = fax.emails.first
381
+ email.emailAddress # An email address to which forwarding of the fax was attempted.
382
+ email.messageStatus # 0 = OK; number smaller than zero = in progress; number greater than zero = error.
383
+ email.completionTime # Completion timestamp.
384
+ ```
385
+
386
+ ## Contributing
387
+
388
+ 1. **Fork** the repo on GitHub
389
+ 2. **Clone** the project to your own machine
390
+ 3. **Commit** changes to your own branch
391
+ 4. **Push** your work back up to your fork
392
+ 5. Submit a **Pull request** so that we can review your changes
393
+
394
+ # License
395
+
396
+ This library is released under the [MIT License](LICENSE).
data/interfax.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ require File.expand_path('lib/interfax/version', File.dirname(__FILE__))
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'interfax'
5
+ s.version = InterFAX::VERSION
6
+ s.summary = "Send and receive faxes with InterFAX"
7
+ s.description = "A wrapper around the InterFAX REST API for sending and receiving faxes."
8
+ s.authors = ["InterFAX", "Cristiano Betta"]
9
+ s.email = ['dev@interfax.net', 'cbetta@gmail.com']
10
+ s.files = Dir.glob('{lib}/**/*') + %w(LICENSE README.md interfax.gemspec)
11
+ s.homepage = 'https://github.com/interfax/interfax-ruby'
12
+ s.license = 'MIT'
13
+
14
+ s.add_runtime_dependency('mimemagic', '~>0.3.1')
15
+
16
+ s.add_development_dependency('rake')
17
+ s.add_development_dependency('fakefs')
18
+ s.add_development_dependency('webmock')
19
+ s.add_development_dependency('minitest')
20
+ end