Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Activity Log #5

Merged
merged 5 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
name: Tests

on:
pull_request:
branches:
- "*"
push:
branches:
- master
branches: [master]
pull_request:
branches: "*"

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ["2.5", "2.6", "2.7", "3.0"]
ruby: ["2.5", "2.6", "2.7", "3.0", "3.2"]

steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -31,4 +30,4 @@ jobs:
run: |
bundle exec rake test
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ client.organization.events
# List/Creaete webhooks
client.organization.list_webhooks(scope: "scope")
client.organization.create_webhook(url: "post_callback_url", events: ["invitee.canceled", "invitee.created"], scope: "scope")

# List activity log
client.organization.activity_log
````

### Webhooks
Expand Down Expand Up @@ -183,4 +186,4 @@ When adding resources, add to the list of resources in lib/calendlyr. Additional

Many thanks [@markets](https://github.com/markets) (our contributor in the shadows) for all comments, details and tips for this rubygem project and for made me grow professionally in my day by day :raised_hands:

Thanks [@excid3](https://github.com/excid3) and his [Vultr.rb](https://github.com/excid3/vultr.rb) rubygem project.
Thanks [@excid3](https://github.com/excid3) and his [Vultr.rb](https://github.com/excid3/vultr.rb) rubygem project.
1 change: 0 additions & 1 deletion calendlyr.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Gem::Specification.new do |spec|

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_development_dependency "rake", "~> 12.0"
Expand Down
1 change: 1 addition & 0 deletions lib/calendlyr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ module Calendlyr
autoload :SchedulingLink, "calendlyr/objects/scheduling_links"
autoload :Membership, "calendlyr/objects/memberships"
autoload :Webhook, "calendlyr/objects/webhooks"
autoload :ActivityLog, "calendlyr/objects/activity_log"
end
4 changes: 2 additions & 2 deletions lib/calendlyr/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module Calendlyr
class Collection
attr_reader :data, :count, :next_page, :next_page_token, :client

def self.from_response(response, key:, type:, client:)
def self.from_response(response, type:, client:)
new(
data: response[key].map { |attrs| type.new(attrs.merge(client: client)) },
data: response["collection"].map { |attrs| type.new(attrs.merge(client: client)) },
count: response.dig("pagination", "count"),
next_page: response.dig("pagination", "next_page"),
client: client
Expand Down
2 changes: 1 addition & 1 deletion lib/calendlyr/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Calendlyr
class Object < OpenStruct
def initialize(attributes)
super to_ostruct(attributes.merge(uuid: extract_uuid(attributes)))
super(to_ostruct(attributes.merge(uuid: extract_uuid(attributes))))
end

def to_ostruct(obj)
Expand Down
7 changes: 7 additions & 0 deletions lib/calendlyr/objects/activity_log.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Calendlyr
class ActivityLog < Object
def associated_organization
@associated_organization ||= Organization.new({"uri" => organization}.merge(client: client))
end
end
end
4 changes: 4 additions & 0 deletions lib/calendlyr/objects/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ def events(user_uri: nil, **params)
def memberships(user_uri: nil, **params)
client.organizations.list_memberships user_uri: user_uri, organization_uri: uri, **params
end

def activity_log(**params)
client.organizations.activity_log organization_uri: uri, **params
end
end
end
8 changes: 8 additions & 0 deletions lib/calendlyr/objects/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@ def associated_user
def associated_organization
@associated_organization ||= Organization.new({"uri" => organization}.merge(client: client))
end

def active?
state == "active"
end

def disabled?
state == "disabled"
end
end
end
2 changes: 1 addition & 1 deletion lib/calendlyr/resources/event_invitees.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Calendlyr
class EventInviteeResource < Resource
def list(event_uuid:, **params)
response = get_request("scheduled_events/#{event_uuid}/invitees", params: params.compact)
Collection.from_response(response, key: "collection", type: EventInvitee, client: client)
Collection.from_response(response, type: EventInvitee, client: client)
end

def retrieve(event_uuid:, invitee_uuid:)
Expand Down
2 changes: 1 addition & 1 deletion lib/calendlyr/resources/event_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Calendlyr
class EventTypeResource < Resource
def list(user_uri:, organization_uri:, **params)
response = get_request("event_types", params: {user: user_uri, organization: organization_uri}.merge(params))
Collection.from_response(response, key: "collection", type: EventType, client: client)
Collection.from_response(response, type: EventType, client: client)
end

def retrieve(event_type_uuid:)
Expand Down
2 changes: 1 addition & 1 deletion lib/calendlyr/resources/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Calendlyr
class EventResource < Resource
def list(user_uri:, organization_uri:, **params)
response = get_request("scheduled_events", params: {user: user_uri, organization: organization_uri}.merge(params).compact)
Collection.from_response(response, key: "collection", type: Event, client: client)
Collection.from_response(response, type: Event, client: client)
end

def retrieve(event_uuid:)
Expand Down
9 changes: 7 additions & 2 deletions lib/calendlyr/resources/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ def invite(organization_uuid:, email:)

def list_invitations(organization_uuid:, **params)
response = get_request("organizations/#{organization_uuid}/invitations", params: params)
Collection.from_response(response, key: "collection", type: Invitation, client: client)
Collection.from_response(response, type: Invitation, client: client)
end

def list_memberships(user_uri: nil, organization_uri: nil, **params)
response = get_request("organization_memberships", params: {user: user_uri, organization: organization_uri}.merge(params).compact)
Collection.from_response(response, key: "collection", type: Membership, client: client)
Collection.from_response(response, type: Membership, client: client)
end

def activity_log(organization_uri: nil, **params)
response = get_request("activity_log_entries", params: {organization: organization_uri}.merge(params).compact)
Collection.from_response(response, type: ActivityLog, client: client)
end

def retrieve_invitation(organization_uuid:, invitation_uuid:)
Expand Down
2 changes: 1 addition & 1 deletion lib/calendlyr/resources/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Calendlyr
class WebhookResource < Resource
def list(organization_uri:, scope:, **params)
response = get_request("webhook_subscriptions", params: {organization: organization_uri, scope: scope}.merge(params).compact)
Collection.from_response(response, key: "collection", type: Webhook, client: client)
Collection.from_response(response, type: Webhook, client: client)
end

def create(url:, events:, organization_uri:, scope:, signing_key: nil, user_uri: nil)
Expand Down
10 changes: 10 additions & 0 deletions test/calendlyr/resources/organizations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def test_list_webhooks
assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", webhooks.next_page_token
end

def test_activity_log
stub(path: "activity_log_entries?organization=#{client.organization.uri}", response: {body: fixture_file("activity_log/list"), status: 200})
activity_log = client.organization.activity_log

assert_equal Calendlyr::Collection, activity_log.class
assert_equal Calendlyr::ActivityLog, activity_log.data.first.class
assert_equal 20, activity_log.count
assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", activity_log.next_page_token
end

def test_create_webhook
body = {url: "https://blah.foo/bar", events: ["invitee.created"], organization: client.organization.uri, scope: "user", user: client.me.uri}
stub(method: :post, path: "webhook_subscriptions", body: body, response: {body: fixture_file("webhooks/create"), status: 201})
Expand Down
1 change: 1 addition & 0 deletions test/calendlyr/resources/webhooks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_retrieve
assert_equal "user", webhook.scope
assert_equal webhook.associated_user, client.users.retrieve(user_uuid: "AAAAAAAAAAAAAAAA")
assert_equal webhook.associated_organization, client.users.retrieve(user_uuid: "AAAAAAAAAAAAAAAA").organization
assert_equal webhook.active?, true
end

def test_delete
Expand Down
38 changes: 38 additions & 0 deletions test/fixtures/activity_log/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"collection": [
{
"occurred_at": "2020-01-02T03:04:05.678Z",
"uri": "https://api.calendly.com/activity_log_entries/ALFKJELNCLKSJDLKFJGELKJ",
"namespace": "User",
"action": "Add",
"actor": {
"uri": "https://api.calendly.com/users/SDLKJENFJKD123",
"type": "User",
"organization": {
"uri": "https://api.calendly.com/organizations/LKJENFLKE293847",
"role": "Owner"
},
"group": {
"uri": "https://api.calendly.com/groups/123987DJLKJEF",
"name": "Development",
"role": "Admin"
},
"display_name": "Test User",
"alternative_identifier": "[email protected]"
},
"fully_qualified_name": "User.Add",
"details": {},
"organization": "https://api.calendly.com/organizations/AAAAAAAAAAAAAAA"
}
],
"pagination": {
"count": 20,
"next_page": "https://api.calendly.com/activity_log?page_token=sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi",
"next_page_token": "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi",
"previous_page": "https://api.calendly.com/activity_log?page_token=dGhpcyBpcyBvbmx5IGFuIGV4YW1wbGUgc3RyaW5n",
"previous_page_token": "dGhpcyBpcyBvbmx5IGFuIGV4YW1wbGUgc3RyaW5n"
},
"last_event_time": "2020-01-02T03:04:05.678Z",
"total_count": 1,
"exceeds_max_total_count": false
}