calendly 0.1.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,23 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/loggable'
4
+
3
5
  module Calendly
4
6
  # calendly module's base error object
5
7
  class Error < StandardError
8
+ include Loggable
9
+
6
10
  def initialize(message = nil)
7
11
  @logger = Calendly.configuration.logger
8
12
  msg = "#{self.class} occured."
9
13
  msg += " status:#{status}" if respond_to?(:status)
10
14
  msg += " message:#{message}"
11
- log msg
15
+ warn_log msg
12
16
  super message
13
17
  end
14
-
15
- private
16
-
17
- def log(msg, level = :warn)
18
- return if @logger.nil?
19
-
20
- @logger.send level, msg
21
- end
22
18
  end
23
19
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calendly
4
+ # Calendly logger utility module.
5
+ module Loggable
6
+ def error_log(msg)
7
+ log msg, :error
8
+ end
9
+
10
+ def warn_log(msg)
11
+ log msg, :warn
12
+ end
13
+
14
+ def info_log(msg)
15
+ log msg, :info
16
+ end
17
+
18
+ def debug_log(msg)
19
+ log msg, :debug
20
+ end
21
+
22
+ private
23
+
24
+ def log(msg, level = :info)
25
+ logger = Calendly.configuration.logger
26
+ return unless logger
27
+ return unless logger.respond_to? level
28
+
29
+ logger.send level, msg
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/client'
4
+ require 'calendly/models/model_utils'
5
+ require 'calendly/models/event_type'
6
+
3
7
  module Calendly
4
8
  # Calendly's event model.
5
9
  # A meeting that has been scheduled
@@ -7,7 +11,7 @@ module Calendly
7
11
  include ModelUtils
8
12
  UUID_RE = %r{\A#{Client::API_HOST}/scheduled_events/(\w+)\z}.freeze
9
13
  TIME_FIELDS = %i[start_time end_time created_at updated_at].freeze
10
- ASSOCIATION = { event_type: EventType }.freeze
14
+ ASSOCIATION = {event_type: EventType}.freeze
11
15
 
12
16
  # @return [String]
13
17
  # unique id of the Event object.
@@ -69,19 +73,29 @@ module Calendly
69
73
  # @param [Hash] opts the optional request parameters.
70
74
  # @option opts [Integer] :count Number of rows to return.
71
75
  # @option opts [String] :email Filter by email.
72
- # @option opts [String] :page_token Pass this to get the next portion of collection.
73
- # @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
76
+ # @option opts [String] :page_token
77
+ # Pass this to get the next portion of collection.
78
+ # @option opts [String] :sort Order results by the specified field and directin.
79
+ # Accepts comma-separated list of {field}:{direction} values.
74
80
  # @option opts [String] :status Whether the scheduled event is active or canceled.
75
81
  # @return [Array<Calendly::Invitee>]
76
82
  # @raise [Calendly::Error] if the uuid is empty.
77
83
  # @raise [Calendly::ApiError] if the api returns error code.
78
84
  # @since 0.1.0
79
85
  def invitees(opts = {})
86
+ return @cached_invitees if @cached_invitees
87
+
80
88
  request_proc = proc { |options| client.event_invitees uuid, options }
81
- auto_pagination request_proc, opts
89
+ @cached_invitees = auto_pagination request_proc, opts
82
90
  end
83
91
 
84
- private
92
+ # @since 0.2.0
93
+ def invitees!(opts = {})
94
+ @cached_invitees = nil
95
+ invitees opts
96
+ end
97
+
98
+ private
85
99
 
86
100
  def after_set_attributes(attrs)
87
101
  super attrs
@@ -89,11 +103,12 @@ module Calendly
89
103
  @location = Location.new loc_params if loc_params&.is_a? Hash
90
104
 
91
105
  inv_cnt_attrs = attrs[:invitees_counter]
92
- if inv_cnt_attrs&.is_a? Hash
93
- @invitees_counter_total = inv_cnt_attrs[:total]
94
- @invitees_counter_active = inv_cnt_attrs[:active]
95
- @invitees_counter_limit = inv_cnt_attrs[:limit]
96
- end
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]
97
112
  end
98
113
  end
99
114
  end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/client'
4
+ require 'calendly/models/model_utils'
5
+
3
6
  module Calendly
4
7
  # Calendly's event type model.
5
8
  # A configuration for a schedulable event
@@ -72,17 +75,16 @@ module Calendly
72
75
  # Whether the profile belongs to a “User” or a “Team”.
73
76
  attr_accessor :owner_type
74
77
 
75
- private
78
+ private
76
79
 
77
80
  def after_set_attributes(attrs)
