plate_api 1.1.8 → 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: '09bf65656de8336735c86096cbce1c5c951523f6b7cfa0d55ef6ed43dbeb1d78'
4
- data.tar.gz: 7145e01a452dbfdb604d83f5d660587fc6deaef70fa98f0b61fcc1c21dfc9137
3
+ metadata.gz: 947c12da1663740de9378f1c065f158630eef3a7cccc901b728f523db3777194
4
+ data.tar.gz: 9c5e26eb8a8e70a7eca3b9511e38e649be72933a52975bcc793d6d79e4268d93
5
5
  SHA512:
6
- metadata.gz: cdad0d6cfd4dee24ff415c3a781eb70d43c3141c340a2526f3cb22cb3748cd7bdf2a9de0151930454b106ea8ce9079f3b8e915e92730e07c00035f0b7d042f40
7
- data.tar.gz: 8819d44883e6ca4be2c1c1a2a657ad76a326c2ddd38d79dced69ab9fd284eff210bd283ac4fa72a07460e93afcf14b69e1434a9514d2019802271893c9c46586
6
+ metadata.gz: 7f0e809ce4944a826e2c4ddf3e085e87ceb96e76a7cf96fa9261e24e27da78d3773abea76c93a8e24ee89fb6a9ba28bd8efa9249d5289248a3fd5df2f6796280
7
+ data.tar.gz: 736048b6087f9c42f0d246d0dc6f5b39d9c09f3dc08957056a47ca2f4c4079c11574691387dace9428fb692c829d7df3c30c41a0880b6b314ba7dfec2896a681
data/.travis.yml CHANGED
@@ -6,7 +6,7 @@ sudo: false
6
6
  language: ruby
7
7
  rvm:
8
8
  - 2.5.1
9
- before_install: gem install bundler -v 1.16.1
9
+ before_install: gem install bundler -v 2.1.4
10
10
  before_script:
11
11
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
12
12
  - chmod +x ./cc-test-reporter
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- plate_api (1.1.8)
4
+ plate_api (1.2.4)
5
5
  faraday (~> 1.0.1)
