plyom_user 0.2.7 → 0.2.8
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/plyom_user.rb +3 -126
- data/lib/plyom_user/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c75d48125274f3a12b4ad36e71277d17551906fe
|
4
|
+
data.tar.gz: 37bab206d257835d018fc69a6706d24d626e9f40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 322fd4426d06331e15fec8d731f4915ac8a35c416f9b04863a44dee0ba92b4de3cdf6ae5b64355a13c62829de5acacca60f3d2377d6b7f2c3c97cbaca146750e
|
7
|
+
data.tar.gz: eb2a54d96c56f794fb61b5442fd318fa61aec4e7d9f5826267dc6c4fb30724d92b333b1f28fbee7d0604a0ed8de3dc052514d95a0868e0dd64ee7c9fb74c6eab
|
data/lib/plyom_user.rb
CHANGED
@@ -1,128 +1,5 @@
|
|
1
1
|
require "plyom_user/version"
|
2
|
-
require "httparty"
|
3
2
|
require "json"
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
class_attribute :id, :name, :email, :username, :password, :password_confirmation, :password_digest, :password_reset_token, :password_reset_sent_at, :status, :token, :created_at, :updated_at
|
8
|
-
|
9
|
-
def initialize(params={})
|
10
|
-
params.each { |var, val| public_send("#{var}=", val) }
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.all
|
14
|
-
list = []
|
15
|
-
response = action_by("read")
|
16
|
-
objs = JSON.parse(response.body)
|
17
|
-
objs.each { |obj| list << self.new(obj) }
|
18
|
-
list
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.find(id)
|
22
|
-
response = action_by("read", id: id)
|
23
|
-
obj = JSON.parse(response.body)
|
24
|
-
self.new(obj)
|
25
|
-
end
|
26
|
-
|
27
|
-
def save
|
28
|
-
param_names = ["name", "email", "username", "password", "password_confirmation", "status"]
|
29
|
-
data = filter_params(param_names)
|
30
|
-
if data.length > 0
|
31
|
-
paramters = { user: data }
|
32
|
-
paramters.update({ id: @id }) if @id.to_i > 0
|
33
|
-
action = @id.to_i > 0 ? "update" : "add"
|
34
|
-
response = PlyomUser.action_by(action, paramters)
|
35
|
-
@id = response['id'] if action == "add"
|
36
|
-
response
|
37
|
-
else
|
38
|
-
nil
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def remove
|
43
|
-
PlyomUser.action_by("del", id: @id)
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
def filter_params(names=[])
|
48
|
-
params = {}
|
49
|
-
self.instance_variables.each do |var|
|
50
|
-
var_name = var.to_s.delete "@"
|
51
|
-
var_value = self.instance_variable_get var
|
52
|
-
params.update({var_name => var_value}) if names.include?(var_name)
|
53
|
-
end
|
54
|
-
params
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.action_by(action, params={})
|
58
|
-
auth_token = { "Authorization" => "Token token=\"#{ENV['plyom_user_token']}\"" }
|
59
|
-
|
60
|
-
case action
|
61
|
-
when "read"
|
62
|
-
HTTParty.get("#{uri}/#{params[:id]}", headers: auth_token)
|
63
|
-
when "add"
|
64
|
-
HTTParty.post("#{uri}", query: params, headers: auth_token)
|
65
|
-
when "del"
|
66
|
-
HTTParty.delete("#{uri}/#{params[:id]}", headers: auth_token)
|
67
|
-
when "update"
|
68
|
-
HTTParty.patch("#{uri}/#{params[:id]}", query: params, headers: auth_token) if params.size > 1
|
69
|
-
HTTParty.put("#{uri}/#{params[:id]}", query: params, headers: auth_token) if params.size == 1
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.uri
|
74
|
-
host = ENV["plyom_user_host"]
|
75
|
-
path = "/api/users"
|
76
|
-
host + path
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class Authentication
|
81
|
-
class_attribute :id, :token, :validation
|
82
|
-
|
83
|
-
def initialize(params)
|
84
|
-
@params = params
|
85
|
-
end
|
86
|
-
|
87
|
-
def authenticated?(token)
|
88
|
-
auth_token = { "Authorization" => "Token token=\"#{token}\"" }
|
89
|
-
paramters = {username_email: @params[:username], password: @params[:password]}
|
90
|
-
response = HTTParty.get("#{self.uri}authentication", headers: auth_token, query: paramters)
|
91
|
-
result = JSON.parse(response.body)
|
92
|
-
if result["success"]
|
93
|
-
@token = result["token"]
|
94
|
-
@validation = 1
|
95
|
-
@id = result["id"]
|
96
|
-
true
|
97
|
-
else
|
98
|
-
false
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def validation
|
103
|
-
@validation
|
104
|
-
end
|
105
|
-
|
106
|
-
def check_token(token)
|
107
|
-
paramters = {token: @token}
|
108
|
-
auth_token = { "Authorization" => "Token token=\"#{token}\"" }
|
109
|
-
response = HTTParty.get("#{self.uri}token_validation", headers: auth_token, query: paramters)
|
110
|
-
response.body
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.validates(validation)
|
114
|
-
if validation == 1
|
115
|
-
true
|
116
|
-
else
|
117
|
-
false
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def uri
|
122
|
-
host = ENV["plyom_user_host"]
|
123
|
-
path = "/api/"
|
124
|
-
host + path
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
end
|
3
|
+
require "httparty"
|
4
|
+
require "plyom_user/user"
|
5
|
+
require "plyom_user/authentication"
|
data/lib/plyom_user/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plyom_user
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Pileggi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -347,7 +347,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
347
347
|
version: '0'
|
348
348
|
requirements: []
|
349
349
|
rubyforge_project:
|
350
|
-
rubygems_version: 2.2.
|
350
|
+
rubygems_version: 2.2.2
|
351
351
|
signing_key:
|
352
352
|
specification_version: 4
|
353
353
|
summary: Development
|