Class: CSVPP::FormatsClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/csvpp/formats_client.rb

Constant Summary collapse

DEFAULT_HOST =
'http://formats.iapps.swissdrg.local'

Instance Method Summary collapse

Constructor Details

#initialize(host: DEFAULT_HOST) ⇒ FormatsClient

Returns a new instance of FormatsClient.



11
12
13
# File 'lib/csvpp/formats_client.rb', line 11

def initialize(host: DEFAULT_HOST)
  self.class.base_uri ENV['FORMATS_HOST'] || host
end

Instance Method Details

#base_uriString

Returns e.g. “formats.iapps.swissdrg.local”.

Returns:



16
17
18
# File 'lib/csvpp/formats_client.rb', line 16

def base_uri
  self.class.base_uri
end

#format(name) ⇒ Format

Parameters:

  • name (String)

Returns:



27
28
29
30
31
32
33
34
35
# File 'lib/csvpp/formats_client.rb', line 27

def format(name)
  response = self.class.get("/api/formats/#{name}")

  if (error = response['error'])
    raise ArgumentError, %{#{error} "#{name}"}
  end

  Format.new(response)
end

#formatsArray<Format>

Returns:



21
22
23
# File 'lib/csvpp/formats_client.rb', line 21

def formats
  self.class.get('/api/formats').map { |hash| Format.new(hash) }
end