Class: Services::AbaqisMdsPush
- Inherits:
-
MdsPush
show all
- Defined in:
- app/models/services/abaqis_mds_push.rb
Constant Summary
collapse
- URI_TEMPLATE =
'%s/stagei/mds30_composite_file'
Instance Attribute Summary
#service_definition
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from MdsPush
#invoke, #push_mds_file
#account_map, #initialize, #server_credentials
Class Method Details
17
18
19
20
|
# File 'app/models/services/abaqis_mds_push.rb', line 17
def self.configured_account(account_id)
svc_def = service_definition
svc_def.configured_accounts.where(account_id: account_id).first if svc_def.present?
end
|
.service_definition ⇒ Object
13
14
15
|
# File 'app/models/services/abaqis_mds_push.rb', line 13
def self.service_definition
ServiceDefinition.where(service_class: self.name.split("::").last).first
end
|
.service_impl ⇒ Object
7
8
9
10
11
|
# File 'app/models/services/abaqis_mds_push.rb', line 7
def self.service_impl
svc_def = service_definition
svc_def.service_implementation if svc_def.present?
end
|
Instance Method Details
#submit_to_service(available_file) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/models/services/abaqis_mds_push.rb', line 22
def submit_to_service(available_file)
account_id = available_file.configured_account.account_id
conf_acct = service_definition.configured_accounts.where(account_id: account_id).first
raise "Account '#{account_id}' is not configured for the MDS Web Service" if conf_acct.blank?
raise "Account '#{account_id}' is not enabled for the MDS Web Service" unless conf_acct.enabled?
mdsws_password = conf_acct.credentials.first.try(:password)
raise "Account '#{account_id}' does not have a password defined for the MDS Web Service" if mdsws_password.blank?
response = RestClient.post(url,
{ :composite_file => File.new(available_file.actual_file_path, 'rb') },
{ 'account-id' => account_id,
'account-password' => mdsws_password }).body
Rails.logger.info response
r = MdsWsResponse.parse_xml_response(response)
if r.status == MdsWsResponse::STATUS_SUCCESS
available_file.update_attribute :status, AvailableFile::STATUS_UPLOADED
else
available_file.update_attributes status: AvailableFile::STATUS_UPLOAD_ERROR, error: r.error_message
end
end
|
#url ⇒ Object
45
46
47
|
# File 'app/models/services/abaqis_mds_push.rb', line 45
def url
format URI_TEMPLATE, service_definition.server_base_url
end
|