Sha256: 0f90849e957634b13cece44dcfbffa868cb3b701dc81044ba957f2053457d8b7

Contents?: true

Size: 1.79 KB

Versions: 4

Compression:

Stored size: 1.79 KB

Contents

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
            response = RestClient.get "#{@datahub_base_url}/status-counts"
            response.body
        end

        def compositions(pool_name='GLOBAL')
            response = RestClient.get "#{@datahub_base_url}/pools/#{pool_name}/compositions"
            response.body
        end

        def publications(pool_name='GLOBAL')
            response = RestClient.get "#{@datahub_base_url}/pools/#{pool_name}/publications"
            response.body
        end

        #POST

        def load_data(file, feed_name='DEFAULT_FEED', raw_item_name)
            data = File.new(file, 'rb')
            http_post "#{@datahub_base_url}/data-feeds/#{feed_name}/items/#{raw_item_name}", data, content_type: 'application/octet-stream'
        end

        def start_composition(pool_name='GLOBAL')
            http_post "#{@datahub_base_url}/pools/#{pool_name}/compositions"
        end

        def start_publication(pool_name='GLOBAL', target_system)
            json_payload = {targetSystemPublications: [
                {targetSystemName: target_system}
            ]}.to_json
            http_post "#{@datahub_base_url}/pools/#{pool_name}/publications", json_payload, {content_type: :json, accept: :json}
        end

        private

        def http_post(url, payload={}, headers={})
            RestClient.post url, payload, headers
        end
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dhclient-0.1.3 lib/dhclient/datahub.rb
dhclient-0.1.2 lib/dhclient/datahub.rb
dhclient-0.1.1 lib/dhclient/datahub.rb
dhclient-0.1.0 lib/dhclient/datahub.rb