almapi 0.1.8 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/almapi/almapi.rb +13 -13
- data/lib/almapi/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 659c6f0d7342d76965200cc2d28add619ff58cb622e66d6e41878dc553110a52
|
4
|
+
data.tar.gz: bc884081477e70ae1d4bea869962f825c427171042ec03cdafdf9045010b5360
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87ab1b72ea1bc7a18631f52d04ccff68c5e68e967b7c073b4b9bb70df9223a39299f3bf9ba97650276bf1275c79299b0088d2162f611fa65ebbc2a85688a0ef9
|
7
|
+
data.tar.gz: 9f87ad03a87626b9560c01720c5937f4bb85494dfbf3252c8aa357603988ff70f52c3479a7c9ff0c2b77356e53139abea7a09e7ffc8a90c611d889bdf94c8370
|
data/lib/almapi/almapi.rb
CHANGED
@@ -61,7 +61,8 @@ module Almapi
|
|
61
61
|
"#{@uri_base}#{resource}" # All other cases
|
62
62
|
end
|
63
63
|
|
64
|
-
|
64
|
+
puts "[Almapi::Api.get] INFO URL #{url_api}"
|
65
|
+
handle_response(@conn.get(url_api), "GET")
|
65
66
|
end
|
66
67
|
|
67
68
|
# Handles a POST request creating the complete URI.
|
@@ -72,7 +73,8 @@ module Almapi
|
|
72
73
|
# @return [Response] : the resulting response
|
73
74
|
def post(resource, data)
|
74
75
|
url_api = "#{@uri_base}#{resource}"
|
75
|
-
|
76
|
+
puts "[Almapi::Api.post] INFO URL #{url_api}"
|
77
|
+
handle_response(@conn.post(url_api, data.to_s), "POST")
|
76
78
|
end
|
77
79
|
|
78
80
|
# Handles a PUT request creating the complete URI.
|
@@ -83,12 +85,8 @@ module Almapi
|
|
83
85
|
# @return [Response] : the resulting response. If error occurs, raises an AlmapiError
|
84
86
|
def put(resource, data)
|
85
87
|
url_api = "#{@uri_base}#{resource}"
|
86
|
-
puts url_api
|
87
|
-
|
88
|
-
handle_response(@conn.put(url_api, data.to_s, "Content-Type" => "application/xml"))
|
89
|
-
rescue StandardError => e
|
90
|
-
puts e
|
91
|
-
end
|
88
|
+
puts "[Almapi::Api.put] INFO URL #{url_api}"
|
89
|
+
handle_response(@conn.put(url_api, data.to_s), "PUT")
|
92
90
|
end
|
93
91
|
|
94
92
|
# Handles a DELETE request creating the complete URI.
|
@@ -98,8 +96,9 @@ module Almapi
|
|
98
96
|
# @param data [String] : an XML string containing data to put.
|
99
97
|
# @return [Response] : the resulting response. If error occurs, raises an AlmapiError
|
100
98
|
def delete(resource, _data)
|
101
|
-
url_api = resource
|
102
|
-
|
99
|
+
url_api = "#{@uri_base}#{resource}"
|
100
|
+
puts "[Almapi::Api.delete] INFO URL #{url_api}"
|
101
|
+
handle_response(@conn.delete(url_api), "DELETE")
|
103
102
|
end
|
104
103
|
|
105
104
|
private
|
@@ -107,16 +106,17 @@ module Almapi
|
|
107
106
|
# [Private] handles the response and decides to raise AlmapiError if necessary
|
108
107
|
#
|
109
108
|
# @param response [Response] mandatory : the response of the API call
|
109
|
+
# @param method [String] mandatory the called HTTP method
|
110
110
|
# @return [Response || AlmapiError] : the resulting response if the API call succeeded, else AlmapiError
|
111
|
-
def handle_response(response)
|
111
|
+
def handle_response(response, method)
|
112
112
|
case response.status
|
113
113
|
when 200
|
114
114
|
# Success
|
115
115
|
response
|
116
116
|
else
|
117
117
|
# Request has been correctly handled but cannot succeed
|
118
|
-
raise Almapi::AlmapiError,
|
119
|
-
|
118
|
+
raise Almapi::AlmapiError,
|
119
|
+
"[Almapi::Api.handle_response] AlmapiError : for method #{method}, #{response.status} -> #{response.body}"
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
data/lib/almapi/version.rb
CHANGED