Class: BundleUp::Unify::Calendar

Inherits:
Base
  • Object
show all
Defined in:
lib/bundleup/unify/calendar.rb,
sig/bundleup/unify/calendar.rbs

Overview

Client for Calendar-related Unify endpoints.

Constant Summary

Constants inherited from Base

Base::API_VERSION, Base::BASE_URL

Instance Attribute Summary

Attributes inherited from Base

#api_key, #connection_id

Instance Method Summary collapse

Methods inherited from Base

#connection, #initialize

Constructor Details

This class inherits a constructor from BundleUp::Unify::Base

Instance Method Details

#events(params = {}) ⇒ { data: Array[calendar_event], metadata: metadata }

Fetches events from the connected calendar provider.

params must carry starts_after and starts_before (ISO 8601) — the endpoint refuses an unbounded listing.

Parameters:

  • params (Hash[Symbol, untyped]) (defaults to: {})

Returns:

  • ({ data: Array[calendar_event], metadata: metadata })

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bundleup/unify/calendar.rb', line 11

def events(params = {})
  raise ArgumentError, 'starts_after and starts_before are required to fetch events.' if window_missing?(params)

  response = connection.get('calendar/events') do |req|
    req.params = params
  end

  raise "Failed to fetch calendar/events: #{response.status}" unless response.success?

  response.body
end

#window_missing?(params) ⇒ Boolean

Parameters:

  • (Hash[Symbol, untyped], nil)

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
# File 'lib/bundleup/unify/calendar.rb', line 25

def window_missing?(params)
  params ||= {}

  %i[starts_after starts_before].any? do |key|
    value = params[key] || params[key.to_s]
    value.nil? || value.to_s.empty?
  end
end