Class: Dina::File
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseModel
custom_headers, endpoint_path, #english_description, find_by_group, #french_description, properties, site
Constructor Details
#initialize(attributes = {}) ⇒ File
Returns a new instance of File.
30
31
32
33
34
35
|
# File 'lib/dina/models/object_store/file.rb', line 30
def initialize(attributes = {})
@id = attributes[:id] || SecureRandom.uuid
@group = attributes[:group] || nil
@is_derivative = attributes[:is_derivative] || false
@file_path = attributes[:file_path] || nil
end
|
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
3
4
5
|
# File 'lib/dina/models/object_store/file.rb', line 3
def file_path
@file_path
end
|
#group ⇒ Object
Returns the value of attribute group.
3
4
5
|
# File 'lib/dina/models/object_store/file.rb', line 3
def group
@group
end
|
#id ⇒ Object
Returns the value of attribute id.
3
4
5
|
# File 'lib/dina/models/object_store/file.rb', line 3
def id
@id
end
|
#is_derivative ⇒ Object
Returns the value of attribute is_derivative.
3
4
5
|
# File 'lib/dina/models/object_store/file.rb', line 3
def is_derivative
@is_derivative
end
|
Class Method Details
.create(attributes = {}) ⇒ Object
24
25
26
27
28
|
# File 'lib/dina/models/object_store/file.rb', line 24
def self.create(attributes = {})
new(attributes).tap do |resource|
resource.save
end
end
|
.find(group:, id:) ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/dina/models/object_store/file.rb', line 13
def self.find(group:, id:)
obj = self.new
obj.group = group
RestClient::Request.execute(
method: :get,
headers: { authorization: Dina::Authentication. },
url: obj.url + "/#{id}",
verify_ssl: verify_ssl
)
end
|
.verify_ssl ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/dina/models/object_store/file.rb', line 5
def self.verify_ssl
begin
connection_options[:ssl][:verify]
rescue
true
end
end
|
Instance Method Details
#endpoint_path ⇒ Object
41
42
43
|
# File 'lib/dina/models/object_store/file.rb', line 41
def endpoint_path
"objectstore-api/"
end
|
#file ⇒ Object
53
54
55
|
# File 'lib/dina/models/object_store/file.rb', line 53
def file
::File.new(file_path)
end
|
#save ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/dina/models/object_store/file.rb', line 57
def save
validate_params
response = RestClient::Request.execute(
method: :post,
headers: { authorization: Dina::Authentication. },
url: (!is_derivative) ? url : url + "/derivative",
payload: {
multipart: true,
file: file
},
verify_ssl: self.class.verify_ssl
)
json = JSON.parse(response, symbolize_names: true)
self.id = json[:uuid]
json
end
|
#table_name ⇒ Object
45
46
47
|
# File 'lib/dina/models/object_store/file.rb', line 45
def table_name
"file/#{group.downcase}"
end
|
#url ⇒ Object
49
50
51
|
# File 'lib/dina/models/object_store/file.rb', line 49
def url
endpoint + "/" + endpoint_path + table_name
end
|