Skip to content

Commit b4d62c9

Browse files
committed
Merge pull request #14 from RadiusNetworks/registration
Registration
2 parents 76ae735 + 4bb11b4 commit b4d62c9

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

lib/kracken.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require "kracken/token_authenticator"
99
require "kracken/credential_authenticator"
1010
require "kracken/authenticator"
11+
require "kracken/registration"
1112

1213
module Kracken
1314
mattr_accessor :config

lib/kracken/registration.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
module Kracken
2+
class Registration
3+
attr_reader :response, :status
4+
5+
def post(params)
6+
@response = connection.post do |req|
7+
req.url '/auth/radius/registration.json'
8+
req.headers['Content-Type'] = 'application/json'
9+
req.body = post_body(params).to_json
10+
end
11+
12+
@status = response.status
13+
14+
self
15+
end
16+
17+
def body
18+
if response
19+
JSON.parse(response.body)
20+
end
21+
end
22+
23+
private
24+
25+
def post_body(params)
26+
{
27+
user: {
28+
first_name: params["first_name"],
29+
last_name: params["last_name"],
30+
email: params["email"],
31+
password: params["password"],
32+
password_confirmation: params["password_confirmation"],
33+
terms_of_service: params["terms_of_service"],
34+
country: params["country"],
35+
},
36+
token: { description: params["token_description"] },
37+
application: {
38+
name: app_id,
39+
secret: app_secret,
40+
},
41+
}
42+
end
43+
44+
def connection
45+
@connection ||= Faraday.new(url: PROVIDER_URL)
46+
end
47+
48+
def app_id
49+
Kracken.config.app_id
50+
end
51+
52+
def app_secret
53+
Kracken.config.app_secret
54+
end
55+
end
56+
end

lib/kracken/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Kracken
2-
VERSION = "0.1.2"
2+
VERSION = "0.2.0"
33
end

spec/kracken/registration_spec.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require 'rails_helper'
2+
3+
module Kracken
4+
RSpec.describe Registration do
5+
6+
let(:valid_registration) {
7+
{
8+
user: {
9+
first_name: "Rory",
10+
last_name: "Williams",
11+
12+
password: "I died and turned into a Roman.",
13+
password_confirmation: "I died and turned into a Roman.",
14+
terms_of_service: true,
15+
country: 'United States',
16+
},
17+
application: { name: "client app_id", secret: "client app_secret" },
18+
token: { description: "RSpec Test Token" }
19+
}
20+
}
21+
22+
def set_request(status, body=nil)
23+
stub_request(:post, "https://account.radiusnetworks.com/auth/radius/registration.json")
24+
.to_return(status: status, body: body)
25+
end
26+
27+
it "parses the json and returns the token" do
28+
reg = Registration.new
29+
set_request 200, {
30+
token: "I am a token",
31+
32+
}.to_json
33+
34+
response = reg.post valid_registration
35+
expect(response.body['token']).to eq "I am a token"
36+
end
37+
38+
it "proxies any errors back to the caller" do
39+
reg = Registration.new
40+
41+
set_request 500, {
42+
message: ["What is that thing on your head?"]
43+
}.to_json
44+
response = reg.post valid_registration
45+
expect(response.body['message']).to eq(["What is that thing on your head?"])
46+
end
47+
48+
end
49+
end

0 commit comments

Comments
 (0)