class Medidata::API::Client
Public Class Methods
# File lib/medidata/api/client.rb, line 16 def initialize(host:, path_prefix: '', lang: 'de') @host = host @lang = lang rest = REST.new( host: host, url_path: [path_prefix], request_headers: { "Accept": "application/json", "Accept-Language": lang, "DenteoSecret": "yes_it's_us" }, ) @rest = rest end
Public Instance Methods
Set credentials for this Client's instance
-
Args :
-
id
->Medidata
client ID -
username
-> Username -
password
-> password
-
# File lib/medidata/api/client.rb, line 38 def auth(id, username, password) @rest.update_headers({ "X-CLIENT-ID": id, "Authorization": "Basic " + Base64.encode64(username + ":" + password).strip }) end
Retrieve download's payload
-
Args :
-
tref
-> download's transmission reference
-
# File lib/medidata/api/client.rb, line 202 def download(tref) params = { "request_headers": { "Accept": "application/octet-stream" }, } res = @rest.ela.downloads._(tref).get(params) case res.status_code when 200 then res.body when 400 then raise BadRequestError.new("bad request") when 401 then raise UnauthenticatedError.new("authentication required to download document") when 403 then raise PermissionError.new("wrong credentials to download document") when 404 then raise MissingError.new("notification not found") else raise "Error downloading document <#{res.status_code}>" end end
Confirm download receipt
All downloads received from Medidata
are pending by default and clients have to manually mark them as “CONFIRMED”. That should be done on a regular basis according to Medidata
.
-
Args :
-
tref
-> download's transmission reference
-
# File lib/medidata/api/client.rb, line 175 def downloads_confirm_receipt(tref) params = { "request_body": { "status": "CONFIRMED" } } res = @rest.ela.downloads._(tref).status.put(params) case res.status_code when 200, 204 then true when 400 then raise BadRequestError.new("bad request") when 401 then raise UnauthenticatedError.new("authentication required to confirm notification receipt") when 403 then raise PermissionError.new("wrong credentials to confirm notification receipt") when 404 then raise MissingError.new("notification not found") else raise "Error updating notification status <#{res.status_code}>" end end
Load pending downloads
-
Args :
-
limit
-> The total number of downloads allowed -
offset
-> Pagination offset
-
# File lib/medidata/api/client.rb, line 143 def downloads_pending(limit: 100, offset: 0) params = { "query_params": { "limit": limit, "offset": offset } } res = @rest.ela.downloads.get(params) case res.status_code when 200 then body = res.parsed_body raise "Invalid downloads response body" unless body.kind_of?(Array) body.map { |row| Medidata::API::Download.new(row) } when 400 then raise BadRequestError.new("bad request") when 401 then raise UnauthenticatedError.new("authentication required to load pending downloads") when 403 then raise PermissionError.new("wrong credentials to load pending downloads") else raise "Error fetching Medidata downloads <#{res.status_code}>" end end
Confirm notification receipt
All notifications received from Medidata
are pending by default and clients have to manually mark them as “read”. That should be done on a regular basis according to Medidata
.
-
Args :
-
id
->Notification
unique identifier
-
# File lib/medidata/api/client.rb, line 262 def notifications_confirm_receipt(id) params = { "request_body": { "notificationFetched": true } } res = @rest.ela.notifications._(id).status.put(params) case res.status_code when 200, 204 then true when 400 then raise BadRequestError.new("bad request") when 401 then raise UnauthenticatedError.new("authentication required to confirm notification receipt") when 403 then raise PermissionError.new("wrong credentials to confirm notification receipt") when 404 then raise MissingError.new("notification not found") else raise "Error updating notification status <#{res.status_code}>" end end
Load pending notifications
-
Args :
-
limit
-> The total number of notifications allowed -
offset
-> Pagination offset
-
# File lib/medidata/api/client.rb, line 230 def notifications_pending(limit: 100, offset: 0) params = { "query_params": { "limit": limit, "offset": offset } } res = @rest.ela.notifications.get(params) case res.status_code when 200 then body = res.parsed_body raise "Invalid notifications response body" unless body.kind_of?(Array) body.map { |row| Medidata::API::Notification.new(row) } when 400 then raise BadRequestError.new("bad request") when 401 then raise UnauthenticatedError.new("authentication required to load pending notifications") when 403 then raise PermissionError.new("wrong credentials to load pending notifications") else raise "Error fetching Medidata notifications <#{res.status_code}>" end end
-
Args :
-
limit
-> The total number of participants allowed -
offset
-> Pagination offset -
query
->ParticipantsQuery
object (optional)
-
# File lib/medidata/api/client.rb, line 49 def participants(limit: 100, offset: 0, query: nil) qs = { "limit": limit, "offset": offset } if query qs["lawtype"] = query.lawType if query.lawType qs["name"] = query.name if query.name qs["glnparticipant"] = query.glnParticipant if query.glnParticipant end params = { "query_params": qs } res = @rest.ela.participants.get(params) case res.status_code when 200 then body = res.parsed_body raise "Invalid participants response body" unless body.kind_of?(Array) body.map { |row| Medidata::API::Participant.new(row) } when 400 then raise BadRequestError.new("bad request") when 401 then raise UnauthenticatedError.new("authentication required to load participants") when 403 then raise PermissionError.new("wrong credentials to load participants") else raise "Error fetching Medidata participants <#{res.status_code}>" end end
-
Args :
-
file
-> File to upload (e.g. Invoice XML) -
info
->Medidata::API::UploadControlData
(optional)
-
# File lib/medidata/api/client.rb, line 85 def upload(file, info = nil) multipart = Medidata::API::MultipartPost.new multipart.with_binary key: "elauploadstream", value: file multipart.with_text key: "elauploadinfo", value: Medidata::API::UploadControlData.new(info).to_json if info bounday = "__MEDI_REST_IN_PEACE__" params = { "request_headers": { "Content-Type": "multipart/form-data; charset=utf-8; boundary=#{bounday}" }, "request_body": multipart.build(bounday) } res = @rest.ela.uploads.post(params) case res.status_code when 201 then # Upload created Medidata::API::Upload.new(res.parsed_body) when 400 then raise BadRequestError.new("bad request") when 401 then raise UnauthenticatedError.new("authentication required to upload") when 403 then raise PermissionError.new("wrong credentials to upload") when 409 then # TODO: Extract transmission reference from response raise ConflictError.new("this file has already been uploaded") else raise "Error uploading to Medidata <#{res.status_code}>" end end
Check upload status
-
Args :
-
tref
-> Upload's transmission reference
-
# File lib/medidata/api/client.rb, line 120 def upload_status(tref) res = @rest.ela.uploads._(tref).status.get case res.status_code when 200 then Medidata::API::Upload.new(res.parsed_body) when 400 then raise BadRequestError.new("bad request") when 401 then raise UnauthenticatedError.new("authentication required to check upload status") when 403 then raise PermissionError.new("wrong credentials to check upload status") when 404 then raise MissingError.new("upload status not found") else raise "Error fetching Medidata upload status <#{res.status_code}>" end end