Class: Hoolp::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/hoolp/client.rb

Constant Summary collapse

USER_AGENT =
"ASK HELMUT Hooolp Client #{VERSION}".freeze
DEFAULT_OPTIONS =
{
  base_url: "http://api2.hooolp.com"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



14
15
16
# File 'lib/hoolp/client.rb', line 14

def initialize(options)
  store_options(options)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/hoolp/client.rb', line 10

def options
  @options
end

Instance Method Details

#api_keyObject



41
42
43
# File 'lib/hoolp/client.rb', line 41

def api_key
  @options.fetch(:api_key)
end

#base_urlObject



37
38
39
# File 'lib/hoolp/client.rb', line 37

def base_url
  @options.fetch(:base_url)
end

#events(location_id:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hoolp/client.rb', line 18

def events(location_id:)
  query = construct_query_arguments(
    resource: "events",
    options: "locations=#{location_id}&ctr=DE"
  )

  response = self.class.get(
    *query
  )

  result = JSON.parse(response.body)

  raise ApiError(result) if !result.is_a?(Array) && result.key?("error")

  result.map do |item|
    Resource::Event.new(item.fetch("event"))
  end
end