Class: Waffle::Maker::Api::Alert

Inherits:
Base
  • Object
show all
Defined in:
lib/waffle/maker/api/alert.rb

Constant Summary collapse

API_PATH =
'/api/v1/alert'

Constants inherited from Base

Base::FORCE_ENCODING

Instance Attribute Summary collapse

Attributes inherited from Base

#headers

Instance Method Summary collapse

Methods inherited from Base

#body_in_hash_format, #body_in_json_format, #get, #http

Constructor Details

#initialize(time_order: nil, from: nil, to: nil, ip: nil, marker: nil) ⇒ Alert

Returns a new instance of Alert.



10
11
12
13
14
15
16
# File 'lib/waffle/maker/api/alert.rb', line 10

def initialize(time_order: nil, from: nil, to: nil, ip: nil, marker: nil)
  @time_order = time_order
  @from = from
  @to = to
  @ip = ip
  @marker = marker
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



8
9
10
# File 'lib/waffle/maker/api/alert.rb', line 8

def from
  @from
end

#ipObject (readonly)

Returns the value of attribute ip.



8
9
10
# File 'lib/waffle/maker/api/alert.rb', line 8

def ip
  @ip
end

#markerObject (readonly)

Returns the value of attribute marker.



8
9
10
# File 'lib/waffle/maker/api/alert.rb', line 8

def marker
  @marker
end

#time_orderObject (readonly)

Returns the value of attribute time_order.



8
9
10
# File 'lib/waffle/maker/api/alert.rb', line 8

def time_order
  @time_order
end

#toObject (readonly)

Returns the value of attribute to.



8
9
10
# File 'lib/waffle/maker/api/alert.rb', line 8

def to
  @to
end

Instance Method Details

#executeObject



18
19
20
# File 'lib/waffle/maker/api/alert.rb', line 18

def execute
  body_in_hash_format
end

#matched_with_routesObject



22
23
24
25
26
# File 'lib/waffle/maker/api/alert.rb', line 22

def matched_with_routes
  body_in_hash_format.tap do |body|
    body['data'].select! { |d| Waffle::Maker::Matcher.new(d['uri'], routes).matched? }
  end
end

#urlObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/waffle/maker/api/alert.rb', line 28

def url
  return @url if @url

  url_string = "#{config.api_host}#{API_PATH}?host=#{config.host}&id=#{config.id}"
  url_string = "#{url_string}&time_order=#{@time_order}" if @time_order
  url_string = "#{url_string}&from=#{@from}" if @from
  url_string = "#{url_string}&to=#{@to}" if @to
  url_string = "#{url_string}&ip=#{@ip}" if @ip
  url_string = "#{url_string}&marker=#{@marker}" if @marker

  @url = URI.parse(url_string)
end