class CtgbIdsConverter::RemoteConverter

Public Class Methods

code(code) click to toggle source
# File lib/ctgb-ids-converter/remote_converter.rb, line 9
def self.code(code)
  convert(code,:sp2r)
end
connected?() click to toggle source
# File lib/ctgb-ids-converter/remote_converter.rb, line 3
def self.connected?
  run_request('/api/check_connection') do |response|
    response.code == 200
  end
end
decode(code) click to toggle source
# File lib/ctgb-ids-converter/remote_converter.rb, line 13
def self.decode(code)
  convert(code,:sr2p)
end

Private Class Methods

convert(code,direction) click to toggle source
# File lib/ctgb-ids-converter/remote_converter.rb, line 19
def self.convert(code,direction)
  run_request("/api/projects/convert/1/#{direction}/#{code}", :method => :put ) do |response|
    case response.code
    when 200
      return JSON.parse(response.response_body)['conv_id']
    when 400
      raise CtgbIdsConverter::WrongIdException
    when 401
      raise CtgbIdsConverter::UnauthorizedConversionException
    else
      raise "Conversion service returned code #{response.code}"
    end
  end
end
get_uri(resource_path) click to toggle source
# File lib/ctgb-ids-converter/remote_converter.rb, line 45
def self.get_uri(resource_path)
  uri_host_part + resource_path + uri_token_part
end
run_request(resource_path, opts = {}) { |response| ... } click to toggle source
# File lib/ctgb-ids-converter/remote_converter.rb, line 34
def self.run_request(resource_path, opts = {}, &block)
  request = Typhoeus::Request.new(get_uri(resource_path), opts)
  request.on_complete do |response|
    # puts response.request.base_url
    # puts response.response_body.class
    return yield(response)
  end
  CtgbIdsConverter.configuration.hydra.queue(request)
  CtgbIdsConverter.configuration.hydra.run
end
uri_host_part() click to toggle source
# File lib/ctgb-ids-converter/remote_converter.rb, line 49
def self.uri_host_part
  "http://#{CtgbIdsConverter.configuration.host}:#{CtgbIdsConverter.configuration.port}"
end
uri_token_part() click to toggle source
# File lib/ctgb-ids-converter/remote_converter.rb, line 53
def self.uri_token_part
  postfix = "token=#{CtgbIdsConverter.configuration.token}"
  postfix.insert(0, '?') unless postfix.start_with? '?'
end