calendlyr 0.7.5 → 0.10.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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +9 -5
  3. data/.gitignore +2 -1
  4. data/CHANGELOG.md +60 -0
  5. data/README.md +31 -79
  6. data/calendlyr.gemspec +4 -5
  7. data/docs/resources/data_compliance.md +1 -1
  8. data/docs/resources/event_types/availability_schedule.md +28 -0
  9. data/docs/resources/event_types/event_type.md +18 -7
  10. data/docs/resources/events/cancellation.md +1 -1
  11. data/docs/resources/events/event.md +2 -2
  12. data/docs/resources/events/invitee.md +17 -0
  13. data/docs/resources/locations/location.md +16 -0
  14. data/docs/resources/organizations/organization.md +0 -9
  15. data/docs/resources/share.md +2 -9
  16. data/docs/resources/webhooks/invitee_payload.md +1 -1
  17. data/docs/resources/webhooks/payload.md +1 -1
  18. data/docs/resources/webhooks/subscription.md +1 -1
  19. data/lib/calendlyr/client.rb +6 -2
  20. data/lib/calendlyr/collection.rb +18 -3
  21. data/lib/calendlyr/error.rb +17 -26
  22. data/lib/calendlyr/object.rb +77 -14
  23. data/lib/calendlyr/objects/event_type.rb +0 -4
  24. data/lib/calendlyr/objects/event_types/availability_schedule.rb +8 -0
  25. data/lib/calendlyr/objects/events/invitee.rb +1 -1
  26. data/lib/calendlyr/objects/location.rb +4 -0
  27. data/lib/calendlyr/objects/organization.rb +0 -4
  28. data/lib/calendlyr/objects/share.rb +0 -5
  29. data/lib/calendlyr/resource.rb +34 -7
  30. data/lib/calendlyr/resources/event_types.rb +16 -7
  31. data/lib/calendlyr/resources/events.rb +5 -0
  32. data/lib/calendlyr/resources/locations.rb +8 -0
  33. data/lib/calendlyr/resources/webhooks.rb +0 -4
  34. data/lib/calendlyr/version.rb +1 -1
  35. data/lib/calendlyr.rb +4 -5
  36. data/test/calendlyr/client_test.rb +14 -0
  37. data/test/calendlyr/collection_test.rb +64 -0
  38. data/test/calendlyr/object_test.rb +32 -1
  39. data/test/calendlyr/objects/event_type_test.rb +0 -15
  40. data/test/calendlyr/objects/event_types/availability_schedule_test.rb +20 -0
  41. data/test/calendlyr/objects/events/cancellation_test.rb +1 -1
  42. data/test/calendlyr/objects/events/guest_test.rb +1 -1
  43. data/test/calendlyr/objects/events/invitee_no_show_test.rb +1 -1
  44. data/test/calendlyr/objects/events/invitee_test.rb +10 -3
  45. data/test/calendlyr/objects/location_test.rb +22 -0
  46. data/test/calendlyr/objects/organization_test.rb +0 -8
  47. data/test/calendlyr/objects/organizations/invitation_test.rb +1 -1
  48. data/test/calendlyr/objects/share_test.rb +3 -9
  49. data/test/calendlyr/resource_test.rb +170 -2
  50. data/test/calendlyr/resources/data_compliance_test.rb +1 -4
  51. data/test/calendlyr/resources/event_types_test.rb +48 -0
  52. data/test/calendlyr/resources/events_test.rb +19 -0
  53. data/test/calendlyr/resources/locations_test.rb +18 -0
  54. data/test/calendlyr/resources/webhooks_test.rb +0 -8
  55. data/test/fixtures/event_invitees/retrieve.json +11 -1
  56. data/test/fixtures/event_type_availability_schedules/list.json +17 -0
  57. data/test/fixtures/event_type_availability_schedules/update.json +3 -0
  58. data/test/fixtures/event_types/create.json +30 -0
  59. data/test/fixtures/event_types/update.json +30 -0
  60. data/test/fixtures/events/create_invitee.json +37 -0
  61. data/test/fixtures/events/retrieve.json +12 -2
  62. data/test/fixtures/locations/list.json +16 -0
  63. data/test/fixtures/objects/event.json +10 -2
  64. data/test/fixtures/objects/event_types/availability_schedule.json +6 -0
  65. data/test/fixtures/objects/location.json +5 -0
  66. data/test/test_helper.rb +9 -7
  67. metadata +32 -50
  68. data/docs/resources/event_types/available_time.md +0 -21
  69. data/docs/resources/event_types/membership.md +0 -29
  70. data/docs/resources/scheduling_link.md +0 -26
  71. data/lib/calendlyr/objects/event_types/available_time.rb +0 -4
  72. data/lib/calendlyr/objects/event_types/membership.rb +0 -11
  73. data/lib/calendlyr/objects/scheduling_link.rb +0 -9
  74. data/lib/calendlyr/resources/outgoing_communications.rb +0 -8
  75. data/lib/calendlyr/resources/scheduling_links.rb +0 -8
  76. data/test/calendlyr/objects/event_types/available_time_test.rb +0 -20
  77. data/test/calendlyr/objects/event_types/membership_test.rb +0 -32
  78. data/test/calendlyr/objects/scheduling_link_test.rb +0 -17
  79. data/test/calendlyr/resources/event_types/membership_test.rb +0 -22
  80. data/test/calendlyr/resources/outgoing_communications_test.rb +0 -16
  81. data/test/calendlyr/resources/scheduling_links_test.rb +0 -15
  82. data/test/fixtures/event_type_available_times/list.json +0 -22
  83. data/test/fixtures/objects/event_types/available_time.json +0 -6
  84. data/test/fixtures/objects/event_types/membership.json +0 -65
  85. data/test/fixtures/objects/scheduling_links/event_type.json +0 -5
  86. data/test/fixtures/outgoing_communications/list.json +0 -26
  87. data/test/fixtures/scheduling_links/create.json +0 -7
  88. data/test/fixtures/webhooks/sample.json +0 -105
