room_tiny_manager 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bac1f2147facd26c81a53c3ebaf0ad3362359167
4
- data.tar.gz: 51e817e1e8caa59ed3d8b092c8f5b7f0015cc9d0
3
+ metadata.gz: 24e48acf6613d348abf4112b03311d302248ffb3
4
+ data.tar.gz: 6987a42aeb8aa8ef26a3d04d9cc74445de6ca5f7
5
5
  SHA512:
6
- metadata.gz: 4b48c96f7f936c6473a725d5608394a35529b15d51b23e6bc89e2416b0f09c48da0a8d2b1e8920343218ac3741c080e55dc5647ca6aa776d4d286d08c9674213
7
- data.tar.gz: 1d9e85171dcda0da42ecd5516052ae1fb4e79bd4ba211b982fc71140ae0e8257683a911df6e061a37b5988df9fff8e5a27176f9defcc82129b343b06dca37d20
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
- TODO: Write usage instructions here
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
 
@@ -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 self.get_properties
23
- raw_result = RestClient.get(ROOMS_END_POINT, {access_token: ACCESS_TOKEN})
24
- JSON.parse(raw_result)
24
+ def get_properties
25
+ @properties
25
26
  end
26
27
 
27
- def self.room_by_city(city=nil)
28
- raise "Missing argument: city" if city.nil?
29
- raw_result = RestClient.get(ROOMS_END_POINT, { params: {access_token: ACCESS_TOKEN, destination: city } })
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 post_a_room
34
-
35
- end
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
@@ -1,3 +1,3 @@
1
1
  module RoomTinyManager
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  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(:rooms) { RoomTinyManager::Fetcher.get_properties["result"] }
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(rooms.length).to be > 0
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
- let(:room) { RoomTinyManager::Fetcher.room_by_city("singapore")["result"].first }
33
+ # describe "#room_by_city" do
34
+ # let(:room) { RoomTinyManager::Fetcher.room_by_city("singapore")["result"].first }
16
35
 
17
- it "room must be in Singapore" do
18
- expect(room["city"]).to eq("Singapore")
19
- end
36
+ # it "room must be in Singapore" do
37
+ # expect(room["city"]).to eq("Singapore")
38
+ # end
20
39
 
21
- it "room must not from New York" do
22
- expect(room["city"]).not_to eq("New York")
23
- end
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
- pending 'Fill some test here'
29
- end
46
+ # describe "#post_a_room" do
47
+ # pending 'Fill some test here'
48
+ # end
30
49
 
31
50
  end
32
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: room_tiny_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Long Nguyen