Class: Tightknit::Resources::CalendarEvents
- Inherits:
-
Object
- Object
- Tightknit::Resources::CalendarEvents
- Defined in:
- lib/tightknit/resources/calendar_events.rb
Overview
The CalendarEvents class provides methods for interacting with the calendar events API. It allows listing, creating, updating, and deleting calendar events.
Instance Method Summary collapse
-
#all(options = {}) ⇒ Hash
Get both past and upcoming events.
-
#format_data(event_data) ⇒ Hash
Format event data for the API.
-
#get(event_id) ⇒ Hash
Get a specific calendar event.
-
#initialize(client) ⇒ CalendarEvents
constructor
Initialize a new CalendarEvents resource.
-
#list(options = {}) ⇒ Hash
Get a list of calendar events.
Constructor Details
#initialize(client) ⇒ CalendarEvents
Initialize a new CalendarEvents resource
22 23 24 |
# File 'lib/tightknit/resources/calendar_events.rb', line 22 def initialize(client) @client = client end |
Instance Method Details
#all(options = {}) ⇒ Hash
Get both past and upcoming events
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 86 87 88 89 90 91 92 93 94 |
# File 'lib/tightknit/resources/calendar_events.rb', line 59 def all( = {}) # Get upcoming events = .dup [:time_filter] = "upcoming" upcoming_response = list() # Get past events = .dup [:time_filter] = "past" past_response = list() # Combine the results if upcoming_response[:success] && past_response[:success] combined_records = [] if upcoming_response[:data] && upcoming_response[:data][:records] combined_records += upcoming_response[:data][:records] end if past_response[:data] && past_response[:data][:records] combined_records += past_response[:data][:records] end # Create a combined response with the same structure { success: true, data: { records: combined_records, total: combined_records.length } } else # If either request failed, return the successful one or the first error upcoming_response[:success] ? upcoming_response : past_response end end |
#format_data(event_data) ⇒ Hash
Format event data for the API
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/tightknit/resources/calendar_events.rb', line 110 def format_data(event_data) # Create a new hash to avoid modifying the original formatted = event_data.dup # Format description if it's a string if formatted[:description].is_a?(String) formatted[:description] = {text: formatted[:description]} end # Format recap if it's a string if formatted[:recap].is_a?(String) formatted[:recap] = {text: formatted[:recap]} end # Format hosts if it's an array of IDs if formatted[:hosts].is_a?(Array) formatted[:hosts] = {slack_user_ids: formatted[:hosts]} end # Format speakers if it's an array of IDs if formatted[:speakers].is_a?(Array) formatted[:speakers] = {slack_user_ids: formatted[:speakers]} end formatted end |
#get(event_id) ⇒ Hash
Get a specific calendar event
101 102 103 |
# File 'lib/tightknit/resources/calendar_events.rb', line 101 def get(event_id) @client.get("calendar_events/#{event_id}") end |
#list(options = {}) ⇒ Hash
Get a list of calendar events
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tightknit/resources/calendar_events.rb', line 34 def list( = {}) page = [:page] || 0 per_page = [:per_page] || 10 time_filter = [:time_filter] status = [:status] || "published" params = { page: page, per_page: per_page, status: status } # Only add time_filter to params if it's specified params[:time_filter] = time_filter if time_filter @client.get("calendar_events", params) end |