@@ -1,31 +1,94 @@
1
- require "ostruct"
2
-
3
1
  module Calendlyr
4
- class Object < OpenStruct
2
+ class Object
5
3
  def self.get_slug(path)
6
4
  path.split("/").last
7
5
  end
8
6
 
9
- def initialize(attributes)
10
- super(to_ostruct(attributes.merge(uuid: extract_uuid(attributes))))
7
+ private_class_method :get_slug
8
+
9
+ def initialize(attributes = nil, add_uuid: true, **kwargs)
10
+ attrs = (attributes || {}).merge(kwargs).dup
11
+ if add_uuid && !attrs.key?(:uuid) && !attrs.key?("uuid")
12
+ attrs = attrs.merge(uuid: extract_uuid(attrs))
13
+ end
14
+
15
+ @attributes = attrs.each_with_object({}) do |(key, value), hash|
16
+ hash[key.to_s] = wrap(value)
17
+ end
11
18
  end
12
19
 
13
- def to_ostruct(obj)
14
- if obj.is_a?(Hash)
15
- OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
16
- elsif obj.is_a?(Array)
17
- obj.map { |o| to_ostruct(o) }
18
- else # Assumed to be a primitive value
19
- obj
20
+ def method_missing(name, *args, &block)
21
+ if args.empty? && block.nil?
22
+ return @attributes[name.to_s] if @attributes.key?(name.to_s)
23
+
24
+ return nil
20
25
  end
26
+
27
+ super
21
28
  end
22
29
 
30
+ def respond_to_missing?(name, include_private = false)
31
+ @attributes.key?(name.to_s) || super
32
+ end
33
+
34
+ def to_h
35
+ @attributes.each_with_object({}) do |(key, value), hash|
36
+ hash[key.to_sym] = unwrap(value)
37
+ end
38
+ end
39
+
40
+ def inspect
41
+ attributes = @attributes.map do |key, value|
42
+ "#{key}=#{value.inspect}"
43
+ end.join(" ")
44
+ "#<#{self.class} #{attributes}>"
45
+ end
46
+
47
+ def ==(other)
48
+ other.is_a?(self.class) && to_h == other.to_h
49
+ end
50
+
51
+ def eql?(other)
52
+ self == other
53
+ end
54
+
55
+ def hash
56
+ to_h.hash
57
+ end
58
+
59
+ private
60
+
23
61
  def extract_uuid(attrs)
