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.
11 12 13 14 15 |
# File 'lib/useragent_api/client.rb', line 11 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)
18 19 20 |
# File 'lib/useragent_api/client.rb', line 18 def api_key @api_key end |
Instance Method Details
#parse(useragent) ⇒ Hash
Parse an useragent using UseragenAPI
25 26 27 28 |
# File 'lib/useragent_api/client.rb', line 25 def parse(useragent) response = request(useragent) parse_as_json(response.body) end |