rest-api-client 0.1.2 → 0.1.3
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/lib/rest/api/client.rb +26 -8
- data/lib/rest/api/client/json_parser.rb +9 -5
- data/lib/rest/api/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d01d93b618bb31e3a949ca9eb6b81bef05994ce
|
4
|
+
data.tar.gz: 4cd4fa9084f708fafad1a00448174bac4c2aec06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d37f961276e07e915b8b0d6c492b75bda9372bfb8577eabf3dd31106031c241ebb0d2e1fd417ea1b28d4417b6210331bd872dd6eec17083d72509450b7e89d4
|
7
|
+
data.tar.gz: c48f75246be03a4e9929d876f400b2e50c046c9217d966b3a94c04b5db49ee481366b3876364dcf27463f81072bd8997f708e9a0d8b08304d338ca7b51fd5393
|
data/lib/rest/api/client.rb
CHANGED
@@ -16,12 +16,18 @@ module RestApiClient
|
|
16
16
|
PATH = ''
|
17
17
|
SERVICE_KEY = ''
|
18
18
|
|
19
|
+
attr_reader :errors
|
20
|
+
|
19
21
|
attribute :id, Integer
|
20
|
-
attribute :created_at,
|
21
|
-
attribute :updated_at,
|
22
|
+
attribute :created_at, DateTime
|
23
|
+
attribute :updated_at, DateTime
|
24
|
+
|
25
|
+
def self.list(params = {})
|
26
|
+
perform_get path, {:type => self, :params => params}
|
27
|
+
end
|
22
28
|
|
23
|
-
def self.
|
24
|
-
perform_get path, {:
|
29
|
+
def self.count(params = {})
|
30
|
+
perform_get "#{path}/count", {:params => params}
|
25
31
|
end
|
26
32
|
|
27
33
|
def self.find(id)
|
@@ -33,9 +39,14 @@ module RestApiClient
|
|
33
39
|
end
|
34
40
|
|
35
41
|
def save!
|
36
|
-
|
37
|
-
|
38
|
-
|
42
|
+
begin
|
43
|
+
klazz = self.class
|
44
|
+
response = perform_post path, {:type => klazz, :params => {get_model_name => self.attributes}}
|
45
|
+
self.attributes = response && response.is_a?(klazz) ? response.attributes : {}
|
46
|
+
rescue RestApiClient::ModelErrorsException => e
|
47
|
+
@errors = e.errors
|
48
|
+
return false
|
49
|
+
end
|
39
50
|
end
|
40
51
|
|
41
52
|
def delete
|
@@ -43,7 +54,14 @@ module RestApiClient
|
|
43
54
|
end
|
44
55
|
|
45
56
|
def update!
|
46
|
-
|
57
|
+
begin
|
58
|
+
klazz = self.class
|
59
|
+
response = perform_put "#{path}/#{id}", {:type => klazz, :params => {get_model_name => self.attributes}}
|
60
|
+
self.attributes = response && response.is_a?(klazz) ? response.attributes : {}
|
61
|
+
rescue RestApiClient::ModelErrorsException => e
|
62
|
+
@errors = e.errors
|
63
|
+
return false
|
64
|
+
end
|
47
65
|
end
|
48
66
|
|
49
67
|
def perform_get(path, args = {}, headers = {})
|
@@ -13,12 +13,16 @@ module RestApiClient
|
|
13
13
|
json_data = json_response['data']
|
14
14
|
end
|
15
15
|
|
16
|
-
if json_data.kind_of?(Array)
|
17
|
-
return json_data.map { |data| data_type.new data }
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
if json_data.kind_of?(Array)
|
17
|
+
return json_data.map { |data| data_type.new data } if data_type
|
18
|
+
return json_data unless json_data.empty?
|
19
|
+
|
20
|
+
elsif json_data.kind_of?(Hash)
|
21
|
+
return data_type.new json_data if data_type
|
21
22
|
return json_data unless json_data.empty?
|
23
|
+
|
24
|
+
else
|
25
|
+
return json_data
|
22
26
|
end
|
23
27
|
return json_response
|
24
28
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|