Class: Radd::Update
- Inherits:
-
Object
- Object
- Radd::Update
- Defined in:
- lib/radd/update.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(env) ⇒ Update
constructor
A new instance of Update.
- #ip ⇒ Object
- #record ⇒ Object
Constructor Details
#initialize(env) ⇒ Update
Returns a new instance of Update.
9 10 11 |
# File 'lib/radd/update.rb', line 9 def initialize(env) @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
3 4 5 |
# File 'lib/radd/update.rb', line 3 def env @env end |
Class Method Details
.call(env) ⇒ Object
5 6 7 |
# File 'lib/radd/update.rb', line 5 def self.call(env) new(env).call end |
Instance Method Details
#call ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/radd/update.rb', line 22 def call raise Forbidden unless record raise InvalidRequest.new('Invalid IP address') unless ip record.ip = ip record.save [200, {'Content-Type' => 'text/plain'}, ["OK #{ip}"]] rescue RaddError => boom status = case boom when InvalidRequest, Sequel::ValidationFailed then 422 when Forbidden then 403 else 500 end respond status, "ERROR #{boom.}" rescue Exception => e respond 500, "ERROR" end |
#ip ⇒ Object
17 18 19 20 |
# File 'lib/radd/update.rb', line 17 def ip addr = env['REMOTE_ADDR'] addr && Radd.valid_ip?(addr) && addr end |
#record ⇒ Object
13 14 15 |
# File 'lib/radd/update.rb', line 13 def record @record ||= Record.where(name: name).first end |