Class: Egg::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/egg-notifier/version.rb,
lib/egg-notifier/egg/notifier.rb,
lib/egg-notifier/egg/exceptions.rb

Defined Under Namespace

Classes: HTTPFailure

Constant Summary collapse

VERSION =
"0.0.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_name, timestamp = Time.now) ⇒ Notifier

Returns a new instance of Notifier.



8
9
10
11
12
13
# File 'lib/egg-notifier/egg/notifier.rb', line 8

def initialize(event_name, timestamp=Time.now)
  @event_name = event_name

  timestamp = Time.parse(timestamp.to_s) unless timestamp.respond_to?(:utc)
  @timestamp = timestamp.utc.iso8601
end

Instance Attribute Details

#event_nameObject

Returns the value of attribute event_name.



6
7
8
# File 'lib/egg-notifier/egg/notifier.rb', line 6

def event_name
  @event_name
end

#timestampObject

Returns the value of attribute timestamp.



6
7
8
# File 'lib/egg-notifier/egg/notifier.rb', line 6

def timestamp
  @timestamp
end

Instance Method Details

#execute!Object

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/egg-notifier/egg/notifier.rb', line 15

def execute!
  raise APIKeyNotDefined unless Egg.api_key
  raise UrlNotDefined    unless Egg.url

  response = self.class.http.post(url.path, params.to_json, headers)

  if Egg.raise_on_failure and !response.kind_of?(Net::HTTPSuccess)
    if response
      raise HTTPFailure.new("#{response.code}: #{response.body}")
    else
      raise HTTPFailure.new("nil HTTP response, that's odd.")
    end
  end

  response
end