class Dodgeball::Client
Constants
- VERSION
Public Class Methods
@param [Hash] opts @option opts [String] :write_key Your project’s write_key @option opts [String] :dodgeball_api_url Your Dodgeball
API URL @option opts [Proc] :on_error Handles error calls from the API. @option opts [Boolean] :ssl Whether to send the call via SSL @option opts [Boolean] :stub Whether to cause all requests to be stubbed, making it easier to test
# File lib/dodgeball/client.rb, line 25 def initialize(opts = {}) symbolize_keys!(opts) Request.stub = opts[:stub] if opts.has_key?(:stub) @write_key = opts[:write_key] @dodgeball_api_url = opts[:dodgeball_api_url] || Defaults::Request::DODGEBALL_API_URL uri = URI(opts[:dodgeball_api_url]) @host = uri.host @port = uri.port @on_error = opts[:on_error] || proc { |status, error| } @ssl = opts[:ssl] || Defaults::Request::SSL check_write_key! end
Public Instance Methods
Verifies an event and executes a workflow
@param [Hash] attrs
@option attrs [Hash] :event Any input to pass to the workflow (required) @option attrs [String] :source_id Id of the user from the client(required) @option attrs [Boolean] :sync Direction to the API to return immediately or wait until the workflow returns its first resolution. @option attrs [String] :verification_id if there was a previous verification executed in the client (optional)
# File lib/dodgeball/client.rb, line 49 def verify(event,source_id,verification_id=nil, sync=true) raise ArgumentError.new('No event provided') unless event raise ArgumentError.new('No source_id provided') unless source_id request_headers={} request_headers[Defaults::Request::SOURCE_ID_HEADER] = source_id request_headers[Defaults::Request::VERIFICATION_ID_HEADER] = verification_id if verification_id body = {event: event, options: {sync: sync}} res=execute_request('verify', body, request_headers) res end
Private Instance Methods
private: Checks that the write_key is properly initialized
# File lib/dodgeball/client.rb, line 80 def check_write_key! raise ArgumentError, 'Write key must be initialized' if @write_key.nil? end
private: Executes a request with common code to handle results.
# File lib/dodgeball/client.rb, line 65 def execute_request(request_function, body, request_specific_headers) path=generate_path(request_function) res = Request.new(:dodgeball_api_url => @dodgeball_api_url, :ssl => @ssl).post(@write_key, path, body, request_specific_headers) @on_error.call(res.status, res.response_body) unless res.status == 200 res end
private: Adds the correct path root
@param [String] Function name to build into a path
# File lib/dodgeball/client.rb, line 75 def generate_path(request_function) Defaults::Request::PATH_ROOT + request_function end