78
81
  super attrs
79
- if attrs[:profile]
82
+ return unless attrs[:profile]
80
83
 
81
- @owner_uri = attrs[:profile][:owner]
82
- @owner_uuid = User.extract_uuid owner_uri
83
- @owner_name = attrs[:profile][:name]
84
- @owner_type = attrs[:profile][:type]
85
- end
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]
86
88
  end
87
89
  end
88
90
  end
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/client'
4
+ require 'calendly/models/model_utils'
5
+ require 'calendly/models/event'
6
+
3
7
  module Calendly
4
8
  # Calendly's Invitee model.
5
9
  # An individual who has been invited to meet with a Calendly member.
@@ -7,7 +11,7 @@ module Calendly
7
11
  include ModelUtils
8
12
  UUID_RE = %r{\A#{Client::API_HOST}/scheduled_events/\w+/invitees/(\w+)\z}.freeze
9
13
  TIME_FIELDS = %i[created_at updated_at].freeze
10
- ASSOCIATION = { event: Event }.freeze
14
+ ASSOCIATION = {event: Event}.freeze
11
15
 
12
16
  # @return [String]
13
17
  # unique id of the Invitee object.
@@ -61,14 +65,12 @@ module Calendly
61
65
  client.event_invitee ev_uuid, uuid
62
66
  end
63
67
 
64
- private
68
+ private
65
69
 
66
70
  def after_set_attributes(attrs)
67
71
  super attrs
68
72
  answers = attrs[:questions_and_answers]
69
- if answers&.is_a? Array
70
- @questions_and_answers = answers.map { |ans| InviteeQuestionAndAnswer.new ans }
71
- end
73
+ @questions_and_answers = answers.map { |ans| InviteeQuestionAndAnswer.new ans } if answers&.is_a? Array
72
74
 
73
75
  trac_attrs = attrs[:tracking]
74
76
  @tracking = InviteeTracking.new trac_attrs if trac_attrs&.is_a? Hash
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/models/model_utils'
4
+
3
5
  module Calendly
4
6
  # Calendly's InviteeQuestionAndAnswer model.
5
7
  # An individual form question and response.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/models/model_utils'
4
+
3
5
  module Calendly
4
6
  # Calendly's InviteeTracking model.
5
7
  # Object that represents UTM and Salesforce tracking parameters associated with the invitee.
@@ -1,52 +1,70 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/models/model_utils'
4
+
3
5
  module Calendly
4
6
  # Calendly's location model.
5
- # Polymorphic base type for the various supported meeting locations.
7
+ # The polymorphic base type for an event location that Calendly supports
6
8
  class Location
7
9
  include ModelUtils
8
10
 
11
+ #
9
12
  # data patterns is below:
10
- # - 1. A meeting at a pre-specified physical location
11
- # - [String] :kind
12
- # - [String] :location A physical location specified by the meeting publisher.
13
- # - 2. Meeting publisher will call the invitee
14
- # - [String] :kind
15
- # - 3. Invitee will call meeting publisher at the specified phone number.
16
- # - [String] :kind
17
- # - [String] :phone_number Phone number invitee should use to reach meeting publisher.
18
- # - 4. Meeting will take place in a Google Meet / Hangout conference.
19
- # - [String] :kind
20
- # - 5. Meeting will take place in a Zoom conference.
21
- # - [String] :kind
22
- # - 6. Meeting will take place in a GotoMeeting conference.
23
- # - [String] :kind
24
- # - [String] :external_id Zoom-supplied conference id.
25
- # - [String] :state Current state of the conference in Zoom.
26
- # - [Hash] :data Arbitrary conference metadata supplied by Zoom.
27
- # - 7. Arbitrary conference metadata supplied by GotoMeeting.
28
- # - [String] :kind
29
- # - [String] :external_id GotoMeeting-supplied conference id.
30
- # - [String] :state Current state of the conference in GotoMeeting.
31
- # - [String] :data Arbitrary conference metadata supplied by GotoMeeting.
32
- # - 8. Meeting location does not fall in a standard category, and is as described by the meeting publisher.
33
- # - [String] :kind
34
- # - [String] :location Location description provided by meeting publisher.
35
- # - 9. Meeting location was specified by invitee.
36
- # - [String] :kind
37
- # - [String] :location Meeting location was specified by invitee.
13
+ #
14
+ # 1. In-Person Meeting: Information about the physical (in-person) event location.
15
+ # @param [String] type Indicates that the event host (publisher) will call the invitee.
16
+ # @param [String] location The physical location specified by the event host (publisher).
17
+ #
18
+ # 2. Outbound Call: Meeting publisher will call the Invitee
19
+ # @param [String] type Indicates that the event host (publisher) will call the invitee.
20
+ # @param [String] location The phone number the event host (publisher) will use to call the invitee.
21
+ #
22
+ # 3. Inbound Call: Invitee will call meeting publisher at the specified phone number.
23
+ # @param [String] type Indicates that the invitee will call the event host.
24
+ # @param [String] location The phone number the invitee will use to call the event host (publisher).
25
+ #
26
+ # 4. Google Conference: Details about an Event that will take place using a Google Meet / Hangout conference.
27
+ # @param [String] type The event location is a Google Meet or Hangouts conference.
28
+ # @param [String] status Indicates the current status of the Google conference.
29
+ # @param [String] join_url Google conference meeting url.
30
+ #
31
+ # 5. Zoom Conference: Meeting will take place in a Zoom conference.
32
+ # @param [String] type The event location is a Zoom conference
33
+ # @param [String] status Indicates the current status of the Zoom conference.
34
+ # @param [String] join_url Zoom meeting url.
35
+ # @param [Hash] data The conference metadata supplied by Zoom.
36
+ #
37
+ # 6. GoToMeeting Conference: Details about an Event that will take place using a GotoMeeting conference
38
+ # @param [String] type The event location is a GoToMeeting conference.
39
+ # @param [String] status Indicates the current status of the GoToMeeting conference.
40
+ # @param [String] join_url GoToMeeting conference meeting url.
41
+ # @param [Hash] data The conference metadata supplied by GoToMeeting.
42
+ #
43
+ # 7. Microsoft Teams Conference:
44
+ # @param [String] type The event location is a Zoom conference.
45
+ # @param [String] status Indicates the current status of the Microsoft Teams conference.
46
+ # @param [String] join_url Microsoft Teams meeting url.
47
+ # @param [Hash] data The conference metadata supplied by Microsoft Teams.
48
+ #
49
+ # 8. Custom Location:
50
+ # Use this to describe an existing Calendly-supported event location.
51
+ # @param [String] type The event location doesn't fall into a standard category defined by the event host (publisher).
52
+ # @param [String] location The event location description provided by the invitee.
53
+ #
54
+ # 9. Invitee Specified Location:
55
+ # Information about an event location that’s specified by the invitee.
56
+ # @param [String] type The event location selected by the invitee.
57
+ # @param [String] location The event location description provided by the invitee.
38
58
  #
39
59
 
40
60
  # @return [String]
41
- attr_accessor :kind
61
+ attr_accessor :type
42
62
  # @return [String]
43
63
  attr_accessor :location
44
64
  # @return [String]
45
- attr_accessor :phone_number
46
- # @return [String]
47
- attr_accessor :external_id
65
+ attr_accessor :status
48
66
  # @return [String]
49
- attr_accessor :state
67
+ attr_accessor :join_url
50
68
  # @return [Hash]
51
69
  attr_accessor :data
52
70
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'time'
4
+ require 'calendly/error'
4
5
 
5
6
  module Calendly
6
7
  # Calendly model utility.
@@ -19,7 +20,7 @@ module Calendly
19
20
  # @raise [Calendly::Error] if the client is nil.
20
21
  # @since 0.1.0
21
22
  def client
22
- raise Error, '@client is not ready.' if !@client || !@client.is_a?(Client)
23
+ raise Error.new('@client is not ready.') if !@client || !@client.is_a?(Client)
23
24
 
24
25
  @client
25
26
  end
@@ -31,7 +32,7 @@ module Calendly
31
32
  # @raise [Calendly::Error] if uuid is not defined.
32
33
  # @since 0.1.0
33
34
  def id
34
- raise Error, 'uuid is not defined.' unless defined? uuid
35
+ raise Error.new('uuid is not defined.') unless defined? uuid
35
36
 
36
37
  uuid
37
38
  end
@@ -58,9 +59,9 @@ module Calendly
58
59
  base.extend ClassMethods
59
60
  end
60
61
 
61
- private
62
+ private
62
63
 
63
- def set_attributes(attrs)
64
+ def set_attributes(attrs) # rubocop:disable all
64
65
  return if attrs.nil?
65
66
  return unless attrs.is_a? Hash
66
67
  return if attrs.empty?
@@ -68,10 +69,10 @@ module Calendly
68
69
  attrs.each do |key, value|
69
70
  next unless respond_to? "#{key}=".to_sym
70
71
 
71
- if defined?(self.class::ASSOCIATION) && self.class::ASSOCIATION.key?(key)
72
- associated_attrs = value.is_a?(Hash) ? value : { uri: value }
72
+ if value && defined?(self.class::ASSOCIATION) && self.class::ASSOCIATION.key?(key)
73
+ associated_attrs = value.is_a?(Hash) ? value : {uri: value}
73
74
  value = self.class::ASSOCIATION[key].new associated_attrs, @client
74
- elsif defined?(self.class::TIME_FIELDS) && self.class::TIME_FIELDS.include?(key)
75
+ elsif value && defined?(self.class::TIME_FIELDS) && self.class::TIME_FIELDS.include?(key)
75
76
  value = Time.parse value
76
77
  end
77
78
  instance_variable_set "@#{key}", value
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'calendly/client'
4
+ require 'calendly/models/model_utils'
5
+
3
6
  module Calendly
4
7
  # Calendly's organization model.
5
8
  class Organization
@@ -25,8 +28,16 @@ module Calendly
25
28
  # @raise [Calendly::ApiError] if the api returns error code.
26
29
  # @since 0.1.0
27
30
  def memberships(opts = {})
31
+ return @cached_memberships if @cached_memberships
32
+
28
33
  request_proc = proc { |options| client.memberships uri, options }
29
- auto_pagination request_proc, opts
34
+ @cached_memberships = auto_pagination request_proc, opts
35
+ end
36
+
37
+ # @since 0.2.0
38
+ def memberships!(opts = {})
39
+ @cached_memberships = nil
40
+ memberships opts
30
41
  end
31
42
 
32
43
  #
@@ -36,15 +47,24 @@ module Calendly
36
47
  # @option opts [Integer] :count Number of rows to return.
37
48
  # @option opts [String] :email Filter by email.
38
49
  # @option opts [String] :page_token Pass this to get the next portion of collection.
39
- # @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
50
+ # @option opts [String] :sort Order results by the specified field and directin.
51
+ # Accepts comma-separated list of {field}:{direction} values.
40
52
  # @option opts [String] :status Filter by status.
41
53
  # @return [Array<Calendly::OrganizationInvitation>]
42
54
  # @raise [Calendly::Error] if the uuid is empty.
43
55
  # @raise [Calendly::ApiError] if the api returns error code.
44
56
  # @since 0.1.0
45
57
  def invitations(opts = {})
58
+ return @cached_invitations if @cached_invitations
59
+
46
60
  request_proc = proc { |options| client.invitations uuid, options }
47
- auto_pagination request_proc, opts
61
+ @cached_invitations = auto_pagination request_proc, opts
62
+ end
63
+
64
+ # @since 0.2.0
65
+ def invitations!(opts = {})
66
+ @cached_invitations = nil
67
+ invitations opts
48
68
  end
49
69
 
50
70
  #
@@ -59,5 +79,45 @@ module Calendly
59
79
  def create_invitation(email)
60
80
  client.create_invitation uuid, email
61
81
  end
82
+
83
+ #
84
+ # Get List of organization scope Webhooks associated with self.
85
+ #
86
+ # @param [Hash] opts the optional request parameters.
87
+ # @option opts [Integer] :count Number of rows to return.
88
+ # @option opts [String] :page_token Pass this to get the next portion of collection.
89
+ # @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
90
+ # Accepts comma-separated list of {field}:{direction} values.
91
+ # @return [Array<Calendly::WebhookSubscription>]
92
+ # @raise [Calendly::Error] if the uri is empty.
93
+ # @raise [Calendly::ApiError] if the api returns error code.
94
+ # @since 0.1.3
95
+ def webhooks(opts = {})
96
+ return @cached_webhooks if @cached_webhooks
97
+
98
+ request_proc = proc { |options| client.webhooks uri, options }
99
+ @cached_webhooks = auto_pagination request_proc, opts
100
+ end
101
+
102
+ # @since 0.2.0
103
+ def webhooks!(opts = {})
104
+ @cached_webhooks = nil
105
+ webhooks opts
106
+ end
107
+
108
+ #
109
+ # Create a user scope webhook associated with self.
110
+ #
111
+ # @param [String] url Canonical reference (unique identifier) for the resource.
112
+ # @param [Array<String>] events List of user events to subscribe to. options: invitee.created or invitee.canceled
113
+ # @return [Calendly::WebhookSubscription]
114
+ # @raise [Calendly::Error] if the url arg is empty.
115
+ # @raise [Calendly::Error] if the events arg is empty.
116
+ # @raise [Calendly::Error] if the uri is empty.
117
+ # @raise [Calendly::ApiError] if the api returns error code.
118
+ # @since 0.1.3
119
+ def create_webhook(url, events)
120
+ client.create_webhook url, events, uri
121
+ end
62
122
  end
63
123
  end