recommender_api 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/api/handler.rb +7 -8
- data/lib/api/version.rb +1 -1
- data/lib/api/web.rb +19 -71
- data/spec/handler_spec.rb +24 -11
- data/spec/spec_helper.rb +1 -11
- data/spec/web_spec.rb +0 -42
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48427bdda282011938492f69cfeb88c7f9c184c5
|
4
|
+
data.tar.gz: 2d3f295e271c1bfd0bfbcde674bd8288fcfa92a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39121436b6105b01d0b1ca93da4477d585fdea217a57cad077c0d0c25ae990f72335e3faafe4fae34bf33af18b31c9708b7cca97bea706d33243ad0ab0956732
|
7
|
+
data.tar.gz: 222dbc6ddab6fce6412f2202f044bf0b0d9815b250b190fe9e0a5e79cc89e04c75a5bc8e2494c75572e5b53d65fa9dabf974ff3e72301dc866af098b8389cdbe
|
data/lib/api/handler.rb
CHANGED
@@ -5,8 +5,8 @@ require 'dbAccessor'
|
|
5
5
|
module Api
|
6
6
|
class Handler
|
7
7
|
|
8
|
-
def self.
|
9
|
-
added = DbAccessor::Writer.write_object(param)
|
8
|
+
def self.create_object(param)
|
9
|
+
added = DbAccessor::Writer.write_object(param)
|
10
10
|
if added[:code] == 201
|
11
11
|
true
|
12
12
|
else
|
@@ -16,12 +16,11 @@ class Handler
|
|
16
16
|
|
17
17
|
def self.connect(param, option)
|
18
18
|
found = AuthManager::Finder.find_object?(param, option)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
19
|
+
found ? SessionManager::Handler.create_session(param, option) : {code: 400, message: "User not connected"}
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.condition_read(param)
|
23
|
+
DbAccessor::Reader.condition_select(param)
|
25
24
|
end
|
26
25
|
|
27
26
|
def self.valid_session(object, token, option)
|
data/lib/api/version.rb
CHANGED
data/lib/api/web.rb
CHANGED
@@ -4,83 +4,31 @@ require_relative 'handler'
|
|
4
4
|
module Api
|
5
5
|
class Web < Sinatra::Base
|
6
6
|
|
7
|
-
post '/apps' do
|
8
|
-
if create(params)
|
9
|
-
status 200
|
10
|
-
body ['Successfully created!']
|
11
|
-
else
|
12
|
-
status 400
|
13
|
-
body ['Sorry, an error occured']
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
7
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
8
|
+
post '/apps/connect' do
|
9
|
+
if connect(params)[:code] == 200
|
10
|
+
status 200
|
11
|
+
body ['Successfully logged!']
|
12
|
+
else
|
13
|
+
status 400
|
14
|
+
body ['Sorry, an error occured']
|
15
|
+
end
|
25
16
|
end
|
26
|
-
|
27
|
-
|
28
|
-
post '/users/connect' do
|
29
|
-
if connect(params)
|
30
|
-
status 200
|
31
|
-
body ['Successfully logged!']
|
32
|
-
else
|
33
|
-
status 400
|
34
|
-
body ['Sorry, an error occured']
|
17
|
+
after do
|
18
|
+
response
|
35
19
|
end
|
36
|
-
end
|
37
20
|
|
38
|
-
|
39
|
-
if connect(params)
|
40
|
-
status 200
|
41
|
-
body ['Successfully logged!']
|
42
|
-
else
|
43
|
-
status 400
|
44
|
-
body ['Sorry, an error occured']
|
45
|
-
end
|
46
|
-
end
|
47
|
-
after do
|
48
|
-
response
|
49
|
-
end
|
21
|
+
private ################
|
50
22
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
option = {user: false, app: true} if (params[:option][:app] == 'true')
|
57
|
-
option
|
58
|
-
end
|
59
|
-
|
60
|
-
def format_object(params)
|
61
|
-
if params[:object][:model_name] == 'User'
|
62
|
-
login = params[:object][:content][:login]
|
63
|
-
password = params[:object][:content][:password]
|
64
|
-
firstname = params[:object][:content][:firstname]
|
65
|
-
lastname = params[:object][:content][:lastname]
|
66
|
-
email = params[:object][:content][:email]
|
67
|
-
gender = params[:object][:content][:gender]
|
68
|
-
object = {model_name: 'User',content: {login: login,password: password,firstname: firstname, lastname: lastname,email: email,gender: gender}}
|
69
|
-
else
|
70
|
-
name = params[:object][:content][:name]
|
71
|
-
api_key = params[:object][:content][:api_key]
|
72
|
-
url = params[:object][:content][:url]
|
73
|
-
user_id = params[:object][:content][:user_id]
|
74
|
-
object = {model_name: 'Application',content: {name: name,api_key: api_key,url: url,user_id: user_id}}
|
23
|
+
def format_option(params)
|
24
|
+
option = {}
|
25
|
+
option = {user: true, app: false} if (params[:option][:user] == 'true')
|
26
|
+
option = {user: false, app: true} if (params[:option][:app] == 'true')
|
27
|
+
option
|
75
28
|
end
|
76
|
-
end
|
77
29
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
def connect(params)
|
83
|
-
Api::Handler.connect(params[:object].to_json, format_option(params))
|
30
|
+
def connect(params)
|
31
|
+
Api::Handler.connect(params[:object].to_json, format_option(params))
|
32
|
+
end
|
84
33
|
end
|
85
34
|
end
|
86
|
-
end
|
data/spec/handler_spec.rb
CHANGED
@@ -8,8 +8,9 @@ describe Api::Handler do
|
|
8
8
|
let(:session_info) { {login: 'login', token: token} }
|
9
9
|
nb = rand(1000)
|
10
10
|
let(:a_user) {{model_name: 'User',content: {login: 'macoumba'+nb.to_s,password: 'passeraa',firstname: 'Ndeye Fatou', lastname: 'Dieng',email: 'macoumba'+nb.to_s+'@gmail.com',gender: 'M'}} }
|
11
|
+
let(:param_for_read) { {model_name: 'User', condition: {login: a_user[:content][:login]}} }
|
11
12
|
|
12
|
-
describe '
|
13
|
+
describe '.connect' do
|
13
14
|
before(:each) do
|
14
15
|
AuthManager::Base.redis_del({list: 'users'})
|
15
16
|
AuthManager::Base.redis_del({list: 'applications'})
|
@@ -19,44 +20,44 @@ describe Api::Handler do
|
|
19
20
|
context 'When user connected' do
|
20
21
|
it {
|
21
22
|
swap_option_to('user')
|
22
|
-
expect(Api::Handler.connect(user.to_json, opt)).to
|
23
|
+
expect(Api::Handler.connect(user.to_json, opt)[:code]).to eq(200)
|
23
24
|
}
|
24
25
|
end
|
25
26
|
context 'When app connected' do
|
26
27
|
it {
|
27
28
|
swap_option_to('app')
|
28
29
|
app[:api_key] = 'api_key'
|
29
|
-
expect(Api::Handler.connect(app.to_json, opt)).to
|
30
|
+
expect(Api::Handler.connect(app.to_json, opt)[:code]).to eq(200)
|
30
31
|
}
|
31
32
|
end
|
32
33
|
context 'When user fails to connect' do
|
33
34
|
it {
|
34
35
|
swap_option_to('user')
|
35
36
|
user[:login] = 'not a login'
|
36
|
-
expect(Api::Handler.connect(user.to_json, opt)).to
|
37
|
+
expect(Api::Handler.connect(user.to_json, opt)[:code]).to eq(400)
|
37
38
|
}
|
38
39
|
end
|
39
40
|
context 'When app fails to connect' do
|
40
41
|
it {
|
41
42
|
swap_option_to('app')
|
42
43
|
app[:api_key] = 'not an api_key'
|
43
|
-
expect(Api::Handler.connect(app.to_json, opt)).to
|
44
|
+
expect(Api::Handler.connect(app.to_json, opt)[:code]).to eq(400)
|
44
45
|
}
|
45
46
|
end
|
46
47
|
end
|
47
|
-
describe '
|
48
|
+
describe '.create_object' do
|
48
49
|
context 'When user account created' do
|
49
|
-
it {
|
50
|
-
expect(Api::Handler.
|
50
|
+
it {
|
51
|
+
expect(Api::Handler.create_object(a_user)).to be_true
|
51
52
|
}
|
52
53
|
end
|
53
54
|
context 'When user account not created' do
|
54
55
|
it {
|
55
|
-
expect(Api::Handler.
|
56
|
+
expect(Api::Handler.create_object(a_user)).to be_false
|
56
57
|
}
|
57
58
|
end
|
58
59
|
end
|
59
|
-
describe '
|
60
|
+
describe '.valid_session' do
|
60
61
|
before(:each) do
|
61
62
|
AuthManager::Base.redis_del({list: 'users'})
|
62
63
|
AuthManager::Base.redis_del({list: 'applications_sessions'})
|
@@ -79,8 +80,20 @@ describe Api::Handler do
|
|
79
80
|
}
|
80
81
|
end
|
81
82
|
end
|
83
|
+
|
84
|
+
describe '.condition_read' do
|
85
|
+
context 'Record found' do
|
86
|
+
it { expect(Api::Handler.condition_read(param_for_read)[:code]).to eq (200)}
|
87
|
+
end
|
88
|
+
context 'Record not found' do
|
89
|
+
it do
|
90
|
+
param_for_read[:condition][:login] = 'not a login'
|
91
|
+
expect(Api::Handler.condition_read(param_for_read)[:code]).to eq(404)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
82
95
|
#to do later
|
83
|
-
describe '
|
96
|
+
describe '.request' do
|
84
97
|
|
85
98
|
end
|
86
99
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,20 +21,10 @@ def parameter_for(object_type)
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def create_object_for(object_type)
|
25
|
-
nb = rand(1000)
|
26
|
-
api_key = UUID.generate
|
27
|
-
if object_type == 'app'
|
28
|
-
{object: {model_name: 'Application',content: {name: 'Axolot'+nb.to_s,api_key: api_key,url: 'http://www.wikimina'+nb.to_s+'.net',user_id: 3 }}}
|
29
|
-
else
|
30
|
-
{object: {model_name: 'User',content: {login: 'nana'+nb.to_s,password: 'passeraa',firstname: 'Ndeye Fatou', lastname: 'Dieng',email: 'nana'+nb.to_s+'@gmail.com',gender: 'M'}} }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
24
|
def bad_parameter_for(object_type)
|
35
25
|
if object_type == 'user'
|
36
26
|
{object: {login: 'not a login',password: 'not a password'}, option: {user: true,app: false} }
|
37
27
|
else
|
38
|
-
{object: {api_key: 'not an api_key'}, option: {user: false,app: true} }
|
28
|
+
{object: {api_key: 'this is not an api_key'}, option: {user: false,app: true} }
|
39
29
|
end
|
40
30
|
end
|
data/spec/web_spec.rb
CHANGED
@@ -12,52 +12,10 @@ describe Api::Web do
|
|
12
12
|
|
13
13
|
before(:all) do
|
14
14
|
AuthManager::Base.redis_del({list: 'applications'})
|
15
|
-
AuthManager::Base.redis_del({ list: 'users' })
|
16
|
-
AuthManager::Base.redis_del({ list: 'users_sessions' })
|
17
15
|
AuthManager::Base.redis_del({ list: 'applications_sessions' } )
|
18
|
-
AuthManager::Base.redis_sadd({list: 'users',object: {login: 'a login',password: 'a password'}})
|
19
16
|
AuthManager::Base.redis_sadd({list: 'applications',object: {api_key: 'an api_key'}})
|
20
17
|
end
|
21
18
|
|
22
|
-
context "POST '/apps'" do
|
23
|
-
app = create_object_for('app')
|
24
|
-
it "returns 200 when an object is created" do
|
25
|
-
post '/apps', app
|
26
|
-
expect(last_response.status).to eq(200)
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
it "returns 400 when the creation fails" do
|
31
|
-
post '/apps', app
|
32
|
-
expect(last_response.status).to eq(400)
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
context "POST '/users'" do
|
38
|
-
user = create_object_for('user')
|
39
|
-
it "returns 200 when a object is created" do
|
40
|
-
post '/users', user
|
41
|
-
expect(last_response.status).to eq(200)
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
it "returns 400 when the creation fails" do
|
46
|
-
post '/users', user
|
47
|
-
expect(last_response.status).to eq(400)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'When a user attemps to log in' do
|
52
|
-
it 'returns 200 code status for success' do
|
53
|
-
post '/users/connect', parameter_for('user')
|
54
|
-
expect(last_response.status).to eq(200)
|
55
|
-
end
|
56
|
-
it 'returns 400 code status for faillure' do
|
57
|
-
post '/users/connect', bad_parameter_for('user')
|
58
|
-
expect(last_response.status).to eq(400)
|
59
|
-
end
|
60
|
-
end
|
61
19
|
|
62
20
|
context 'When an app attemps to log in' do
|
63
21
|
it 'returns 200 code status for success' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recommender_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- binette && atacraft
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|