Skip to content

Commit

Permalink
Merge pull request #44 from koshilife/#43_support_filter_by_active_fl…
Browse files Browse the repository at this point in the history
…ag_in_event_types

support for filtering Event Types by 'active' or 'inactive' status
  • Loading branch information
koshilife committed Mar 8, 2022
2 parents 7ddd032 + 25cef42 commit 07aed56
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.8.3 - 2022-03-08

- support for filtering Event Types by 'active' or 'inactive' status. (#43)

## 0.8.2 - 2022-02-26

- support cancellation field in the response of scheduled event endpoints. (#41)
Expand Down
6 changes: 4 additions & 2 deletions lib/calendly/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def event_type(uuid)
#
# @param [String] org_uri the specified organization (organization's uri).
# @param [Hash] options the optional request parameters. Optional.
# @option options [Boolean] :active Return only active event types if true, only inactive if false, or all event types if this parameter is omitted.
# @option options [Integer] :count Number of rows to return.
# @option options [String] :page_token Pass this to get the next portion of collection.
# @option options [String] :sort Order results by the specified field and direction. Accepts comma-separated list of {field}:{direction} values.
Expand All @@ -119,7 +120,7 @@ def event_type(uuid)
def event_types(org_uri, options: nil)
check_not_empty org_uri, 'org_uri'

opts_keys = %i[count page_token sort]
opts_keys = %i[active count page_token sort]
params = {organization: org_uri}
params = merge_options options, opts_keys, params
body = request :get, 'event_types', params: params
Expand All @@ -134,6 +135,7 @@ def event_types(org_uri, options: nil)
#
# @param [String] user_uri the specified user (user's uri).
# @param [Hash] options the optional request parameters. Optional.
# @option options [Boolean] :active Return only active event types if true, only inactive if false, or all event types if this parameter is omitted.
# @option options [Integer] :count Number of rows to return.
# @option options [String] :page_token Pass this to get the next portion of collection.
# @option options [String] :sort Order results by the specified field and direction. Accepts comma-separated list of {field}:{direction} values.
Expand All @@ -146,7 +148,7 @@ def event_types(org_uri, options: nil)
def event_types_by_user(user_uri, options: nil)
check_not_empty user_uri, 'user_uri'

opts_keys = %i[count page_token sort]
opts_keys = %i[active count page_token sort]
params = {user: user_uri}
params = merge_options options, opts_keys, params
body = request :get, 'event_types', params: params
Expand Down
1 change: 1 addition & 0 deletions lib/calendly/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def create_invitation(email)
# Returns all Event Types associated with self.
#
# @param [Hash] options the optional request parameters. Optional.
# @option options [Boolean] :active Return only active event types if true, only inactive if false, or all event types if this parameter is omitted.
# @option options [Integer] :count Number of rows to return.
# @option options [String] :page_token Pass this to get the next portion of collection.
# @option options [String] :sort Order results by the specified field and direction.
Expand Down
1 change: 1 addition & 0 deletions lib/calendly/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def organization_membership!
# Returns all Event Types associated with self.
#
# @param [Hash] options the optional request parameters. Optional.
# @option options [Boolean] :active Return only active event types if true, only inactive if false, or all event types if this parameter is omitted.
# @option options [Integer] :count Number of rows to return.
# @option options [String] :page_token Pass this to get the next portion of collection.
# @option options [String] :sort Order results by the specified field and direction.
Expand Down
2 changes: 1 addition & 1 deletion lib/calendly/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Calendly
VERSION = '0.8.2'
VERSION = '0.8.3'
end
28 changes: 28 additions & 0 deletions test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,20 @@ def test_that_it_returns_all_items_of_event_type_across_pages
assert_event_type001 event_types_page2[0]
end

def test_that_it_returns_active_items_of_event_type
org_uri = 'https://api.calendly.com/organizations/ORG001'
res_body = load_test_data 'event_types_003.json'
params = {organization: org_uri, active: true}

url = "#{HOST}/event_types?#{URI.encode_www_form(params)}"
add_stub_request :get, url, res_body: res_body

event_types, next_params = @client.event_types org_uri, options: {active: true}
assert_equal 1, event_types.length
assert_nil next_params
assert_event_type001 event_types[0]
end

def test_that_it_raises_an_argument_error_on_event_types
proc_arg_is_empty = proc do
@client.event_types ''
Expand Down Expand Up @@ -260,6 +274,20 @@ def test_that_it_returns_all_items_of_event_type_by_user_across_pages
assert_event_type001 event_types_page2[0]
end

def test_that_it_returns_active_items_of_event_type_by_user
user_uri = 'https://api.calendly.com/users/U001'
res_body = load_test_data 'event_types_003.json'
params = {user: user_uri, active: true}

url = "#{HOST}/event_types?#{URI.encode_www_form(params)}"
add_stub_request :get, url, res_body: res_body

event_types, next_params = @client.event_types_by_user user_uri, options: {active: true}
assert_equal 1, event_types.length
assert_nil next_params
assert_event_type001 event_types[0]
end

def test_that_it_raises_an_argument_error_on_event_types_by_user
proc_arg_is_empty = proc do
@client.event_types_by_user ''
Expand Down
32 changes: 32 additions & 0 deletions test/testdata/event_types_003.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"collection": [
{
"active": true,
"color": "#000001",
"created_at": "2020-07-01T03:00:00.000000Z",
"custom_questions": [],
"description_html": null,
"description_plain": null,
"duration": 15,
"internal_note": null,
"kind": "solo",
"name": "15 Minute Meeting",
"pooling_type": null,
"profile": {
"name": "FooBar",
"owner": "https://api.calendly.com/users/U001",
"type": "User"
},
"scheduling_url": "https://calendly.com/foobar/15min",
"secret": false,
"slug": "15min",
"type": "StandardEventType",
"updated_at": "2020-07-11T03:00:00.000000Z",
"uri": "https://api.calendly.com/event_types/ET001"
}
],
"pagination": {
"count": 1,
"next_page": null
}
}

0 comments on commit 07aed56

Please sign in to comment.