Class: BerlinBuehnen::Client

Inherits:
Object
  • Object
show all
Includes:
HTTMultiParty
Defined in:
lib/berlin_buehnen/client.rb

Constant Summary collapse

USER_AGENT =
"ASK HELMUT BerlinBuehnen API Wrapper #{VERSION}"
API_USERNAME_PARAM_NAME =
"username"
API_KEY_PARAM_NAME =
"api_key"
API_VERSION =
"v1"
API_FORMAT =
"json"
DEFAULT_OPTIONS =
{
  site: "www.berlin-buehnen.de",
  language: "de"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


17
18
19
20
21
# File 'lib/berlin_buehnen/client.rb', line 17

def initialize(options = {})
  store_options(options)
  raise ArgumentError, "An api key must be present" if api_key.nil?
  raise ArgumentError, "An api username must be present" if api_username.nil?
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#api_hostObject



49
50
51
# File 'lib/berlin_buehnen/client.rb', line 49

def api_host
  host
end

#api_keyObject



40
41
42
# File 'lib/berlin_buehnen/client.rb', line 40

def api_key
  @options[:api_key]
end

#api_languageObject



53
54
55
# File 'lib/berlin_buehnen/client.rb', line 53

def api_language
  @options[:language]
end

#api_urlObject



57
58
59
# File 'lib/berlin_buehnen/client.rb', line 57

def api_url
  [api_host, api_language, "api", API_VERSION].join("/")
end

#api_usernameObject

accessors for options



36
37
38
# File 'lib/berlin_buehnen/client.rb', line 36

def api_username
  @options[:username]
end

#get(path, query = {}, options = {}) ⇒ Object



23
24
25
26
27
# File 'lib/berlin_buehnen/client.rb', line 23

def get(path, query={}, options={})
  handle_response {
    self.class.get(*construct_query_arguments(path, options.merge(:query => query)))
  }
end

#head(path, query = {}, options = {}) ⇒ Object



29
30
31
32
33
# File 'lib/berlin_buehnen/client.rb', line 29

def head(path, query={}, options={})
  handle_response {
    self.class.head(*construct_query_arguments(path, options.merge(:query => query)))
  }
end

#siteObject Also known as: host



44
45
46
# File 'lib/berlin_buehnen/client.rb', line 44

def site
  @options[:site]
end