Class: EventifyPro::Client
- Inherits:
-
Object
- Object
- EventifyPro::Client
- Defined in:
- lib/eventify_pro/client.rb
Overview
EventifyPro::Client allows to publish events.
To instantiate very basic client use this code: ‘client = EventifyPro::Client.new(api_key: ’personal_api_key’)‘ Then use it this way: `client.publish(type: ’OrderPosted’, data: { order_id: 10, amount: 3000 })‘
Configuration
raise_errors: By default client will not throw any exception. publish will return either true or false depending on the result of publishing. It’s possible to configure client to throw an EventifyPro::Error if exception wasn’t published. ‘EventifyPro::Client.new(api_key: ’personal_api_key’, raise_errors: true)‘
logger: By default client will write errors to STDOUT, but it’s possible to pass any custom logger that responds to .info(message): ‘EventifyPro::Client.new(api_key: ’personal_api_key’, logger: Rails.logger)‘
Constant Summary collapse
- BASE_URI =
'http://api.eventify.pro/v1'
Instance Method Summary collapse
-
#initialize(api_key: nil, raise_errors: false, logger: EventifyPro::DefaultLogger.new) ⇒ Client
constructor
rubocop:disable LineLength.
- #publish(type:, data:) ⇒ Object
Constructor Details
#initialize(api_key: nil, raise_errors: false, logger: EventifyPro::DefaultLogger.new) ⇒ Client
rubocop:disable LineLength
35 36 37 38 39 40 41 |
# File 'lib/eventify_pro/client.rb', line 35 def initialize(api_key: nil, raise_errors: false, logger: EventifyPro::DefaultLogger.new) # rubocop:disable LineLength @api_key = api_key || ENV['EVENTIFY_PRO_API_KEY'] validate_api_key_presence! @raise_errors = raise_errors @logger = logger end |
Instance Method Details
#publish(type:, data:) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/eventify_pro/client.rb', line 43 def publish(type:, data:) response = post_request('events', type, data) = response['error_message'] || '' raise Error, unless .empty? true rescue => e process_error(e, 'publish', type: type, data: data) false end |