6
- mimemagic (~> 0.3.3)
6
+ mime-types (~> 3.3.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -30,7 +30,9 @@ GEM
30
30
  hashdiff (1.0.1)
31
31
  i18n (1.8.2)
32
32
  concurrent-ruby (~> 1.0)
33
- mimemagic (0.3.5)
33
+ mime-types (3.3.1)
34
+ mime-types-data (~> 3.2015)
35
+ mime-types-data (3.2021.0225)
34
36
  minitest (5.14.1)
35
37
  multipart-post (2.1.1)
36
38
  public_suffix (4.0.5)
data/lib/plate_api.rb CHANGED
@@ -9,6 +9,7 @@ require "plate_api/delete_request"
9
9
  require "plate_api/post_request"
10
10
  require "plate_api/post_multipart_request"
11
11
  require "plate_api/put_request"
12
+ require "plate_api/error"
12
13
 
13
14
 
14
15
  module PlateApi
@@ -0,0 +1,5 @@
1
+ module Error
2
+ class Response < StandardError
3
+
4
+ end
5
+ end
@@ -5,39 +5,37 @@ module PlateApi
5
5
  attr_reader :handling_class
6
6
 
7
7
  def initialize(handling_class, api_connector)
8
- raise ArgumentError.new("`handling_class` given for #new is not valid") unless handling_class
9
- raise ArgumentError.new("`api_connector` given for #new is not valid") unless api_connector
8
+ raise ArgumentError, "`handling_class` given for #new is not valid" unless handling_class
9
+ raise ArgumentError, "`api_connector` given for #new is not valid" unless api_connector
10
10
  @handling_class = handling_class
11
11
  @api_connector = api_connector
12
12
  end
13
13
 
14
14
  def find(id)
15
- raise ArgumentError.new("`id` given for #find is not valid") unless id
15
+ raise ArgumentError, "`id` given for #find is not valid" unless id
16
16
  result = @api_connector.get(resource_path(id))
17
17
  if result["data"]
18
18
  return new_object(result["data"])
19
19
  else
20
- puts "PlateApi: No success: #{result}"
21
- return nil
20
+ raise Error::Response, result
22
21
  end
23
22
  end
24
23
 
25
24
  def update(id, attributes)
26
- raise ArgumentError.new("`id` given for #update is not valid") unless id
27
- raise ArgumentError.new("`attributes` given for #update is not valid") unless attributes.is_a? Hash
25
+ raise ArgumentError, "`id` given for #update is not valid" unless id
26
+ raise ArgumentError, "`attributes` given for #update is not valid" unless attributes.is_a? Hash
28
27
  result = @api_connector.put(resource_path(id), {"data" => attributes})
29
28
 
30
29
  if result["data"]
31
30
  return new_object(result["data"])
32
31
  else
33
- puts "PlateApi: No success: #{result}"
34
- return nil
32
+ raise Error::Response, result
35
33
  end
36
34
  end
37
35
 
38
36
  def create(parent, attributes, create_method=:post)
39
- raise ArgumentError.new("`parent` given for #create is not valid") unless parent
40
- raise ArgumentError.new("`attributes` given for #create is not valid") unless attributes.is_a? Hash
37
+ raise ArgumentError, "`parent` given for #create is not valid" unless parent
38
+ raise ArgumentError, "`attributes` given for #create is not valid" unless attributes.is_a? Hash
41
39
  parameters = case create_method
42
40
  when :post
43
41
  {"data" => attributes}
@@ -50,32 +48,29 @@ module PlateApi
50
48
  if result["data"]
51
49
  return new_object(result["data"])
52
50
  else
53
- puts "PlateApi: No success: #{result}"
54
- return nil
51
+ raise Error::Response, result
55
52
  end
56
53
  end
57
54
 
58
55
  def delete(id)
59
- raise ArgumentError.new("`id` given for #find is not valid") unless id
56
+ raise ArgumentError, "`id` given for #find is not valid" unless id
60
57
  result = @api_connector.delete(resource_path(id))
61
58
  if result["data"]
62
59
  return new_object(result["data"])
63
60
  else
64
- puts "PlateApi: No success: #{result}"
65
- return nil
61
+ raise Error::Response, result
66
62
  end
67
63
  end
68
64
 
69
65
  def index(parent_class, parent_id, extra_params={})
70
- raise ArgumentError.new("`parent_id` given for #index is not valid") unless parent_id
71
- raise ArgumentError.new("`parent_class` given for #index is not valid") unless parent_class
66
+ raise ArgumentError, "`parent_id` given for #index is not valid" unless parent_id
67
+ raise ArgumentError, "`parent_class` given for #index is not valid" unless parent_class
72
68
 
73
69
  result = @api_connector.get(collection_path(parent_class, parent_id), extra_params)
74
70
  if result["data"]
75
71
  return result["data"].map{|x| new_object(x)}
76
72
  else
77
- puts "PlateApi: No success: #{result}"
78
- return nil
73
+ raise Error::Response, result
79
74
  end
80
75
  end
81
76
 
@@ -84,8 +79,7 @@ module PlateApi
84
79
  if result["meta"]
85
80
  return result["meta"]["pagination"]["total_records"]
86
81
  else
87
- puts "PlateApi: No success: #{result}"
88
- return nil
82
+ raise Error::Response, result
89
83
  end
90
84
  end
91
85
 
@@ -107,7 +101,7 @@ module PlateApi
107
101
 
108
102
  def collection_path(parent_class=nil, parent_id=nil)
109
103
  if (parent_class != nil) ^ (parent_id != nil)
110
- raise ArgumentError.new("An invalid combination `parent_class` and `parent_id` is given. Provide both or none.")
104
+ raise ArgumentError, "An invalid combination `parent_class` and `parent_id` is given. Provide both or none."
111
105
  end
112
106
 
113
107
  if parent_class
@@ -1,11 +1,8 @@
1
- require 'mimemagic'
2
-
3
1
  module PlateApi
4
2
  class PostMultipartRequest < Request
5
3
  HttpAdapter = :net_http
6
- MimeMagic.add('image/jpeg', extensions: "jfif")
7
4
 
8
- def initialize(public_key, secret, path, parameters={}, custom_server=nil)
5
+ def initialize(public_key, secret, path, parameters = {}, custom_server = nil)
9
6
  super(public_key, secret, "POST", path, custom_server)
10
7
 
11
8
  @post_parameters = map_parameters(parameters)
@@ -13,19 +10,32 @@ module PlateApi
13
10
 
14
11
  def extra_builder_options(builder)
15
12
  builder.request :multipart
16
- builder.request :url_encoded
13
+ builder.request :url_encoded
17
14
  end
18
15
 
19
16
  def extra_request_options(request)
20
17
  request.body = @post_parameters
21
18
  end
22
19
 
20
+ def mime_type(full_path)
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
31
+ end
32
+
23
33
  def map_parameters(parameters)
24
34
  parameters.keys.each do |key|
25
35
  val = parameters[key]
26
36
  if val.is_a? File
27
37
  full_path = File.expand_path(val)
28
- mime_type = MimeMagic.by_path(full_path).type
38
+ mime_type = mime_type(full_path)
29
39
  parameters[key] = Faraday::UploadIO.new(full_path, mime_type)
30
40
  end
31
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.1.8"
2
+ VERSION = "1.2.4"
3
3
  end
data/plate_api.gemspec CHANGED
@@ -1,20 +1,19 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "plate_api/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = 'plate_api'
8
- spec.version = PlateApi::VERSION
9
- spec.date = '2019-01-05'
10
- spec.summary = "Connector for the Plate API"
6
+ spec.name = "plate_api"
7
+ spec.version = PlateApi::VERSION
8
+ spec.date = "2019-01-05"
9
+ spec.summary = "Connector for the Plate API"
11
10
  spec.description = "This gem can be used to connect to the Plate API. It takes care
12
11
  of the authentication procedure. It also provides a basic wrapper around the Plate API,
13
12
  so objects in Plate can be manipulated as local objects."
14
- spec.authors = ["David Kortleven", "Harmen Fuite"]
15
- spec.email = ['david@getplate.com', 'harmen@getplate.com']
16
- spec.files = ["lib/plate_api.rb"]
17
- spec.license = 'MIT'
13
+ spec.authors = ["David Kortleven", "Harmen Fuite"]
14
+ spec.email = ["david@getplate.com", "harmen@getplate.com"]
15
+ spec.files = ["lib/plate_api.rb"]
16
+ spec.license = "MIT"
18
17
 
19
18
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
19
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -22,19 +21,20 @@ Gem::Specification.new do |spec|
22
21
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
23
22
  else
24
23
  raise "RubyGems 2.0 or newer is required to protect against " \
25
- "public gem pushes."
24
+ "public gem pushes."
26
25
  end
27
26
 
28
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
29
28
  f.match(%r{^(test|spec|features)/})
30
29
  end
31
- spec.bindir = "exe"
32
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
32
  spec.require_paths = ["lib"]
34
33
 
35
34
  spec.add_dependency "faraday", "~> 1.0.1"
35
+ spec.add_dependency "mime-types", "~> 3.3.1"
36
36
  # spec.add_dependency "faraday_middleware", "~> 0.13.1"
37
- spec.add_dependency "mimemagic", "~> 0.3.3"
37
+ # spec.add_dependency "mimemagic", "~> 0.3.10"
38
38
 
39
39
  spec.add_development_dependency "bundler", "~> 2.1.4"
40
40
  spec.add_development_dependency "rake", "~> 13.0"
@@ -44,5 +44,4 @@ Gem::Specification.new do |spec|
44
44
  spec.add_development_dependency "simplecov"
45
45
  spec.add_development_dependency "simplecov-console"
46
46
  spec.add_development_dependency "byebug"
47
-
48
47
  end
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.1.8
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Kortleven
@@ -26,19 +26,19 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: 1.0.1
28
28
  - !ruby/object:Gem::Dependency
29
- name: mimemagic
29
+ name: mime-types
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 0.3.3
34
+ version: 3.3.1
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 0.3.3
41
+ version: 3.3.1
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -175,6 +175,7 @@ files:
175
175
  - lib/plate_api.rb
176
176
  - lib/plate_api/connector.rb
177
177
  - lib/plate_api/delete_request.rb
178
+ - lib/plate_api/error.rb
178
179
  - lib/plate_api/get_request.rb
179
180
  - lib/plate_api/object_handler.rb
180
181
  - lib/plate_api/plate_object/attachment.rb