Class: IntellisenseRuby::Request
- Inherits:
-
Object
- Object
- IntellisenseRuby::Request
- Defined in:
- lib/intellisense-ruby/request.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Request
constructor
public: Creates a new request object to send analytics batch.
-
#post(secret, batch) ⇒ Object
public: Posts the secret and batch of messages to the API.
Constructor Details
#initialize(options = {}) ⇒ Request
public: Creates a new request object to send analytics batch
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/intellisense-ruby/request.rb', line 14 def initialize( = {}) [:url] ||= IntellisenseRuby::Defaults::Request::BASE_URL [:ssl] ||= IntellisenseRuby::Defaults::Request::SSL [:headers] ||= IntellisenseRuby::Defaults::Request::HEADERS @path = [:path] || IntellisenseRuby::Defaults::Request::PATH @conn = Faraday.new() do |faraday| faraday.request :json faraday.response :json, :content_type => /\bjson$/ faraday.adapter Faraday.default_adapter end end |
Instance Method Details
#post(secret, batch) ⇒ Object
public: Posts the secret and batch of messages to the API.
returns - Response of the status and error if it exists
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/intellisense-ruby/request.rb', line 31 def post(secret, batch) status, error = nil, nil begin res = @conn.post do |req| req.[:timeout] = 8 req.[:open_timeout] = 3 req.url(@path) req.body = IntellisenseRuby::JSON::dump(secret: secret, batch: batch) end status = res.status error = res.body["error"] rescue Exception => err status = -1 error = "Connection error: #{err}" end IntellisenseRuby::Response.new(status, error) end |