calendly 0.4.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,19 +7,24 @@ module Calendly
7
7
  class Configuration
8
8
  # @return [String]
9
9
  attr_accessor :client_id
10
+
10
11
  # @return [String]
11
12
  attr_accessor :client_secret
13
+
12
14
  # @return [String]
13
15
  attr_accessor :token
16
+
14
17
  # @return [String]
15
18
  attr_accessor :refresh_token
19
+
16
20
  # @return [Integer]
17
21
  attr_accessor :token_expires_at
22
+
18
23
  # @return [Logger]
19
24
  attr_accessor :logger
20
25
 
21
26
  def initialize
22
- @logger = Logger.new STDOUT
27
+ @logger = Logger.new $stdout
23
28
  @logger.level = :warn
24
29
  end
25
30
  end
@@ -3,37 +3,52 @@
3
3
  require 'calendly/client'
4
4
  require 'calendly/models/model_utils'
5
5
  require 'calendly/models/event_type'
6
+ require 'calendly/models/guest'
7
+ require 'calendly/models/invitees_counter'
8
+ require 'calendly/models/location'
6
9
 
7
10
  module Calendly
8
11
  # Calendly's event model.
9
- # A meeting that has been scheduled
12
+ # A meeting that has been scheduled.
10
13
  class Event
11
14
  include ModelUtils
