Class: KirguduSso::Client
- Inherits:
-
Object
- Object
- KirguduSso::Client
- Defined in:
- app/models/kirgudu_sso/client.rb
Instance Attribute Summary collapse
-
#application_id ⇒ Object
Returns the value of attribute application_id.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
-
#initialize(application_id, secret_key) ⇒ Client
constructor
A new instance of Client.
- #logout ⇒ Object
- #reset_password ⇒ Object
- #user_delete(email, password, options = {}) ⇒ Object
- #user_login(email, password, options = {}) ⇒ Object
- #user_register(user, options = {}) ⇒ Object
Constructor Details
#initialize(application_id, secret_key) ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'app/models/kirgudu_sso/client.rb', line 6 def initialize(application_id, secret_key) self.application_id = application_id self.secret_key = secret_key end |
Instance Attribute Details
#application_id ⇒ Object
Returns the value of attribute application_id.
3 4 5 |
# File 'app/models/kirgudu_sso/client.rb', line 3 def application_id @application_id end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
4 5 6 |
# File 'app/models/kirgudu_sso/client.rb', line 4 def secret_key @secret_key end |
Instance Method Details
#logout ⇒ Object
47 48 49 |
# File 'app/models/kirgudu_sso/client.rb', line 47 def logout end |
#reset_password ⇒ Object
126 127 128 |
# File 'app/models/kirgudu_sso/client.rb', line 126 def reset_password end |
#user_delete(email, password, options = {}) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/models/kirgudu_sso/client.rb', line 88 def user_delete(email, password, = {}) result_hash = { status: ::ChupakabraTools::ApiStatus.id_by_tag("unknown"), message: "" } # data for post to sso server local_data = { application_id: self.application_id, secret_key: self.secret_key, email: email, password: password } sso_server_result = nil begin # posting request to sso server with supplied data in var 'local_data' response = Net::HTTP.post_form(URI.parse("#{self.get_sso_website_url}/api/applications/users/delete"), local_data) begin # Deserializing Result from JSON Resoponse sso_server_result = ActiveSupport::JSON.decode(response.body) sso_server_result.symbolize_keys! # setting result from server result_hash[:status] = sso_server_result[:status] result_hash[:user] = sso_server_result[:data] rescue result_hash[:status] = ::ChupakabraTools::ApiStatus.id_by_tag("json_response_error") end rescue Exception => e result_hash[:status] = ::ChupakabraTools::ApiStatus.id_by_tag("http_error") end #raise "SSO: #{sso_server_result.to_json}" result_hash[:message] = ::ChupakabraTools::ApiStatus[result_hash[:status]] result_hash end |
#user_login(email, password, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/kirgudu_sso/client.rb', line 11 def user_login(email, password, = {}) # data for post to sso server local_data = { application_id: self.application_id, secret_key: self.secret_key, email: email, password: password } sso_server_result = nil response = nil begin # posting request to sso server with supplied data in var 'local_data' response = Net::HTTP.post_form(URI.parse("#{self.get_sso_website_url}/api/applications/users/login"), local_data) rescue Exception => e raise "#{::ChupakabraTools::ApiStatus[ChupakabraTools::ApiStatus.id_by_tag("http_error")]}. #{e.}" end begin # Deserializing Result from JSON Resoponse sso_server_result = ActiveSupport::JSON.decode(response.body) rescue Exception => e raise ::ChupakabraTools::ApiStatus[ChupakabraTools::ApiStatus.id_by_tag("json_response_error")] end sso_server_result.symbolize_keys! #raise "SSO: #{sso_server_result.to_json}" if sso_server_result[:status] != ChupakabraTools::ApiStatus.id_by_tag("ok") raise ChupakabraTools::ApiStatus[sso_server_result[:status]] end sso_server_result[:data] end |
#user_register(user, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/kirgudu_sso/client.rb', line 51 def user_register(user, = {}) result_hash = { status: ::ChupakabraTools::ApiStatus.id_by_tag("unknown"), message: "" } # data for post to sso server local_data = { application_id: self.application_id, secret_key: self.secret_key, user: user } sso_server_result = nil begin # posting request to sso server with supplied data in var 'local_data' response = Net::HTTP.post_form(URI.parse("#{self.get_sso_website_url}/api/applications/users/register"), local_data) begin # Deserializing Result from JSON Resoponse sso_server_result = ActiveSupport::JSON.decode(response.body) sso_server_result.symbolize_keys! # setting result from server result_hash[:status] = sso_server_result[:status] result_hash[:user] = sso_server_result[:data] rescue result_hash[:status] = ::ChupakabraTools::ApiStatus.id_by_tag("json_response_error") end rescue Exception => e result_hash[:status] = ::ChupakabraTools::ApiStatus.id_by_tag("http_error") end #raise "SSO: #{sso_server_result.to_json}" result_hash[:message] = ::ChupakabraTools::ApiStatus[result_hash[:status]] result_hash end |