24
- attrs["uri"] ? get_slug(attrs["uri"]) : nil
62
+ uri = attrs["uri"] || attrs[:uri]
63
+ uri ? get_slug(uri) : nil
25
64
  end
26
65
 
66
+ protected
67
+
27
68
  def get_slug(path)
28
- Calendlyr::Object.get_slug(path)
69
+ self.class.send(:get_slug, path)
70
+ end
71
+
72
+ private
73
+
74
+ def wrap(value)
75
+ if value.is_a?(Hash)
76
+ self.class.new(value, add_uuid: false)
77
+ elsif value.is_a?(Array)
78
+ value.map { |item| wrap(item) }
79
+ else
80
+ value
81
+ end
82
+ end
83
+
84
+ def unwrap(value)
85
+ if value.is_a?(self.class)
86
+ value.to_h
87
+ elsif value.is_a?(Array)
88
+ value.map { |item| unwrap(item) }
89
+ else
90
+ value
91
+ end
29
92
  end
30
93
  end
31
94
  end
@@ -7,9 +7,5 @@ module Calendlyr
7
7
  def create_share(**params)
8
8
  client.shares.create(**params.merge(event_type: uri))
9
9
  end
10
-
11
- def available_times(start_time:, end_time:, **params)
12
- client.event_types.list_available_times(**params.merge(event_type: uri, start_time: start_time, end_time: end_time))
13
- end
14
10
  end
15
11
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calendlyr
4
+ module EventTypes
5
+ class AvailabilitySchedule < Object
6
+ end
7
+ end
8
+ end
@@ -1,7 +1,7 @@
1
1
  module Calendlyr
2
2
  class Events::Invitee < Object
3
3
  def cancel(reason: nil)
4
- client.events.cancel(uuid: uuid, reason: reason)
4
+ client.events.cancel(uuid: get_slug(event), reason: reason)
5
5
  end
6
6
 
7
7
  def create_no_shows
@@ -0,0 +1,4 @@
1
+ module Calendlyr
2
+ class Location < Object
3
+ end
4
+ end
@@ -43,10 +43,6 @@ module Calendlyr
43
43
  client.webhooks.create(**params.merge(organization: uri, url: url, events: events, scope: scope))
44
44
  end
45
45
 
46
- def sample_webhook_data(event:, scope:, **params)
47
- client.webhooks.sample_webhook_data(event: event, scope: scope, organization: uri, **params)
48
- end
49
-
50
46
  # Invitations
51
47
  def invite_user(email:, **params)
52
48
  client.organizations.invite(**params.merge(organization_uuid: uuid, email: email))
@@ -1,9 +1,4 @@
1
1
  module Calendlyr
2
2
  class Share < Object
3
- def associated_scheduling_links
4
- scheduling_links.map do |scheduling_link|
5
- SchedulingLink.new(scheduling_link.to_h.merge(client: client))
6
- end
7
- end
8
3
  end
9
4
  end
@@ -8,6 +8,8 @@ module Calendlyr
8
8
  attr_reader :client
9
9
 
10
10
  ERROR_CODES = %w[400 401 403 404 424 429 500]
11
+ MAX_RETRIES = 3
12
+ RETRY_BACKOFF = [1, 2, 4]
11
13
 
12
14
  def initialize(client)
13
15
  @client = client
@@ -23,6 +25,14 @@ module Calendlyr
23
25
  handle_response request(url, Net::HTTP::Post, body: body)
24
26
  end
25
27
 
