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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09bf65656de8336735c86096cbce1c5c951523f6b7cfa0d55ef6ed43dbeb1d78'
4
- data.tar.gz: 7145e01a452dbfdb604d83f5d660587fc6deaef70fa98f0b61fcc1c21dfc9137
3
+ metadata.gz: c4adf706bf694ce9826fd9ed0e2b6a5376038cb7efd99167bebddee74bf2ff2b
4
+ data.tar.gz: a90b502c510ca13f87e464ba026ab53ad16737f77ad6954d23b075afcfbc0bea
5
5
  SHA512:
6
- metadata.gz: cdad0d6cfd4dee24ff415c3a781eb70d43c3141c340a2526f3cb22cb3748cd7bdf2a9de0151930454b106ea8ce9079f3b8e915e92730e07c00035f0b7d042f40
7
- data.tar.gz: 8819d44883e6ca4be2c1c1a2a657ad76a326c2ddd38d79dced69ab9fd284eff210bd283ac4fa72a07460e93afcf14b69e1434a9514d2019802271893c9c46586
6
+ metadata.gz: a84c77342116a513c6e8f16b62b9059ef069afe29910d7e5aa74abfc14e94da3328f1f80a31c4633ff9320c4e454dd81e63e48a0c29919664636af92e5ebdd1d
7
+ data.tar.gz: b0a78eab66e3da0a6e0b7350c80bb624f35b01e56bdd703b63997404a2e929282155acd9b5d2c86ba1d9d5d06909a04c44286dafb050c7b6d57921dd96790546
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- plate_api (1.1.8)
4
+ plate_api (1.2.0)
5
5
  faraday (~> 1.0.1)
6
6
  mimemagic (~> 0.3.3)
7
7
 
@@ -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,3 +1,3 @@
1
1
  module PlateApi
2
- VERSION = "1.1.8"
2
+ VERSION = "1.2.0"
3
3
  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.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