Skip to content

Commit cb94b20

Browse files
authoredMar 7, 2025··
add list and delete to users (#8)
1 parent 9c0970d commit cb94b20

File tree

4 files changed

+149
-1
lines changed

4 files changed

+149
-1
lines changed
 

‎.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@
4646
.rvmrc
4747

4848
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
49-
# .rubocop-https?--*
49+
# .rubocop-https?--*
50+
.env*
51+
!.env.example
52+
53+
/kb

‎README.md

+16
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ EmbedWorkflow::Users.upsert(name: "Jane Smith", id: user["id"], config: config)
129129
EmbedWorkflow::Users.fetch(key: "api-user-1")
130130
```
131131

132+
### List users
133+
134+
```ruby
135+
# List all users
136+
EmbedWorkflow::Users.list
137+
138+
# List with pagination
139+
EmbedWorkflow::Users.list(starting_after: "550e8400-e29b-41d4-a716-446655440000", limit: 10)
140+
```
141+
142+
### Delete a user
143+
144+
```ruby
145+
EmbedWorkflow::Users.delete(key: "api-user-1")
146+
```
147+
132148
### Catch a webhook
133149

134150
```ruby

‎lib/embed_workflow/users.rb

+17
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ def upsert(key:, name: nil, email: nil, config: nil)
2828
def fetch(key:)
2929
get_request(path: "#{RESOURCE_BASE_PATH}/#{key}")
3030
end
31+
32+
def list(starting_after: nil, ending_before: nil, limit: nil)
33+
params = {
34+
starting_after: starting_after,
35+
ending_before: ending_before,
36+
limit: limit
37+
}.compact
38+
39+
get_request(
40+
path: RESOURCE_BASE_PATH,
41+
params: params
42+
)
43+
end
44+
45+
def delete(key:)
46+
delete_request(path: "#{RESOURCE_BASE_PATH}/#{key}")
47+
end
3148
end
3249
end
3350
end

‎spec/users_spec.rb

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../lib/embed_workflow"
4+
require "net/http"
5+
6+
describe "users" do
7+
before do
8+
allow_any_instance_of(EmbedWorkflow::Client)
9+
.to receive(:execute_request)
10+
.with(instance_of(Net::HTTPRequest))
11+
.and_return("response")
12+
end
13+
14+
describe "#list" do
15+
before do
16+
allow_any_instance_of(EmbedWorkflow::Client)
17+
.to receive(:get_request)
18+
.with({ path: "/api/v1/users", params: {} })
19+
.and_return("response")
20+
end
21+
22+
it "sends the correct parameters to the users API" do
23+
EmbedWorkflow::Users.list
24+
end
25+
26+
context "with pagination parameters" do
27+
before do
28+
allow_any_instance_of(EmbedWorkflow::Client)
29+
.to receive(:get_request)
30+
.with({ path: "/api/v1/users", params: { starting_after: "550e8400-e29b-41d4-a716-446655440000", limit: 10 } })
31+
.and_return("response")
32+
end
33+
34+
it "sends the correct pagination parameters" do
35+
EmbedWorkflow::Users.list(starting_after: "550e8400-e29b-41d4-a716-446655440000", limit: 10)
36+
end
37+
end
38+
end
39+
40+
describe "#fetch" do
41+
before do
42+
allow_any_instance_of(EmbedWorkflow::Client)
43+
.to receive(:get_request)
44+
.with({ path: "/api/v1/users/api-user-1" })
45+
.and_return("response")
46+
end
47+
48+
it "sends the correct parameters to the users API" do
49+
EmbedWorkflow::Users.fetch(key: "api-user-1")
50+
end
51+
end
52+
53+
describe "#delete" do
54+
before do
55+
allow_any_instance_of(EmbedWorkflow::Client)
56+
.to receive(:delete_request)
57+
.with({ path: "/api/v1/users/api-user-1" })
58+
.and_return("response")
59+
end
60+
61+
it "sends the correct parameters to the users API" do
62+
EmbedWorkflow::Users.delete(key: "api-user-1")
63+
end
64+
end
65+
66+
describe "#upsert" do
67+
context "with minimum parameters" do
68+
before do
69+
allow_any_instance_of(EmbedWorkflow::Client)
70+
.to receive(:put_request)
71+
.with({
72+
path: "/api/v1/users/api-user-1",
73+
body: { key: "api-user-1" }
74+
})
75+
.and_return("response")
76+
end
77+
78+
it "sends the correct parameters to the users API" do
79+
EmbedWorkflow::Users.upsert(key: "api-user-1")
80+
end
81+
end
82+
83+
context "with all parameters" do
84+
before do
85+
config = { user_data: { foo: "bar" } }
86+
allow_any_instance_of(EmbedWorkflow::Client)
87+
.to receive(:put_request)
88+
.with({
89+
path: "/api/v1/users/api-user-1",
90+
body: {
91+
key: "api-user-1",
92+
name: "Jane Doe",
93+
email: "jane@example.com",
94+
config: config
95+
}
96+
})
97+
.and_return("response")
98+
end
99+
100+
it "sends the correct parameters to the users API" do
101+
config = { user_data: { foo: "bar" } }
102+
EmbedWorkflow::Users.upsert(
103+
key: "api-user-1",
104+
name: "Jane Doe",
105+
email: "jane@example.com",
106+
config: config
107+
)
108+
end
109+
end
110+
end
111+
end

0 commit comments

Comments
 (0)
Please sign in to comment.