session_manager 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 99b4d5e7ccb73991486dc249c4bceb19e81eb216
4
+ data.tar.gz: 3c25975edf9d5991f3a7b868b7a4c0cedfd94ed5
5
+ SHA512:
6
+ metadata.gz: 33adb3d3f40d04ee051a4b76ab424f48279538746d6c98d8419c05d3645e36a4bb6cd5aa7c77768fa3a27ee11615624b249e91ef66ecee35a259fed540e3787e
7
+ data.tar.gz: 386b9348f90d8c3ff634caebb22cabfcaf4a608b677cfda952217667193f3fa2597f02ef70db93eef4f975e47bab58ada13430dffce5bed0df3d881cb3bb5cc0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in session_manager.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 fabira
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # SessionManager
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'session_manager'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install session_manager
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/session_manager/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ require "session_manager/version"
2
+ require "session_manager/session_handler"
3
+
4
+ module SessionManager
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,22 @@
1
+ module SessionManager
2
+
3
+ class Base
4
+ attr_accessor :redis, :uuid
5
+
6
+ USERS_SESSIONS = 'users_sessions'
7
+ APPS_SESSIONS = 'applications_sessions'
8
+
9
+ def initialize
10
+ @redis = Redis.current
11
+ @uuid = UUID.new
12
+ end
13
+
14
+ def generate_token
15
+ @uuid.generate
16
+ end
17
+
18
+ end
19
+ end
20
+
21
+
22
+
@@ -0,0 +1,45 @@
1
+ require 'redis'
2
+ require 'json'
3
+ require 'uuid'
4
+ require_relative 'base'
5
+
6
+ class Session_Handler < SessionManager::Base
7
+
8
+ def create_session(attribute,option)
9
+ param = parse_json(attribute)
10
+ collection = collection(option)
11
+ token = generate_token
12
+ session = session_generator(option,param,token)
13
+ @redis.sadd(collection,session.to_json)
14
+
15
+ end
16
+
17
+ def verify_session(object,option)
18
+ collection = collection(option)
19
+ @redis.sismember(collection,object)
20
+ end
21
+
22
+ def delete_session(object,option)
23
+ collection = collection(option)
24
+ @redis.srem(collection,object)
25
+ end
26
+
27
+ def collection(option)
28
+ user = option.fetch(:user) || false
29
+ app = option.fetch(:app) || false
30
+ collection = user ? USERS_SESSIONS : APPS_SESSIONS
31
+ return collection
32
+ end
33
+
34
+ def parse_json(param)
35
+ JSON.parse(param)
36
+ end
37
+
38
+ def session_generator(option, param, token)
39
+ option[:user] ? { login: param['login'],token: token} : { api_key: param['api_key'],token: token}
40
+ end
41
+
42
+
43
+
44
+
45
+ end
@@ -0,0 +1,3 @@
1
+ module SessionManager
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'session_manager/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "session_manager"
8
+ spec.version = SessionManager::VERSION
9
+ spec.authors = ["fabira && atakem"]
10
+ spec.email = ["fabira90@gmail.com, atacraft@gmail.com"]
11
+ spec.summary = %q{"session manager"}
12
+ spec.description = %q{"module that create,delete and verify users' and apps' sessions"}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake", "~> 10.3", ">= 10.3.1"
23
+ spec.add_development_dependency "redis", "~> 3.0", ">= 3.0.7"
24
+
25
+ #(we added) development dependencies
26
+ spec.required_ruby_version = ">= 2.0"
27
+ spec.add_development_dependency "rspec", "~>2.6"
28
+ spec.add_development_dependency "uuid", "~> 2.3", ">= 2.3.7"
29
+ end
@@ -0,0 +1,2 @@
1
+ require 'session_manager'
2
+ require 'json'
@@ -0,0 +1,73 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Session_Handler do
4
+
5
+ let (:session_handler) { Session_Handler.new }
6
+ let (:login) { {login: 'login'}.to_json}
7
+ let (:api_key) { {api_key: '01'}.to_json}
8
+ let (:user_option) { {user: true, app: false}}
9
+ let (:app_option) { {user: false, app: true}}
10
+ let (:user_session) {{login: 'login',token: 'jdijenfdeifiirifffjr'}.to_json}
11
+ let (:not_user_session) {{login: 'login',token: 'jdijenfd'}.to_json}
12
+ let (:app_session) {{api_key: '01',token: 'jdijenfdeifiirifffjr'}.to_json}
13
+ let (:not_app_session) {{api_key: '02',token: 'jdijenfdeifiirr'}.to_json}
14
+
15
+ before :each do
16
+ redis=Redis.current
17
+ redis.del('users_sessions')
18
+ redis.del('applications_sessions')
19
+ redis.sadd('users_sessions',user_session)
20
+ redis.sadd('applications_sessions',app_session)
21
+
22
+ end
23
+ describe "#create_session" do
24
+ context "when a user's session is created" do
25
+ it { expect(session_handler.create_session(login,user_option ) ).to be_true}
26
+ end
27
+
28
+ context "When an app's session is created" do
29
+ it { expect(session_handler.create_session(api_key,app_option ) ).to be_true }
30
+ end
31
+ end
32
+
33
+ describe "#verify_session" do
34
+ context "when a user's session is found" do
35
+ it { expect(session_handler.verify_session(user_session,user_option) ).to be_true}
36
+ end
37
+
38
+
39
+ context "when a user's session is not found" do
40
+ it { expect(session_handler.verify_session(not_user_session,user_option) ).to be_false}
41
+ end
42
+
43
+
44
+ context "when app's session is found" do
45
+ it { expect(session_handler.verify_session(app_session,app_option) ).to be_true}
46
+ end
47
+
48
+ context "when app's session is not found" do
49
+ it { expect(session_handler.verify_session(not_app_session,app_option) ).to be_false}
50
+ end
51
+ end
52
+
53
+ describe "#delete_session" do
54
+ context "when a user's session is deleted" do
55
+ it { expect(session_handler.delete_session(user_session,user_option)).to be_true}
56
+ end
57
+
58
+ context "when a user's session is not deleted" do
59
+ it { expect(session_handler.delete_session(not_user_session,user_option)).to be_false}
60
+ end
61
+
62
+ context "when a app's session is found" do
63
+ it { expect(session_handler.delete_session(app_session,app_option)).to be_true}
64
+ end
65
+
66
+ context "when a app's session is not found" do
67
+ it { expect(session_handler.delete_session(not_app_session,app_option)).to be_false}
68
+ end
69
+ end
70
+
71
+
72
+
73
+ end
@@ -0,0 +1,2 @@
1
+ require 'fixtures/environment'
2
+ require 'session_manager'
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: session_manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - fabira && atakem
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 10.3.1
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '10.3'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 10.3.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: redis
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 3.0.7
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.0'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 3.0.7
67
+ - !ruby/object:Gem::Dependency
68
+ name: rspec
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '2.6'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '2.6'
81
+ - !ruby/object:Gem::Dependency
82
+ name: uuid
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '2.3'
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 2.3.7
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '2.3'
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 2.3.7
101
+ description: '"module that create,delete and verify users'' and apps'' sessions"'
102
+ email:
103
+ - fabira90@gmail.com, atacraft@gmail.com
104
+ executables: []
105
+ extensions: []
106
+ extra_rdoc_files: []
107
+ files:
108
+ - ".gitignore"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/session_manager.rb
114
+ - lib/session_manager/base.rb
115
+ - lib/session_manager/session_handler.rb
116
+ - lib/session_manager/version.rb
117
+ - session_manager.gemspec
118
+ - spec/fixtures/environment.rb
119
+ - spec/session_handler_spec.rb
120
+ - spec/spec_helper.rb
121
+ homepage: ''
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '2.0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.2.2
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: '"session manager"'
145
+ test_files:
146
+ - spec/fixtures/environment.rb
147
+ - spec/session_handler_spec.rb
148
+ - spec/spec_helper.rb