12
15
  UUID_RE = %r{\A#{Client::API_HOST}/scheduled_events/(\w+)\z}.freeze
13
16
  TIME_FIELDS = %i[start_time end_time created_at updated_at].freeze
14
- ASSOCIATION = {event_type: EventType}.freeze
17
+ ASSOCIATION = {
18
+ event_type: EventType,
19
+ event_guests: Guest,
20
+ invitees_counter: InviteesCounter,
21
+ location: Location
22
+ }.freeze
15
23
 
16
24
  # @return [String]
17
25
  # unique id of the Event object.
18
26
  attr_accessor :uuid
27
+
19
28
  # @return [String]
20
29
  # Canonical resource reference.
21
30
  attr_accessor :uri
31
+
22
32
  # @return [String]
23
33
  # Name of the event.
24
34
  attr_accessor :name
35
+
25
36
  # @return [String]
26
37
  # Whether the event is active or canceled.
27
38
  attr_accessor :status
39
+
28
40
  # @return [Time]
29
41
  # Moment when event is (or was) scheduled to begin.
30
42
  attr_accessor :start_time
43
+
31
44
  # @return [Time]
32
45
  # Moment when event is (or was) scheduled to end.
33
46
  attr_accessor :end_time
47
+
34
48
  # @return [Time]
35
49
  # Moment when user record was first created.
36
50
  attr_accessor :created_at
51
+
37
52
  # @return [Time]
38
53
  # Moment when user record was last updated.
39
54
  attr_accessor :updated_at
@@ -46,15 +61,17 @@ module Calendly
46
61
  # location in this event.
47
62
  attr_accessor :location
48
63
 
49
- # @return [Integer]
50
- # number of total invitees in this event.
51
- attr_accessor :invitees_counter_total
52
- # @return [Integer]
53
- # number of active invitees in this event.
54
- attr_accessor :invitees_counter_active
55
- # @return [Integer]
56
- # max invitees in this event.
57
- attr_accessor :invitees_counter_limit
64
+ # @return [InviteesCounter]
65
+ # invitees counter.
66
+ attr_accessor :invitees_counter
67
+
68
+ # @return [Array<User>]
69
+ # Event membership list.
70
+ attr_accessor :event_memberships
71
+
72
+ # @return [Array<Guest>]
73
+ # Additional people added to an event by an invitee.
74
+ attr_accessor :event_guests
58
75
 
59
76
  #
60
77
  # Get Scheduled Event associated with self.
@@ -83,7 +100,7 @@ module Calendly
83
100
  # @raise [Calendly::ApiError] if the api returns error code.
84
101
  # @since 0.1.0
85
102
  def invitees(opts = {})
86
- return @cached_invitees if @cached_invitees
103
+ return @cached_invitees if defined?(@cached_invitees) && @cached_invitees
87
104
 
88
105
  request_proc = proc { |options| client.event_invitees uuid, options }
89
106
  @cached_invitees = auto_pagination request_proc, opts
@@ -99,16 +116,12 @@ module Calendly
99
116
 
100
117
  def after_set_attributes(attrs)
101
118
  super attrs
102
- loc_params = attrs[:location]
103
- @location = Location.new loc_params if loc_params&.is_a? Hash
104
-
105
- inv_cnt_attrs = attrs[:invitees_counter]
106
- return unless inv_cnt_attrs
107
- return unless inv_cnt_attrs.is_a? Hash
108
-
109
- @invitees_counter_total = inv_cnt_attrs[:total]
110
- @invitees_counter_active = inv_cnt_attrs[:active]
111
- @invitees_counter_limit = inv_cnt_attrs[:limit]
119
+ if event_memberships.is_a? Array # rubocop:disable Style/GuardClause
120
+ @event_memberships = event_memberships.map do |params|
121
+ uri = params[:user]
122
+ User.new({uri: uri}, @client)
123
+ end
124
+ end
112
125
  end
113
126
  end
114
127
  end
@@ -2,89 +2,144 @@
2
2
 
3
3
  require 'calendly/client'
4
4
  require 'calendly/models/model_utils'
5
+ require 'calendly/models/event_type_profile'
6
+ require 'calendly/models/event_type_custom_question'
5
7
 
6
8
  module Calendly
7
9
  # Calendly's event type model.
8
- # A configuration for a schedulable event
10
+ # A configuration for a schedulable event.
9
11
  class EventType
10
12
  include ModelUtils
11
13
  UUID_RE = %r{\A#{Client::API_HOST}/event_types/(\w+)\z}.freeze
12
14
  TIME_FIELDS = %i[created_at updated_at].freeze
15
+ ASSOCIATION = {profile: EventTypeProfile, custom_questions: EventTypeCustomQuestion}.freeze
13
16
 
14
17
  # @return [String]
15
18
  # unique id of the EventType object.
16
19
  attr_accessor :uuid
20
+
17
21
  # @return [String]
18
22
  # Canonical resource reference.
19
23
  attr_accessor :uri
24
+
20
25
  # @return [Boolean]
21
26
  # Is this event type currently active?
22
27
  attr_accessor :active
28
+
23
29
  # @return [String]
24
30
  # The web page styling color for this event type,
25
31
  # expressed as a hexadecimal RGB value (e.g. #fa12e4).
26
32
  attr_accessor :color
33
+
27
34
  # @return [String]
28
35
  # Longer text description with HTML formatting.
29
36
  attr_accessor :description_html
37
+
30
38
  # @return [String]
31
39
  # Longer text description in plain text.
32
40
  attr_accessor :description_plain
41
+
33
42
  # @return [Integer]
34
43
  # Length of event type in minutes.
35
44
  attr_accessor :duration
45
+
36
46
  # @return [String]
37
47
  # Optional internal note on an event type.
38
48
  attr_accessor :internal_note
49
+
39
50
  # @return [String]
40
51
  # Whether the event type is “solo” or with a “group”.
41
52
  attr_accessor :kind
53
+
42
54
  # @return [String]
43
55
  # Human-readable name. Note: some Event Types don't have a name.
44
56
  attr_accessor :name
57
+
45
58
  # @return [String]
46
59
  # Whether the event type is "round_robin" or "collective".
47
60
  # This value is null if the event type does not pool team members' availability.
48
61
  attr_accessor :pooling_type
62
+
49
63
  # @return [String]
50
64
  # The full URL of the web page for this event type.
51
65
  attr_accessor :scheduling_url
66
+
52
67
  # @return [String]
53
68
  # Unique human-readable slug used in page URL.
54
69
  attr_accessor :slug
70
+
55
71
  # @return [String]
56
72
  # Whether the event type is a “StandardEventType” or an "AdhocEventType”.
57
73
  attr_accessor :type
74
+
75
+ # @return [Boolean]
76
+ # Indicates if the event type is hidden on the owner's main scheduling page.
77
+ attr_accessor :secret
78
+
58
79
  # @return [Time]
59
80
  # Moment when event type was eventually created.
60
81
  attr_accessor :created_at
82
+
61
83
  # @return [Time]
62
84
  # Moment when event type was last updated.
63
85
  attr_accessor :updated_at
64
86
 
65
- # @return [String]
66
- # uuid of User or Team object.
67
- attr_accessor :owner_uuid
68
- # @return [String]
69
- # Reference to the profile owner.
70
- attr_accessor :owner_uri
71
- # @return [String]
72
- # Human-readable name.
73
- attr_accessor :owner_name
74
- # @return [String]
75
- # Whether the profile belongs to a “User” or a “Team”.
76
- attr_accessor :owner_type
87
+ # @return [EventTypeProfile]
88
+ # The profile of the User that's associated with the Event Type.
89
+ attr_accessor :profile
77
90
 
78
- private
91
+ # @return [Array<EventTypeCustomQuestion>]
92
+ # A collection of custom questions.
93
+ attr_accessor :custom_questions
94
+
95
+ # The owner user if the profile belongs to a "user" (individual).
96
+ # @return [User]
97
+ # @since 0.6.0
98
+ def owner_user
99
+ profile&.owner_user
100
+ end
79
101
 
80
- def after_set_attributes(attrs)
81
- super attrs
82
- return unless attrs[:profile]
102
+ # The owner team if the profile belongs to a "team".
103
+ # @return [Team]
104
+ # @since 0.6.0
105
+ def owner_team
106
+ profile&.owner_team
107
+ end
108
+
109
+ #
110
+ # Get EventType associated with self.
111
+ #
112
+ # @return [Calendly::EventType]
113
+ # @raise [Calendly::Error] if the uuid is empty.
114
+ # @raise [Calendly::ApiError] if the api returns error code.
115
+ # @since 0.5.1
116
+ def fetch
117
+ client.event_type uuid
118
+ end
119
+
120
+ #
121
+ # Create an associated scheduling link.
122
+ #
123
+ # @param [String] max_event_count The max number of events that can be scheduled using this scheduling link.
124
+ # @return [Hash]
125
+ # e.g.
126
+ # {
127
+ # booking_url: "https://calendly.com/s/FOO-BAR-SLUG",
128
+ # owner: "https://api.calendly.com/event_types/GBGBDCAADAEDCRZ2",
129
+ # owner_type: "EventType"
130
+ # }
131
+ # @raise [Calendly::Error] if the uri is empty.
132
+ # @raise [Calendly::Error] if the max_event_count arg is empty.
133
+ # @raise [Calendly::ApiError] if the api returns error code.
134
+ # @since 0.5.2
135
+ def create_schedule_link(max_event_count = 1)
136
+ client.create_schedule_link uri, max_event_count, resource_type: 'EventType'
137
+ end
138
+
139
+ private
83
140
 
84
- @owner_uri = attrs[:profile][:owner]
85
- @owner_uuid = User.extract_uuid owner_uri
86
- @owner_name = attrs[:profile][:name]
87
- @owner_type = attrs[:profile][:type]
141
+ def inspect_attributes
142
+ super + %i[active kind scheduling_url]
88
143
  end
89
144
  end
90
145
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'calendly/models/model_utils'
4
+
5
+ module Calendly
6
+ # Calendly's custom question model.
7
+ class EventTypeCustomQuestion
8
+ include ModelUtils
9
+
10
+ # @return [String]
11
+ # The custom question that the host created for the event type.
12
+ attr_accessor :name
13
+
14
+ # @return [String]
15
+ # The type of response that the invitee provides to the custom question;
16
+ # can be one or multiple lines of text, a phone number, or single- or multiple-select.
17
+ attr_accessor :type
18
+
19
+ # @return [Integer]
20
+ # The numerical position of the question on the event booking page after the name and email address fields.
21
+ attr_accessor :position
22
+
23
+ # @return [Boolean]
24
+ # true if the question created by the host is turned ON and visible on the event booking page;
25
+ # false if turned OFF and invisible on the event booking page.
26
+ attr_accessor :enabled
27
+
28
+ # @return [Boolean]
29
+ # true if a response to the question created by the host is required for invitees to book the event type;
30
+ # false if not required.
31
+ attr_accessor :required
32
+
33
+ # @return [Array<String>]
34
+ # The invitee’s option(s) for single_select or multi_select type of responses.
35
+ attr_accessor :answer_choices
36
+
37
+ # @return [Boolean]
38
+ # true if the custom question lets invitees record a written response in addition to single-select or multiple-select type of responses;
39
+ # false if it doesn’t.
40
+ attr_accessor :include_other
41
+
42
+ private
43
+
44
+ def inspect_attributes
45
+ super + %i[enabled position]
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'calendly/models/model_utils'
4
+
5
+ module Calendly
6
+ # Calendly's event type profile model.
7
+ class EventTypeProfile
8
+ include ModelUtils
9
+
10
+ # @return [String]
11
+ # Indicates if the profile belongs to a "user" (individual) or "team"
12
+ attr_accessor :type
13
+
14
+ # @return [String]
15
+ # Human-readable name for the profile of the user that's associated with the event type
16
+ attr_accessor :name
17
+
18
+ # @return [String]
19
+ # The unique reference to the user associated with the profile
20
+ attr_accessor :owner
21
+
22
+ # @return [User]
23
+ # The owner user if the profile belongs to a "user" (individual).
24
+ attr_accessor :owner_user
25
+
26
+ # @return [Team]
27
+ # The owner team if the profile belongs to a "team".
28
+ attr_accessor :owner_team
29
+
30
+ # whether type is user or not.
31
+ # @return [Boolean]
32
+ # @since 0.6.0
33
+ def type_user?
34
+ type&.downcase == 'user'
35
+ end
36
+
37
+ # whether type is team or not.
38
+ # @return [Boolean]
39
+ # @since 0.6.0
40
+ def type_team?
41
+ type&.downcase == 'team'
42
+ end
43
+
44
+ private
45
+
46
+ def after_set_attributes(attrs)
47
+ super attrs
48
+ if owner # rubocop:disable Style/GuardClause
49
+ @owner_user = User.new({uri: owner}, @client) if type_user?
50
+ @owner_team = Team.new({uri: owner}, @client) if type_team?
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'calendly/models/model_utils'
4
+
5
+ module Calendly
6
+ # Calendly's guest model.
7
+ # Additional people added to an event by an invitee.
8
+ class Guest
9
+ include ModelUtils
10
+ TIME_FIELDS = %i[created_at updated_at].freeze
11
+
12
+ # @return [String]
13
+ attr_accessor :email
14
+
15
+ # @return [Time]
16
+ attr_accessor :created_at
17
+
18
+ # @return [Time]
19
+ attr_accessor :updated_at
20
+ end
21
+ end
@@ -3,60 +3,99 @@
3
3
  require 'calendly/client'
4
4
  require 'calendly/models/model_utils'
5
5
  require 'calendly/models/event'
6
+ require 'calendly/models/invitee_cancellation'
7
+ require 'calendly/models/invitee_payment'
8
+ require 'calendly/models/invitee_question_and_answer'
9
+ require 'calendly/models/invitee_tracking'
6
10
 
7
11
  module Calendly
8
- # Calendly's Invitee model.
12
+ # Calendly's invitee model.
9
13
  # An individual who has been invited to meet with a Calendly member.
10
14
  class Invitee
11
15
  include ModelUtils
12
16
  UUID_RE = %r{\A#{Client::API_HOST}/scheduled_events/\w+/invitees/(\w+)\z}.freeze
13
17
  TIME_FIELDS = %i[created_at updated_at].freeze
14
- ASSOCIATION = {event: Event}.freeze
18
+ ASSOCIATION = {
19
+ event: Event,
20
+ cancellation: InviteeCancellation,
21
+ payment: InviteePayment,
22
+ questions_and_answers: InviteeQuestionAndAnswer,
23
+ tracking: InviteeTracking
24
+ }.freeze
15
25
 
16
26
  # @return [String]
17
27
  # unique id of the Invitee object.
18
28
  attr_accessor :uuid
29
+
19
30
  # @return [String]
20
31
  # Canonical resource reference.
21
32
  attr_accessor :uri
33
+
22
34
  # @return [String]
23
35
  # The invitee's email address.
24
36
  attr_accessor :email
37
+
25
38
  # @return [String]
26
39
  # The invitee's human-readable name.
27
40
  attr_accessor :name
41
+
42
+ # @return [String]
43
+ # The first name of the invitee who booked the event when the event type is configured to use separate fields for
44
+ # first name and last name. Null when event type is configured to use a single field for name.
45
+ attr_accessor :first_name
46
+
47
+ # @return [String]
48
+ # The last name of the invitee who booked the event when the event type is configured to use separate fields
49
+ # for first name and last name. Null when event type is configured to use a single field for name.
50
+ attr_accessor :last_name
51
+
28
52
  # @return [String]
29
53
  # Whether the invitee has canceled or is still active.
30
54
  attr_accessor :status
55
+
31
56
  # @return [String]
32
57
  # Timezone offest to use when presenting time information to invitee.
33
58
  attr_accessor :timezone
59
+
34
60
  # @return [String]
35
61
  # Text (SMS) reminder phone number.
36
62
  attr_accessor :text_reminder_number
63
+
37
64
  # @return [Boolean]
38
65
  # Indicates if this invitee has rescheduled.
39
66
  # If true, a reference to the new Invitee instance is provided in the new_invitee field.
40
67
  attr_accessor :rescheduled
68
+
41
69
  # @return [String, nil]
42
70
  # Reference to old Invitee instance that got rescheduled.
43
71
  attr_accessor :old_invitee
72
+
44
73
  # @return [String, nil]
45
74
  # Link to new invitee, after reschedule.
46
75
  attr_accessor :new_invitee
76
+
47
77
  # @return [String]
48
78
  # Link to cancelling the event for the invitee.
49
79
  attr_accessor :cancel_url
80
+
50
81
  # @return [String]
51
82
  # Link to rescheduling the event for the invitee.
52
83
  attr_accessor :reschedule_url
84
+
53
85
  # @return [Time]
54
86
  # Moment when user record was first created.
55
87
  attr_accessor :created_at
88
+
56
89
  # @return [Time]
57
90
  # Moment when user record was last updated.
58
91
  attr_accessor :updated_at
59
92
 
93
+ # @return [InviteeCancellation] Provides data pertaining to the cancellation of the Invitee.
94
+ attr_accessor :cancellation
95
+
96
+ # @return [InviteePayment] Invitee payment.
97
+ attr_accessor :payment
98
+
60
99
  # @return [Event]
61
100
  # Reference to Event associated with this invitee.
62
101
  attr_accessor :event
@@ -80,16 +119,5 @@ module Calendly
80
119
  ev_uuid = event.uuid if event
81
120
  client.event_invitee ev_uuid, uuid
82
121
  end
83
-
84
- private
85
-
86
- def after_set_attributes(attrs)
87
- super attrs
88
- answers = attrs[:questions_and_answers]
89
- @questions_and_answers = answers.map { |ans| InviteeQuestionAndAnswer.new ans } if answers&.is_a? Array
90
-
91
- trac_attrs = attrs[:tracking]
92
- @tracking = InviteeTracking.new trac_attrs if trac_attrs&.is_a? Hash
93
- end
94
122
  end
95
123
  end