Skip to content
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ client = ActivitySmith::Client.new(
### Send a Push Notification

```ruby
response = client.notifications.send_push_notification(
response = client.notifications.send(
{
title: "Build Failed",
message: "CI pipeline failed on main branch"
Expand All @@ -45,7 +45,7 @@ response = client.notifications.send_push_notification(
### Start a Live Activity

```ruby
start = client.live_activities.start_live_activity(
start = client.live_activities.start(
{
content_state: {
title: "Deploy",
Expand All @@ -62,7 +62,7 @@ activity_id = start.activity_id
### Update a Live Activity

```ruby
update = client.live_activities.update_live_activity(
update = client.live_activities.update(
{
activity_id: activity_id,
content_state: {
Expand All @@ -76,7 +76,7 @@ update = client.live_activities.update_live_activity(
### End a Live Activity

```ruby
finish = client.live_activities.end_live_activity(
finish = client.live_activities.end(
{
activity_id: activity_id,
content_state: {
Expand All @@ -92,7 +92,7 @@ finish = client.live_activities.end_live_activity(

```ruby
begin
client.notifications.send_push_notification(
client.notifications.send(
{ title: "Build Failed" }
)
rescue OpenapiClient::ApiError => e
Expand Down
2 changes: 2 additions & 0 deletions lib/activitysmith.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

require_relative "activitysmith/version"
require_relative "activitysmith/notifications"
require_relative "activitysmith/live_activities"
require_relative "activitysmith/client"
4 changes: 2 additions & 2 deletions lib/activitysmith/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def initialize(api_key:, base_url: nil)
config.host = base_url.to_s.sub(%r{/+$}, "") unless base_url.to_s.strip.empty?

api_client = OpenapiClient::ApiClient.new(config)
@notifications = OpenapiClient::PushNotificationsApi.new(api_client)
@live_activities = OpenapiClient::LiveActivitiesApi.new(api_client)
@notifications = Notifications.new(OpenapiClient::PushNotificationsApi.new(api_client))
@live_activities = LiveActivities.new(OpenapiClient::LiveActivitiesApi.new(api_client))
end

private
Expand Down
44 changes: 44 additions & 0 deletions lib/activitysmith/live_activities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

module ActivitySmith
class LiveActivities
def initialize(api)
@api = api
end

def start(request, opts = {})
@api.start_live_activity(request, opts)
end

def update(request, opts = {})
@api.update_live_activity(request, opts)
end

def end(request, opts = {})
@api.end_live_activity(request, opts)
end

# Backward-compatible aliases.
def start_live_activity(live_activity_start_request, opts = {})
@api.start_live_activity(live_activity_start_request, opts)
end

def update_live_activity(live_activity_update_request, opts = {})
@api.update_live_activity(live_activity_update_request, opts)
end

def end_live_activity(live_activity_end_request, opts = {})
@api.end_live_activity(live_activity_end_request, opts)
end

def method_missing(name, *args, &block)
return @api.public_send(name, *args, &block) if @api.respond_to?(name)

super
end

def respond_to_missing?(name, include_private = false)
@api.respond_to?(name, include_private) || super
end
end
end
28 changes: 28 additions & 0 deletions lib/activitysmith/notifications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module ActivitySmith
class Notifications
def initialize(api)
@api = api
end

def send(request, opts = {})
@api.send_push_notification(request, opts)
end

# Backward-compatible alias.
def send_push_notification(push_notification_request, opts = {})
@api.send_push_notification(push_notification_request, opts)
end

def method_missing(name, *args, &block)
return @api.public_send(name, *args, &block) if @api.respond_to?(name)

super
end

def respond_to_missing?(name, include_private = false)
@api.respond_to?(name, include_private) || super
end
end
end
4 changes: 4 additions & 0 deletions test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def test_constructs_when_generated_client_is_present

refute_nil client.notifications
refute_nil client.live_activities
assert_respond_to client.notifications, :send
assert_respond_to client.live_activities, :start
assert_respond_to client.live_activities, :update
assert_respond_to client.live_activities, :end
rescue RuntimeError => error
skip "Generated OpenAPI client is not present yet." if error.message.include?("Generated Ruby client not found")

Expand Down