File tree Expand file tree Collapse file tree 4 files changed +107
-1
lines changed Expand file tree Collapse file tree 4 files changed +107
-1
lines changed Original file line number Diff line number Diff line change 8
8
require "kracken/token_authenticator"
9
9
require "kracken/credential_authenticator"
10
10
require "kracken/authenticator"
11
+ require "kracken/registration"
11
12
12
13
module Kracken
13
14
mattr_accessor :config
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 1
1
module Kracken
2
- VERSION = "0.1.2 "
2
+ VERSION = "0.2.0 "
3
3
end
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments