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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a3dfbe463b4a2b68ed2c2112e20b10c560e22e476ea00f668478593fa17ad4c
4
- data.tar.gz: 9482729939a3299f1b9d9066b5b2146ed416ac91499afdc420e1a8a24236c2aa
3
+ metadata.gz: cd95bdf4521b8b1880b53a508ef24ca440d9de77777aae796d7b02d45c33271b
4
+ data.tar.gz: 0e4fb8f0e96a9b3c898d28e0e02f544790baa148b9010d43b9c443e44c1cb823
5
5
  SHA512:
6
- metadata.gz: f4a76d509f8c268e6692600b7322d9497738efdabc839b1127c8a29a36c5f1239ba3586614b0707b4077f368ac479db350bdb4dba991ae87f610eccb11891115
7
- data.tar.gz: 4616ca07aa6192f710acc16d2826fa626fd94a41b0884bf054cae0863513e518f36d6962c7c35a3543c32fd36e57f30c1557b00cfdb78b6a749acb2940a48998
6
+ metadata.gz: f89eda4514b9ef511a10e09ab30b31709d23428dd90cac1032215eabaf951c4d475a45f35a574fd486c14e8108f360923eefe21c929169bfb3f243f21418efec
7
+ data.tar.gz: 4905a09c32fff4b66effe1d0b1c34a406f825c3257a529f2d21b953aa8b500c8f75cdbbc4bcf119d8262d3e78f243acfe31a2f039350e2979073f8345d201f5f
@@ -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
- return true
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
- return true
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
- return true
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
@@ -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
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trophonius
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kempen Automatisering