lib/bloodbath/event.rb in bloodbath-1.1.0 vs lib/bloodbath/event.rb in bloodbath-1.1.1

- old
+ new

@@ -1,11 +1,13 @@ # frozen_string_literal: true + require "net/http" require "pry" require "json" require_relative "utils/threading" +require_relative "utils/verbose" module Bloodbath module Adapters class Rest include Bloodbath::Utils::Threading @@ -34,12 +36,12 @@ def check_api_key raise Bloodbath::Error, "Please set your API key through Bloodbath.api_key = 'my-api-key'" unless config.api_key end - def asynchronously - threading { yield } + def asynchronously(&block) + threading(&block) end def synchronous_call_with_response http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.instance_of?(URI::HTTPS) @@ -48,10 +50,12 @@ request["Content-Type"] = "application/json" request.body = body.to_json response = http.request(request) serialized_response_from(response.body) + rescue Net::ReadTimeout, SocketError + raise Bloodbath::Error, "Bloodbath API is unavailable. Please check that your Internet connection is active." end def serialized_response_from(body) return {} if body.nil? @@ -88,9 +92,10 @@ module Bloodbath class Event class << self def method_missing(method_name, args = {}, &block) return new.send(method_name, &block) if args == {} + new.send(method_name, args, &block) end def respond_to_missing?(method_name, include_private = false) super