Class: ROM::HTTP::Gateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/rom/http/gateway.rb

Overview

HTTP gateway

Examples:

config = {
  uri: 'http://jsonplaceholder.typicode.com',
  headers: { Accept: 'applicaiton/json' }
}

gateway = ROM::HTTP::Gateway.new(config)
users   = gateway.dataset(:users)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Gateway

HTTP gateway interface

Parameters:

  • config (Hash)

    configuration options @option config [String] :uri The base API for the HTTP service @option config [Hash] :headers Default request headers

See Also:



37
38
39
40
# File 'lib/rom/http/gateway.rb', line 37

def initialize(config)
  @datasets = Concurrent::Map.new
  @config = config
end

Instance Attribute Details

#configObject (readonly)



26
27
28
# File 'lib/rom/http/gateway.rb', line 26

def config
  @config
end

#datasetsObject (readonly)



26
27
28
# File 'lib/rom/http/gateway.rb', line 26

def datasets
  @datasets
end

Instance Method Details

#[](name) ⇒ Dataset

Retrieve dataset with the given name

Parameters:

  • name (String)

    dataaset name

Returns:



49
50
51
# File 'lib/rom/http/gateway.rb', line 49

def [](name)
  datasets.fetch(name)
end

#dataset(name) ⇒ Dataset

Build dataset with the given name

Parameters:

  • name (String)

    dataaset name

Returns:



60
61
62
# File 'lib/rom/http/gateway.rb', line 60

def dataset(name)
  datasets[name] = dataset_class.new(**dataset_options(name))
end

#dataset?(name) ⇒ Boolean

Check if dataset exists

Parameters:

  • name (String)

    dataset name

Returns:

  • (Boolean)


69
70
71
# File 'lib/rom/http/gateway.rb', line 69

def dataset?(name)
  datasets.key?(name)
end