Class: Meeseeks::HTTPTrap
- Inherits:
-
Object
- Object
- Meeseeks::HTTPTrap
- Defined in:
- lib/meeseeks/http_trap.rb
Instance Attribute Summary collapse
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#submit_count ⇒ Object
readonly
Returns the value of attribute submit_count.
Instance Method Summary collapse
-
#initialize(data_submission_url) ⇒ HTTPTrap
constructor
A new instance of HTTPTrap.
- #stats ⇒ Object
- #submit(measurements) ⇒ Object
Constructor Details
#initialize(data_submission_url) ⇒ HTTPTrap
Returns a new instance of HTTPTrap.
11 12 13 14 |
# File 'lib/meeseeks/http_trap.rb', line 11 def initialize(data_submission_url) @uri = URI.parse(data_submission_url) @submit_count = 0 end |
Instance Attribute Details
#last ⇒ Object (readonly)
Returns the value of attribute last.
9 10 11 |
# File 'lib/meeseeks/http_trap.rb', line 9 def last @last end |
#submit_count ⇒ Object (readonly)
Returns the value of attribute submit_count.
9 10 11 |
# File 'lib/meeseeks/http_trap.rb', line 9 def submit_count @submit_count end |
Instance Method Details
#stats ⇒ Object
26 27 28 29 30 31 |
# File 'lib/meeseeks/http_trap.rb', line 26 def stats { submit_count: @submit_count, last_submit_at: @last&.time } end |
#submit(measurements) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/meeseeks/http_trap.rb', line 16 def submit(measurements) req = request(measurements) res = http.request(req) @last = OpenStruct.new(time: Time.now, request: req, response: res) @submit_count += 1 JSON.parse res.body end |