Class: DummyOscar::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dummy_oscar/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_file:, host:, command:, library: nil) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
# File 'lib/dummy_oscar/client.rb', line 7

def initialize(config_file:, host:, command:, library: nil)
  raise DummyOscar::ArgumentError, "Pleaes specify command argument." if command.nil?

  @command = command
  @commands = {}
  @host = host
  parse_config_file(config_file: config_file, library: library)
end

Instance Method Details

#startObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dummy_oscar/client.rb', line 16

def start
  request = @commands[@command]
  raise DummyOscar::ArgumentError, "'#{@command}' did not find." if request.nil?

  request_options = {}
  request_options[:body] = request["body"] unless request["body"].nil?
  request_options[:query] = request["query"] unless request["query"].nil?

  response = HTTParty.public_send(request["method"].downcase, URI.join(@host, request["path"]).to_s, request_options)
  $stdout.puts response.body
end