ruby-fiix-cmms-client 0.1.1 → 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,16 +48,14 @@ module Ruby
|
|
|
44
48
|
end
|
|
45
49
|
end
|
|
46
50
|
|
|
47
|
-
def upload_file(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
.merge(DEFAULT_CLIENT_VERSION)
|
|
54
|
-
.merge(normalized)
|
|
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
|
+
}
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
upload_request(descriptions: [description], files: { field_name.to_s => file })
|
|
57
59
|
end
|
|
58
60
|
|
|
59
61
|
private
|
|
@@ -83,13 +85,13 @@ module Ruby
|
|
|
83
85
|
raise ConnectionError, "Failed to connect to Fiix API: #{e.message}"
|
|
84
86
|
end
|
|
85
87
|
|
|
86
|
-
def
|
|
88
|
+
def upload_request(descriptions:, files:)
|
|
87
89
|
boundary = "----RubyFiixCmms#{SecureRandom.hex(16)}"
|
|
88
|
-
body =
|
|
90
|
+
body = build_upload_body(descriptions, files, boundary)
|
|
89
91
|
|
|
90
|
-
http = build_http
|
|
91
|
-
req = Net::HTTP::Post.new(@
|
|
92
|
-
req["Authorization"] = @
|
|
92
|
+
http = build_http(@upload_uri)
|
|
93
|
+
req = Net::HTTP::Post.new(@upload_uri.request_uri)
|
|
94
|
+
req["Authorization"] = @upload_sig
|
|
93
95
|
req["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
|
|
94
96
|
req.body = body
|
|
95
97
|
|
|
@@ -98,26 +100,25 @@ module Ruby
|
|
|
98
100
|
raise ConnectionError, "Failed to connect to Fiix API: #{e.message}"
|
|
99
101
|
end
|
|
100
102
|
|
|
101
|
-
def build_http
|
|
102
|
-
http = Net::HTTP.new(
|
|
103
|
+
def build_http(uri = @uri)
|
|
104
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
103
105
|
http.use_ssl = true
|
|
104
106
|
http
|
|
105
107
|
end
|
|
106
108
|
|
|
107
|
-
def
|
|
109
|
+
def build_upload_body(descriptions, files, boundary)
|
|
108
110
|
parts = []
|
|
109
111
|
|
|
110
|
-
# Send all params as a single JSON field named "data"
|
|
111
112
|
parts << "--#{boundary}\r\n" \
|
|
112
|
-
"Content-Disposition: form-data; name=\"
|
|
113
|
-
"Content-Type:
|
|
114
|
-
"#{JSON.generate(
|
|
113
|
+
"Content-Disposition: form-data; name=\"descriptions\"\r\n" \
|
|
114
|
+
"Content-Type: application/json\r\n\r\n" \
|
|
115
|
+
"#{JSON.generate(descriptions)}\r\n"
|
|
115
116
|
|
|
116
|
-
|
|
117
|
+
files.each do |field_name, file|
|
|
117
118
|
filename = file.respond_to?(:path) ? File.basename(file.path) : "upload"
|
|
118
119
|
file_content = file.respond_to?(:read) ? file.read : file
|
|
119
120
|
parts << "--#{boundary}\r\n" \
|
|
120
|
-
"Content-Disposition: form-data; name=\"
|
|
121
|
+
"Content-Disposition: form-data; name=\"#{field_name}\"; filename=\"#{filename}\"\r\n" \
|
|
121
122
|
"Content-Type: application/octet-stream\r\n\r\n" \
|
|
122
123
|
"#{file_content}\r\n"
|
|
123
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)
|