module DHClient class Datahub def initialize(base_url="http://localhost:8080/datahub-webapp/v1", username="admin", password="nimda") uri = URI.parse(base_url) @datahub_base_url = "#{uri.scheme}://#{username}:#{password}@#{uri.host}:#{uri.port}#{uri.path}" end #GET def version response = ::RestClient.get "#{@datahub_base_url}/version" response.body end def status(opts={}) response = RestClient.get "#{@datahub_base_url}/status-counts", {}, accept: opts[:format] ||:json response.body end def compositions(pool_name='GLOBAL', opts) response = RestClient.get "#{@datahub_base_url}/pools/#{pool_name}/compositions", {}, accept: opts[:format] ||:json response.body end def publications(pool_name='GLOBAL', opts) response = RestClient.get "#{@datahub_base_url}/pools/#{pool_name}/publications", {}, accept: opts[:format] ||:json response.body end #POST def load_data(file, feed_name='DEFAULT_FEED', raw_item_name, opts) data = File.new(file, 'rb') http_post "#{@datahub_base_url}/data-feeds/#{feed_name}/items/#{raw_item_name}", data, content_type: 'application/octet-stream', accept: opts[:format] ||:json end def start_composition(pool_name='GLOBAL', opts) http_post "#{@datahub_base_url}/pools/#{pool_name}/compositions", {}, {accept: opts[:format]||:json} end def start_publication(pool_name='GLOBAL', target_system, opts) json_payload = {targetSystemPublications: [ {targetSystemName: target_system} ]}.to_json http_post "#{@datahub_base_url}/pools/#{pool_name}/publications", json_payload, {content_type: :json, accept: opts[:format]||:json} end private def http_post(url, payload={}, headers={}) RestClient.post url, payload, headers end end end