Skip to content

Commit

Permalink
Merge pull request #46 from koshilife/feature/#45-support-noshow-apis
Browse files Browse the repository at this point in the history
support no show apis
  • Loading branch information
koshilife committed Apr 14, 2022
2 parents 07aed56 + 8ff8324 commit 42678a0
Show file tree
Hide file tree
Showing 31 changed files with 428 additions and 100 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# CHANGELOG

## 0.9.0 - 2022-04-14

- supported no show APIs. (#45)
- `GET /invitee_no_shows/{no_show_uuid}`
- `POST /invitee_no_shows`
- `DELETE /invitee_no_shows/{no_show_uuid}`
- changed files:
- Client
- (Add method) invitee_no_show
- (Add method) create_invitee_no_show
- (Add method) delete_invitee_no_show
- Invitee model
- (Add field) no_show
- (Add method) mark_no_show
- (Add method) unmark_no_show
- (New) InviteeNoShow model
- To simplify `require` statements changed `Model::ASSOCIATION` constant to class methods and removed unused lines.

## 0.8.3 - 2022-03-08

- support for filtering Event Types by 'active' or 'inactive' status. (#43)
Expand Down
1 change: 1 addition & 0 deletions calendly.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'codecov'
spec.add_development_dependency 'minitest'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'webmock'
end
2 changes: 2 additions & 0 deletions lib/calendly.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'calendly/client'
require 'calendly/models/model_utils'
Dir[
File.join(
File.dirname(__FILE__),
Expand Down
50 changes: 50 additions & 0 deletions lib/calendly/client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'oauth2'
require 'calendly/loggable'

module Calendly
# Calendly apis client.
Expand Down Expand Up @@ -281,6 +282,55 @@ def event_invitees(uuid, options: nil)
[evs, next_page_params(body)]
end

#
# Get Invitee No Show
# Returns information about a specified Invitee No Show.
#
# @param [String] uuid the specified no show.
# @return [Calendly::InviteeNoShow]
# @raise [Calendly::Error] if the uuid arg is empty.
# @raise [Calendly::ApiError] if the api returns error code.
# @since 0.9.0
def invitee_no_show(uuid)
check_not_empty uuid, 'uuid'
body = request :get, "invitee_no_shows/#{uuid}"
InviteeNoShow.new body[:resource], self
end

#
# Create Invitee No Show
# Marks an Invitee as a No Show.
#
# @param [String] invitee_uri the specified invitee's uri.
# @return [Calendly::InviteeNoShow]
# @raise [Calendly::Error] if the invitee_uri arg is empty.
# @raise [Calendly::ApiError] if the api returns error code.
# @since 0.9.0
def create_invitee_no_show(invitee_uri)
check_not_empty invitee_uri, 'invitee_uri'
body = request(
:post,
'invitee_no_shows',
body: {invitee: invitee_uri}
)
InviteeNoShow.new body[:resource], self
end

#
# Delete Invitee No Show
# Undoes marking an Invitee as a No Show.
#
# @param [String] uuid the specified no show.
# @return [true]
# @raise [Calendly::Error] if the uuid arg is empty.
# @raise [Calendly::ApiError] if the api returns error code.
# @since 0.9.0
def delete_invitee_no_show(uuid)
check_not_empty uuid, 'uuid'
request :delete, "invitee_no_shows/#{uuid}"
true
end

#
# Returns information about a user's organization membership
#
Expand Down
25 changes: 10 additions & 15 deletions lib/calendly/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
# frozen_string_literal: true

require 'calendly/client'
require 'calendly/models/model_utils'
require 'calendly/models/event_type'
require 'calendly/models/guest'
require 'calendly/models/invitee_cancellation'
require 'calendly/models/invitees_counter'
require 'calendly/models/location'

module Calendly
# Calendly's event model.
# A meeting that has been scheduled.
class Event
include ModelUtils
UUID_RE = %r{\A#{Client::API_HOST}/scheduled_events/(#{UUID_FORMAT})\z}.freeze
TIME_FIELDS = %i[start_time end_time created_at updated_at].freeze
ASSOCIATION = {
event_type: EventType,
event_guests: Guest,
cancellation: InviteeCancellation,
invitees_counter: InviteesCounter,
location: Location
}.freeze

def self.association
{
event_type: EventType,
event_guests: Guest,
cancellation: InviteeCancellation,
invitees_counter: InviteesCounter,
location: Location
}
end

# @return [String]
# unique id of the Event object.
Expand Down
13 changes: 7 additions & 6 deletions lib/calendly/models/event_type.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# frozen_string_literal: true

require 'calendly/client'
require 'calendly/models/model_utils'
require 'calendly/models/event_type_profile'
require 'calendly/models/event_type_custom_question'

module Calendly
# Calendly's event type model.
# A configuration for a schedulable event.
class EventType
include ModelUtils
UUID_RE = %r{\A#{Client::API_HOST}/event_types/(#{UUID_FORMAT})\z}.freeze
TIME_FIELDS = %i[created_at updated_at].freeze
ASSOCIATION = {profile: EventTypeProfile, custom_questions: EventTypeCustomQuestion}.freeze

def self.association
{
profile: EventTypeProfile,
custom_questions: EventTypeCustomQuestion
}
end

# @return [String]
# unique id of the EventType object.
Expand Down
2 changes: 0 additions & 2 deletions lib/calendly/models/event_type_custom_question.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'calendly/models/model_utils'

module Calendly
# Calendly's custom question model.
class EventTypeCustomQuestion
Expand Down
2 changes: 0 additions & 2 deletions lib/calendly/models/event_type_profile.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'calendly/models/model_utils'

module Calendly
# Calendly's event type profile model.
class EventTypeProfile
Expand Down
2 changes: 0 additions & 2 deletions lib/calendly/models/guest.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'calendly/models/model_utils'

module Calendly
# Calendly's guest model.
# Additional people added to an event by an invitee.
Expand Down
83 changes: 65 additions & 18 deletions lib/calendly/models/invitee.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
# frozen_string_literal: true

require 'calendly/client'
require 'calendly/models/model_utils'
require 'calendly/models/event'
require 'calendly/models/invitee_cancellation'
require 'calendly/models/invitee_payment'
require 'calendly/models/invitee_question_and_answer'
require 'calendly/models/invitee_tracking'

module Calendly
# Calendly's invitee model.
# An individual who has been invited to meet with a Calendly member.
class Invitee
include ModelUtils
UUID_RE = %r{\A#{Client::API_HOST}/scheduled_events/#{UUID_FORMAT}/invitees/(#{UUID_FORMAT})\z}.freeze
UUID_RE = %r{\A#{Client::API_HOST}/scheduled_events/(#{UUID_FORMAT})/invitees/(#{UUID_FORMAT})\z}.freeze
UUID_RE_INDEX = 2
TIME_FIELDS = %i[created_at updated_at].freeze
ASSOCIATION = {
event: Event,
cancellation: InviteeCancellation,
payment: InviteePayment,
questions_and_answers: InviteeQuestionAndAnswer,
tracking: InviteeTracking
}.freeze

def self.association
{
event: Event,
cancellation: InviteeCancellation,
payment: InviteePayment,
no_show: InviteeNoShow,
questions_and_answers: InviteeQuestionAndAnswer,
tracking: InviteeTracking
}
end

def self.extract_event_uuid(str)
m = extract_uuid_match str
return unless m

m[1]
end

# @return [String]
# unique id of the Invitee object.
Expand Down Expand Up @@ -96,6 +100,10 @@ class Invitee
# @return [InviteePayment] Invitee payment.
attr_accessor :payment

# @return [InviteeNoShow, nil]
# Provides data pertaining to the associated no show for the Invitee.
attr_accessor :no_show

# @return [Event]
# Reference to Event associated with this invitee.
attr_accessor :event
Expand All @@ -116,8 +124,47 @@ class Invitee
# @raise [Calendly::ApiError] if the api returns error code.
# @since 0.1.0
def fetch
ev_uuid = event.uuid if event
client.event_invitee ev_uuid, uuid
client.event_invitee event&.uuid, uuid
end

#
# Marks as a No Show.
# If already marked as a No Show, do nothing.
#
# @return [Calendly::InviteeNoShow]
# @raise [Calendly::Error] if the uri is empty.
# @raise [Calendly::ApiError] if the api returns error code.
# @since 0.9.0
def mark_no_show
return no_show if no_show

@no_show = client.create_invitee_no_show uri
end

#
# Unmarks as a No Show.
# If already unmarked as a No Show, do nothing.
#
# @return [true, nil]
# @raise [Calendly::Error] if the no_show.uuid is empty.
# @raise [Calendly::ApiError] if the api returns error code.
# @since 0.9.0
def unmark_no_show
return unless no_show

no_show.delete
@no_show = nil
true
end

private

def after_set_attributes(attrs)
super attrs
if event.nil? && attrs[:uri]
event_uuid = Invitee.extract_event_uuid attrs[:uri]
@event = Event.new({uuid: event_uuid}, @client) if event_uuid
end
end
end
end
2 changes: 0 additions & 2 deletions lib/calendly/models/invitee_cancellation.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'calendly/models/model_utils'

module Calendly
# Calendly's invitee cancellation model.
# Provides data pertaining to the cancellation of the Invitee.
Expand Down
54 changes: 54 additions & 0 deletions lib/calendly/models/invitee_no_show.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

module Calendly
# Calendly's invitee no show model.
class InviteeNoShow
include ModelUtils
UUID_RE = %r{\A#{Client::API_HOST}/invitee_no_shows/(#{UUID_FORMAT})\z}.freeze
TIME_FIELDS = %i[created_at].freeze

def self.association
{
invitee: Invitee
}
end

# @return [String]
# unique id of the InviteeNoShow object.
attr_accessor :uuid

# @return [String]
# Canonical reference (unique identifier) for the no show.
attr_accessor :uri

# @return [Time]
# The moment when the no show was created.
attr_accessor :created_at

# @return [Invitee, nil]
# The associated Invitee.
attr_accessor :invitee

#
# Get Invitee No Show associated with self.
#
# @return [Calendly::InviteeNoShow]
# @raise [Calendly::Error] if the uuid is empty.
# @raise [Calendly::ApiError] if the api returns error code.
# @since 0.9.0
def fetch
client.invitee_no_show uuid
end

#
# Unmarks as a No Show.
#
# @return [true]
# @raise [Calendly::Error] if the uuid is empty.
# @raise [Calendly::ApiError] if the api returns error code.
# @since 0.9.0
def delete
client.delete_invitee_no_show uuid
end
end
end
2 changes: 0 additions & 2 deletions lib/calendly/models/invitee_payment.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'calendly/models/model_utils'

module Calendly
# Calendly's invitee payment model.
class InviteePayment
Expand Down
2 changes: 0 additions & 2 deletions lib/calendly/models/invitee_question_and_answer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'calendly/models/model_utils'

module Calendly
# Calendly's question and answer model.
# An individual form question and response.
Expand Down
2 changes: 0 additions & 2 deletions lib/calendly/models/invitee_tracking.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'calendly/models/model_utils'

module Calendly
# Calendly's invitee tracking model.
# Object that represents UTM and Salesforce tracking parameters associated with the invitee.
Expand Down
2 changes: 0 additions & 2 deletions lib/calendly/models/invitees_counter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'calendly/models/model_utils'

module Calendly
# Calendly's invitees counter model.
class InviteesCounter
Expand Down

0 comments on commit 42678a0

Please sign in to comment.