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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@
.rvmrc

# Used by RuboCop. Remote config files pulled in from inherit_from directive.
# .rubocop-https?--*
# .rubocop-https?--*
.env*
!.env.example

/kb
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ EmbedWorkflow::Users.upsert(name: "Jane Smith", id: user["id"], config: config)
EmbedWorkflow::Users.fetch(key: "api-user-1")
```

### List users

```ruby
# List all users
EmbedWorkflow::Users.list

# List with pagination
EmbedWorkflow::Users.list(starting_after: "550e8400-e29b-41d4-a716-446655440000", limit: 10)
```

### Delete a user

```ruby
EmbedWorkflow::Users.delete(key: "api-user-1")
```

### Catch a webhook

```ruby
Expand Down
17 changes: 17 additions & 0 deletions lib/embed_workflow/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ def upsert(key:, name: nil, email: nil, config: nil)
def fetch(key:)
get_request(path: "#{RESOURCE_BASE_PATH}/#{key}")
end

def list(starting_after: nil, ending_before: nil, limit: nil)
params = {
starting_after: starting_after,
ending_before: ending_before,
limit: limit
}.compact

get_request(
path: RESOURCE_BASE_PATH,
params: params
)
end

def delete(key:)
delete_request(path: "#{RESOURCE_BASE_PATH}/#{key}")
end
end
end
end
111 changes: 111 additions & 0 deletions spec/users_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# frozen_string_literal: true

require_relative "../lib/embed_workflow"
require "net/http"

describe "users" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:execute_request)
.with(instance_of(Net::HTTPRequest))
.and_return("response")
end

describe "#list" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:get_request)
.with({ path: "/api/v1/users", params: {} })
.and_return("response")
end

it "sends the correct parameters to the users API" do
EmbedWorkflow::Users.list
end

context "with pagination parameters" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:get_request)
.with({ path: "/api/v1/users", params: { starting_after: "550e8400-e29b-41d4-a716-446655440000", limit: 10 } })
.and_return("response")
end

it "sends the correct pagination parameters" do
EmbedWorkflow::Users.list(starting_after: "550e8400-e29b-41d4-a716-446655440000", limit: 10)
end
end
end

describe "#fetch" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:get_request)
.with({ path: "/api/v1/users/api-user-1" })
.and_return("response")
end

it "sends the correct parameters to the users API" do
EmbedWorkflow::Users.fetch(key: "api-user-1")
end
end

describe "#delete" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:delete_request)
.with({ path: "/api/v1/users/api-user-1" })
.and_return("response")
end

it "sends the correct parameters to the users API" do
EmbedWorkflow::Users.delete(key: "api-user-1")
end
end

describe "#upsert" do
context "with minimum parameters" do
before do
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:put_request)
.with({
path: "/api/v1/users/api-user-1",
body: { key: "api-user-1" }
})
.and_return("response")
end

it "sends the correct parameters to the users API" do
EmbedWorkflow::Users.upsert(key: "api-user-1")
end
end

context "with all parameters" do
before do
config = { user_data: { foo: "bar" } }
allow_any_instance_of(EmbedWorkflow::Client)
.to receive(:put_request)
.with({
path: "/api/v1/users/api-user-1",
body: {
key: "api-user-1",
name: "Jane Doe",
email: "jane@example.com",
config: config
}
})
.and_return("response")
end

it "sends the correct parameters to the users API" do
config = { user_data: { foo: "bar" } }
EmbedWorkflow::Users.upsert(
key: "api-user-1",
name: "Jane Doe",
email: "jane@example.com",
config: config
)
end
end
end
end
Loading