28
+ def patch_request(url, body:)
29
+ handle_response request(url, Net::HTTP::Patch, body: body)
30
+ end
31
+
32
+ def put_request(url, body:)
33
+ handle_response request(url, Net::HTTP::Put, body: body)
34
+ end
35
+
26
36
  def delete_request(url, params: {})
27
37
  handle_response request(url, Net::HTTP::Delete, params: params)
28
38
  end
@@ -37,30 +47,47 @@ module Calendlyr
37
47
 
38
48
  http = Net::HTTP.new(uri.host, uri.port)
39
49
  http.use_ssl = true
40
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
50
+ http.open_timeout = client.open_timeout
51
+ http.read_timeout = client.read_timeout
41
52
 
42
53
  request = req_type.new(uri)
43
54
  request["Content-Type"] = "application/json"
44
55
  request["Authorization"] = "Bearer #{client.token}"
45
56
  request.body = body.to_json if body.any?
46
57
 
47
- http.request(request)
58
+ attempts = 0
59
+
60
+ loop do
61
+ response = http.request(request)
62
+ return response unless response.code == "429"
63
+ return response if attempts >= MAX_RETRIES
64
+
65
+ sleep retry_after_seconds(response, attempts)
66
+ attempts += 1
67
+ end
48
68
  end
49
69
 
50
70
  def handle_response(response)
51
- return true unless response.read_body
71
+ body_string = response.body.to_s
52
72
 
53
73
  body = begin
54
- JSON.parse(response.read_body)
55
- rescue
74
+ body_string.empty? ? {} : JSON.parse(body_string)
75
+ rescue JSON::ParserError
56
76
  {}
57
77
  end
58
78
 
59
79
  if ERROR_CODES.include? response.code
60
80
  raise ResponseErrorHandler.new(response.code, body).error
61
- else
62
- body
63
81
  end
82
+
83
+ body
84
+ end
85
+
86
+ def retry_after_seconds(response, attempt)
87
+ retry_after = response["Retry-After"]
88
+ return retry_after.to_i if retry_after&.match?(/^\d+$/)
89
+
90
+ RETRY_BACKOFF.fetch(attempt)
64
91
  end
65
92
  end
66
93
  end
@@ -14,15 +14,24 @@ module Calendlyr
14
14
  EventType.new post_request("one_off_event_types", body: body).dig("resource").merge(client: client)
15
15
  end
16
16
 
17
- def list_memberships(event_type:, **params)
18
- response = get_request("event_type_memberships", params: {event_type: event_type}.merge(params))
19
- Collection.from_response(response, type: EventTypes::Membership, client: client)
17
+ def create(name:, duration:, pooling_type:, **params)
18
+ body = {name: name, duration: duration, pooling_type: pooling_type}.merge(params)
19
+ EventType.new post_request("event_types", body: body).dig("resource").merge(client: client)
20
20
  end
21
21
 
22
- # Available Times
23
- def list_available_times(event_type:, start_time:, end_time:, **params)
24
- response = get_request("event_type_available_times", params: {event_type: event_type, start_time: start_time, end_time: end_time}.merge(params))
25
- Collection.from_response(response, type: EventTypes::AvailableTime, client: client)
22
+ def update(uuid:, **params)
23
+ EventType.new patch_request("event_types/#{uuid}", body: params).dig("resource").merge(client: client)
24
+ end
25
+
26
+ # Availability Schedules
27
+ def list_availability_schedules(event_type_uuid:, **params)
28
+ response = get_request("event_type_availability_schedules", params: {event_type_uuid: event_type_uuid}.merge(params))
29
+ Collection.from_response(response, type: EventTypes::AvailabilitySchedule, client: client)
30
+ end
31
+
32
+ def update_availability_schedule(event_type_uuid:, availability_schedules:, **params)
33
+ body = {event_type_uuid: event_type_uuid, availability_schedules: availability_schedules}.merge(params)
34
+ patch_request("event_type_availability_schedules", body: body)
26
35
  end
27
36
  end
28
37
  end
