lib/util/vsac_api.rb in cqm-parsers-3.2.0.2 vs lib/util/vsac_api.rb in cqm-parsers-4.0.0.0

- old
+ new

@@ -5,11 +5,11 @@ module VSAC # Generic VSAC related exception. class VSACError < StandardError end - # Error represnting a not found response from the API. Includes OID for reporting to user. + # Error representing a not found response from the API. Includes OID for reporting to user. class VSNotFoundError < VSACError attr_reader :oid def initialize(oid) super("Value Set (#{oid}) was not found.") @oid = oid @@ -21,19 +21,19 @@ def initialize super('Resource not found.') end end - # Error represnting a program not found response from the API. + # Error representing a program not found response from the API. class VSACProgramNotFoundError < VSACError attr_reader :oid def initialize(program) super("VSAC Program #{program} does not exist.") end end - # Error represnting a response from the API that had no concepts. + # Error representing a response from the API that had no concepts. class VSEmptyError < VSACError attr_reader :oid def initialize(oid) super("Value Set (#{oid}) is empty.") @oid = oid @@ -48,18 +48,18 @@ end # Raised when the user credentials were invalid. class VSACInvalidCredentialsError < VSACError def initialize - super('VSAC ULMS credentials are invalid.') + super('VSAC UMLS credentials are invalid.') end end # Raised when a call requiring auth is attempted when no ticket_granting_ticket or credentials were provided. class VSACNoCredentialsError < VSACError def initialize - super('VSAC ULMS credentials were not provided.') + super('VSAC UMLS credentials were not provided.') end end # Raised when the arguments passed in are bad. class VSACArgumentError < VSACError @@ -91,11 +91,11 @@ unless check_config @config raise VSACArgumentError.new("Required param :config is missing required URLs.") end # if a ticket_granting_ticket was passed in, check it and raise errors if found - # username and password will be ignored + # VSAC API Key will be ignored if !options[:ticket_granting_ticket].nil? provided_ticket_granting_ticket = options[:ticket_granting_ticket] if provided_ticket_granting_ticket[:ticket].nil? || provided_ticket_granting_ticket[:expires].nil? raise VSACArgumentError.new("Optional param :ticket_granting_ticket is missing :ticket or :expires") end @@ -103,13 +103,13 @@ raise VSACTicketExpiredError.new if Time.now > provided_ticket_granting_ticket[:expires] @ticket_granting_ticket = { ticket: provided_ticket_granting_ticket[:ticket], expires: provided_ticket_granting_ticket[:expires] } - # if username and password were provided use them to get a ticket granting ticket - elsif !options[:username].nil? && !options[:password].nil? - @ticket_granting_ticket = get_ticket_granting_ticket(options[:username], options[:password]) + # if api key was provided use it to get a ticket granting ticket + elsif !options[:api_key].nil? + @ticket_granting_ticket = get_ticket_granting_ticket(options[:api_key]) end end ## # Gets the list of profiles. This may be used without credentials. @@ -302,16 +302,14 @@ return Typhoeus::Request.new("#{@config[:auth_url]}/Ticket/#{@ticket_granting_ticket[:ticket]}", method: :post, params: { service: TICKET_SERVICE_PARAM}) end - # Use your username and password to retrive a ticket granting ticket from VSAC - def get_ticket_granting_ticket(username, password) + # Use your API Key to retrive a ticket granting ticket from VSAC + def get_ticket_granting_ticket(api_key) response = Typhoeus.post( "#{@config[:auth_url]}/Ticket", - # looks like typheous sometimes switches the order of username/password when encoding - # which vsac cant handle (!?), so encode first - body: URI.encode_www_form(username: username, password: password) + body: URI.encode_www_form(apikey: api_key) ) raise VSACInvalidCredentialsError.new if response.response_code == 401 validate_http_status(response.response_code) return { ticket: String.new(response.body), expires: Time.now + 8.hours } end