interfax 1.0.1 → 1.1.0

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: d294e821fce170d8c40efeca152aa0f490eb567e
4
- data.tar.gz: 099bd020ef2e65f9673475cbeec4868ceae70b44
3
+ metadata.gz: 55720a871ff442165ff9c12c3c1c8b51bd4cab07
4
+ data.tar.gz: c36611237b5d777b2526e96261cad0519d679a22
5
5
  SHA512:
6
- metadata.gz: 7d2deadcb67d1c753df38456224cbf06ffe6eddb35e7d1481b9693d67c1f7d5f6ee2a1c27437bd381ed1ca23252bb35be0e46f03dcc43c4f1dfd95ee07c54dab
7
- data.tar.gz: d32542d6f649c3ccdf497fa229e6ee43ed28532204abcfb67a9a55a86bfc3ba81c46b5d6f5fd9cc9e40bf67fd7cea81b054108ef7c7b29bab21a29b38042b01c
6
+ metadata.gz: bf3283be3e11cdacc296af03433775a172ac14cc28fbec679359677e1fb0416ab9ef587400823d8e72ba07731af15abb98bbc5a1954511878352df59734ee3d5
7
+ data.tar.gz: f7a4fac0ac9322ad16f579f2f4c8957d89b218187132797273340922b0c67a7ac5450906945a93503f60a4123b227e39c7c48dda53a9fc87c84058ea2a8bb31e
data/README.md CHANGED
@@ -39,7 +39,7 @@ The client follows the [12-factor](http://12factor.net/config) apps principle an
39
39
  # Initialize using parameters
40
40
  interfax = InterFAX::Client.new(username: '...', password: '...')
41
41
 
42
- # Alternatice: Initialize using environment variables
42
+ # Alternative: Initialize using environment variables
43
43
  # * INTERFAX_USERNAME
44
44
  # * INTERFAX_PASSWORD
45
45
  interfax = InterFAX::Client.new
@@ -248,14 +248,14 @@ interfax.inbound.find(123456)
248
248
 
249
249
  `interfax.inbound.image(fax_id)`
250
250
 
251
- Retrieves a single fax's image.
251
+ Retrieves a single fax's image. This can be a PDF or a TIFF file.
252
252
 
253
253
  ```ruby
254
254
  image = interfax.inbound.image(123456)
255
255
  => #<InterFAX::Image>
256
256
  image.data
257
257
  => # "....binary data...."
258
- image.save('fax.tiff')
258
+ image.save("path/to/fax.#{image.extension}")
259
259
  => # saves image to file
260
260
  ```
261
261
 
@@ -513,8 +513,18 @@ document.id # Extracts the ID from the URI (the API does not return the ID)
513
513
  1. **Fork** the repo on GitHub
514
514
  2. **Clone** the project to your own machine
515
515
  3. **Commit** changes to your own branch
516
- 4. **Push** your work back up to your fork
517
- 5. Submit a **Pull request** so that we can review your changes
516
+ 4. **Test** the changes you have made
517
+ 5. **Push** your work back up to your fork
518
+ 6. Submit a **Pull request** so that we can review your changes
519
+
520
+ ### Testing
521
+
522
+ Before submitting a contribution please ensure all tests pass.
523
+
524
+ ```sh
525
+ bundle install # install dependencies
526
+ rake spec # run all tests
527
+ ```
518
528
 
519
529
  ## License
520
530
 
@@ -104,6 +104,8 @@ module InterFAX
104
104
  when Net::HTTPSuccess
105
105
  if response['location']
106
106
  response['location']
107
+ elsif tiff?(response) || pdf?(response)
108
+ return [response.body, response['Content-Type']]
107
109
  elsif json?(response)
108
110
  begin
109
111
  JSON.parse(response.body)
@@ -128,11 +130,23 @@ module InterFAX
128
130
  end
129
131
  end
130
132
 
133
+ def pdf?(response)
134
+ type?(response, 'application/pdf')
135
+ end
136
+
137
+ def tiff?(response)
138
+ type?(response, 'image/tiff')
139
+ end
140
+
131
141
  def json?(response)
142
+ type?(response, 'text/json')
143
+ end
144
+
145
+ def type?(response, mime_type)
132
146
  content_type = response['Content-Type']
133
- json_header = content_type && content_type.split(';').first == 'text/json'
147
+ correct_header = content_type && content_type.split(';').first == mime_type
134
148
  has_body = response.body && response.body.length > 0
135
- json_header && has_body
149
+ correct_header && has_body
136
150
  end
137
151
  end
138
152
  end
@@ -7,6 +7,14 @@ class InterFAX::Image < InterFAX::Object
7
7
  result
8
8
  end
9
9
 
10
+ def extension
11
+ if mimeType == 'application/pdf'
12
+ 'pdf'
13
+ else
14
+ 'tiff'
15
+ end
16
+ end
17
+
10
18
  def save filename
11
19
  File.open(filename, 'wb') do |file|
12
20
  file.write(data)
@@ -18,8 +18,8 @@ class InterFAX::Inbound
18
18
  end
19
19
 
20
20
  def image fax_id
21
- data = @client.get("/inbound/faxes/#{fax_id}/image")
22
- InterFAX::Image.new(data: data, client: @client)
21
+ data, mimeType = @client.get("/inbound/faxes/#{fax_id}/image")
22
+ InterFAX::Image.new(data: data, client: @client, mimeType: mimeType)
23
23
  end
24
24
 
25
25
  def mark fax_id, options = {}
@@ -38,8 +38,8 @@ class InterFAX::Outbound
38
38
  end
39
39
 
40
40
  def image fax_id
41
- data = @client.get("/outbound/faxes/#{fax_id}/image")
42
- InterFAX::Image.new(data: data, client: @client)
41
+ data, mimeType = @client.get("/outbound/faxes/#{fax_id}/image")
42
+ InterFAX::Image.new(data: data, client: @client, mimeType: mimeType)
43
43
  end
44
44
 
45
45
  def cancel fax_id
@@ -1,3 +1,3 @@
1
1
  module InterFAX
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
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.1
4
+ version: 1.1.0
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-11 00:00:00.000000000 Z
12
+ date: 2016-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mimemagic