ruby-fiix-cmms-client 0.1.0 → 0.2.0
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 853c18ca53326409075479df9752eb7275b87db31ae147e058d3d5a2cb413c18
|
|
4
|
+
data.tar.gz: 2a7a76bc625691de142cb31dd32031ad15b8feba1613208e6e17a9808b361fc4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c21bdbf18edd94292bbaaa4c6f4031047ebc497115a50e7d429e2d8ee7ad8e4799757aef506d7a8d50c1fa483c1ff960884a618e8e027ec6f6e841350d5c15f
|
|
7
|
+
data.tar.gz: 9daceaebdf2a2681a64b35b9e410280818f587144f0ea2bac4ec893c230800d2f391f44db673c87e7642c8a5b78ead4b65694e91dad85912a69adbcab923631d
|
|
@@ -30,9 +30,13 @@ module Ruby
|
|
|
30
30
|
|
|
31
31
|
validate_credentials!
|
|
32
32
|
|
|
33
|
-
@base_url
|
|
34
|
-
@signature
|
|
35
|
-
@uri
|
|
33
|
+
@base_url = Auth.base_url(@subdomain, @api_key, @access_key)
|
|
34
|
+
@signature = Auth.sign(@api_secret, @base_url)
|
|
35
|
+
@uri = URI.parse(@base_url)
|
|
36
|
+
|
|
37
|
+
@upload_url = Auth.upload_url(@subdomain, @api_key, @access_key)
|
|
38
|
+
@upload_sig = Auth.sign(@api_secret, @upload_url)
|
|
39
|
+
@upload_uri = URI.parse(@upload_url)
|
|
36
40
|
end
|
|
37
41
|
|
|
38
42
|
OPERATIONS.each do |method_name, request_type|
|
|
@@ -44,10 +48,14 @@ module Ruby
|
|
|
44
48
|
end
|
|
45
49
|
end
|
|
46
50
|
|
|
47
|
-
def upload_file(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
def upload_file(source_info:, source_id:, file:, field_name: "file_part_1")
|
|
52
|
+
description = {
|
|
53
|
+
"sourceInfo" => source_info.to_s,
|
|
54
|
+
"sourceIdString" => source_id.to_s,
|
|
55
|
+
"fieldName" => field_name.to_s
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
upload_request(descriptions: [description], files: { field_name.to_s => file })
|
|
51
59
|
end
|
|
52
60
|
|
|
53
61
|
private
|
|
@@ -77,13 +85,13 @@ module Ruby
|
|
|
77
85
|
raise ConnectionError, "Failed to connect to Fiix API: #{e.message}"
|
|
78
86
|
end
|
|
79
87
|
|
|
80
|
-
def
|
|
88
|
+
def upload_request(descriptions:, files:)
|
|
81
89
|
boundary = "----RubyFiixCmms#{SecureRandom.hex(16)}"
|
|
82
|
-
body =
|
|
90
|
+
body = build_upload_body(descriptions, files, boundary)
|
|
83
91
|
|
|
84
|
-
http = build_http
|
|
85
|
-
req = Net::HTTP::Post.new(@
|
|
86
|
-
req["Authorization"] = @
|
|
92
|
+
http = build_http(@upload_uri)
|
|
93
|
+
req = Net::HTTP::Post.new(@upload_uri.request_uri)
|
|
94
|
+
req["Authorization"] = @upload_sig
|
|
87
95
|
req["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
|
|
88
96
|
req.body = body
|
|
89
97
|
|
|
@@ -92,26 +100,25 @@ module Ruby
|
|
|
92
100
|
raise ConnectionError, "Failed to connect to Fiix API: #{e.message}"
|
|
93
101
|
end
|
|
94
102
|
|
|
95
|
-
def build_http
|
|
96
|
-
http = Net::HTTP.new(
|
|
103
|
+
def build_http(uri = @uri)
|
|
104
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
97
105
|
http.use_ssl = true
|
|
98
106
|
http
|
|
99
107
|
end
|
|
100
108
|
|
|
101
|
-
def
|
|
109
|
+
def build_upload_body(descriptions, files, boundary)
|
|
102
110
|
parts = []
|
|
103
111
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
end
|
|
112
|
+
parts << "--#{boundary}\r\n" \
|
|
113
|
+
"Content-Disposition: form-data; name=\"descriptions\"\r\n" \
|
|
114
|
+
"Content-Type: application/json\r\n\r\n" \
|
|
115
|
+
"#{JSON.generate(descriptions)}\r\n"
|
|
109
116
|
|
|
110
|
-
|
|
117
|
+
files.each do |field_name, file|
|
|
111
118
|
filename = file.respond_to?(:path) ? File.basename(file.path) : "upload"
|
|
112
119
|
file_content = file.respond_to?(:read) ? file.read : file
|
|
113
120
|
parts << "--#{boundary}\r\n" \
|
|
114
|
-
"Content-Disposition: form-data; name=\"
|
|
121
|
+
"Content-Disposition: form-data; name=\"#{field_name}\"; filename=\"#{filename}\"\r\n" \
|
|
115
122
|
"Content-Type: application/octet-stream\r\n\r\n" \
|
|
116
123
|
"#{file_content}\r\n"
|
|
117
124
|
end
|
|
@@ -15,6 +15,12 @@ module Ruby
|
|
|
15
15
|
"&signatureMethod=HmacSHA256&signatureVersion=1"
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def upload_url(subdomain, api_key, access_key)
|
|
19
|
+
"https://#{subdomain}.macmms.com/api/upload" \
|
|
20
|
+
"?action=uploadFile&appKey=#{api_key}&accessKey=#{access_key}" \
|
|
21
|
+
"&signatureMethod=HmacSHA256&signatureVersion=1"
|
|
22
|
+
end
|
|
23
|
+
|
|
18
24
|
def sign(api_secret, url)
|
|
19
25
|
message = url.sub("https://", "")
|
|
20
26
|
OpenSSL::HMAC.hexdigest("SHA256", api_secret, message)
|