Class: NotAnalyticsClient::Hit
- Inherits:
-
Object
- Object
- NotAnalyticsClient::Hit
- Defined in:
- lib/not_analytics_client/hit.rb
Instance Method Summary collapse
-
#initialize(app_id:, event: nil, key: nil) ⇒ Hit
constructor
A new instance of Hit.
- #payload ⇒ Object
- #post!(not_analytics_url:) ⇒ Object
Constructor Details
#initialize(app_id:, event: nil, key: nil) ⇒ Hit
Returns a new instance of Hit.
9 10 11 12 13 |
# File 'lib/not_analytics_client/hit.rb', line 9 def initialize(app_id:, event: nil, key: nil) @app_id = app_id @event = event @key = key end |
Instance Method Details
#payload ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/not_analytics_client/hit.rb', line 15 def payload { hit: { app_id: @app_id, event: @event, **auth_params, } }.to_json end |
#post!(not_analytics_url:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/not_analytics_client/hit.rb', line 25 def post!(not_analytics_url:) uri = URI(not_analytics_url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == 'https' request = Net::HTTP::Post.new(uri.request_uri, { 'Content-Type' => 'application/json' }) request.body = payload http.request(request) end |