almapi 0.1.8 → 0.1.9
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 +9 -10
- 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: 8b5ba5d80ae25614a6560df36126d04a5ab3eb574ce5026ca5b5c8cacddf3a70
|
4
|
+
data.tar.gz: 26cad93394125cbaa1bfc11c6a9ef20e4dd38366815d59a4a43d21b744e31115
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebef23941dbf9a8b0fc8dbbc1b1ab1496f3bc341aab56329a7f39ca9817270a714feb57adf02a204b97231d70f5a23217d9344a8f1f99ddaadcd469e4c2d7b28
|
7
|
+
data.tar.gz: aa8a1ec97ab087310cd1c5f428db752ca7f76504bc0b90fdfe07cacba3006337829532c17b36d60d6b8ec71dbb4377e9de6de1e862852921b8e394282e1ec2a7
|
data/lib/almapi/almapi.rb
CHANGED
@@ -61,6 +61,7 @@ module Almapi
|
|
61
61
|
"#{@uri_base}#{resource}" # All other cases
|
62
62
|
end
|
63
63
|
|
64
|
+
puts "[Almapi::Api.get] INFO URL #{url_api}"
|
64
65
|
handle_response(@conn.get(url_api))
|
65
66
|
end
|
66
67
|
|
@@ -72,6 +73,7 @@ module Almapi
|
|
72
73
|
# @return [Response] : the resulting response
|
73
74
|
def post(resource, data)
|
74
75
|
url_api = "#{@uri_base}#{resource}"
|
76
|
+
puts "[Almapi::Api.post] INFO URL #{url_api}"
|
75
77
|
handle_response(@conn.post(url_api, data.to_s))
|
76
78
|
end
|
77
79
|
|
@@ -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))
|
92
90
|
end
|
93
91
|
|
94
92
|
# Handles a DELETE request creating the complete URI.
|
@@ -98,7 +96,8 @@ 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
|
99
|
+
url_api = "#{@uri_base}#{resource}"
|
100
|
+
puts "[Almapi::Api.delete] INFO URL #{url_api}"
|
102
101
|
handle_response(@conn.delete(url_api))
|
103
102
|
end
|
104
103
|
|
@@ -107,16 +106,16 @@ 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, "AlmapiError : #{response.status} -> #{response.body}"
|
119
|
-
p @conn
|
118
|
+
raise Almapi::AlmapiError, "[Almapi::Api.handle_response] AlmapiError : for method #{method}, #{response.status} -> #{response.body}"
|
120
119
|
end
|
121
120
|
end
|
122
121
|
end
|
data/lib/almapi/version.rb
CHANGED