Class: Novu::Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Api::Topics

#add_subscribers, #create_topic, #delete_topic, #remove_subscribers, #rename_topic, #subscriber_topic, #topic, #topics

Methods included from Api::Tenants

#create_tenant, #delete_tenant, #tenant, #tenants, #update_tenant

Methods included from Api::Subscribers

#bulk_create_subscribers, #chat_oauth, #create_subscriber, #delete_subscriber, #delete_subscriber_credentials, #mark_all_subscriber_messages, #mark_message_action_seen, #mark_subscriber_feed_seen, #provider_oauth_redirect, #subscriber, #subscriber_notification_feed, #subscriber_preferences, #subscriber_unseen_notification_count, #subscribers, #update_subscriber, #update_subscriber_credentials, #update_subscriber_online_status, #update_subscriber_preference

Methods included from Api::Organizations

#create_organization, #current_organization, #current_organization_members, #delete_organization_member, #organization_branding, #organizations, #rename_organization

Methods included from Api::Notification

#notification, #notifications, #notifications_graph_stats, #notifications_stats

Methods included from Api::NotificationTemplates

#create_notification_template, #create_notification_template_blueprint, #delete_notification_template, #notification_template, #notification_template_blueprint, #notification_templates, #update_notification_template, #update_notification_template_status

Methods included from Api::NotificationGroups

#create_notification_group, #notification_groups

Methods included from Api::Messages

#delete_message, #messages

Methods included from Api::Layouts

#create_layout, #delete_layout, #layout, #layouts, #make_default_layout, #update_layout

Methods included from Api::Integrations

#active_integrations, #channel_limit, #create_integration, #delete_integration, #in_app_status, #integrations, #set_integration_as_primary, #update_integration, #webhook_provider_status

Methods included from Api::InboundParse

#validate_mx_record_setup_for_inbound_parse

Methods included from Api::Feeds

#create_feed, #delete_feed, #feeds

Methods included from Api::ExecutionDetails

#execution_details

Methods included from Api::Events

#broadcast_event, #cancel_triggered_event, #trigger_bulk_event, #trigger_event

Methods included from Api::Environments

#api_keys, #create_environment, #current_environment, #environments, #regenerate_api_keys, #update_environment, #update_widget_settings

Methods included from Api::Connection

#delete, #get, #patch, #post, #put

Methods included from Api::Changes

#apply_bulk_changes, #apply_change, #changes, #count_changes

Methods included from Api::Blueprints

#get_blueprint, #group_blueprints_by_category

Constructor Details

#initialize(access_token: nil, idempotency_key: nil, enable_retry: false, retry_config: {}, backend_url: "https://api.novu.co/v1") ⇒ Client

Returns a new instance of Client.

Parameters:

  • `access_token` (String)
  • `idempotency_key` (String)
  • `enable_retry` (Boolean)
  • `retry_config` (Hash)
    • max_retries [Integer]

    • initial_delay [Integer]

    • max_delay [Integer]



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/novu/client.rb', line 56

def initialize(access_token: nil, idempotency_key: nil, enable_retry: false, retry_config: {}, backend_url: "https://api.novu.co/v1")
  raise ArgumentError, "Api Key cannot be blank or nil" if access_token.blank?

  @idempotency_key = idempotency_key.blank? ? UUID.new.generate : idempotency_key

  @enable_retry = enable_retry
  @access_token = access_token.to_s.strip
  @retry_attempts = 0

  retry_config = defaults_retry_config.merge(retry_config)
  @max_retries = retry_config[:max_retries]
  @initial_delay = retry_config[:initial_delay]
  @max_delay = retry_config[:max_delay]

  self.class.base_uri(backend_url)

  self.class.default_options.merge!(headers: { 
	"Authorization" => "ApiKey #{@access_token}",
	"User-Agent" => "novu/ruby/#{Novu::VERSION}" 
}
			)

  # Configure the exponential backoff - specifying initial and maximal delays, default is 4s and 60s respectively
  if @enable_retry
    @retry_config = retry_config
    @backoff = ExponentialBackoff.new(@initial_delay, @max_delay)
  end
rescue ArgumentError => e
  puts "Error initializing Novu client: #{e.message}"
end

Instance Attribute Details

#enable_retryObject

Returns the value of attribute enable_retry.



47
48
49
# File 'lib/novu/client.rb', line 47

def enable_retry
  @enable_retry
end

#idempotency_keyObject

Returns the value of attribute idempotency_key.



47
48
49
# File 'lib/novu/client.rb', line 47

def idempotency_key
  @idempotency_key
end

#initial_delayObject

Returns the value of attribute initial_delay.



47
48
49
# File 'lib/novu/client.rb', line 47

def initial_delay
  @initial_delay
end

#max_delayObject

Returns the value of attribute max_delay.



47
48
49
# File 'lib/novu/client.rb', line 47

def max_delay
  @max_delay
end

#max_retriesObject

Returns the value of attribute max_retries.



47
48
49
# File 'lib/novu/client.rb', line 47

def max_retries
  @max_retries
end