Class: Services::SltcApi
- Inherits:
-
Object
- Object
- Services::SltcApi
- Defined in:
- app/models/services/sltc_api.rb
Constant Summary collapse
- BATCH_SIZE =
100
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #assessment_request(provider_id, uploaded_after, uploaded_before, status) ⇒ Object
- #assessment_request_status(request_id) ⇒ Object
- #download_assessment_request(request_id) ⇒ Object
- #download_batch(batch_id) ⇒ Object
-
#initialize(base_uri, api_key, account, username, password) ⇒ SltcApi
constructor
A new instance of SltcApi.
- #list_batches(provider, pull_from, pull_to) ⇒ Object
- #list_providers ⇒ Object
- #search_assessments(provider, pull_from, pull_to, status = 'Accepted') ⇒ Object
- #upload_batch(provider_id, path) ⇒ Object
Constructor Details
#initialize(base_uri, api_key, account, username, password) ⇒ SltcApi
Returns a new instance of SltcApi.
21 22 23 24 25 26 27 |
# File 'app/models/services/sltc_api.rb', line 21 def initialize(base_uri, api_key, account, username, password) @base_uri = base_uri @api_key = api_key @account = account @username = username @password = password end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
7 8 9 |
# File 'app/models/services/sltc_api.rb', line 7 def account @account end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
7 8 9 |
# File 'app/models/services/sltc_api.rb', line 7 def api_key @api_key end |
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
7 8 9 |
# File 'app/models/services/sltc_api.rb', line 7 def base_uri @base_uri end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
7 8 9 |
# File 'app/models/services/sltc_api.rb', line 7 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
7 8 9 |
# File 'app/models/services/sltc_api.rb', line 7 def username @username end |
Class Method Details
.for_configured_account(configured_account) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/models/services/sltc_api.rb', line 9 def self.for_configured_account(configured_account) service_definition = configured_account.service_definition mapped_account = configured_account.account_mapping credentials = configured_account.credentials.last SltcApi.new(service_definition.server_base_url, service_definition.credentials.last.token, mapped_account.account_code, configured_account.username, credentials.password) end |
Instance Method Details
#assessment_request(provider_id, uploaded_after, uploaded_before, status) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/models/services/sltc_api.rb', line 120 def assessment_request(provider_id, uploaded_after, uploaded_before, status) parameters = { 'provider_id' => provider_id, 'status_updated_after' => uploaded_after.strftime("%Y-%m-%dT%H:%MZ"), 'status_updated_before' => uploaded_before.strftime("%Y-%m-%dT%H:%MZ"), 'status' => status } get_response do RestClient::Request.execute(method: :post, url: build_url(:MdsAssessmentsAsync), payload: parameters.to_json, user: "#{username}@#{account}", password: password, headers: authentication_headers.merge({ :content_type => :json, 'Accept' => 'application/json' })) end end |
#assessment_request_status(request_id) ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'app/models/services/sltc_api.rb', line 110 def assessment_request_status(request_id) get_response do RestClient::Request.execute(method: :get, url: build_url(:MdsAssessmentsAsync, request_id), user: "#{username}@#{account}", password: password, headers: authentication_headers.merge( { 'Accept' => 'application/json' })) end end |
#download_assessment_request(request_id) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'app/models/services/sltc_api.rb', line 100 def download_assessment_request(request_id) get_response(true) do RestClient::Request.execute(method: :get, url: build_url(:MdsAssessmentsAsync, request_id), user: "#{username}@#{account}", password: password, headers: authentication_headers.merge({ 'Accept' => 'application/octet-stream' })) end end |
#download_batch(batch_id) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'app/models/services/sltc_api.rb', line 90 def download_batch(batch_id) get_response(true) do RestClient::Request.execute(method: :get, url: build_url(:MdsBatches, batch_id), user: "#{username}@#{account}", password: password, headers: authentication_headers.merge( { 'Accept' => 'application/octet-stream' } )) end end |
#list_batches(provider, pull_from, pull_to) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/services/sltc_api.rb', line 39 def list_batches(provider, pull_from, pull_to) batches = [] page = 1 while true response = get_response do RestClient::Request.execute(method: :get, url: build_url(:MdsBatches, { provider_id: provider, page: page, uploaded_after: pull_from, uploaded_before: pull_to }), user: "#{username}@#{account}", password: password, headers: authentication_headers.merge({ 'Accept' => 'application/json' })) end batches += response if response.size < BATCH_SIZE break else page += 1 end end batches end |
#list_providers ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'app/models/services/sltc_api.rb', line 29 def list_providers get_response do RestClient::Request.execute(method: :get, url: build_url(:Providers), user: "#{username}@#{account}", password: password, headers: authentication_headers.merge({ 'Accept' => 'application/json' })) end end |
#search_assessments(provider, pull_from, pull_to, status = 'Accepted') ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/services/sltc_api.rb', line 63 def search_assessments(provider, pull_from, pull_to, status='Accepted') get_response do RestClient::Request.execute(method: :get, url: build_url(:MdsAssessments, { provider_id: provider, status_updated_after: pull_from, status_updated_before: pull_to, status: status }), user: "#{username}@#{account}", password: password, headers: authentication_headers.merge({ 'Accept' => 'application/json' })) end end |
#upload_batch(provider_id, path) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/services/sltc_api.rb', line 76 def upload_batch(provider_id, path) file = nil File.open(path, "rb") { |f| file = f.read } get_response do RestClient::Request.execute(method: :post, url: build_url(:MdsBatches, { filename: path }), payload: file, user: "#{username}@#{account}", password: password, headers: authentication_headers.merge( { :content_type => 'application/octet-stream', 'Accept' => 'application/json' } )) end end |