Class: ApiBomb::Fighter

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/api_bomb/fighter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths: nil, base_url: nil, options: {}) ⇒ Fighter

Returns a new instance of Fighter.



6
7
8
9
10
# File 'lib/api_bomb/fighter.rb', line 6

def initialize(paths: nil, base_url: nil, options: {})
  @base_url = base_url
  @options = options
  @paths = paths
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



4
5
6
# File 'lib/api_bomb/fighter.rb', line 4

def base_url
  @base_url
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/api_bomb/fighter.rb', line 4

def options
  @options
end

#pathsObject (readonly)

Returns the value of attribute paths.



4
5
6
# File 'lib/api_bomb/fighter.rb', line 4

def paths
  @paths
end

Instance Method Details

#fireObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/api_bomb/fighter.rb', line 12

def fire
  route = @paths.pick

  url = URI::join(base_url, route.path)
  response = nil
  hold_time = Benchmark.measure do
    response = HTTP.send(
      route.action,
      url,
      ApiBomb::LambdaHash.hasharize(options.merge(route.options))
    )
  end

  return OpenStruct.new(response: response, hold_time: hold_time.real)
end