@@ -23,6 +23,11 @@ module Calendlyr
23
23
  Events::Invitee.new get_request("scheduled_events/#{event_uuid}/invitees/#{invitee_uuid}").dig("resource").merge(client: client)
24
24
  end
25
25
 
26
+ def create_invitee(event_type:, start_time:, invitee:, **params)
27
+ body = {event_type: event_type, start_time: start_time, invitee: invitee}.merge(params)
28
+ Events::Invitee.new post_request("invitees", body: body).dig("invitee").merge(client: client)
29
+ end
30
+
26
31
  # Invitee No Show
27
32
  def retrieve_invitee_no_show(uuid:)
28
33
  Events::InviteeNoShow.new get_request("invitee_no_shows/#{uuid}").dig("resource").merge(client: client)
@@ -0,0 +1,8 @@
1
+ module Calendlyr
2
+ class LocationsResource < Resource
3
+ def list(**params)
4
+ response = get_request("locations", params: params)
5
+ Collection.from_response(response, type: Location, client: client)
6
+ end
7
+ end
8
+ end
@@ -17,9 +17,5 @@ module Calendlyr
17
17
  def delete(webhook_uuid:)
18
18
  delete_request("webhook_subscriptions/#{webhook_uuid}")
19
19
  end
20
-
21
- def sample_webhook_data(event:, organization:, scope:, **params)
22
- Object.new get_request("sample_webhook_data", params: params.merge(event: event, organization: organization, scope: scope)).merge(client: client)
23
- end
24
20
  end
25
21
  end
@@ -1,3 +1,3 @@
1
1
  module Calendlyr
2
- VERSION = "0.7.5"
2
+ VERSION = "0.10.0"
3
3
  end
data/lib/calendlyr.rb CHANGED
@@ -7,6 +7,7 @@ module Calendlyr
7
7
  autoload :Resource, "calendlyr/resource"
8
8
 
9
9
  # Errors
10
+ autoload :ERROR_TYPES, "calendlyr/error"
10
11
  autoload :BadRequest, "calendlyr/error"
11
12
  autoload :Error, "calendlyr/error"
12
13
  autoload :ExternalCalendarError, "calendlyr/error"
@@ -25,9 +26,8 @@ module Calendlyr
25
26
  autoload :EventTypesResource, "calendlyr/resources/event_types"
26
27
  autoload :GroupsResource, "calendlyr/resources/groups"
27
28
  autoload :OrganizationsResource, "calendlyr/resources/organizations"
28
- autoload :OutgoingCommunicationsResource, "calendlyr/resources/outgoing_communications"
29
+ autoload :LocationsResource, "calendlyr/resources/locations"
29
30
  autoload :RoutingFormsResource, "calendlyr/resources/routing_forms"
30
- autoload :SchedulingLinksResource, "calendlyr/resources/scheduling_links"
31
31
  autoload :SharesResource, "calendlyr/resources/shares"
32
32
  autoload :UsersResource, "calendlyr/resources/users"
33
33
  autoload :WebhooksResource, "calendlyr/resources/webhooks"
@@ -38,8 +38,8 @@ module Calendlyr
38
38
  autoload :EventType, "calendlyr/objects/event_type"
39
39
  autoload :Group, "calendlyr/objects/group"
40
40
  autoload :Organization, "calendlyr/objects/organization"
41
+ autoload :Location, "calendlyr/objects/location"
41
42
  autoload :RoutingForm, "calendlyr/objects/routing_form"
42
- autoload :SchedulingLink, "calendlyr/objects/scheduling_link"
43
43
  autoload :Share, "calendlyr/objects/share"
44
44
  autoload :User, "calendlyr/objects/user"
45
45
 
@@ -57,8 +57,7 @@ module Calendlyr
57
57
  end
58
58
 
59
59
  module EventTypes
60
- autoload :AvailableTime, "calendlyr/objects/event_types/available_time"
61
- autoload :Membership, "calendlyr/objects/event_types/membership"
60
+ autoload :AvailabilitySchedule, "calendlyr/objects/event_types/availability_schedule"
62
61
  autoload :Profile, "calendlyr/objects/event_types/profile"
