auth-lh 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0a4cb9df6ecbe0a99d2075d19eea0ac5d50dc23
4
- data.tar.gz: ee3147313f880505454c8a0ca2b986e50b7756b3
3
+ metadata.gz: 98562fdddb3a360ded41d9a4da6c6446a56ead1f
4
+ data.tar.gz: 6b149b16cf450eeecbca8810e43c3d934a68063a
5
5
  SHA512:
6
- metadata.gz: e0140b71fee0abccf3b3ec3a115963bd7ce72eac86bbdbfba9e801733ca19121a661da54a9773ed60b7a5ee9b954f5696bbcab9212c751e618ace36bcf456fde
7
- data.tar.gz: 6a62e41c5dabc33a8cacd20dc83ae8d7a51922e261c8193412e5f2d7e7f2efaac83340398e1962813bc4ce5db7a68a6b9b4f3a044f157eb09cc21a8a50226ec4
6
+ metadata.gz: e55169ec641d2ec0d29313c9cf9bf9b063de5c6f64f3a069ec53dfa7a508a39d5d1d8a1e5a961a9e03f48f58d05b709da333013c234f1a663a372784a7dcc6fd
7
+ data.tar.gz: ae28e2f2dd8939799e230136dfc720d543517c739be218057183a6936ff2de0d03b845fcca3708de7330afd98563bee09f56d644678beb0e969698bc82aeb84a
data/CHANGELOG.md CHANGED
@@ -25,3 +25,7 @@
25
25
  ## v0.0.7
26
26
 
27
27
  * Make return url optional
28
+
29
+ ## v0.0.8
30
+
31
+ * Changed auth interface.
data/lib/auth/lh.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'auth/lh/api'
2
- require 'auth/lh/login_attempt'
3
- require 'auth/lh/session_response'
4
- require 'auth/lh/user'
1
+ require 'auth_lh/api'
2
+ require 'auth_lh/login_attempt'
3
+ require 'auth_lh/session_response'
4
+ require 'auth_lh/user'
5
5
 
6
6
  require 'auth/lh/version'
7
7
 
@@ -1,5 +1,5 @@
1
1
  module Auth
2
2
  module Lh
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
@@ -0,0 +1,63 @@
1
+ module AuthLh
2
+ class Api
3
+ def self.configure(args={})
4
+ @endpoint = (args[:endpoint] || 'https://auth.lhconfort.com.ar')
5
+ @return_url = args[:return_url]
6
+ @application_code = args[:application_code]
7
+ @access_token = args[:access_token]
8
+ end
9
+
10
+ def self.logged_user(session_token, remote_ip)
11
+ result = get_request '/logged_user', {
12
+ app_code: @application_code,
13
+ session_token: session_token,
14
+ remote_ip: remote_ip
15
+ }
16
+
17
+ SessionResponse.new(result)
18
+ end
19
+
20
+ def self.login_url
21
+ login_attempt = create_login_attempt
22
+ "#{@endpoint}/login?attempt=#{login_attempt.token}"
23
+ end
24
+
25
+ def self.logout_url
26
+ "#{@endpoint}/logout?return=#{CGI::escape(@return_url)}"
27
+ end
28
+
29
+ def self.get_user(code_or_login)
30
+ User.new(get_request("/api/users/#{code_or_login}"))
31
+ end
32
+
33
+ def self.get_users(filters={})
34
+ results = get_request("/api/users", filters)
35
+ results.map { |r| User.new(r) }
36
+ end
37
+
38
+ protected
39
+
40
+ def self.create_login_attempt
41
+ params = { app_code: @application_code }
42
+
43
+ if @return_url
44
+ params[:return_url] = @return_url
45
+ end
46
+
47
+ LoginAttempt.new(post_request('/login_attempts', params))
48
+ end
49
+
50
+ def self.get_request(action, params={})
51
+ response = RestClient.get("#{@endpoint}#{action}", {params: params}.merge(auth_headers))
52
+ JSON.parse(response.body)
53
+ end
54
+
55
+ def self.post_request(action, params={})
56
+ JSON.parse(RestClient.post("#{@endpoint}#{action}", params, auth_headers))
57
+ end
58
+
59
+ def self.auth_headers
60
+ { authorization: "Token token=\"#{@access_token}\"" }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,11 @@
1
+ module AuthLh
2
+ class LoginAttempt
3
+ attr_accessor :token
4
+
5
+ def initialize(attributes={})
6
+ attributes.each do |k,v|
7
+ self.send("#{k}=", v)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module AuthLh
2
+ class SessionResponse
3
+ attr_accessor :user, :success, :reason, :login_url
4
+
5
+ def initialize(attributes={})
6
+ attributes.each do |k,v|
7
+ if k.to_s == 'user'
8
+ self.user = User.new(v) if v.present?
9
+ else
10
+ self.send("#{k}=", v)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module AuthLh
2
+ class User
3
+ attr_accessor :code, :email, :jabber, :name, :login, :shop_code,
4
+ :is_admin, :allow_remote_access, :last_activity
5
+
6
+ def initialize(attributes={})
7
+ attributes.each do |k,v|
8
+ self.send("#{k}=", v)
9
+ end
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auth-lh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matias Hick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-18 00:00:00.000000000 Z
11
+ date: 2013-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,12 +62,12 @@ files:
62
62
  - LICENSE.md
