plate_api 1.2.2 → 1.2.4

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
  SHA256:
3
- metadata.gz: 251666f577ba0ea7439b6dfa90acfe15e9ac7724a827a8133f4eaf092124d109
4
- data.tar.gz: a4e9c0676b64b4e324826864045cd09ba1b3e5ef68d4f6ed1b58821b136f54dd
3
+ metadata.gz: 947c12da1663740de9378f1c065f158630eef3a7cccc901b728f523db3777194
4
+ data.tar.gz: 9c5e26eb8a8e70a7eca3b9511e38e649be72933a52975bcc793d6d79e4268d93
5
5
  SHA512:
6
- metadata.gz: a691fd2429453636ebb4f0c4fbe3aa1498a2550374f5eb220ba25135dc3580d95a4e34f074e4c948b6e5a326505c0a82e17fe928b2a0ac05d0cbb1556c307879
7
- data.tar.gz: '09a484411bf28eb37862f11b514ae3e43385b904bad989fa448cb5174ef1b3ea2793c4289186d9b4b0de5eceb37a249fbcebc15d5ac885499eda6e309040b65f'
6
+ metadata.gz: 7f0e809ce4944a826e2c4ddf3e085e87ceb96e76a7cf96fa9261e24e27da78d3773abea76c93a8e24ee89fb6a9ba28bd8efa9249d5289248a3fd5df2f6796280
7
+ data.tar.gz: 736048b6087f9c42f0d246d0dc6f5b39d9c09f3dc08957056a47ca2f4c4079c11574691387dace9428fb692c829d7df3c30c41a0880b6b314ba7dfec2896a681
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- plate_api (1.2.2)
4
+ plate_api (1.2.4)
5
5
  faraday (~> 1.0.1)
6
+ mime-types (~> 3.3.1)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -29,6 +30,9 @@ GEM
29
30
  hashdiff (1.0.1)
30
31
  i18n (1.8.2)
31
32
  concurrent-ruby (~> 1.0)
33
+ mime-types (3.3.1)
34
+ mime-types-data (~> 3.2015)
35
+ mime-types-data (3.2021.0225)
32
36
  minitest (5.14.1)
33
37
  multipart-post (2.1.1)
34
38
  public_suffix (4.0.5)
@@ -18,7 +18,16 @@ module PlateApi
18
18
  end
19
19
 
20
20
  def mime_type(full_path)
21
- IO.popen(["file", "--brief", "--mime-type", full_path], in: :close, err: :close) { |io| io.read.chomp }
21
+ begin
22
+ IO.popen(["file", "--brief", "--mime-type", full_path], in: :close, err: :close) { |io| io.read.chomp }
23
+ rescue SystemCallError
24
+ # determine mime_type based on extension as a fallback, in case `file` is not installed on the client machine
25
+ mime_type_fallback(full_path)
26
+ end
27
+ end
28
+
29
+ def mime_type_fallback(full_path)
30
+ MIME::Types.type_for(full_path).first.content_type
22
31
  end
23
32
 
24
33
  def map_parameters(parameters)
@@ -26,7 +35,7 @@ module PlateApi
26
35
  val = parameters[key]
27
36
  if val.is_a? File
28
37
  full_path = File.expand_path(val)
29
- mime_type = self.mime_type(full_path)
38
+ mime_type = mime_type(full_path)
30
39
  parameters[key] = Faraday::UploadIO.new(full_path, mime_type)
31
40
  end
32
41
  end
@@ -1,22 +1,22 @@
1
1
  require "faraday"
2
2
  # require 'faraday_middleware'
3
- require 'time'
3
+ require "time"
4
4
  require "base64"
5
5
  require "openssl"
6
6
  require "json"
7
-
7
+ require "mime-types"
8
8
 
9
9
  module PlateApi
10
10
  class Request
11
11
  DefaultApiBaseEndpoint = "https://www.startwithplate.com/api/v2"
12
12
  HttpAdapter = Faraday.default_adapter
13
13
 
14
- def initialize(public_key, secret, method, path, custom_server=nil)
14
+ def initialize(public_key, secret, method, path, custom_server = nil)
15
15
  base_api_endpoint = custom_server ? custom_server : DefaultApiBaseEndpoint
16
16
 
17
17
  @connection = ::Faraday.new(url: base_api_endpoint) do |faraday|
18
18
  extra_builder_options(faraday)
19
- faraday.adapter HttpAdapter
19
+ faraday.adapter HttpAdapter
20
20
  end
21
21
 
22
22
  @public_key = public_key
@@ -25,20 +25,20 @@ module PlateApi
25
25
  @path = strip_path(path)
26
26
  end
27
27
 
28
- def execute(response_type=:raw)
28
+ def execute(response_type = :raw)
29
29
  response = @connection.send(@method.downcase) do |request|
30
30
  request.url url_path
31
- request.headers['Date'] = request_date
32
- request.headers['Authorization'] = calculate_signature
31
+ request.headers["Date"] = request_date
32
+ request.headers["Authorization"] = calculate_signature
33
33
  extra_request_options(request)
34
34
  end
35
35
 
36
36
  return case response_type
37
- when :raw
38
- return response.body
39
- when :json
40
- return JSON.parse(response.body)
41
- end
37
+ when :raw
38
+ return response.body
39
+ when :json
40
+ return JSON.parse(response.body)
41
+ end
42
42
  end
43
43
 
44
44
  def request_date
@@ -72,7 +72,7 @@ module PlateApi
72
72
  end
73
73
 
74
74
  def strip_path(path)
75
- path.gsub(/^\/|\/$/, '')
75
+ path.gsub(/^\/|\/$/, "")
76
76
  end
77
77
  end
78
78
  end
@@ -1,3 +1,3 @@
1
1
  module PlateApi
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.4"
3
3
  end
data/plate_api.gemspec CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ["lib"]
33
33
 
34
34
  spec.add_dependency "faraday", "~> 1.0.1"
35
+ spec.add_dependency "mime-types", "~> 3.3.1"
35
36
  # spec.add_dependency "faraday_middleware", "~> 0.13.1"
36
37
  # spec.add_dependency "mimemagic", "~> 0.3.10"
37
38
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plate_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Kortleven
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: 1.0.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: mime-types
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 3.3.1
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 3.3.1
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: bundler
30
44
  requirement: !ruby/object:Gem::Requirement