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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/panoptes/client.rb +35 -2
- data/lib/panoptes/client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 17d69c6ab0b817b8209baabb9f6a6b49c16bed87
|
|
4
|
+
data.tar.gz: e5a76b94566fa5d192de12bd561c7185e42df147
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 839985a07133691668eadfd52c4ab6093dec2f64558d2d1b144b7d119dc249eded91d0246e95a261043fe617533539a83c47c5283350f3b2b83e922ba640505b
|
|
7
|
+
data.tar.gz: a19c99d25899d15b059cd887f4fa54388c578f6191011601467b7de5530df0dc32c9641b27c261953ea8ceb272d7105d5178749ef99f6a4a494f1c09537d7d63
|
data/CHANGELOG.md
CHANGED
data/lib/panoptes/client.rb
CHANGED
|
@@ -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)
|
|
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)
|
|
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
|