room_tiny_manager 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/room_tiny_manager.rb +36 -10
- data/lib/room_tiny_manager/version.rb +1 -1
- data/spec/room_tiny_manager/fetcher_spec.rb +33 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24e48acf6613d348abf4112b03311d302248ffb3
|
4
|
+
data.tar.gz: 6987a42aeb8aa8ef26a3d04d9cc74445de6ca5f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b76fed5099c9e8342a9f5a8ca5dd713100cb45b3d5c29d4d830f26eb01fc204354b785aade9d99dd6fa5d0ba12ce1c1e689c84005ff90014efade37a0e017c2
|
7
|
+
data.tar.gz: ffe885e269fc67b2b4f624879db4b06a82abd976b7cb27046da20ec62589c6bab42359803d3b36a900b39b5da60b5b368b73f1b3cd740dfd3b1e6232aba1f977
|
data/README.md
CHANGED
@@ -18,7 +18,17 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
* To create a new fetcher
|
22
|
+
input = "{\"properties\":[{\"property_adress\":\"72 Central Park W\",\"apartment_no\":\"7\",\"zip_code\":\"8002\",\"town\":\"Zurich\",\"country\":\"Swiss\",\"property_description\":\"fake description of the property\",\"bedrooms_no\":\"1\",\"max_people\":\"2\",\"source_id\":\"68123\"}]}"
|
23
|
+
|
24
|
+
fetcher = RoomTinyManager::Fetcher.new(input)
|
25
|
+
|
26
|
+
* To get properties
|
27
|
+
fetcher.get_properties
|
28
|
+
|
29
|
+
* To post a room
|
30
|
+
fetcher.post_a_room
|
31
|
+
|
22
32
|
|
23
33
|
## Contributing
|
24
34
|
|
data/lib/room_tiny_manager.rb
CHANGED
@@ -14,25 +14,51 @@ module RoomTinyManager
|
|
14
14
|
## FIXME: I added my access_token
|
15
15
|
## Can be more general, that some one use the gem can set their access token
|
16
16
|
ROOMS_END_POINT = "https://api.roomorama.com/v1.0/rooms.json"
|
17
|
+
HOST_ROOM_END_POINT = "https://api.roomorama.com/v1.0/host/rooms.json"
|
17
18
|
ACCESS_TOKEN = "0WGRIQTVZyf9a6kudI8zmq5QAmMCGzRlhD1jq97T54"
|
18
19
|
|
19
|
-
def initialize
|
20
|
+
def initialize(properties_input)
|
21
|
+
@properties = parse_input(properties_input)
|
20
22
|
end
|
21
23
|
|
22
|
-
def
|
23
|
-
|
24
|
-
JSON.parse(raw_result)
|
24
|
+
def get_properties
|
25
|
+
@properties
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
raw_result = RestClient.get(
|
28
|
+
# Post new room to the following end_point "https://api.roomorama.com/v1.0/host/rooms.json"
|
29
|
+
def post_a_room
|
30
|
+
raw_result = RestClient.get(HOST_ROOM_END_POINT, { params: @properties.first.merge(access_token: ACCESS_TOKEN) })
|
30
31
|
JSON.parse(raw_result)
|
31
32
|
end
|
32
33
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
34
|
+
# def self.room_by_city(city=nil)
|
35
|
+
# raise "Missing argument: city" if city.nil?
|
36
|
+
# raw_result = RestClient.get(ROOMS_END_POINT, { params: {access_token: ACCESS_TOKEN, destination: city } })
|
37
|
+
# JSON.parse(raw_result)
|
38
|
+
# end
|
39
|
+
|
40
|
+
private
|
41
|
+
def parse_input(properties)
|
42
|
+
properties = JSON.parse(properties)["properties"]
|
43
|
+
|
44
|
+
rooms = []
|
45
|
+
properties.each do |property|
|
46
|
+
map_p = {
|
47
|
+
address: property["property_address"],
|
48
|
+
apartment_number: property["apartment_no"],
|
49
|
+
postal_code: property["zip_code"],
|
50
|
+
city: property["town"],
|
51
|
+
country: property["country"],
|
52
|
+
description: property["property_description"],
|
53
|
+
number_of_bedrooms: property["bedrooms_no"],
|
54
|
+
max_guests: property["max_people"],
|
55
|
+
internal_id: property["source_id"]
|
56
|
+
}
|
57
|
+
rooms << map_p
|
58
|
+
end
|
59
|
+
|
60
|
+
rooms
|
61
|
+
end
|
36
62
|
|
37
63
|
end
|
38
64
|
end
|
@@ -2,31 +2,50 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module RoomTinyManager
|
4
4
|
describe Fetcher do
|
5
|
+
|
6
|
+
let(:sigle_input) { "{\"properties\":[{\"property_address\":\"72 Central Park W\",\"apartment_no\":\"7\",\"zip_code\":\"8002\",\"town\":\"Zurich\",\"country\":\"Swiss\",\"property_description\":\"fake description of the property\",\"bedrooms_no\":\"1\",\"max_people\":\"2\",\"source_id\":\"68123\"}]}" }
|
7
|
+
|
8
|
+
let(:multiple_inputs) {
|
9
|
+
"{\"properties\":[{\"property_address\":\"72 Central Park W\",\"apartment_no\":\"7\",\"zip_code\":\"8002\",\"town\":\"Zurich\",\"country\":\"Swiss\",\"property_description\":\"fake description of the property\",\"bedrooms_no\":\"1\",\"max_people\":\"2\",\"source_id\":\"68123\"},
|
10
|
+
{\"property_address\":\"72 Central Park W\",\"apartment_no\":\"4\",\"zip_code\":\"8002\",\"town\":\"Saigon\",\"country\":\"Vietnam\",\"property_description\":\"fake description of the property\",\"bedrooms_no\":\"1\",\"max_people\":\"2\",\"source_id\":\"12345\"}
|
11
|
+
]}"
|
12
|
+
}
|
13
|
+
|
5
14
|
describe "#get_properties" do
|
6
15
|
|
7
|
-
let(:
|
16
|
+
let(:fetcher1) { RoomTinyManager::Fetcher.new(sigle_input) }
|
17
|
+
let(:fetcher2) { RoomTinyManager::Fetcher.new(multiple_inputs) }
|
18
|
+
|
19
|
+
it "returns 1 property" do
|
20
|
+
expect(fetcher1.get_properties.count).to eq(1)
|
21
|
+
end
|
8
22
|
|
9
23
|
it "returns list of properties" do
|
10
|
-
expect(
|
24
|
+
expect(fetcher2.get_properties.count).to be > 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it "post new room" do
|
28
|
+
result = fetcher1.post_a_room
|
29
|
+
expect(result["status"]).to eq(200)
|
11
30
|
end
|
12
31
|
end
|
13
32
|
|
14
|
-
describe "#room_by_city" do
|
15
|
-
|
33
|
+
# describe "#room_by_city" do
|
34
|
+
# let(:room) { RoomTinyManager::Fetcher.room_by_city("singapore")["result"].first }
|
16
35
|
|
17
|
-
|
18
|
-
|
19
|
-
|
36
|
+
# it "room must be in Singapore" do
|
37
|
+
# expect(room["city"]).to eq("Singapore")
|
38
|
+
# end
|
20
39
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
40
|
+
# it "room must not from New York" do
|
41
|
+
# expect(room["city"]).not_to eq("New York")
|
42
|
+
# end
|
43
|
+
# end
|
25
44
|
|
26
45
|
|
27
|
-
describe "#post_a_room" do
|
28
|
-
|
29
|
-
end
|
46
|
+
# describe "#post_a_room" do
|
47
|
+
# pending 'Fill some test here'
|
48
|
+
# end
|
30
49
|
|
31
50
|
end
|
32
51
|
end
|