63
62
  end
64
63
 
@@ -19,4 +19,18 @@ class ClientTest < Minitest::Test
19
19
  assert client.respond_to?(:users)
20
20
  refute client.respond_to?(:useers)
21
21
  end
22
+
23
+ def test_default_timeouts
24
+ new_client = Calendlyr::Client.new(token: "fake")
25
+
26
+ assert_equal 30, new_client.open_timeout
27
+ assert_equal 30, new_client.read_timeout
28
+ end
29
+
30
+ def test_custom_timeouts
31
+ new_client = Calendlyr::Client.new(token: "fake", open_timeout: 10, read_timeout: 15)
32
+
33
+ assert_equal 10, new_client.open_timeout
34
+ assert_equal 15, new_client.read_timeout
35
+ end
22
36
  end
@@ -0,0 +1,64 @@
1
+ require "test_helper"
2
+
3
+ class CollectionTest < Minitest::Test
4
+ def build_collection
5
+ data = [
6
+ Calendlyr::Object.new(name: "Alice"),
7
+ Calendlyr::Object.new(name: "Bob")
8
+ ]
9
+
10
+ Calendlyr::Collection.new(data: data, count: 2, next_page: nil, client: client)
11
+ end
12
+
13
+ def test_each_yields_items
14
+ collection = build_collection
15
+ names = []
16
+
17
+ collection.each do |item|
18
+ names << item.name
19
+ end
20
+
21
+ assert_equal %w[Alice Bob], names
22
+ end
23
+
24
+ def test_map_is_available_from_enumerable
25
+ collection = build_collection
26
+
27
+ assert_equal %w[Alice Bob], collection.map(&:name)
28
+ end
29
+
30
+ def test_collection_responds_to_select
31
+ collection = build_collection
32
+
33
+ assert collection.respond_to?(:select)
34
+ end
35
+
36
+ def test_count_without_block_returns_metadata_count
37
+ collection = Calendlyr::Collection.new(
38
+ data: [Calendlyr::Object.new(name: "Alice")],
39
+ count: 10,
40
+ next_page: nil,
41
+ client: client
42
+ )
43
+
44
+ assert_equal 10, collection.count
45
+ end
46
+
47
+ def test_count_with_block_uses_enumerable_count
48
+ collection = build_collection
49
+
50
+ assert_equal(1, collection.count { |item| item.name == "Alice" })
51
+ end
52
+
53
+ def test_count_with_argument_uses_enumerable_count
54
+ alice = Calendlyr::Object.new(name: "Alice")
55
+ collection = Calendlyr::Collection.new(
56
+ data: [alice, Calendlyr::Object.new(name: "Bob")],
57
+ count: 10,
58
+ next_page: nil,
59
+ client: client
60
+ )
61
+
62
+ assert_equal 1, collection.count(alice)
63
+ end
64
+ end
@@ -15,7 +15,38 @@ class ObjectTest < Minitest::Test
15
15
 
16
16
  def test_array
17
17
  object = Calendlyr::Object.new(foo: [{bar: :baz}], client: nil)
18
- assert_equal OpenStruct, object.foo.first.class
18
+ assert_equal Calendlyr::Object, object.foo.first.class
19
19
  assert_equal :baz, object.foo.first.bar
20
20
  end
21
+
22
+ def test_uuid_extraction_from_string_uri
23
+ object = Calendlyr::Object.new("uri" => "https://api.calendly.com/users/ABC123")
24
+
25
+ assert_equal "ABC123", object.uuid
26
+ end
27
+
28
+ def test_missing_attribute_returns_nil
29
+ object = Calendlyr::Object.new(name: "test")
30
+
31
+ assert_nil object.nonexistent
32
+ end
33
+
34
+ def test_respond_to_existing_attribute
35
+ object = Calendlyr::Object.new(name: "test")
36
+
37
+ assert object.respond_to?(:name)
38
+ end
39
+
40
+ def test_to_h_returns_deep_hash
41
+ object = Calendlyr::Object.new("profile" => {"age" => 30, "items" => [{"id" => 1}]})
42
+
43
+ assert_equal({profile: {age: 30, items: [{id: 1}]}, uuid: nil}, object.to_h)
44
+ end
45
+
46
+ def test_equals_other_object_with_same_attributes
47
+ first = Calendlyr::Object.new(name: "test")
48
+ second = Calendlyr::Object.new(name: "test")
49
+
50
+ assert_equal first, second
51
+ end
21
52
  end
