Class: AlprRuby::Connection
- Inherits:
-
Object
- Object
- AlprRuby::Connection
- Defined in:
- lib/alpr_ruby/connection.rb
Constant Summary collapse
- BASE_URL =
'https://api.openalpr.com/v1'.freeze
Instance Method Summary collapse
- #call(endpoint:, method:, params: {}) ⇒ Object
-
#initialize(secret:) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(secret:) ⇒ Connection
Returns a new instance of Connection.
7 8 9 |
# File 'lib/alpr_ruby/connection.rb', line 7 def initialize(secret:) @secret = secret end |
Instance Method Details
#call(endpoint:, method:, params: {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/alpr_ruby/connection.rb', line 11 def call(endpoint:, method:, params: {}) response = Typhoeus::Request.new( "#{BASE_URL}/#{endpoint}", method: method, params: { secret_key: @secret }.merge!(params), ).run if response.response_code != 200 AlprRuby::Error.new(code: response.response_code).render end JSON.parse(response.response_body) end |