Skip to content

Commit cb86dbf

Browse files
committed
Added example.
1 parent 0391d40 commit cb86dbf

File tree

2 files changed

+50
-37
lines changed

2 files changed

+50
-37
lines changed

README.md

+2-37
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,9 @@ Or install it yourself as:
2020

2121
## Usage
2222

23-
Once the gem is installed, you can call FusionAuth APIs like this:
23+
Once the gem is installed, you can call FusionAuth APIs.
2424

25-
```ruby
26-
require 'fusionauth/fusionauth_client'
27-
28-
# Construct the FusionAuth Client
29-
client = FusionAuth::FusionAuthClient.new(
30-
'<YOUR_API_KEY>',
31-
'http://localhost:9011'
32-
)
33-
34-
# Create a user + registration
35-
id = SecureRandom.uuid
36-
client.register(id, {
37-
:user => {
38-
:firstName => 'Ruby',
39-
:lastName => 'Client',
40-
:email => 'ruby.client.test@fusionauth.io',
41-
:password => 'password'
42-
},
43-
:registration => {
44-
:applicationId => application_id,
45-
:data => {
46-
:foo => 'bar'
47-
},
48-
:preferredLanguages => %w(en fr),
49-
:roles => %w(user)
50-
}
51-
})
52-
53-
# Authenticate the user
54-
response = client.login({
55-
:loginId => 'ruby.client.test@fusionauth.io',
56-
:password => 'password',
57-
:applicationId => application_id
58-
})
59-
user = response.success.response.user
60-
```
25+
See examples in the `examples` directory.
6126

6227
## Questions and support
6328

examples/login.rb

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
require 'fusionauth/fusionauth_client'
2+
require 'securerandom'
3+
4+
# Construct the FusionAuth Client
5+
client = FusionAuth::FusionAuthClient.new(
6+
'APIKEY',
7+
'http://localhost:9011'
8+
)
9+
10+
application_id = '20ce6dac-b985-4c77-bb59-6369249f884b'
11+
12+
# Create a user + registration
13+
id = SecureRandom.uuid
14+
response = client.register(id, {
15+
:user => {
16+
:firstName => 'Ruby',
17+
:lastName => 'Client',
18+
:email => 'ruby.client.test@fusionauth.io',
19+
:password => 'password'
20+
},
21+
:registration => {
22+
:applicationId => application_id,
23+
:data => {
24+
:foo => 'bar'
25+
},
26+
:preferredLanguages => %w(en fr),
27+
:roles => %w(user)
28+
}
29+
})
30+
31+
unless response.success_response
32+
print response.error_response
33+
exit
34+
end
35+
36+
# Authenticate the user
37+
response = client.login({
38+
:loginId => 'ruby.client.test@fusionauth.io',
39+
:password => 'password',
40+
:applicationId => application_id
41+
})
42+
43+
if response.success_response
44+
user = response.success_response.user
45+
print user.id
46+
else
47+
print response.error_response
48+
end

0 commit comments

Comments
 (0)