Skip to content

Commit

Permalink
Merge pull request #49 from koshilife/feature/#48-support-cancel-even…
Browse files Browse the repository at this point in the history
…t-api

support Cancel Event API
  • Loading branch information
koshilife committed May 2, 2022
2 parents d888437 + 7d134c3 commit 817a198
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 22 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Ruby CI
on: [push]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1']

steps:
- uses: actions/checkout@v3
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Install dependencies
run: bundle install
- name: Run tests
run: bundle exec rake test
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
21 changes: 0 additions & 21 deletions .github/workflows/test.yml

This file was deleted.

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## 0.11.0 - 2022-05-02

- supported a API `POST /scheduled_events/{uuid}/cancellation`. (#48)
- changed files:
- Client
- (Add method) cancel_event
- Event
- (Add method) cancel
- improved CI to test by multiple Ruby versions.

## 0.10.0 - 2022-04-15

- supported a API `POST /data_compliance/deletion/invitees`. (#28)
Expand Down
20 changes: 20 additions & 0 deletions lib/calendly/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,26 @@ def scheduled_events(org_uri, options: nil)
[evs, next_page_params(body)]
end

#
# Cancels specified event.
#
# @param [String] uuid the event's unique indentifier.
# @param [Hash] options the optional request parameters. Optional.
# @option options [String] :reason reason for cancellation.
# @return [InviteeCancellation]
# @raise [Calendly::Error] if the uuid arg is empty.
# @raise [Calendly::ApiError] if the api returns error code.
# @since 0.11.0
def cancel_event(uuid, options: nil)
check_not_empty uuid, 'uuid'

opts_keys = %i[reason]
params = merge_options options, opts_keys

body = request :post, "scheduled_events/#{uuid}/cancellation", body: params
InviteeCancellation.new body[:resource], self
end

#
# Get List of scheduled events belonging to a specific user.
#
Expand Down
13 changes: 13 additions & 0 deletions lib/calendly/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ def fetch
client.scheduled_event uuid
end

#
# Cancels specified event.
#
# @param [Hash] options the optional request parameters. Optional.
# @option options [String] :reason reason for cancellation.
# @return [InviteeCancellation]
# @raise [Calendly::Error] if the uuid is empty.
# @raise [Calendly::ApiError] if the api returns error code.
# @since 0.11.0
def cancel(options: nil)
client.cancel_event uuid, options: options
end

#
# Returns all Event Invitees associated with self.
#
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.10.0'
VERSION = '0.11.0'
end
16 changes: 16 additions & 0 deletions test/assert_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,22 @@ def assert_event013(ev)
assert_equal [], ev.event_guests
end

def assert_invitee_cancel001(invitee_cancel)
assert invitee_cancel.is_a? Calendly::InviteeCancellation
assert invitee_cancel.client.is_a? Calendly::Client
assert_equal 'FooBar', invitee_cancel.canceled_by
assert_nil invitee_cancel.reason
assert_equal 'host', invitee_cancel.canceler_type
end

def assert_invitee_cancel002(invitee_cancel)
assert invitee_cancel.is_a? Calendly::InviteeCancellation
assert invitee_cancel.client.is_a? Calendly::Client
assert_equal 'FooBar', invitee_cancel.canceled_by
assert_equal 'something', invitee_cancel.reason
assert_equal 'host', invitee_cancel.canceler_type
end

def assert_event101_invitee001(inv)
assert inv.client.is_a? Calendly::Client
assert_equal 'INV001', inv.id
Expand Down
34 changes: 34 additions & 0 deletions test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,40 @@ def test_that_it_raises_an_argument_error_on_scheduled_events_by_user
assert_required_error proc_arg_is_empty, 'user_uri'
end

#
# test for cancel_event
#

def test_that_it_cancels_a_specific_event
ev_uuid = 'EV001'
res_body = load_test_data 'cancel_event_001.json'

url = "#{HOST}/scheduled_events/#{ev_uuid}/cancellation"
add_stub_request :post, url, req_body: {}, res_body: res_body

invitee_cancel = @client.cancel_event ev_uuid
assert_invitee_cancel001 invitee_cancel
end

def test_that_it_cancels_a_specific_event_with_reason
ev_uuid = 'EV001'
req_body = {reason: 'something'}
res_body = load_test_data 'cancel_event_002.json'

url = "#{HOST}/scheduled_events/#{ev_uuid}/cancellation"
add_stub_request :post, url, req_body: req_body, res_body: res_body

invitee_cancel = @client.cancel_event ev_uuid, options: req_body
assert_invitee_cancel002 invitee_cancel
end

def test_that_it_raises_an_argument_error_on_cancel_event
proc_arg_is_empty = proc do
@client.cancel_event ''
end
assert_required_error proc_arg_is_empty, 'uuid'
end

#
# test for event_invitee
#
Expand Down
26 changes: 26 additions & 0 deletions test/models/event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ def test_that_it_returns_an_associated_event
assert_event001 @event.fetch
end

def test_that_it_cancels_a_specific_event
res_body = load_test_data 'cancel_event_001.json'
url = "#{@ev_uri}/cancellation"
add_stub_request :post, url, req_body: {}, res_body: res_body

invitee_cancel = @event.cancel
assert_invitee_cancel001 invitee_cancel
end

def test_that_it_cancels_a_specific_event_with_reason
req_body = {reason: 'something'}
res_body = load_test_data 'cancel_event_002.json'
url = "#{@ev_uri}/cancellation"
add_stub_request :post, url, req_body: req_body, res_body: res_body

invitee_cancel = @event.cancel options: req_body
assert_invitee_cancel002 invitee_cancel
end

def test_that_it_returns_an_error_client_is_not_ready_on_cancel
proc_client_is_blank = proc do
@event_no_client.cancel
end
assert_error proc_client_is_blank, '@client is not ready.'
end

def test_that_it_returns_event_invitees_in_single_page
res_body = load_test_data 'scheduled_event_invitees_101.json'
url = "#{@ev_uri}/invitees"
Expand Down
7 changes: 7 additions & 0 deletions test/testdata/cancel_event_001.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"resource": {
"canceled_by": "FooBar",
"canceler_type": "host",
"reason": null
}
}
7 changes: 7 additions & 0 deletions test/testdata/cancel_event_002.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"resource": {
"canceled_by": "FooBar",
"canceler_type": "host",
"reason": "something"
}
}

0 comments on commit 817a198

Please sign in to comment.