panoptes-client 0.1.2 → 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
  SHA1:
3
- metadata.gz: 40b2527eeb600cf63f267b3071936d72b2dddce2
4
- data.tar.gz: 1b2fd340c6cb5184ef9bd760424beb09d3061fc5
3
+ metadata.gz: 17d69c6ab0b817b8209baabb9f6a6b49c16bed87
4
+ data.tar.gz: e5a76b94566fa5d192de12bd561c7185e42df147
5
5
  SHA512:
6
- metadata.gz: 90df2960778551ca9d8b56dbd9b95aec2ae8745c148b4fffd68d63666d3a9f9719ca58feb595bc8b496a1190d0d0bfd48ebee78dbdeb421cac611122d37844a6
7
- data.tar.gz: 4c8f39d85b67f407fc2b3ef0ceee7bcdca1755c0f980cf633685e9883784c2a561e2e0ec0e3abf60704e12b4faf53ff98e14add04a58a25ca6c5954f94404f9c
6
+ metadata.gz: 839985a07133691668eadfd52c4ab6093dec2f64558d2d1b144b7d119dc249eded91d0246e95a261043fe617533539a83c47c5283350f3b2b83e922ba640505b
7
+ data.tar.gz: a19c99d25899d15b059cd887f4fa54388c578f6191011601467b7de5530df0dc32c9641b27c261953ea8ceb272d7105d5178749ef99f6a4a494f1c09537d7d63
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.2.0
2
+
3
+ * Raise errors on certain server response statuses.
4
+ * Add put/patch/delete requests.
5
+
1
6
  # 0.1.2
2
7
 
3
8
  * Fix bug with client_id/client_secret authentication
@@ -10,6 +10,11 @@ require "panoptes/client/user_groups"
10
10
 
11
11
  module Panoptes
12
12
  class Client
13
+ class GenericError < StandardError; end
14
+ class ConnectionFailed < GenericError; end
15
+ class ResourceNotFound < GenericError; end
16
+ class ServerError < GenericError; end
17
+
13
18
  include Panoptes::Client::Me
14
19
  include Panoptes::Client::Projects
15
20
  include Panoptes::Client::Subjects
@@ -39,11 +44,28 @@ module Panoptes
39
44
  end
40
45
 
41
46
  def get(path, query = {})
42
- conn.get("/api" + path, query).body
47
+ response = conn.get("/api" + path, query)
48
+ handle_response(response)
43
49
  end
44
50
 
45
51
  def post(path, body = {})
46
- conn.post("/api" + path, body).body
52
+ response = conn.post("/api" + path, body)
53
+ handle_response(response)
54
+ end
55
+
56
+ def put(path, body = {})
57
+ response = conn.put("/api" + path, body)
58
+ handle_response(response)
59
+ end
60
+
61
+ def patch(path, body = {})
62
+ response = conn.patch("/api" + path, body)
63
+ handle_response(response)
64
+ end
65
+
66
+ def delete(path, query = {})
67
+ response = conn.delete("/api" + path, query)
68
+ handle_response(response)
47
69
  end
48
70
 
49
71
  # Get a path and perform automatic depagination
@@ -70,5 +92,16 @@ module Panoptes
70
92
  def conn
71
93
  @conn
72
94
  end
95
+
96
+ def handle_response(response)
97
+ case response.status
98
+ when 404
99
+ raise ResourceNotFound, status: response.status, body: response.body
100
+ when 400..600
101
+ raise ServerError
102
+ else
103
+ response.body
104
+ end
105
+ end
73
106
  end
74
107
  end
@@ -1,5 +1,5 @@
1
1
  module Panoptes
2
2
  class Client
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panoptes-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis