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
25 changes: 8 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,15 @@ gem install activitysmith
```ruby
require "activitysmith"

client = ActivitySmith::Client.new(api_key: ENV.fetch("ACTIVITYSMITH_API_KEY"))
```

You can also override the API host:

```ruby
client = ActivitySmith::Client.new(
api_key: ENV.fetch("ACTIVITYSMITH_API_KEY"),
base_url: "https://activitysmith.com/api"
)
activitysmith = ActivitySmith::Client.new(api_key: ENV.fetch("ACTIVITYSMITH_API_KEY"))
```

## Usage

### Send a Push Notification

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

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

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

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

```ruby
begin
client.notifications.send(
activitysmith.notifications.send(
{ title: "Build Failed" }
)
rescue OpenapiClient::ApiError => e
Expand All @@ -102,8 +93,8 @@ end

## API Surface

- `client.notifications`
- `client.live_activities`
- `activitysmith.notifications`
- `activitysmith.live_activities`

## Requirements

Expand Down
3 changes: 1 addition & 2 deletions lib/activitysmith/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ module ActivitySmith
class Client
attr_reader :notifications, :live_activities

def initialize(api_key:, base_url: nil)
def initialize(api_key:)
raise ArgumentError, "ActivitySmith: api_key is required" if api_key.to_s.strip.empty?

load_generated_client!

config = OpenapiClient::Configuration.new
config.access_token = api_key
config.host = base_url.to_s.sub(%r{/+$}, "") unless base_url.to_s.strip.empty?

api_client = OpenapiClient::ApiClient.new(config)
@notifications = Notifications.new(OpenapiClient::PushNotificationsApi.new(api_client))
Expand Down