Class: SmartId::Api::Request
- Inherits:
-
Object
- Object
- SmartId::Api::Request
- Defined in:
- lib/smart_id/api/request.rb
Constant Summary collapse
- DEMO_BASE_URL =
"https://sid.demo.sk.ee/smart-id-rp/v1/"
- PRODUCTION_BASE_URL =
"https://rp-api.smart-id.com/v1/"
- DEMO_SSL_KEY =
"QLZIaH7Qx9Rjq3gyznQuNsvwMQb7maC5L4SLu/z5qNU="
- PROD_KEY_EXPIRY =
Date.new(2020,11,5)
- PRODUCTION_SSL_KEY =
"l2uvq6ftLN4LZ+8Un+71J2vH1BT9wTbtrE5+Fj3Vc5g="
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(method, uri, params) ⇒ Request
constructor
A new instance of Request.
- #maybe_warn_of_ssl_key_expiry ⇒ Object
Constructor Details
#initialize(method, uri, params) ⇒ Request
Returns a new instance of Request.
12 13 14 15 16 17 |
# File 'lib/smart_id/api/request.rb', line 12 def initialize(method, uri, params) @method = method @url = self.class.const_get("#{SmartId.environment}_BASE_URL") + uri @params = params @logger = Logger.new(STDOUT) end |
Class Method Details
.execute(method:, uri:, params:) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/smart_id/api/request.rb', line 19 def self.execute(method:, uri:, params:) begin api_request = new(method, uri, params) api_request.execute rescue RestClient::RequestFailed => e case e.http_code when 471 raise SmartId::IncorrectAccountLevelError when 403 raise SmartId::InvalidPermissionsError when 404 raise SmartId::UserNotFoundError when 480 raise SmartId::OutdatedApiError when 580 raise SmartId::SystemUnderMaintenanceError else raise SmartId::ConnectionError.new(e) end rescue RestClient::SSLCertificateNotVerified raise SmartId::SSLCertificateNotVerified end end |
Instance Method Details
#execute ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/smart_id/api/request.rb', line 49 def execute maybe_warn_of_ssl_key_expiry if @method.to_sym == :post attrs = post_request_attrs else attrs = get_request_attrs end request = RestClient::Request.execute(**attrs) end |
#maybe_warn_of_ssl_key_expiry ⇒ Object
43 44 45 46 47 |
# File 'lib/smart_id/api/request.rb', line 43 def maybe_warn_of_ssl_key_expiry if (PROD_KEY_EXPIRY - Date.today).to_i < 60 @logger.warn("[Smart-id-Ruby] SSL KEY for security checks will soon expire, please update to newer version of this gem") end end |