Class: PDND::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pdnd-ruby-client/client.rb

Overview

Questa classe gestisce le operazioni di comunicazione con il back-end PDND.

Examples:

client = PDND::Client.new(config)
client.request_api

PDND Client collapse

PDND Client collapse

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_searchObject

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_urlObject

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

#debugBoolean

Flag per attivare il logging in console

Returns:

  • (Boolean)

    the current value of debug



20
21
22
# File 'lib/pdnd-ruby-client/client.rb', line 20

def debug
  @debug
end

#filtersObject

Returns the value of attribute filters.



21
22
23
# File 'lib/pdnd-ruby-client/client.rb', line 21

def filters
  @filters
end

#status_urlObject

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

#tokenString

Il token di autenticazione JWT

Returns:

  • (String)

    the current value of token



20
21
22
# File 'lib/pdnd-ruby-client/client.rb', line 20

def token
  @token
end

#token_expObject

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_sslObject

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_statusObject



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_apiObject

Raises:



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