sfax 0.1.1 → 0.2.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: 74afcc0d5d5f12617755eb6a4f7e278ec822550e
4
- data.tar.gz: 2f3847a6d32c964084bec36f96c856bf6791e909
3
+ metadata.gz: 5fdaa7dc60428262e6a5e7329b1472404011e5ac
4
+ data.tar.gz: 15ff36354f2180a0a85179f22ec134a30f093378
5
5
  SHA512:
6
- metadata.gz: 0f9dfb22c0fa53fac0f78aef202835ccf7e4225d9eec7b5e00be899c0ce6123500ab5b5dfa2c16fb3bdf121eb53f126b60c687c01db1025cf6a860e031d6c4f2
7
- data.tar.gz: c2abb34593bb8fbe8f2d301f3806581e5a4e1597435ae6062a7fff39b8f17a78891c7e223bc2b0b80833226844a08176caba100ac962fc353fa0f4c089b281bb
6
+ metadata.gz: 2fa0aad3bfb66aed503049d66802e23133fbd21231fe18b64069d414254061caa223eca4be737a806b5c9d81c3225782e931ae26f86062c423e434d253cd3692
7
+ data.tar.gz: d0d558856c8f2a9dcb4b6fd4973fcacf9b8c280f760c6115ec787df6e5f8cd3c8f85e5b1645f55f14519fd3cb6aefeae301eae9bdf9767040ed2189c17d1bad7
data/lib/sfax/client.rb CHANGED
@@ -35,8 +35,17 @@ module SFax
35
35
  fetch('SendFaxQueueId')
36
36
  end
37
37
 
38
+ def response_object.success?
39
+ fetch('isSuccess')
40
+ end
41
+
42
+ def response_object.message
43
+ fetch('message')
44
+ end
45
+
38
46
  response_object.tap do |o|
39
- raise SendFaxError if o.fax_id == -1
47
+ raise SendFaxError, o.message unless o.success?
48
+ raise SendFaxError, o.message if o.fax_id.to_s == SEND_FAX_QUEUE_ID_ERROR_VALUE
40
49
  end
41
50
  end
42
51
 
@@ -2,5 +2,7 @@ module SFax
2
2
  module Constants
3
3
  SFAX_URL = 'https://api.sfaxme.com'.freeze
4
4
  SEND_FAX_PATH = '/api/sendfax'.freeze
5
+
6
+ SEND_FAX_QUEUE_ID_ERROR_VALUE = '-1'.freeze
5
7
  end
6
8
  end
data/lib/sfax/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SFax
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -17,7 +17,9 @@ RSpec.describe SFax::Client do
17
17
  let(:file) { StringIO.new('data') }
18
18
  let(:recipient_name) { nil }
19
19
  let(:token) { SecureRandom.hex }
20
+ let(:message) { SecureRandom.hex }
20
21
  let(:send_fax_queue_id) { rand(1_000_000) }
22
+ let(:is_success) { true }
21
23
  let!(:send_fax_request) do
22
24
  stub_request(:post, 'https://api.sfaxme.com/api/sendfax').with(query: {
23
25
  'token' => token,
@@ -26,6 +28,8 @@ RSpec.describe SFax::Client do
26
28
  'RecipientName' => recipient_name,
27
29
  }).and_return(body: {
28
30
  'SendFaxQueueId' => send_fax_queue_id,
31
+ 'isSuccess' => is_success,
32
+ 'message' => message,
29
33
  }.to_json)
30
34
  end
31
35
 
@@ -50,12 +54,24 @@ RSpec.describe SFax::Client do
50
54
  end
51
55
 
52
56
  context 'send_fax_queue_id is -1' do
53
- let(:send_fax_queue_id) { -1 }
57
+ let(:send_fax_queue_id) { '-1' }
54
58
 
55
59
  specify do
56
60
  expect {
57
61
  subject.send_fax(fax_number: fax_number, file: file, recipient_name: recipient_name)
58
- }.to raise_error(described_class::SendFaxError)
62
+ }.to raise_error(described_class::SendFaxError, message)
63
+
64
+ expect(send_fax_request).to have_been_requested
65
+ end
66
+ end
67
+
68
+ context 'isSuccess is false' do
69
+ let(:is_success) { false }
70
+
71
+ specify do
72
+ expect {
73
+ subject.send_fax(fax_number: fax_number, file: file, recipient_name: recipient_name)
74
+ }.to raise_error(described_class::SendFaxError, message)
59
75
 
60
76
  expect(send_fax_request).to have_been_requested
61
77
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Schneider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-31 00:00:00.000000000 Z
11
+ date: 2017-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday