trophonius 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trophonius_record.rb +25 -3
- data/lib/trophonius_request.rb +33 -0
- 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: cd95bdf4521b8b1880b53a508ef24ca440d9de77777aae796d7b02d45c33271b
|
4
|
+
data.tar.gz: 0e4fb8f0e96a9b3c898d28e0e02f544790baa148b9010d43b9c443e44c1cb823
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f89eda4514b9ef511a10e09ab30b31709d23428dd90cac1032215eabaf951c4d475a45f35a574fd486c14e8108f360923eefe21c929169bfb3f243f21418efec
|
7
|
+
data.tar.gz: 4905a09c32fff4b66effe1d0b1c34a406f825c3257a529f2d21b953aa8b500c8f75cdbbc4bcf119d8262d3e78f243acfe31a2f039350e2979073f8345d201f5f
|
data/lib/trophonius_record.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require 'trophonius_config'
|
3
5
|
|
@@ -32,7 +34,7 @@ module Trophonius
|
|
32
34
|
if response['messages'][0]['code'] != '0'
|
33
35
|
Error.throw_error(response['messages'][0]['code'])
|
34
36
|
else
|
35
|
-
|
37
|
+
true
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
@@ -47,7 +49,7 @@ module Trophonius
|
|
47
49
|
if response['messages'][0]['code'] != '0'
|
48
50
|
Error.throw_error(response['messages'][0]['code'])
|
49
51
|
else
|
50
|
-
|
52
|
+
true
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
@@ -68,7 +70,27 @@ module Trophonius
|
|
68
70
|
if response['messages'][0]['code'] != '0'
|
69
71
|
Error.throw_error(response['messages'][0]['code'])
|
70
72
|
else
|
71
|
-
|
73
|
+
true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Uploads a file to a container field of the record
|
79
|
+
# Throws a FileMaker error if upload failed
|
80
|
+
#
|
81
|
+
# @param [String] container_name: Case sensitive name of the container field on the layout
|
82
|
+
# @param [Integer] container_repitition: Number of the repitition of the container field to set
|
83
|
+
# @param [Tempfile or File] file: File to upload
|
84
|
+
#
|
85
|
+
# @return [True] if successful
|
86
|
+
def upload(container_name:, container_repitition: 1, file:)
|
87
|
+
url = URI("http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records/#{record_id}/containers/#{container_name}/#{container_repitition}")
|
88
|
+
|
89
|
+
response = Request.upload_file_request(url, "Bearer #{Request.get_token}", file)
|
90
|
+
if response['messages'][0]['code'] != '0'
|
91
|
+
Error.throw_error(response['messages'][0]['code'])
|
92
|
+
else
|
93
|
+
true
|
72
94
|
end
|
73
95
|
end
|
74
96
|
end
|
data/lib/trophonius_request.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'base64'
|
2
4
|
require 'trophonius_connection'
|
5
|
+
require 'uri'
|
6
|
+
require 'net/http'
|
3
7
|
|
4
8
|
module Trophonius
|
5
9
|
module Trophonius::Request
|
@@ -37,6 +41,35 @@ module Trophonius
|
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
44
|
+
##
|
45
|
+
# Crafts and runs a HTTP request for uploading a file to a container
|
46
|
+
#
|
47
|
+
# @param [URI] urlparam: the url to make the request to
|
48
|
+
#
|
49
|
+
# @param [String] auth: the authentication required for the request
|
50
|
+
#
|
51
|
+
# @param [Tempfile or File] file: file to upload
|
52
|
+
#
|
53
|
+
# @return [JSON] parsed json of the response
|
54
|
+
def self.upload_file_request(url_param, auth, file)
|
55
|
+
url = URI(url_param)
|
56
|
+
|
57
|
+
https = Net::HTTP.new(url.host, url.port)
|
58
|
+
https.use_ssl = true
|
59
|
+
|
60
|
+
request = Net::HTTP::Post.new(url)
|
61
|
+
request['Authorization'] = auth.to_s
|
62
|
+
request['Content-Type'] = 'multipart/form-data;'
|
63
|
+
form_data = [['upload', file]]
|
64
|
+
request.set_form form_data, 'multipart/form-data'
|
65
|
+
response = https.request(request)
|
66
|
+
begin
|
67
|
+
JSON.parse(response.read_body)
|
68
|
+
rescue Exception
|
69
|
+
Error.throw_error('1631')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
40
73
|
##
|
41
74
|
# Gets the current FileMaker token
|
42
75
|
#
|