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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb6918b7e7c9f7ebd49f2255ce6d447e9b3ac8608a2847790b9bde4434325622
4
- data.tar.gz: 0b3fe11572d763268e2ae1be8c2b42a77a816d8ea4687855389ba93fb654624e
3
+ metadata.gz: 659c6f0d7342d76965200cc2d28add619ff58cb622e66d6e41878dc553110a52
4
+ data.tar.gz: bc884081477e70ae1d4bea869962f825c427171042ec03cdafdf9045010b5360
5
5
  SHA512:
6
- metadata.gz: 94f9e303a9ccd2fa37fe182c8b1b1d5039cda9f5f9c551fee3706dc9f6520aee4567f8600f8148b48179a9818583687be6de25555b773d6b2d4021c39501a2ae
7
- data.tar.gz: cee651945fb60c85d80b364782d8485c06305a805ebcc16e3e6b3e53f6684da98695844196a3ea43edd09cf389dc3ef013323766594a9d6e4743c72a4c64a3d1
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
- handle_response(@conn.get(url_api))
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
- handle_response(@conn.post(url_api, data.to_s))
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
- begin
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.to_s
102
- handle_response(@conn.delete(url_api))
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, "AlmapiError : #{response.status} -> #{response.body}"
119
- p @conn
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Almapi
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.11"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: almapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - jszenb