Class: UseragentApi::Client
- Inherits:
-
Object
- Object
- UseragentApi::Client
- Defined in:
- lib/useragent_api/client.rb
Overview
A class which wraps calls to UseragentAPI
Instance Attribute Summary collapse
-
#api_key ⇒ String
readonly
Returns the api key.
Instance Method Summary collapse
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
-
#parse(useragent) ⇒ Hash
Parse an useragent using UseragenAPI.
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 |
# File 'lib/useragent_api/client.rb', line 13 def initialize(api_key) raise ArgumentError, 'invalid API key' if api_key.empty? @api_key = api_key.freeze freeze end |
Instance Attribute Details
#api_key ⇒ String (readonly)
Returns the api key
20 21 22 |
# File 'lib/useragent_api/client.rb', line 20 def api_key @api_key end |
Instance Method Details
#parse(useragent) ⇒ Hash
Parse an useragent using UseragenAPI
27 28 29 30 |
# File 'lib/useragent_api/client.rb', line 27 def parse(useragent) response = request(useragent) parse_as_json(response.body) end |