calendly 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calendly
4
+ # Calendly's Invitee model.
5
+ # An individual who has been invited to meet with a Calendly member.
6
+ class Invitee
7
+ include ModelUtils
8
+ UUID_RE = %r{\A#{Client::API_HOST}/scheduled_events/\w+/invitees/(\w+)\z}.freeze
9
+ TIME_FIELDS = %i[created_at updated_at].freeze
10
+ ASSOCIATION = { event: Event }.freeze
11
+
12
+ # @return [String]
13
+ # unique id of the Invitee object.
14
+ attr_accessor :uuid
15
+ # @return [String]
16
+ # Canonical resource reference.
17
+ attr_accessor :uri
18
+ # @return [String]
19
+ # The invitee's email address.
20
+ attr_accessor :email
21
+ # @return [String]
22
+ # The invitee's human-readable name.
23
+ attr_accessor :name
24
+ # @return [String]
25
+ # Whether the invitee has canceled or is still active.
26
+ attr_accessor :status
27
+ # @return [String]
28
+ # Timezone offest to use when presenting time information to invitee.
29
+ attr_accessor :timezone
30
+ # @return [String]
31
+ # Text (SMS) reminder phone number.
32
+ attr_accessor :text_reminder_number
33
+ # @return [Time]
34
+ # Moment when user record was first created.
35
+ attr_accessor :created_at
36
+ # @return [Time]
37
+ # Moment when user record was last updated.
38
+ attr_accessor :updated_at
39
+
40
+ # @return [Event]
41
+ # Reference to Event associated with this invitee.
42
+ attr_accessor :event
43
+
44
+ # @return [Array<Calendly::InviteeQuestionAndAnswer>]
45
+ # A collection of form responses from the invitee.
46
+ attr_accessor :questions_and_answers
47
+
48
+ # @return [Calendly::InviteeTracking]
49
+ attr_accessor :tracking
50
+
51
+ #
52
+ # Get Event Invitee associated with self.
53
+ #
54
+ # @return [Calendly::Invitee]
55
+ # @raise [Calendly::Error] if the event.uuid is empty.
56
+ # @raise [Calendly::Error] if the uuid is empty.
57
+ # @raise [Calendly::ApiError] if the api returns error code.
58
+ # @since 0.1.0
59
+ def fetch
60
+ ev_uuid = event.uuid if event
61
+ client.event_invitee ev_uuid, uuid
62
+ end
63
+
64
+ private
65
+
66
+ def after_set_attributes(attrs)
67
+ super attrs
68
+ answers = attrs[:questions_and_answers]
69
+ if answers&.is_a? Array
70
+ @questions_and_answers = answers.map { |ans| InviteeQuestionAndAnswer.new ans }
71
+ end
72
+
73
+ trac_attrs = attrs[:tracking]
74
+ @tracking = InviteeTracking.new trac_attrs if trac_attrs&.is_a? Hash
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calendly
4
+ # Calendly's InviteeQuestionAndAnswer model.
5
+ # An individual form question and response.
6
+ class InviteeQuestionAndAnswer
7
+ include ModelUtils
8
+
9
+ # @return [String]
10
+ # The question from the event booking confirmation form.
11
+ attr_accessor :question
12
+ # @return [String]
13
+ # The answer supplied by the invitee to this question.
14
+ attr_accessor :answer
15
+ # @return [Integer]
16
+ # The position of this question in the event booking confirmation form.
17
+ attr_accessor :position
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calendly
4
+ # Calendly's InviteeTracking model.
5
+ # Object that represents UTM and Salesforce tracking parameters associated with the invitee.
6
+ class InviteeTracking
7
+ include ModelUtils
8
+
9
+ # @return [String]
10
+ # UTM campaign tracking parameter.
11
+ attr_accessor :utm_campaign
12
+ # @return [String]
13
+ # UTM source tracking parameter.
14
+ attr_accessor :utm_source
15
+ # @return [String]
16
+ # UTM medium tracking parameter.
17
+ attr_accessor :utm_medium
18
+ # @return [String]
19
+ # UTM content tracking parameter.
20
+ attr_accessor :utm_content
21
+ # @return [String]
22
+ # UTM term tracking parameter.
23
+ attr_accessor :utm_term
24
+ # @return [String]
25
+ # Salesforce Record ID.
26
+ attr_accessor :salesforce_uuid
27
+ end
28
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calendly
4
+ # Calendly's location model.
5
+ # Polymorphic base type for the various supported meeting locations.
6
+ class Location
7
+ include ModelUtils
8
+
9
+ # 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.
38
+ #
39
+
40
+ # @return [String]
41
+ attr_accessor :kind
42
+ # @return [String]
43
+ attr_accessor :location
44
+ # @return [String]
45
+ attr_accessor :phone_number
46
+ # @return [String]
47
+ attr_accessor :external_id
48
+ # @return [String]
49
+ attr_accessor :state
50
+ # @return [Hash]
51
+ attr_accessor :data
52
+ end
53
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ module Calendly
6
+ # Calendly model utility.
7
+ module ModelUtils
8
+ # @param [Hash] attrs the attributes of the model.
9
+ # @param [Calendly::Client] the api client.
10
+ def initialize(attrs = nil, client = nil)
11
+ @client = client
12
+ set_attributes attrs
13
+ end
14
+
15
+ #
16
+ # Returns api client.
17
+ #
18
+ # @return [Calendly::Client]
19
+ # @raise [Calendly::Error] if the client is nil.
20
+ # @since 0.1.0
21
+ def client
22
+ raise Error, '@client is not ready.' if !@client || !@client.is_a?(Client)
23
+
24
+ @client
25
+ end
26
+
27
+ #
28
+ # alias of uuid.
29
+ #
30
+ # @return [String]
31
+ # @raise [Calendly::Error] if uuid is not defined.
32
+ # @since 0.1.0
33
+ def id
34
+ raise Error, 'uuid is not defined.' unless defined? uuid
35
+
36
+ uuid
37
+ end
38
+
39
+ def inspect
40
+ description = "uuid:#{uuid}" if respond_to? :uuid
41
+ "\#<#{self.class}:#{object_id} #{description}>"
42
+ end
43
+
44
+ module ClassMethods
45
+ def extract_uuid(str)
46
+ return unless defined? self::UUID_RE
47
+ return unless str
48
+ return if str.empty?
49
+
50
+ m = self::UUID_RE.match str
51
+ return if m.nil?
52
+
53
+ m[1]
54
+ end
55
+ end
56
+
57
+ def self.included(base)
58
+ base.extend ClassMethods
59
+ end
60
+
61
+ private
62
+
63
+ def set_attributes(attrs)
64
+ return if attrs.nil?
65
+ return unless attrs.is_a? Hash
66
+ return if attrs.empty?
67
+
68
+ attrs.each do |key, value|
69
+ next unless respond_to? "#{key}=".to_sym
70
+
71
+ if defined?(self.class::ASSOCIATION) && self.class::ASSOCIATION.key?(key)
72
+ associated_attrs = value.is_a?(Hash) ? value : { uri: value }
73
+ value = self.class::ASSOCIATION[key].new associated_attrs, @client
74
+ elsif defined?(self.class::TIME_FIELDS) && self.class::TIME_FIELDS.include?(key)
75
+ value = Time.parse value
76
+ end
77
+ instance_variable_set "@#{key}", value
78
+ end
79
+ after_set_attributes(attrs)
80
+ end
81
+
82
+ def after_set_attributes(attrs)
83
+ @uuid = self.class.extract_uuid(attrs[:uri]) if respond_to? :uuid=
84
+ end
85
+
86
+ #
87
+ # Get all collection from single page or plurality of pages.
88
+ #
89
+ # @param [Proc] request_proc the procedure of request portion of collection.
90
+ # @param [Hash] opts the optional request parameters for the procedure.
91
+ # @return [Array<Calendly::Model>]
92
+ # @since 0.1.0
93
+ def auto_pagination(request_proc, opts)
94
+ items = []
95
+ loop do
96
+ new_items, next_opts = request_proc.call opts
97
+ items = [*items, *new_items]
98
+ break unless next_opts
99
+
100
+ opts = next_opts
101
+ end
102
+ items
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calendly
4
+ # Calendly's organization model.
5
+ class Organization
6
+ include ModelUtils
7
+ UUID_RE = %r{\A#{Client::API_HOST}/organizations/(\w+)\z}.freeze
8
+
9
+ # @return [String]
10
+ # unique id of the Organization object.
11
+ attr_accessor :uuid
12
+ # @return [String]
13
+ # Canonical resource reference.
14
+ attr_accessor :uri
15
+
16
+ #
17
+ # Get List memberships of all users belonging to self.
18
+ #
19
+ # @param [Hash] opts the optional request parameters.
20
+ # @option opts [Integer] :count Number of rows to return.
21
+ # @option opts [String] :email Filter by email.
22
+ # @option opts [String] :page_token Pass this to get the next portion of collection.
23
+ # @return [Array<Calendly::OrganizationMembership>]
24
+ # @raise [Calendly::Error] if the uri is empty.
25
+ # @raise [Calendly::ApiError] if the api returns error code.
26
+ # @since 0.1.0
27
+ def memberships(opts = {})
28
+ request_proc = proc { |options| client.memberships uri, options }
29
+ auto_pagination request_proc, opts
30
+ end
31
+
32
+ #
33
+ # Get Organization Invitations.
34
+ #
35
+ # @param [Hash] opts the optional request parameters.
36
+ # @option opts [Integer] :count Number of rows to return.
37
+ # @option opts [String] :email Filter by email.
38
+ # @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.
40
+ # @option opts [String] :status Filter by status.
41
+ # @return [Array<Calendly::OrganizationInvitation>]
42
+ # @raise [Calendly::Error] if the uuid is empty.
43
+ # @raise [Calendly::ApiError] if the api returns error code.
44
+ # @since 0.1.0
45
+ def invitations(opts = {})
46
+ request_proc = proc { |options| client.invitations uuid, options }
47
+ auto_pagination request_proc, opts
48
+ end
49
+
50
+ #
51
+ # Invite a person to an Organization.
52
+ #
53
+ # @param [String] email Email of the person being invited.
54
+ # @return [Calendly::OrganizationInvitation]
55
+ # @raise [Calendly::Error] if the uuid is empty.
56
+ # @raise [Calendly::Error] if the email is empty.
57
+ # @raise [Calendly::ApiError] if the api returns error code.
58
+ # @since 0.1.0
59
+ def create_invitation(email)
60
+ client.create_invitation uuid, email
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calendly
4
+ # Calendly's organization invitation model.
5
+ class OrganizationInvitation
6
+ include ModelUtils
7
+ UUID_RE = %r{\A#{Client::API_HOST}/organizations/\w+/invitations/(\w+)\z}.freeze
8
+ TIME_FIELDS = %i[created_at updated_at last_sent_at].freeze
9
+ ASSOCIATION = { user: User, organization: Organization }.freeze
10
+
11
+ # @return [String]
12
+ # unique id of the OrganizationInvitation object.
13
+ attr_accessor :uuid
14
+ # @return [String]
15
+ # Canonical resource reference.
16
+ attr_accessor :uri
17
+ # @return [String]
18
+ # Invited person's email.
19
+ attr_accessor :email
20
+ # @return [String]
21
+ # Invitation status.
22
+ attr_accessor :status
23
+ # @return [Time]
24
+ # Moment when user record was first created.
25
+ attr_accessor :created_at
26
+ # @return [Time]
27
+ # Moment when user record was last updated.
28
+ attr_accessor :updated_at
29
+ # @return [Time]
30
+ # Moment when the last invitation was sent.
31
+ attr_accessor :last_sent_at
32
+
33
+ # @return [Organization]
34
+ # Reference to Organization associated with this invitation.
35
+ attr_accessor :organization
36
+
37
+ # @return [User]
38
+ # If a person accepted the invitation, a reference to their User.
39
+ attr_accessor :user
40
+
41
+ #
42
+ # Get Organization Invitation associated with self.
43
+ #
44
+ # @return [Calendly::OrganizationInvitation]
45
+ # @raise [Calendly::Error] if the organization.uuid is empty.
46
+ # @raise [Calendly::Error] if the uuid is empty.
47
+ # @raise [Calendly::ApiError] if the api returns error code.
48
+ # @since 0.1.0
49
+ def fetch
50
+ org_uuid = organization.uuid if organization
51
+ client.invitation org_uuid, uuid
52
+ end
53
+
54
+ #
55
+ # Revoke self Invitation.
56
+ #
57
+ # @return [true]
58
+ # @raise [Calendly::Error] if the organization.uuid is empty.
59
+ # @raise [Calendly::Error] if the uuid is empty.
60
+ # @raise [Calendly::ApiError] if the api returns error code.
61
+ # @since 0.1.0
62
+ def delete
63
+ org_uuid = organization.uuid if organization
64
+ client.delete_invitation org_uuid, uuid
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calendly
4
+ # Calendly's organization membership model.
5
+ class OrganizationMembership
6
+ include ModelUtils
7
+ UUID_RE = %r{\A#{Client::API_HOST}/organization_memberships/(\w+)\z}.freeze
8
+ TIME_FIELDS = %i[created_at updated_at].freeze
9
+ ASSOCIATION = { user: User, organization: Organization }.freeze
10
+
11
+ # @return [String]
12
+ # unique id of the OrganizationMembership object.
13
+ attr_accessor :uuid
14
+ # @return [String]
15
+ # Canonical resource reference.
16
+ attr_accessor :uri
17
+ # @return [String]
18
+ # User's role within the organization
19
+ attr_accessor :role
20
+ # @return [Time]
21
+ # Moment when user record was first created.
22
+ attr_accessor :created_at
23
+ # @return [Time]
24
+ # Moment when user record was last updated.
25
+ attr_accessor :updated_at
26
+
27
+ # @return [Calendly::User]
28
+ # Primary account details of a specific user.
29
+ attr_accessor :user
30
+
31
+ # @return [Organization]
32
+ # Reference to Organization associated with this membership.
33
+ attr_accessor :organization
34
+
35
+ #
36
+ # Get Organization Membership associated with self.
37
+ #
38
+ # @return [Calendly::OrganizationMembership]
39
+ # @raise [Calendly::Error] if the uuid is empty.
40
+ # @raise [Calendly::ApiError] if the api returns error code.
41
+ # @since 0.1.0
42
+ def fetch
43
+ client.membership uuid
44
+ end
45
+
46
+ #
47
+ # Remove self from associated Organization.
48
+ #
49
+ # @raise [Calendly::Error] if the uuid is empty.
50
+ # @raise [Calendly::ApiError] if the api returns error code.
51
+ # @since 0.1.0
52
+ def delete
53
+ client.delete_membership uuid
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calendly
4
+ # Calendly's user model.
5
+ # Primary account details of a specific user.
6
+ class User
7
+ include ModelUtils
8
+ UUID_RE = %r{\A#{Client::API_HOST}/users/(\w+)\z}.freeze
9
+ TIME_FIELDS = %i[created_at updated_at].freeze
10
+
11
+ # @return [String]
12
+ # unique id of the User object.
13
+ attr_accessor :uuid
14
+ # @return [String]
15
+ # Canonical resource reference.
16
+ attr_accessor :uri
17
+ # @return [String]
18
+ # User's human-readable name.
19
+ attr_accessor :name
20
+ # @return [String]
21
+ # Unique readable value used in page URL.
22
+ attr_accessor :slug
23
+ # @return [String]
24
+ # User's email address.
25
+ attr_accessor :email
26
+ # @return [String]
27
+ # URL of user's avatar image.
28
+ attr_accessor :avatar_url
29
+ # @return [String]
30
+ # URL of user's event page.
31
+ attr_accessor :scheduling_url
32
+ # @return [String]
33
+ # Timezone offest to use when presenting time information to user.
34
+ attr_accessor :timezone
35
+ # @return [Time]
36
+ # Moment when user record was first created.
37
+ attr_accessor :created_at
38
+ # @return [Time]
39
+ # Moment when user record was last updated.
40
+ attr_accessor :updated_at
41
+
42
+ #
43
+ # Get basic information associated with self.
44
+ #
45
+ # @return [Calendly::User]
46
+ # @raise [Calendly::Error] if the uuid is empty.
47
+ # @raise [Calendly::ApiError] if the api returns error code.
48
+ # @since 0.1.0
49
+ def fetch
50
+ client.user uuid
51
+ end
52
+
53
+ #
54
+ # Get an organization membership information associated with self.
55
+ #
56
+ # @return [Calendly::OrganizationMembership]
57
+ # @raise [Calendly::Error] if the uri is empty.
58
+ # @since 0.1.0
59
+ def organization_membership
60
+ mems, = client.memberships_by_user uri
61
+ mems.first
62
+ end
63
+
64
+ #
65
+ # Returns all Event Types associated with self.
66
+ #
67
+ # @param [Hash] opts the optional request parameters.
68
+ # @option opts [Integer] :count Number of rows to return.
69
+ # @option opts [String] :page_token Pass this to get the next portion of collection.
70
+ # @option opts [String] :sort Order results by the specified field and direction. Accepts comma-separated list of {field}:{direction} values.
71
+ # @return [Array<Calendly::EventType>]
72
+ # @raise [Calendly::Error] if the uri is empty.
73
+ # @raise [Calendly::ApiError] if the api returns error code.
74
+ # @since 0.1.0
75
+ def event_types(opts = {})
76
+ request_proc = proc { |options| client.event_types uri, options }
77
+ auto_pagination request_proc, opts
78
+ end
79
+
80
+ #
81
+ # Returns all Scheduled Events associated with self.
82
+ #
83
+ # @param [Hash] opts the optional request parameters.
84
+ # @option opts [Integer] :count Number of rows to return.
85
+ # @option opts [String] :invitee_email Return events scheduled with the specified invitee email
86
+ # @option opts [String] :max_start_time Upper bound (inclusive) for an event's start time to filter by.
87
+ # @option opts [String] :min_start_time Lower bound (inclusive) for an event's start time to filter by.
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
+ # @option opts [String] :status Whether the scheduled event is active or canceled
91
+ # @return [Array<Calendly::Event>]
92
+ # @raise [Calendly::Error] if the uri is empty.
93
+ # @raise [Calendly::ApiError] if the api returns error code.
94
+ # @since 0.1.0
95
+ def scheduled_events(opts = {})
96
+ request_proc = proc { |options| client.scheduled_events uri, options }
97
+ auto_pagination request_proc, opts
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calendly
4
+ VERSION = '0.1.0'
5
+ end
data/lib/calendly.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zeitwerk'
4
+ loader = Zeitwerk::Loader.for_gem
5
+ loader.collapse('**/models')
6
+ loader.setup
7
+
8
+ # module for Calendly apis client
9
+ module Calendly
10
+ class << self
11
+ def configure
12
+ yield configuration
13
+ end
14
+
15
+ def configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+ end
19
+ end