auth-lh 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98562fdddb3a360ded41d9a4da6c6446a56ead1f
4
- data.tar.gz: 6b149b16cf450eeecbca8810e43c3d934a68063a
3
+ metadata.gz: ea7a9dc6ed58444c7872e2aee7893aefb47a8c4d
4
+ data.tar.gz: 0b933e0716c002029937f28811c02851d50be865
5
5
  SHA512:
6
- metadata.gz: e55169ec641d2ec0d29313c9cf9bf9b063de5c6f64f3a069ec53dfa7a508a39d5d1d8a1e5a961a9e03f48f58d05b709da333013c234f1a663a372784a7dcc6fd
7
- data.tar.gz: ae28e2f2dd8939799e230136dfc720d543517c739be218057183a6936ff2de0d03b845fcca3708de7330afd98563bee09f56d644678beb0e969698bc82aeb84a
6
+ metadata.gz: e039f9a052cc0c055cc47eb6cd633aaf79ca2694d131f606c66d10936eab6ca4c2c88a4fa88244c8412c04e7584477430d6980e55d74327d91d07067f083f2cd
7
+ data.tar.gz: 640e349c9477bc2561bd964caabcef37927ac6d70d400693991b8380978d978a3476e6fdfbb61f5d11353fcf5a15aa2b851fb62bdd65951852e1cd6dbb4d4f34
data/CHANGELOG.md CHANGED
@@ -29,3 +29,7 @@
29
29
  ## v0.0.8
30
30
 
31
31
  * Changed auth interface.
32
+
33
+ ## v0.0.9
34
+
35
+ * Changed auth interface again.
data/lib/auth/lh.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'auth_lh/api'
1
+ require 'auth_lh'
2
2
  require 'auth_lh/login_attempt'
3
3
  require 'auth_lh/session_response'
4
4
  require 'auth_lh/user'
@@ -1,5 +1,5 @@
1
1
  module Auth
2
2
  module Lh
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
data/lib/auth_lh.rb ADDED
@@ -0,0 +1,61 @@
1
+ module AuthLh
2
+ def self.configure(args={})
3
+ @endpoint = (args[:endpoint] || 'https://auth.lhconfort.com.ar')
4
+ @return_url = args[:return_url]
5
+ @application_code = args[:application_code]
6
+ @access_token = args[:access_token]
7
+ end
8
+
9
+ def self.logged_user(session_token, remote_ip)
10
+ result = get_request '/logged_user', {
11
+ app_code: @application_code,
12
+ session_token: session_token,
13
+ remote_ip: remote_ip
14
+ }
15
+
16
+ SessionResponse.new(result)
17
+ end
18
+
19
+ def self.login_url
20
+ login_attempt = create_login_attempt
21
+ "#{@endpoint}/login?attempt=#{login_attempt.token}"
22
+ end
23
+
24
+ def self.logout_url
25
+ "#{@endpoint}/logout?return=#{CGI::escape(@return_url)}"
26
+ end
27
+
28
+ def self.get_user(code_or_login)
29
+ User.new(get_request("/api/users/#{code_or_login}"))
30
+ end
31
+
32
+ def self.get_users(filters={})
33
+ results = get_request("/api/users", filters)
34
+ results.map { |r| User.new(r) }
35
+ end
36
+
37
+ protected
38
+
39
+ def self.create_login_attempt
40
+ params = { app_code: @application_code }
41
+
42
+ if @return_url
43
+ params[:return_url] = @return_url
44
+ end
45
+
46
+ LoginAttempt.new(post_request('/login_attempts', params))
47
+ end
48
+
49
+ def self.get_request(action, params={})
50
+ response = RestClient.get("#{@endpoint}#{action}", {params: params}.merge(auth_headers))
51
+ JSON.parse(response.body)
52
+ end
53
+
54
+ def self.post_request(action, params={})
55
+ JSON.parse(RestClient.post("#{@endpoint}#{action}", params, auth_headers))
56
+ end
57
+
58
+ def self.auth_headers
59
+ { authorization: "Token token=\"#{@access_token}\"" }
60
+ end
61
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auth-lh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matias Hick
@@ -64,10 +64,10 @@ files:
64
64
  - CHANGELOG.md
65
65
  - lib/auth/lh/version.rb
66
66
  - lib/auth/lh.rb
67
- - lib/auth_lh/api.rb
68
67
  - lib/auth_lh/login_attempt.rb
69
68
  - lib/auth_lh/session_response.rb
70
69
  - lib/auth_lh/user.rb
70
+ - lib/auth_lh.rb
71
71
  homepage: https://github.com/unformattmh/auth-lh
72
72
  licenses:
73
73
  - MIT
data/lib/auth_lh/api.rb DELETED
@@ -1,63 +0,0 @@
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