Class: Dodgeball::Client

Inherits:
Object
  • Object
show all
Includes:
Logging, Logging, Utils
Defined in:
lib/dodgeball/client.rb,
lib/dodgeball/client/utils.rb,
lib/dodgeball/client/logging.rb,
lib/dodgeball/client/request.rb,
lib/dodgeball/client/version.rb,
lib/dodgeball/client/defaults.rb,
lib/dodgeball/client/response.rb,
lib/dodgeball/client/backoff_policy.rb

Defined Under Namespace

Modules: Defaults, Logging, Utils Classes: BackoffPolicy, PrefixedLogger, Request, Response

Constant Summary collapse

VERSION =
'0.0.1'

Constants included from Utils

Utils::UTC_OFFSET_WITHOUT_COLON, Utils::UTC_OFFSET_WITH_COLON

Instance Method Summary collapse

Methods included from Logging

included, #logger

Methods included from Utils

#date_in_iso8601, #datetime_in_iso8601, #formatted_offset, #isoify_dates, #isoify_dates!, #seconds_to_utc_offset, #stringify_keys, #symbolize_keys, #symbolize_keys!, #time_in_iso8601, #uid

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :write_key (String)

    Your project's write_key

  • :dodgeball_api_url (String)

    Your Dodgeball API URL

  • :on_error (Proc)

    Handles error calls from the API.

  • :ssl (Boolean)

    Whether to send the call via SSL

  • :stub (Boolean)

    Whether to cause all requests to be stubbed, making it easier to test



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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

Instance Method Details

#verify(event, source_id, verification_id = nil, sync = true) ⇒ Object

Verifies an event and executes a workflow

Parameters:

  • attrs (Hash)

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
56
57
58
# 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