@@ -7,13 +7,6 @@ class EventTypeObjectTest < Minitest::Test
7
7
  json = JSON.parse(fixture_file("objects/event_type")).merge(client: client)
8
8
  @event_type = Calendlyr::EventType.new(json)
9
9
 
10
- event_type_uri = "https://api.calendly.com/event_types/AAAAAAAAAAAAAAAA"
11
- @start_time = "2020-01-02T20:00:00.000000Z"
12
- @end_time = "2020-01-07T24:00:00.000000Z"
13
-
14
- response = {body: fixture_file("event_type_available_times/list"), status: 200}
15
- stub(path: "event_type_available_times?event_type=#{event_type_uri}&start_time=#{@start_time}&end_time=#{@end_time}", response: response)
16
-
17
10
  event_type_uri = "https://api.calendly.com/event_types/AAAAAAAAAAAAAAAA"
18
11
  response = {body: fixture_file("shares/create"), status: 201}
19
12
  stub(method: :post, path: "shares", body: {event_type: event_type_uri}, response: response)
@@ -32,12 +25,4 @@ class EventTypeObjectTest < Minitest::Test
32
25
  assert_instance_of Calendlyr::Share, share
33
26
  assert_equal 1, share.scheduling_links.size
34
27
  end
35
-
36
- def test_available_times
37
- available_times = @event_type.available_times(start_time: @start_time, end_time: @end_time)
38
-
39
- assert 3, available_times.data.size
40
- assert "available", available_times.data.first.status
41
- assert_instance_of Calendlyr::EventTypes::AvailableTime, available_times.data.first
42
- end
43
28
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ module EventTypes
6
+ class AvailabilityScheduleObjectTest < Minitest::Test
7
+ def setup
8
+ json = JSON.parse(fixture_file("objects/event_types/availability_schedule")).merge(client: client)
9
+ @availability_schedule = Calendlyr::EventTypes::AvailabilitySchedule.new(json)
10
+ end
11
+
12
+ def test_uri
13
+ assert_equal "https://api.calendly.com/event_type_availability_schedules/AAAAAAAAAAAAAAAA", @availability_schedule.uri
14
+ end
15
+
16
+ def test_event_type
17
+ assert_equal "https://api.calendly.com/event_types/BBBBBBBBBBBBBBBB", @availability_schedule.event_type
18
+ end
19
+ end
20
+ end
@@ -10,7 +10,7 @@ module Events
10
10
  end
11
11
 
12
12
  def test_canceled_by
13
- assert "string", @cancellation.canceled_by
13
+ assert_equal "string", @cancellation.canceled_by
14
14
  end
15
15
  end
16
16
  end
@@ -10,7 +10,7 @@ module Events
10
10
  end
11
11
 
12
12
  def test_email
13
- assert "user@example.com", @guest.email
13
+ assert_equal "user@example.com", @guest.email
14
14
  end
15
15
  end
16
16
  end
@@ -10,7 +10,7 @@ module Events
10
10
  end
11
11
 
12
12
  def test_created_at
13
- assert "2019-01-02T03:04:05.678123Z", @invitee_no_show.created_at
13
+ assert_equal "2019-01-02T03:04:05.678123Z", @invitee_no_show.created_at
14
14
  end
15
15
 
16
16
  def test_delete
@@ -10,14 +10,21 @@ module Events
10
10
  end
11
11
 
12
12
  def test_email
13
- assert "user@example.com", @invitee.email
13
+ assert_equal "test@example.com", @invitee.email
14
14
  end
