calendly 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{.rubocom.yml → .rubocop.yml} +11 -9
- data/CHANGELOG.md +34 -8
- data/README.md +48 -31
- data/Rakefile +8 -6
- data/calendly.gemspec +0 -1
- data/lib/calendly.rb +12 -4
- data/lib/calendly/api_error.rb +5 -3
- data/lib/calendly/client.rb +144 -39
- data/lib/calendly/error.rb +5 -9
- data/lib/calendly/loggable.rb +32 -0
- data/lib/calendly/models/event.rb +25 -10
- data/lib/calendly/models/event_type.rb +9 -7
- data/lib/calendly/models/invitee.rb +7 -5
- data/lib/calendly/models/invitee_question_and_answer.rb +2 -0
- data/lib/calendly/models/invitee_tracking.rb +2 -0
- data/lib/calendly/models/location.rb +2 -0
- data/lib/calendly/models/model_utils.rb +8 -7
- data/lib/calendly/models/organization.rb +63 -3
- data/lib/calendly/models/organization_invitation.rb +6 -1
- data/lib/calendly/models/organization_membership.rb +51 -1
- data/lib/calendly/models/user.rb +35 -6
- data/lib/calendly/models/webhook_subscription.rb +75 -0
- data/lib/calendly/version.rb +1 -1
- metadata +6 -18
data/lib/calendly/error.rb
CHANGED
@@ -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
|
-
|
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 = {
|
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
|
73
|
-
#
|
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
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
78
|
+
private
|
76
79
|
|
77
80
|
def after_set_attributes(attrs)
|
78
81
|
super attrs
|
79
|
-
|
82
|
+
return unless attrs[:profile]
|
80
83
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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 = {
|
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
|
-
|
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,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
|
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
|
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
|
-
|
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 : {
|
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.
|
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
|
@@ -1,12 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'calendly/client'
|
4
|
+
require 'calendly/models/model_utils'
|
5
|
+
require 'calendly/models/organization'
|
6
|
+
require 'calendly/models/user'
|
7
|
+
|
3
8
|
module Calendly
|
4
9
|
# Calendly's organization invitation model.
|
5
10
|
class OrganizationInvitation
|
6
11
|
include ModelUtils
|
7
12
|
UUID_RE = %r{\A#{Client::API_HOST}/organizations/\w+/invitations/(\w+)\z}.freeze
|
8
13
|
TIME_FIELDS = %i[created_at updated_at last_sent_at].freeze
|
9
|
-
ASSOCIATION = {
|
14
|
+
ASSOCIATION = {user: User, organization: Organization}.freeze
|
10
15
|
|
11
16
|
# @return [String]
|
12
17
|
# unique id of the OrganizationInvitation object.
|
@@ -1,12 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'calendly/client'
|
4
|
+
require 'calendly/models/model_utils'
|
5
|
+
require 'calendly/models/organization'
|
6
|
+
require 'calendly/models/user'
|
7
|
+
|
3
8
|
module Calendly
|
4
9
|
# Calendly's organization membership model.
|
5
10
|
class OrganizationMembership
|
6
11
|
include ModelUtils
|
7
12
|
UUID_RE = %r{\A#{Client::API_HOST}/organization_memberships/(\w+)\z}.freeze
|
8
13
|
TIME_FIELDS = %i[created_at updated_at].freeze
|
9
|
-
ASSOCIATION = {
|
14
|
+
ASSOCIATION = {user: User, organization: Organization}.freeze
|
10
15
|
|
11
16
|
# @return [String]
|
12
17
|
# unique id of the OrganizationMembership object.
|
@@ -52,5 +57,50 @@ module Calendly
|
|
52
57
|
def delete
|
53
58
|
client.delete_membership uuid
|
54
59
|
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Get List of user scope Webhooks associated with self.
|
63
|
+
#
|
64
|
+
# @param [Hash] opts the optional request parameters.
|
65
|
+
# @option opts [Integer] :count Number of rows to return.
|
66
|
+
# @option opts [String] :page_token Pass this to get the next portion of collection.
|
67
|
+
# @option opts [String] :sort Order results by the specified field and directin. Accepts comma-separated list of {field}:{direction} values.
|
68
|
+
# Accepts comma-separated list of {field}:{direction} values.
|
69
|
+
# @return [Array<Calendly::WebhookSubscription>]
|
70
|
+
# @raise [Calendly::Error] if the organization.uri is empty.
|
71
|
+
# @raise [Calendly::Error] if the user.uri is empty.
|
72
|
+
# @raise [Calendly::ApiError] if the api returns error code.
|
73
|
+
# @since 0.1.3
|
74
|
+
def user_scope_webhooks(opts = {})
|
75
|
+
return @cached_user_scope_webhooks if @cached_user_scope_webhooks
|
76
|
+
|
77
|
+
org_uri = organization.uri if organization
|
78
|
+
user_uri = user.uri if user
|
79
|
+
request_proc = proc { |options| client.user_scope_webhooks org_uri, user_uri, options }
|
80
|
+
@cached_user_scope_webhooks = auto_pagination request_proc, opts
|
81
|
+
end
|
82
|
+
|
83
|
+
# @since 0.2.0
|
84
|
+
def user_scope_webhooks!(opts = {})
|
85
|
+
@cached_user_scope_webhooks = nil
|
86
|
+
user_scope_webhooks opts
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Create a user scope webhook associated with self.
|
91
|
+
#
|
92
|
+
# @param [String] url Canonical reference (unique identifier) for the resource.
|
93
|
+
# @param [Array<String>] events List of user events to subscribe to. options: invitee.created or invitee.canceled
|
94
|
+
# @return [Calendly::WebhookSubscription]
|
95
|
+
# @raise [Calendly::Error] if the url arg is empty.
|
96
|
+
# @raise [Calendly::Error] if the events arg is empty.
|
97
|
+
# @raise [Calendly::Error] if the organization.uri is empty.
|
98
|
+
# @raise [Calendly::ApiError] if the api returns error code.
|
99
|
+
# @since 0.1.3
|
100
|
+
def create_user_scope_webhook(url, events)
|
101
|
+
org_uri = organization.uri if organization
|
102
|
+
user_uri = user.uri if user
|
103
|
+
client.create_webhook url, events, org_uri, user_uri
|
104
|
+
end
|
55
105
|
end
|
56
106
|
end
|