Class: Plyom::Authentication
- Inherits:
-
Object
- Object
- Plyom::Authentication
- Defined in:
- lib/plyom_user.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authenticated?(token) ⇒ Boolean
- #check_token(token) ⇒ Object
-
#initialize(params) ⇒ Authentication
constructor
A new instance of Authentication.
- #uri ⇒ Object
- #validation ⇒ Object
Constructor Details
#initialize(params) ⇒ Authentication
Returns a new instance of Authentication.
157 158 159 |
# File 'lib/plyom_user.rb', line 157 def initialize(params) @params = params end |
Class Method Details
.validates(validation) ⇒ Object
187 188 189 190 191 192 193 |
# File 'lib/plyom_user.rb', line 187 def self.validates(validation) if validation == 1 true else false end end |
Instance Method Details
#authenticated?(token) ⇒ Boolean
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/plyom_user.rb', line 161 def authenticated?(token) auth_token = { "Authorization" => "Token token=\"#{token}\"" } paramters = {username_email: @params[:username], password: @params[:password]} response = HTTParty.get("#{self.uri}authentication", headers: auth_token, query: paramters) result = JSON.parse(response.body) if result["success"] @token = result["token"] @validation = 1 @id = result["id"] true else false end end |
#check_token(token) ⇒ Object
180 181 182 183 184 185 |
# File 'lib/plyom_user.rb', line 180 def check_token(token) paramters = {token: @token} auth_token = { "Authorization" => "Token token=\"#{token}\"" } response = HTTParty.get("#{self.uri}token_validation", headers: auth_token, query: paramters) response.body end |
#uri ⇒ Object
195 196 197 198 199 |
# File 'lib/plyom_user.rb', line 195 def uri host = ENV["plyom_user_host"] path = "/api/" host + path end |
#validation ⇒ Object
176 177 178 |
# File 'lib/plyom_user.rb', line 176 def validation @validation end |