Class: Flexipass::Client
- Inherits:
-
Object
- Object
- Flexipass::Client
- Defined in:
- lib/flexipass/client.rb
Overview
The Client class is responsible for making API requests to the Flexipass server.
Instance Method Summary collapse
-
#company ⇒ Object
Returns an instance of the Company class.
-
#door ⇒ Object
Returns an instance of the Door class.
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#mobile_key ⇒ Object
Returns an instance of the MobileKey class.
-
#send_request(method, endpoint, params = {}) ⇒ Hash
Sends a request to the Flexipass server.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/flexipass/client.rb', line 7 def initialize Flexipass.configuration.validate! @conn = Faraday.new(url: Flexipass.configuration.server_address) do |faraday| if Flexipass.configuration.enable_logging # Create a logger instance logger = Logger.new(STDOUT) logger.level = Logger::DEBUG faraday.response :logger, logger, bodies: true # Set bodies: true to log request and response bodies end faraday.request :url_encoded faraday.adapter Faraday.default_adapter faraday.headers['Content-Type'] = 'application/json' faraday.headers['Authorization'] = basic_auth_header end end |
Instance Method Details
#company ⇒ Object
Returns an instance of the Company class.
34 35 36 |
# File 'lib/flexipass/client.rb', line 34 def company @company ||= Company.new(self) end |
#door ⇒ Object
Returns an instance of the Door class.
29 30 31 |
# File 'lib/flexipass/client.rb', line 29 def door @door ||= Door.new(self) end |
#mobile_key ⇒ Object
Returns an instance of the MobileKey class.
24 25 26 |
# File 'lib/flexipass/client.rb', line 24 def mobile_key @mobile_key ||= MobileKey.new(self) end |
#send_request(method, endpoint, params = {}) ⇒ Hash
Sends a request to the Flexipass server.
45 46 47 48 49 50 51 52 53 |
# File 'lib/flexipass/client.rb', line 45 def send_request(method, endpoint, params = {}) response = @conn.send(method.downcase) do |req| req.url endpoint req.params['companyToken'] = Flexipass.configuration.company_token req.body = params.to_json if ['POST', 'PUT'].include?(method.upcase) end handle_response(response) end |