plate_api 1.1.8 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/plate_api.rb +1 -0
- data/lib/plate_api/error.rb +5 -0
- data/lib/plate_api/object_handler.rb +17 -23
- data/lib/plate_api/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4adf706bf694ce9826fd9ed0e2b6a5376038cb7efd99167bebddee74bf2ff2b
|
4
|
+
data.tar.gz: a90b502c510ca13f87e464ba026ab53ad16737f77ad6954d23b075afcfbc0bea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a84c77342116a513c6e8f16b62b9059ef069afe29910d7e5aa74abfc14e94da3328f1f80a31c4633ff9320c4e454dd81e63e48a0c29919664636af92e5ebdd1d
|
7
|
+
data.tar.gz: b0a78eab66e3da0a6e0b7350c80bb624f35b01e56bdd703b63997404a2e929282155acd9b5d2c86ba1d9d5d06909a04c44286dafb050c7b6d57921dd96790546
|
data/Gemfile.lock
CHANGED
data/lib/plate_api.rb
CHANGED
@@ -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
|
9
|
-
raise ArgumentError
|
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
|
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
|
-
|
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
|
27
|
-
raise ArgumentError
|
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
|
-
|
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
|
40
|
-
raise ArgumentError
|
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
|
-
|
54
|
-
return nil
|
51
|
+
raise Error::Response, result
|
55
52
|
end
|
56
53
|
end
|
57
54
|
|
58
55
|
def delete(id)
|
59
|
-
raise ArgumentError
|
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
|
-
|
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
|
71
|
-
raise ArgumentError
|
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
|
-
|
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
|
-
|
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
|
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
|
data/lib/plate_api/version.rb
CHANGED
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.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Kortleven
|
@@ -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
|