wubook_wired 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/wired.rb +137 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 291f933f0ed3400f09627d2a5f4ebcdeeebc57c0
|
4
|
+
data.tar.gz: b51065c1d1fe0eab74fe6a43b7d66dce36a0c552
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b6b58816977c8da654ea659f4385256088dd6cedff4041ab9215de454d097abb8e727bfba4f87ed6f6a52c7cdc367128453faa7bcc72606e4c3751996488025
|
7
|
+
data.tar.gz: 080baf2470b05c7a9f444927490c9a9c73504509a4f92bd40f37cd50edd68409db87076f55a05c79c14f930eefe329a0dba0820139d9c03fd6bd2d1b8f6209d5
|
data/lib/wired.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'xmlrpc/client'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
# class XMLRPC::Client
|
6
|
+
# def set_debug
|
7
|
+
# @http.set_debug_output($stderr);
|
8
|
+
# end
|
9
|
+
# end
|
10
|
+
|
11
|
+
# Implementation of the WuBook API.
|
12
|
+
# The Documentation can be found here: https://sites.google.com/site/wubookdocs/wired/wired-pms-xml
|
13
|
+
class Wired
|
14
|
+
def initialize(config)
|
15
|
+
# The config will contain the following keys: account_code, password, provider_key
|
16
|
+
@config = config
|
17
|
+
end
|
18
|
+
|
19
|
+
def config
|
20
|
+
@config
|
21
|
+
end
|
22
|
+
|
23
|
+
# Requests a token from the server.
|
24
|
+
# The token is stored in this object and will be used automatically.
|
25
|
+
def aquire_token
|
26
|
+
token_data = server.call("acquire_token", @config['account_code'], @config['password'], @config['provider_key'])
|
27
|
+
status = token_data[0]
|
28
|
+
@token = token_data[1]
|
29
|
+
if (is_error(status))
|
30
|
+
error_message = decode_error(status)
|
31
|
+
raise "Unable to aquire token. Reason: #{error_message}, Message: #{data}"
|
32
|
+
end
|
33
|
+
@token
|
34
|
+
end
|
35
|
+
|
36
|
+
def is_token_valid(token = @token)
|
37
|
+
response = server.call("is_token_valid", token)
|
38
|
+
status = response[0]
|
39
|
+
status == 0
|
40
|
+
end
|
41
|
+
|
42
|
+
# Releases the token fetched by #aquire_token
|
43
|
+
def release_token(token = @token)
|
44
|
+
response = server.call("release_token", token)
|
45
|
+
|
46
|
+
handle_response(response, "Unable to release token")
|
47
|
+
@token = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
# Fetch rooms
|
51
|
+
def fetch_rooms(lcode, token = @token)
|
52
|
+
response = server.call("fetch_rooms", token, lcode)
|
53
|
+
|
54
|
+
handle_response(response, "Unable to fetch room data")
|
55
|
+
end
|
56
|
+
|
57
|
+
# Update room values
|
58
|
+
# ==== Attributes
|
59
|
+
# * +dfrom+ - A Ruby date object (start date)
|
60
|
+
# * +rooms+ - A hash with the following structure: [{'id' => room_id, 'days' => [{'avail' => 0}, {'avail' => 1}]}]
|
61
|
+
def update_rooms_values(lcode, dfrom, rooms, token = @token)
|
62
|
+
response = server.call("update_rooms_values", token, lcode, dfrom.strftime('%d/%m/%Y'), rooms)
|
63
|
+
|
64
|
+
handle_response(response, "Unable to update room data")
|
65
|
+
end
|
66
|
+
|
67
|
+
# Request data about rooms.
|
68
|
+
# ==== Attributes
|
69
|
+
# * +dfrom+ - A Ruby date object (start date)
|
70
|
+
# * +dto+ - A Ruby date object (end date)
|
71
|
+
# * +rooms+ - An array containing the requested room ids
|
72
|
+
def fetch_rooms_values(lcode, dfrom, dto, rooms = nil, token = @token)
|
73
|
+
if rooms != nil then
|
74
|
+
response = server.call("fetch_rooms_values", token, lcode, dfrom.strftime('%d/%m/%Y'), dto.strftime('%d/%m/%Y'), rooms)
|
75
|
+
else
|
76
|
+
response = server.call("fetch_rooms_values", token, lcode, dfrom.strftime('%d/%m/%Y'), dto.strftime('%d/%m/%Y'))
|
77
|
+
end
|
78
|
+
|
79
|
+
handle_response(response, "Unable to fetch room values")
|
80
|
+
end
|
81
|
+
|
82
|
+
protected
|
83
|
+
|
84
|
+
def handle_response(response, message)
|
85
|
+
status = response[0]
|
86
|
+
data = response[1]
|
87
|
+
if (is_error(status))
|
88
|
+
error_message = decode_error(status)
|
89
|
+
raise "#{message}. Reason: #{error_message}, Message: #{data}"
|
90
|
+
end
|
91
|
+
data
|
92
|
+
end
|
93
|
+
|
94
|
+
def decode_error(code)
|
95
|
+
codes = {
|
96
|
+
0 => 'Ok',
|
97
|
+
-1 => 'Authentication Failed',
|
98
|
+
-2 => 'Invalid Token',
|
99
|
+
-3 => 'Server is busy: releasing tokens is now blocked. Please, retry again later',
|
100
|
+
-4 => 'Token Request: requesting frequence too high',
|
101
|
+
-5 => 'Token Expired',
|
102
|
+
-6 => 'Lodging is not active',
|
103
|
+
-7 => 'Internal Error',
|
104
|
+
-8 => 'Token used too many times: please, create a new token',
|
105
|
+
-9 => 'Invalid Rooms for the selected facility',
|
106
|
+
-10 => 'Invalid lcode',
|
107
|
+
-11 => 'Shortname has to be unique. This shortname is already used',
|
108
|
+
-12 => 'Room Not Deleted: Special Offer Involved',
|
109
|
+
-13 => 'Wrong call: pass the correct arguments, please',
|
110
|
+
-14 => 'Please, pass the same number of days for each room',
|
111
|
+
-15 => 'This plan is actually in use',
|
112
|
+
-100 => 'Invalid Input',
|
113
|
+
-101 => 'Malformed dates or restrictions unrespected',
|
114
|
+
-1000 => 'Invalid Lodging/Portal code',
|
115
|
+
-1001 => 'Invalid Dates',
|
116
|
+
-1002 => 'Booking not Initialized: use facility_request()',
|
117
|
+
-1003 => 'Objects not Available',
|
118
|
+
-1004 => 'Invalid Customer Data',
|
119
|
+
-1005 => 'Invalid Credit Card Data or Credit Card Rejected',
|
120
|
+
-1006 => 'Invalid Iata',
|
121
|
+
-1007 => 'No room was requested: use rooms_request()'
|
122
|
+
}
|
123
|
+
codes[code]
|
124
|
+
end
|
125
|
+
|
126
|
+
def server
|
127
|
+
server = XMLRPC::Client.new2 ("https://wubook.net/xrws/")
|
128
|
+
#server.set_debug
|
129
|
+
server
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
def is_error(code)
|
134
|
+
code.to_i < 0
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wubook_wired
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stefan Eilers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: You can use this Class for accessing the WuBook API called 'Wired'.
|
14
|
+
email: se@intelligentmobiles.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/wired.rb
|
20
|
+
homepage: http://www.intelligentmobiles.com
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Integration of the WuBook Wired API
|
44
|
+
test_files: []
|