Class: Reservix::Client

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

Constant Summary collapse

USER_AGENT =
"ASK HELMUT Reservix API Wrapper #{VERSION}"
API_KEY_PARAM_NAME =
"api-key"
API_SUBHOST =
"api"
API_VERSION =
"1"
DEFAULT_OPTIONS =
{
  site: "reservix.de",
  use_ssl: true,
  api_module: "sale"
}

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
# File 'lib/reservix/client.rb', line 17

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

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#api_hostObject



70
71
72
# File 'lib/reservix/client.rb', line 70

def api_host
  [API_SUBHOST, host].join(".")
end

#api_keyObject

accessors for options



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

def api_key
  @options[:api_key]
end

#api_moduleObject



61
62
63
# File 'lib/reservix/client.rb', line 61

def api_module
  @options[:api_module]
end

#api_urlObject



74
75
76
# File 'lib/reservix/client.rb', line 74

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

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



40
41
42
43
44
# File 'lib/reservix/client.rb', line 40

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

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



22
23
24
25
26
# File 'lib/reservix/client.rb', line 22

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

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



46
47
48
49
50
# File 'lib/reservix/client.rb', line 46

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

#post(path, body = {}, options = {}) ⇒ Object



28
29
30
31
32
# File 'lib/reservix/client.rb', line 28

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

#put(path, body = {}, options = {}) ⇒ Object



34
35
36
37
38
# File 'lib/reservix/client.rb', line 34

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

#siteObject Also known as: host



65
66
67
# File 'lib/reservix/client.rb', line 65

def site
  @options[:site]
end

#use_ssl?Boolean

Returns:

  • (Boolean)


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

def use_ssl?
  @options[:use_ssl]
end