class Reckoner::Cdp::API::StreamingCore
Constants
- STATUS
Public Class Methods
new(token, endpoint, client_id, connection)
click to toggle source
# File lib/reckoner/cdp/api/streaming_core.rb, line 21 def initialize(token, endpoint, client_id, connection) @endpoint = endpoint || Reckoner::Cdp::STREAMING_ENDPOINT @client_id = client_id || Reckoner::Cdp::STREAMING_CLIENT_ID @connection = connection || default_connection @token = token || "" end
Private Instance Methods
check_error(res)
click to toggle source
# File lib/reckoner/cdp/api/streaming_core.rb, line 43 def check_error(res) case res.status when STATUS[:unauthorized] raise Reckoner::Cdp::UnauthorizedError, res.body when STATUS[:client_error] raise Reckoner::Cdp::ClientError, res.body when STATUS[:server_error] raise Reckoner::Cdp::ServerError, res.body else nil end end
default_connection()
click to toggle source
# File lib/reckoner/cdp/api/streaming_core.rb, line 56 def default_connection opt = { headers: { Accept: 'application/json' }, url: @endpoint, request: { params_encoder: Faraday::NestedParamsEncoder } } @default_connection ||= Faraday.new(opt) do |conn| conn.request :json conn.response :json, content_type: /\b(json|javascript)$/ conn.adapter Faraday.default_adapter end end
get(path, params)
click to toggle source
# File lib/reckoner/cdp/api/streaming_core.rb, line 30 def get(path, params) res = @connection.get do |req| req.url path, params req.options.timeout = 5 req.options.open_timeout = 5 req.headers['Date'] = Time.now.httpdate req.headers['Content-Type'] = 'application/json' req.headers['Authorization'] = 'Bearer ' + @token end check_error(res) res.body end