15
15
 
16
16
  def test_cancel
17
+ invitee = Calendlyr::Events::Invitee.new(
18
+ JSON.parse(fixture_file("objects/events/invitee")).merge(
19
+ "event" => "https://api.calendly.com/scheduled_events/EVT123",
20
+ "uri" => "https://api.calendly.com/scheduled_events/EVT123/invitees/INV456",
21
+ :client => client
22
+ )
23
+ )
17
24
  response = {body: fixture_file("events/cancel_invitee"), status: 201}
18
- stub(method: :post, path: "scheduled_events/#{@invitee.uuid}/cancellation", response: response)
25
+ stub(method: :post, path: "scheduled_events/EVT123/cancellation", response: response)
19
26
 
20
- cancellation = @invitee.cancel(reason: "I'm busy")
27
+ cancellation = invitee.cancel(reason: "I'm busy")
21
28
 
22
29
  assert_instance_of Calendlyr::Events::Cancellation, cancellation
23
30
  assert_equal "host", cancellation.canceler_type
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class LocationObjectTest < Minitest::Test
6
+ def setup
7
+ json = JSON.parse(fixture_file("objects/location")).merge(client: client)
8
+ @location = Calendlyr::Location.new(json)
9
+ end
10
+
11
+ def test_uri
12
+ assert_equal "https://api.calendly.com/locations/AAAAAAAAAAAAAAAA", @location.uri
13
+ end
14
+
15
+ def test_type
16
+ assert_equal "zoom", @location.type
17
+ end
18
+
19
+ def test_display_name
20
+ assert_equal "Zoom", @location.display_name
21
+ end
22
+ end
@@ -111,14 +111,6 @@ class OrganizatonObjectTest < Minitest::Test
111
111
  assert @organization.create_webhook(**body)
112
112
  end
113
113
 
114
- def test_sample_webhook_data
115
- stub(path: "sample_webhook_data?event=invitee.created&scope=organization&organization=https://api.calendly.com/organizations/012345678901234567890", response: {body: fixture_file("webhooks/sample"), status: 200})
116
- webhook_data = @organization.sample_webhook_data(event: "invitee.created", scope: "organization")
117
-
118
- assert_instance_of Calendlyr::Object, webhook_data
119
- assert_equal "invitee.created", webhook_data.event
120
- end
121
-
122
114
  def test_invite_user
123
115
  email = "email@example.com"
124
116
  response = {body: fixture_file("organizations/invite"), status: 201}
@@ -12,7 +12,7 @@ module Organizations
12
12
  stub(method: :delete, path: "organizations/#{@invitation.associated_organization.uuid}/invitations/#{@invitation.uuid}", response: response)
13
13
 
14
14
  response = {body: fixture_file("users/retrieve"), status: 200}
15
- stub(path: "users/#{Calendlyr::Object.get_slug(@invitation.user)}", response: response)
15
+ stub(path: "users/#{@invitation.user.split("/").last}", response: response)
16
16
  end
17
17
 
18
18
  def test_associated_organization
@@ -3,17 +3,11 @@
3
3
  require "test_helper"
4
4
 
5
5
  class ShareObjectTest < Minitest::Test
6
- def test_associated_scheduling_links
6
+ def test_share
7
7
  json = JSON.parse(fixture_file("objects/share")).merge(client: client)
8
8
  @share = Calendlyr::Share.new(json)
9
9
 
10
- response = {body: fixture_file("event_types/retrieve"), status: 200}
11
- stub(path: "event_types/AAAAAAAAAAAAAAAA", response: response)
12
-
13
- scheculing_links = @share.associated_scheduling_links
14
-
15
- assert_equal 1, scheculing_links.size
16
- assert_equal Calendlyr::SchedulingLink, scheculing_links.first.class
17
- assert_equal Calendlyr::EventType, scheculing_links.first.event_type.class
10
+ assert_instance_of Calendlyr::Share, @share
11
+ assert_equal 1, @share.scheduling_links.size
18
12
  end
19
13
  end