phaxio 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/phaxio/client.rb +19 -6
- data/lib/phaxio/version.rb +1 -1
- data/phaxio.gemspec +1 -0
- data/spec/client_spec.rb +32 -0
- data/spec/support/files/test.txt +1 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12ce42728923c83667571c73e2c0320f41a3f579
|
4
|
+
data.tar.gz: f6840ec8c126853273bd76f68d3399b3f5a24989
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f805c26607a691b2af4e692cd5c8c6cf4b24a624b711527f72e85ee49287071369087e261d41eb292a7a9747cf32e26cd7ac67f3b15018d906cf1c9a8a4ceeb
|
7
|
+
data.tar.gz: a1bc1b11cfa3244f1361a526c0439bfc9dab5c82efe45e80ee888c5d01920af8e190dc5336b232980d0c57ee3162f3ffa6c5220ecba65b5fc98c577a92275526
|
data/lib/phaxio/client.rb
CHANGED
@@ -55,10 +55,7 @@ module Phaxio
|
|
55
55
|
body = JSON.parse(response.body).with_indifferent_access
|
56
56
|
else
|
57
57
|
extension = MimeTypeHelper.extension_for_mimetype content_type
|
58
|
-
filename = File.join(
|
59
|
-
Dir.tmpdir,
|
60
|
-
Dir::Tmpname.make_tmpname('phaxio-', "download.#{extension}")
|
61
|
-
)
|
58
|
+
filename = File.join Dir.tmpdir, tmpname(extension)
|
62
59
|
File.open(filename, 'wb') { |file| file.write response.body }
|
63
60
|
body = {'success' => response.success?, 'data' => File.open(filename, 'rb')}
|
64
61
|
end
|
@@ -93,12 +90,23 @@ module Phaxio
|
|
93
90
|
end
|
94
91
|
end
|
95
92
|
|
93
|
+
def tmpname(extension)
|
94
|
+
t = Time.now.strftime("%Y%m%d")
|
95
|
+
"phaxio-#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-download.#{extension}"
|
96
|
+
end
|
97
|
+
|
96
98
|
def post endpoint, params = {}
|
97
99
|
# Handle file params
|
98
100
|
params.each do |k, v|
|
99
101
|
next unless k.to_s == 'file'
|
100
|
-
|
101
|
-
|
102
|
+
|
103
|
+
if v.is_a? Array
|
104
|
+
file_param = v.map { |file| file_to_param file }
|
105
|
+
else
|
106
|
+
file_param = file_to_param v
|
107
|
+
end
|
108
|
+
|
109
|
+
params[k] = file_param
|
102
110
|
end
|
103
111
|
|
104
112
|
conn.post endpoint, params
|
@@ -130,6 +138,11 @@ module Phaxio
|
|
130
138
|
api_secret: Phaxio.api_secret
|
131
139
|
}
|
132
140
|
end
|
141
|
+
|
142
|
+
def file_to_param file
|
143
|
+
mime_type = MimeTypeHelper.mimetype_for_file file.path
|
144
|
+
Faraday::UploadIO.new file, mime_type
|
145
|
+
end
|
133
146
|
end
|
134
147
|
end
|
135
148
|
end
|
data/lib/phaxio/version.rb
CHANGED
data/phaxio.gemspec
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -32,6 +32,38 @@ RSpec.describe Phaxio::Client do
|
|
32
32
|
client.request :get, endpoint, params
|
33
33
|
end
|
34
34
|
|
35
|
+
it 'handles a single file param' do
|
36
|
+
file_path = File.expand_path File.join('..', 'support', 'files', 'test.pdf'), __FILE__
|
37
|
+
params = {to: '+12258888888', file: File.open(file_path)}
|
38
|
+
expect(test_connection).to receive(:post) do |request_endpoint, request_params|
|
39
|
+
expect(request_params[:file]).to be_a(Faraday::UploadIO)
|
40
|
+
expect(request_params[:file].original_filename).to eq(File.basename(file_path))
|
41
|
+
test_response 200
|
42
|
+
end
|
43
|
+
|
44
|
+
client.request :post, 'faxes', params
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'handles multiple file params' do
|
48
|
+
file_names = ['test.pdf', 'test.txt']
|
49
|
+
file_paths = file_names.map do |file_name|
|
50
|
+
File.expand_path File.join('..', 'support', 'files', file_name), __FILE__
|
51
|
+
end
|
52
|
+
params = {to: '+12258888888', file: file_paths.map { |file_path| File.open(file_path) }}
|
53
|
+
|
54
|
+
expect(test_connection).to receive(:post) do |request_endpoint, request_params|
|
55
|
+
expect(request_params[:file]).to be_a(Array)
|
56
|
+
correct_file_params = request_params[:file].all? do |file_param|
|
57
|
+
file_param.is_a? Faraday::UploadIO
|
58
|
+
end
|
59
|
+
expect(correct_file_params).to eq(true)
|
60
|
+
expect(request_params[:file].map(&:original_filename)).to eq(file_names)
|
61
|
+
test_response 200
|
62
|
+
end
|
63
|
+
|
64
|
+
client.request :post, 'faxes', params
|
65
|
+
end
|
66
|
+
|
35
67
|
it 'uses the configured API key and secret by default' do
|
36
68
|
expect(test_connection).to receive(:get) do |_endpoint, request_params|
|
37
69
|
expect(request_params[:api_key]).to eq(Phaxio.api_key)
|
@@ -0,0 +1 @@
|
|
1
|
+
OK
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phaxio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Negrotto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- spec/support/credentials.rb
|
98
98
|
- spec/support/expectations.rb
|
99
99
|
- spec/support/files/test.pdf
|
100
|
+
- spec/support/files/test.txt
|
100
101
|
- spec/support/vcr.rb
|
101
102
|
- spec/support/vcr_cassettes/resources/account/status.yml
|
102
103
|
- spec/support/vcr_cassettes/resources/fax/cancel.yml
|
@@ -117,7 +118,8 @@ files:
|
|
117
118
|
- spec/support/vcr_cassettes/resources/public/area_codes/list.yml
|
118
119
|
- spec/support/vcr_cassettes/resources/public/country/list.yml
|
119
120
|
homepage: https://github.com/phaxio/phaxio-ruby
|
120
|
-
licenses:
|
121
|
+
licenses:
|
122
|
+
- MIT
|
121
123
|
metadata: {}
|
122
124
|
post_install_message:
|
123
125
|
rdoc_options: []
|
@@ -135,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
137
|
version: '0'
|
136
138
|
requirements: []
|
137
139
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.5.
|
140
|
+
rubygems_version: 2.5.2.2
|
139
141
|
signing_key:
|
140
142
|
specification_version: 4
|
141
143
|
summary: Official ruby gem for interacting with Phaxio's API.
|