zumata 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/zumata/client.rb +11 -9
- data/lib/zumata/config.rb +20 -0
- data/lib/zumata/version.rb +1 -1
- data/lib/zumata.rb +1 -0
- data/spec/zumata_spec.rb +15 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fae9db9329572abb06c48e7e61ae5731ba87983a
|
4
|
+
data.tar.gz: 56cf1d78d47d19c41ab232af68ee75e12b6193ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a4e2243b8d2ec44e4ca8eec597127566ecbae9314624c29a7c05a3686f066da7d845a9686f3a0a6a20578ccc218362b493efb00abb3bb9581f087cd31e8446c
|
7
|
+
data.tar.gz: b70e448b490ec57c7db72f243e4d39dcb1d188c5af7d2ef4fb39ef4ee5b6179eca7d86977d632cba555e38c1d6f88550a9a5e6627431e88bbf37a94ab537df4a
|
data/lib/zumata/client.rb
CHANGED
@@ -9,19 +9,21 @@ module Zumata
|
|
9
9
|
class Client
|
10
10
|
include HTTParty
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@api_key = api_key
|
12
|
+
def initialize opts={}
|
13
|
+
raise Zumata::ClientConfigError.new("No API URL configured") if Zumata.configuration.nil? || Zumata.configuration.api_url == ''
|
14
|
+
@api_url = Zumata.configuration.api_url
|
15
|
+
@api_key = opts[:api_key] unless opts[:api_key].nil?
|
17
16
|
@timeout = 600
|
18
17
|
end
|
19
18
|
|
19
|
+
def get_api_key
|
20
|
+
@api_key || Zumata.configuration.api_key
|
21
|
+
end
|
20
22
|
|
21
23
|
# GET /search
|
22
24
|
def search_by_destination destination, opts={}
|
23
25
|
|
24
|
-
q = { api_key: opts[:api_key] ||
|
26
|
+
q = { api_key: opts[:api_key] || get_api_key,
|
25
27
|
destination: destination,
|
26
28
|
rooms: opts[:rooms] || 1,
|
27
29
|
adults: opts[:adults] || 2,
|
@@ -36,7 +38,7 @@ module Zumata
|
|
36
38
|
q[:lang] = opts[:lang] if opts[:lang]
|
37
39
|
q[:timeout] = opts[:timeout] if opts[:timeout]
|
38
40
|
|
39
|
-
res = self.class.get("/search", query: q).response
|
41
|
+
res = self.class.get("#{@api_url}/search", query: q).response
|
40
42
|
|
41
43
|
# todo - handle errors from search
|
42
44
|
Zumata::GenericResponse.new(context: q, code: res.code.to_i, body: res.body)
|
@@ -50,12 +52,12 @@ module Zumata
|
|
50
52
|
# raise InvalidRequestError unless valid_guest_params?(guest)
|
51
53
|
# raise InvalidRequestError unless valid_payment_params?(payment)
|
52
54
|
|
53
|
-
body_params = { api_key: opts[:api_key] ||
|
55
|
+
body_params = { api_key: opts[:api_key] || get_api_key,
|
54
56
|
booking_key: booking_key,
|
55
57
|
guest: guest,
|
56
58
|
payment: payment }
|
57
59
|
|
58
|
-
res = self.class.post("/book", body: body_params.to_json, headers: { 'Content-Type' => 'application/json' }, timeout: @timeout)
|
60
|
+
res = self.class.post("#{@api_url}/book", body: body_params.to_json, headers: { 'Content-Type' => 'application/json' }, timeout: @timeout)
|
59
61
|
|
60
62
|
status_code = res.code.to_i
|
61
63
|
raise Zumata::GeneralError, res.body unless VALID_STATUS_CODES.include?(status_code)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Zumata
|
2
|
+
class << self
|
3
|
+
attr_accessor :configuration
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configure
|
7
|
+
self.configuration ||= Configuration.new
|
8
|
+
yield(configuration)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Configuration
|
12
|
+
attr_accessor :api_url, :api_key
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@api_url = ''
|
16
|
+
@api_key = nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/lib/zumata/version.rb
CHANGED
data/lib/zumata.rb
CHANGED
data/spec/zumata_spec.rb
CHANGED
@@ -4,11 +4,19 @@ require './lib/zumata'
|
|
4
4
|
|
5
5
|
describe "Zumata::Client" do
|
6
6
|
|
7
|
+
vcr_recorded_checkin = '11/15/2014'
|
8
|
+
vcr_recorded_checkout = '11/16/2014'
|
9
|
+
|
7
10
|
raise Zumata::TestConfigError unless ENV["ZUMATA_API_KEY"]
|
8
|
-
sample_api_key = ENV["ZUMATA_API_KEY"]
|
9
11
|
|
10
12
|
before(:each) do
|
11
|
-
|
13
|
+
|
14
|
+
Zumata.configure do |config|
|
15
|
+
config.api_url = ENV["ZUMATA_API_URL"]
|
16
|
+
config.api_key = ENV["ZUMATA_API_KEY"]
|
17
|
+
end
|
18
|
+
|
19
|
+
@client = Zumata::Client.new
|
12
20
|
end
|
13
21
|
|
14
22
|
describe "search_by_destination" do
|
@@ -17,7 +25,7 @@ describe "Zumata::Client" do
|
|
17
25
|
|
18
26
|
# note - when recording the cassette this requires a cached search w/ results to exist
|
19
27
|
destination_id = "f75a8cff-c26e-4603-7b45-1b0f8a5aa100" # Singapore
|
20
|
-
results = @client.search_by_destination destination_id
|
28
|
+
results = @client.search_by_destination destination_id, {checkin: vcr_recorded_checkin, checkout: vcr_recorded_checkout}
|
21
29
|
data = JSON.parse(results.body)
|
22
30
|
expect(data["searchCompleted"]).to_not be(nil)
|
23
31
|
expect(data["content"]["hotels"].length).to be > 0
|
@@ -89,7 +97,7 @@ describe "Zumata::Client" do
|
|
89
97
|
|
90
98
|
destination_id = "53d32e78-c548-42af-5236-fb89e0977722" # Barcelona
|
91
99
|
results = VCR.use_cassette('search_by_destination_done_2', :record => :new_episodes) do
|
92
|
-
@client.search_by_destination destination_id
|
100
|
+
@client.search_by_destination destination_id, {checkin: vcr_recorded_checkin, checkout: vcr_recorded_checkout}
|
93
101
|
end
|
94
102
|
|
95
103
|
data = JSON.parse(results.body)
|
@@ -112,7 +120,7 @@ describe "Zumata::Client" do
|
|
112
120
|
|
113
121
|
destination_id = "f75a8cff-c26e-4603-7b45-1b0f8a5aa100" # Singapore
|
114
122
|
results = VCR.use_cassette('search_by_destination_done', :record => :new_episodes) do
|
115
|
-
@client.search_by_destination(destination_id)
|
123
|
+
@client.search_by_destination(destination_id, {checkin: vcr_recorded_checkin, checkout: vcr_recorded_checkout})
|
116
124
|
end
|
117
125
|
|
118
126
|
data = JSON.parse(results.body)
|
@@ -134,7 +142,7 @@ describe "Zumata::Client" do
|
|
134
142
|
|
135
143
|
destination_id = "f75a8cff-c26e-4603-7b45-1b0f8a5aa100" # Singapore
|
136
144
|
results = VCR.use_cassette('search_by_destination_done', :record => :new_episodes) do
|
137
|
-
@client.search_by_destination destination_id
|
145
|
+
@client.search_by_destination destination_id, {checkin: vcr_recorded_checkin, checkout: vcr_recorded_checkout}
|
138
146
|
end
|
139
147
|
|
140
148
|
data = JSON.parse(results.body)
|
@@ -154,7 +162,7 @@ describe "Zumata::Client" do
|
|
154
162
|
|
155
163
|
destination_id = "53d32e78-c548-42af-5236-fb89e0977722" # Barcelona
|
156
164
|
results = VCR.use_cassette('search_by_destination_done_2', :record => :new_episodes) do
|
157
|
-
@client.search_by_destination destination_id
|
165
|
+
@client.search_by_destination destination_id, {checkin: vcr_recorded_checkin, checkout: vcr_recorded_checkout}
|
158
166
|
end
|
159
167
|
|
160
168
|
data = JSON.parse(results.body)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zumata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- Rakefile
|
129
129
|
- lib/zumata.rb
|
130
130
|
- lib/zumata/client.rb
|
131
|
+
- lib/zumata/config.rb
|
131
132
|
- lib/zumata/errors.rb
|
132
133
|
- lib/zumata/responses.rb
|
133
134
|
- lib/zumata/version.rb
|