63
63
  - README.md
64
64
  - CHANGELOG.md
65
- - lib/auth/lh/api.rb
66
- - lib/auth/lh/login_attempt.rb
67
- - lib/auth/lh/session_response.rb
68
- - lib/auth/lh/user.rb
69
65
  - lib/auth/lh/version.rb
70
66
  - lib/auth/lh.rb
67
+ - lib/auth_lh/api.rb
68
+ - lib/auth_lh/login_attempt.rb
69
+ - lib/auth_lh/session_response.rb
70
+ - lib/auth_lh/user.rb
71
71
  homepage: https://github.com/unformattmh/auth-lh
72
72
  licenses:
73
73
  - MIT
data/lib/auth/lh/api.rb DELETED
@@ -1,69 +0,0 @@
1
- module Auth
2
- module Lh
3
- class Api
4
- include Singleton
5
-
6
- attr_accessor :endpoint, :return_url, :application_code, :access_token
7
-
8
- def self.configure(args={})
9
- instance.endpoint = (args[:endpoint] || 'https://auth.lhconfort.com.ar')
10
- instance.return_url = args[:return_url]
11
- instance.application_code = args[:application_code]
12
- instance.access_token = args[:access_token]
13
- end
14
-
15
- def logged_user(session_token, remote_ip)
16
- result = get_request '/logged_user', {
17
- app_code: @application_code,
18
- session_token: session_token,
19
- remote_ip: remote_ip
20
- }
21
-
22
- SessionResponse.new(result)
23
- end
24
-
25
- def login_url
26
- login_attempt = create_login_attempt
27
- "#{@endpoint}/login?attempt=#{login_attempt.token}"
28
- end
29
-
30
- def logout_url
31
- "#{@endpoint}/logout?return=#{CGI::escape(@return_url)}"
32
- end
33
-
34
- def get_user(code_or_login)
35
- User.new(get_request("/api/users/#{code_or_login}"))
36
- end
37
-
38
- def get_users(filters={})
39
- results = get_request("/api/users", filters)
40
- results.map { |r| User.new(r) }
41
- end
42
-
43
- protected
44
-
45
- def create_login_attempt
46
- params = { app_code: @application_code }
47
-
48
- if @return_url
49
- params[:return_url] = @return_url
50
- end
51
-
52
- LoginAttempt.new(post_request('/login_attempts', params))
53
- end
54
-
55
- def get_request(action, params={})
56
- response = RestClient.get("#{@endpoint}#{action}", {params: params}.merge(auth_headers))
57
- JSON.parse(response.body)
58
- end
59
-
60
- def post_request(action, params={})
61
- JSON.parse(RestClient.post("#{@endpoint}#{action}", params, auth_headers))
62
- end
63
-
64
- def auth_headers
65
- { authorization: "Token token=\"#{@access_token}\"" }
66
- end
67
- end
68
- end
69
- end
@@ -1,13 +0,0 @@
1
- module Auth
2
- module Lh
3
- class LoginAttempt
4
- attr_accessor :token
5
-
6
- def initialize(attributes={})
7
- attributes.each do |k,v|
8
- self.send("#{k}=", v)
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,17 +0,0 @@
1
- module Auth
2
- module Lh
3
- class SessionResponse
4
- attr_accessor :user, :success, :reason, :login_url
5
-
6
- def initialize(attributes={})
7
- attributes.each do |k,v|
8
- if k.to_s == 'user'
9
- self.user = User.new(v) if v.present?
10
- else
11
- self.send("#{k}=", v)
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
data/lib/auth/lh/user.rb DELETED
@@ -1,14 +0,0 @@
1
- module Auth
2
- module Lh
3
- class User
4
- attr_accessor :code, :email, :jabber, :name, :login, :shop_code,
5
- :is_admin, :allow_remote_access, :last_activity
6
-
7
- def initialize(attributes={})
8
- attributes.each do |k,v|
9
- self.send("#{k}=", v)
10
- end
11
- end
12
- end
13
- end
14
- end