Class: UseragentApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/useragent_api/client.rb

Overview

A class which wraps calls to UseragentAPI

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)

    when ‘api_key` is invalid

See Also:



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_keyString (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