Class: LittleBlueFox::Client
- Inherits:
-
Object
- Object
- LittleBlueFox::Client
- Defined in:
- lib/littlebluefox/client.rb
Instance Attribute Summary collapse
-
#endpoint_url ⇒ Object
readonly
Returns the value of attribute endpoint_url.
Instance Method Summary collapse
-
#initialize(access_token, endpoint_url = DefaultEndpointUrl) ⇒ Client
constructor
A new instance of Client.
- #push(event) ⇒ Object
Constructor Details
#initialize(access_token, endpoint_url = DefaultEndpointUrl) ⇒ Client
Returns a new instance of Client.
10 11 12 13 |
# File 'lib/littlebluefox/client.rb', line 10 def initialize(access_token, endpoint_url = DefaultEndpointUrl) @access_token = access_token @endpoint_url = endpoint_url end |
Instance Attribute Details
#endpoint_url ⇒ Object (readonly)
Returns the value of attribute endpoint_url.
8 9 10 |
# File 'lib/littlebluefox/client.rb', line 8 def endpoint_url @endpoint_url end |
Instance Method Details
#push(event) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/littlebluefox/client.rb', line 15 def push(event) http = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port) http.use_ssl = true if endpoint_uri.port == 443 req = Net::HTTP::Post.new("/") req["Content-Type"] = "application/json" req["Authorization"] = "Bearer: #{@access_token}" req.body = event.to_json resp = http.request(req) if resp.code == '' raise UnexpectedResponseCode.new(ExpectedResponseCode, nil) end status_code = resp.code.to_i case status_code when 200..299 return true else raise UnexpectedResponseCode.new(ExpectedResponseCode, status_code) end end |