Skip to content

Commit 34b19a7

Browse files
authored
feat(solution2/pms): Add file upload (#589)
* feat(solution2/pms): Add file upload * fix(solution2/pms): include payload * fix(solution2/pms): include content-length
1 parent e8de49f commit 34b19a7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

drivers/solutions2/pms.cr

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,21 @@ class PMS < PlaceOS::Driver
171171
request("GET", "/api/parking/full-notifications")
172172
end
173173

174+
def upload_vehicle_documents(vehicle_id : String, file_name : String, file_in_base64 : String)
175+
method = "POST"
176+
resource = "/api/vehicles/upload-documents/#{vehicle_id}"
177+
payload = {
178+
"Files" => [{"FileName" => file_name, "Base64" => file_in_base64}]
179+
}.to_json
180+
headers = get_headers
181+
headers["Content-Length"] = payload.bytesize.to_s
182+
183+
logger.debug { {msg: "#{method} #{resource}:", headers: headers.to_json, payload: payload} } if @debug_payload
184+
response = http(method: method, path: resource, headers: headers, body: payload)
185+
logger.debug { "RESPONSE code: #{response.status_code}, body: #{response.body}" } if @debug_payload
186+
raise "failed to #{method} #{resource}, code #{response.status_code}, body: #{response.body}" unless response.success?
187+
end
188+
174189
private def request(method : String, resource : String, payload : String? = nil, params : Hash(String, String?) | URI::Params = URI::Params.new)
175190
headers = get_headers("application/x-www-form-urlencoded")
176191
logger.debug { {msg: "#{method} #{resource}:", headers: headers.to_json, payload: payload} } if @debug_payload

0 commit comments

Comments
 (0)