Class: Justlogging::Transmitter
- Inherits:
-
Object
- Object
- Justlogging::Transmitter
- Defined in:
- lib/justlogging/transmitter.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
Instance Method Summary collapse
- #encoded_message(payload) ⇒ Object
-
#initialize(endpoint, action, api_key) ⇒ Transmitter
constructor
A new instance of Transmitter.
- #message(encoded_hash) ⇒ Object
- #transmit(payload) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(endpoint, action, api_key) ⇒ Transmitter
Returns a new instance of Transmitter.
10 11 12 13 14 |
# File 'lib/justlogging/transmitter.rb', line 10 def initialize(endpoint, action, api_key) @endpoint = endpoint @action = action @api_key = api_key end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
8 9 10 |
# File 'lib/justlogging/transmitter.rb', line 8 def action @action end |
#api_key ⇒ Object
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/justlogging/transmitter.rb', line 8 def api_key @api_key end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
8 9 10 |
# File 'lib/justlogging/transmitter.rb', line 8 def endpoint @endpoint end |
Instance Method Details
#encoded_message(payload) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/justlogging/transmitter.rb', line 29 def (payload) encoded_payload = {}.tap do |hsh| payload.each do |key, val| hsh[key] = ActiveSupport::JSON.encode(val) end end (encoded_payload) end |
#message(encoded_hash) ⇒ Object
38 39 40 41 42 |
# File 'lib/justlogging/transmitter.rb', line 38 def (encoded_hash) Net::HTTP::Post.new(uri.request_uri).tap do |post| post.set_form_data({'api_key' => api_key}.merge(encoded_hash)) end end |
#transmit(payload) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/justlogging/transmitter.rb', line 20 def transmit(payload) begin result = http_client.request((payload)) result.code rescue nil end end |
#uri ⇒ Object
16 17 18 |
# File 'lib/justlogging/transmitter.rb', line 16 def uri URI("#{@endpoint}/#{@action}") end |