Class: Notu::Api
- Inherits:
-
Object
- Object
- Notu::Api
- Defined in:
- lib/notu/api.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_API_KEY =
'91f5d6a201de58e0c0a0d858573dddf0'.freeze
- FORMAT =
'json'.freeze
- HOST =
'ws.audioscrobbler.com'.freeze
- VERSION =
'2.0'.freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
-
#initialize(api_key: DEFAULT_API_KEY) ⇒ Api
constructor
A new instance of Api.
- #url(params = {}) ⇒ Object
Constructor Details
#initialize(api_key: DEFAULT_API_KEY) ⇒ Api
Returns a new instance of Api.
12 13 14 |
# File 'lib/notu/api.rb', line 12 def initialize(api_key: DEFAULT_API_KEY) @api_key = api_key.try(:squish).presence || raise(Error.new('API key must be specified')) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
10 11 12 |
# File 'lib/notu/api.rb', line 10 def api_key @api_key end |
Instance Method Details
#url(params = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/notu/api.rb', line 16 def url(params = {}) params = (params || {}).symbolize_keys params.merge!(api_key:, format: FORMAT) query_string = params.map { |name, value| "#{CGI.escape(name.to_s)}=#{CGI.escape(value.to_s)}" }.join('&') "https://#{HOST}/#{VERSION}?#{query_string}" end |