dock-api 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b2d8dbfadbcc5cfb8a38a080f8ab47689fe0de13a108f95ce1560735672f90d
4
- data.tar.gz: '0460937cfd6cd14517ccbc4f4633bb6e9039d0205788e7d1321f0ea16fd3fdc4'
3
+ metadata.gz: 9ffa5a3079b9356617100eef3ac4fa3bd8db8a1ab8c9b3ef70aa3f3d7d4725f6
4
+ data.tar.gz: 145c477c979df419caac602e33a319a47b735f49a1a9630465471cada7aeb083
5
5
  SHA512:
6
- metadata.gz: da2480f9b19c951e0ddc93e76781dbc347c8c2978430b5bdfe2e0c5f1b4c703e76abafb7f7b5e2f94e8156d1bf821d9c07716979168b6b64160672110dfe8576
7
- data.tar.gz: 3f2232e85226c00be8909173db6406ece2d430b11d0da51dc23b9abed674bbbf0807045c56eed7ca761840f1980621f30c198a645c26bd44a00f890326262d68
6
+ metadata.gz: 8ce7bf83264987bba66e372fd147123df4b123753643d8197d305b5d7a411d00503279a81fadcc111603afff1ab29debae6cd779b340d9627e180e859290b38b
7
+ data.tar.gz: 71e7dd28066b9645cf97c993cd2230f0e27ef111f5b990890293f4559e37a3e24f614c73a474a4734bd71d90b5d6c7dd3a870446861567f0972444c434693281
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dock-api (0.1.0)
4
+ dock-api (0.2.0)
5
5
  faraday (>= 2.0.0.alpha.pre.4)
6
6
  httpx (>= 0.18)
7
7
 
data/README.md CHANGED
@@ -103,6 +103,8 @@ Dock::Api::Verify.verify
103
103
 
104
104
  ### Documentations
105
105
 
106
+ Gem documentation: https://www.rubydoc.info/github/robinbortlik/dock-api/main
107
+
106
108
  Official Dock API documentation: https://docs.api.dock.io/#the-dock-api
107
109
 
108
110
  Swagger console: https://swagger.api.dock.io/
@@ -2,6 +2,12 @@
2
2
 
3
3
  module Dock
4
4
  module Api
5
+ class NotFound < StandardError; end
6
+ class BadRequest < StandardError; end
7
+ class RequestError < StandardError; end
8
+ class Unauthorized < StandardError; end
9
+ class MethodNotAllowed < StandardError; end
10
+
5
11
  class Base
6
12
  class << self
7
13
  def connection
@@ -9,19 +15,42 @@ module Dock
9
15
  end
10
16
 
11
17
  def get(url)
12
- connection.get(url).body
18
+ handle_status do
19
+ connection.get(url)
20
+ end
13
21
  end
14
22
 
15
23
  def delete(url)
16
- connection.delete(url).body
24
+ handle_status do
25
+ connection.delete(url)
26
+ end
17
27
  end
18
28
 
19
29
  def post(url, data)
20
- connection.post(url, data).body
30
+ handle_status do
31
+ connection.post(url, data)
32
+ end
21
33
  end
22
34
 
23
35
  def patch(url, data)
24
- connection.patch(url, data).body
36
+ handle_status do
37
+ connection.patch(url, data)
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def handle_status
44
+ response = yield
45
+ case response.status
46
+ when 400 then raise(Dock::Api::BadRequest, response.body)
47
+ when 401 then raise(Dock::Api::Unauthorized, response.body)
48
+ when 404 then raise(Dock::Api::NotFound, response.body)
49
+ when 405 then raise(Dock::Api::MethodNotAllowed, response.body)
50
+ when 500 then raise(Dock::Api::RequestError, response.body)
51
+ else
52
+ response.body
53
+ end
25
54
  end
26
55
  end
27
56
  end
@@ -6,8 +6,8 @@ module Dock
6
6
  NAMESPACE = '/presentations'
7
7
 
8
8
  class << self
9
- def create(**attrs)
10
- post(NAMESPACE.to_s, attrs)
9
+ def create(attrs = {})
10
+ post(NAMESPACE, attrs)
11
11
  end
12
12
  end
13
13
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dock
4
4
  module Api
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dock-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Bortlik