Class: PDND::Client
- Inherits:
-
Object
- Object
- PDND::Client
- Defined in:
- lib/pdnd-ruby-client/client.rb
Overview
Questa classe gestisce le operazioni di comunicazione con il back-end PDND.
PDND Client collapse
-
#api_search ⇒ Object
Returns the value of attribute api_search.
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#debug ⇒ Boolean
Flag per attivare il logging in console.
-
#filters ⇒ Object
Returns the value of attribute filters.
-
#status_url ⇒ Object
Returns the value of attribute status_url.
-
#token ⇒ String
Il token di autenticazione JWT.
-
#token_exp ⇒ Object
Returns the value of attribute token_exp.
-
#verify_ssl ⇒ Object
Returns the value of attribute verify_ssl.
PDND Client collapse
- #check_status ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #request_api ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pdnd-ruby-client/client.rb', line 24 def initialize(config) @config = config @verify_ssl = true @debug = false @api_url = '' @api_search = '' @status_url = '' @filters = [] @token = '' @token_exp = '' end |
Instance Attribute Details
#api_search ⇒ Object
Returns the value of attribute api_search.
21 22 23 |
# File 'lib/pdnd-ruby-client/client.rb', line 21 def api_search @api_search end |
#api_url ⇒ Object
Returns the value of attribute api_url.
21 22 23 |
# File 'lib/pdnd-ruby-client/client.rb', line 21 def api_url @api_url end |
#debug ⇒ Boolean
Flag per attivare il logging in console
20 21 22 |
# File 'lib/pdnd-ruby-client/client.rb', line 20 def debug @debug end |
#filters ⇒ Object
Returns the value of attribute filters.
21 22 23 |
# File 'lib/pdnd-ruby-client/client.rb', line 21 def filters @filters end |
#status_url ⇒ Object
Returns the value of attribute status_url.
21 22 23 |
# File 'lib/pdnd-ruby-client/client.rb', line 21 def status_url @status_url end |
#token ⇒ String
Il token di autenticazione JWT
20 21 22 |
# File 'lib/pdnd-ruby-client/client.rb', line 20 def token @token end |
#token_exp ⇒ Object
Returns the value of attribute token_exp.
21 22 23 |
# File 'lib/pdnd-ruby-client/client.rb', line 21 def token_exp @token_exp end |
#verify_ssl ⇒ Object
Returns the value of attribute verify_ssl.
21 22 23 |
# File 'lib/pdnd-ruby-client/client.rb', line 21 def verify_ssl @verify_ssl end |
Instance Method Details
#check_status ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/pdnd-ruby-client/client.rb', line 49 def check_status validate_status_config response = perform_request(@status_url) body = response.body.force_encoding('UTF-8') [response.status, JSON.parse(body)] end |
#request_api ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pdnd-ruby-client/client.rb', line 36 def request_api validate_api_config build_api_uri log_api_search response = perform_request(@api_search.to_s) body = response.body.force_encoding('UTF-8') raise PDND::APIError.new(response.status, body) unless response.success? puts "📡 Response: #{body}" if @debug [response.status, JSON.parse(body)] end |