Class: WebinarJam::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/webinarjam/client.rb

Overview

HTTP client for the WebinarJam / EverWebinar API.

Every endpoint is a POST with a form-encoded body and returns JSON, except unsubscribe which returns 204 No Content.

Constant Summary collapse

BASE_URL =
"https://api.webinarjam.com"
PRODUCTS =
%i[webinarjam everwebinar].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: ENV["WEBINARJAM_API_KEY"], product: :webinarjam, base_url: BASE_URL, open_timeout: 10, read_timeout: 30, max_retries: 0) ⇒ Client

Returns a new instance of Client.

Parameters:

  • api_key (String) (defaults to: ENV["WEBINARJAM_API_KEY"])

    account-wide API key (defaults to ENV)

  • product (Symbol) (defaults to: :webinarjam)

    :webinarjam or :everwebinar

  • max_retries (Integer) (defaults to: 0)

    automatic retries (with backoff) on HTTP 429

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/webinarjam/client.rb', line 21

def initialize(api_key: ENV["WEBINARJAM_API_KEY"], product: :webinarjam,
               base_url: BASE_URL, open_timeout: 10, read_timeout: 30,
               max_retries: 0)
  if api_key.nil? || api_key.to_s.empty?
    raise ConfigurationError,
          "api_key is required (pass api_key: or set ENV[\"WEBINARJAM_API_KEY\"])"
  end
  product = product.to_sym
  raise ArgumentError, "product must be one of #{PRODUCTS.inspect}" unless PRODUCTS.include?(product)

  @api_key = api_key
  @product = product
  @base_url = base_url
  @open_timeout = open_timeout
  @read_timeout = read_timeout
  @max_retries = max_retries
end

Instance Attribute Details

#max_retriesObject (readonly)

Returns the value of attribute max_retries.



16
17
18
# File 'lib/webinarjam/client.rb', line 16

def max_retries
  @max_retries
end

#productObject (readonly)

Returns the value of attribute product.



16
17
18
# File 'lib/webinarjam/client.rb', line 16

def product
  @product
end

Instance Method Details

#countriesHash

Retrieve the list of countries and states/provinces whose ids can be used in the country/state registration fields.

Returns:

  • (Hash)

    { status: "success", countries: [...] }



54
55
56
# File 'lib/webinarjam/client.rb', line 54

def countries
  post("countries")
end

#register(webinar_id:, first_name:, email:, schedule:, **params) ⇒ Hash

Register a user to a webinar.

Optional params include: last_name, country, state, timezone_id, ip_address, phone_country_code, phone, twilio_consent. EverWebinar additionally accepts date and timezone (e.g. "GMT-5"). Custom registration fields are passed by their label, as returned by #webinar.

Returns:

  • (Hash)

    { status: "success", user: ... }



65
66
67
68
69
# File 'lib/webinarjam/client.rb', line 65

def register(webinar_id:, first_name:, email:, schedule:, **params)
  post("register", params.merge(
    webinar_id: webinar_id, first_name: first_name, email: email, schedule: schedule
  ))
end

#registrants(webinar_id:, schedule_id:, **params) ⇒ Hash

Get a list of registrants and attendees for one webinar session.

Optional params include: attended_live, attended_replay, purchased, page, attended_live_timestamp, attended_replay_timestamp, date_range, search.

Returns:

  • (Hash)


77
78
79
# File 'lib/webinarjam/client.rb', line 77

def registrants(webinar_id:, schedule_id:, **params)
  post("registrants", params.merge(webinar_id: webinar_id, schedule_id: schedule_id))
end

#unsubscribe(webinar_id:, lead_id:) ⇒ true

Unsubscribe a lead from a webinar's notification queue.

Returns:

  • (true)

    the API responds with 204 No Content on success



83
84
85
86
# File 'lib/webinarjam/client.rb', line 83

def unsubscribe(webinar_id:, lead_id:)
  post("unsubscribe", webinar_id: webinar_id, lead_id: lead_id)
  true
end

#webinar(webinar_id) ⇒ Hash

Get details about one particular webinar.

Returns:

  • (Hash)

    { status: "success", webinar: ... }



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

def webinar(webinar_id)
  post("webinar", webinar_id: webinar_id)
end

#webinarsHash

Retrieve the full list of webinars published in the account.

Returns:

  • (Hash)

    { status: "success", webinars: [...] }



41
42
43
# File 'lib/webinarjam/client.rb', line 41

def webinars
  post("webinars")
end