roomorama_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.travis.yml +8 -0
- data/CHANGELOG +23 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +77 -0
- data/Rakefile +11 -0
- data/lib/roomorama_api/version.rb +3 -0
- data/lib/roomorama_api.rb +182 -0
- data/roomorama_api.gemspec +23 -0
- data/test/fixtures/destinations/all.json +58174 -0
- data/test/fixtures/favorites/create.json +7 -0
- data/test/fixtures/favorites/list.json +28 -0
- data/test/fixtures/hosts/properties/list.json +84 -0
- data/test/fixtures/hosts/properties/show.json +81 -0
- data/test/fixtures/perks/get_data.json +25 -0
- data/test/fixtures/perks/list.json +453 -0
- data/test/fixtures/properties/availabilities.json +346 -0
- data/test/fixtures/properties/find.json +250 -0
- data/test/fixtures/properties/find_similar.json +119 -0
- data/test/fixtures/properties/get_data.json +105 -0
- data/test/fixtures/properties/price_check.json +29 -0
- data/test/fixtures/properties/reviews.json +149 -0
- data/test/fixtures/users/get_data.json +13 -0
- data/test/fixtures/users/me.json +29 -0
- data/test/fixtures/users/register.json +29 -0
- data/test/fixtures/users/reviews.json +989 -0
- data/test/fixtures/users/update_profile.json +13 -0
- data/test/minitest_helper.rb +57 -0
- data/test/roomorama_api_test.rb +175 -0
- metadata +161 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'fakeweb'
|
3
|
+
|
4
|
+
FakeWeb.allow_net_connect = false
|
5
|
+
|
6
|
+
def fixture_file(filename, options={})
|
7
|
+
return '' if filename == ''
|
8
|
+
|
9
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
|
10
|
+
fixture = File.read(file_path)
|
11
|
+
|
12
|
+
case File.extname(file_path)
|
13
|
+
when '.json'
|
14
|
+
options[:parse] ? JSON.parse(fixture) : fixture
|
15
|
+
else
|
16
|
+
fixture
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def stub_get(url, filename, options={})
|
22
|
+
opts = {
|
23
|
+
:body => error_or_standard_body(filename, options)
|
24
|
+
}.merge(options)
|
25
|
+
FakeWeb.register_uri(:get, url, opts)
|
26
|
+
end
|
27
|
+
|
28
|
+
def stub_post(url, filename, options={})
|
29
|
+
opts = {
|
30
|
+
:body => error_or_standard_body(filename, options),
|
31
|
+
}.merge(options)
|
32
|
+
FakeWeb.register_uri(:post, url, opts)
|
33
|
+
end
|
34
|
+
|
35
|
+
def stub_delete(url, filename, options={})
|
36
|
+
opts = {
|
37
|
+
:body => error_or_standard_body(filename, options),
|
38
|
+
}.merge(options)
|
39
|
+
FakeWeb.register_uri(:delete, url, opts)
|
40
|
+
end
|
41
|
+
|
42
|
+
def stub_put(url, filename, options={})
|
43
|
+
opts = {
|
44
|
+
:body => error_or_standard_body(filename, options),
|
45
|
+
}.merge(options)
|
46
|
+
FakeWeb.register_uri(:put, url, opts)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def error_or_standard_body(filename, options)
|
51
|
+
error_options = options.delete(:error)
|
52
|
+
body = fixture_file(error_options ? 'error_template.json' : filename)
|
53
|
+
body = body.gsub(/%error_code%/, error_options[:code])
|
54
|
+
.gsub(/%error_type%/, error_options[:type])
|
55
|
+
.gsub(/%error_message%/, error_options[:message]) if error_options
|
56
|
+
body
|
57
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
require 'roomorama_api'
|
3
|
+
|
4
|
+
class RoomoramaApiTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
OAUTH_TOKEN = 'xxx' # Insert OAuth token to test
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@client = RoomoramaApi::Client.new(OAUTH_TOKEN)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_order
|
13
|
+
:alpha
|
14
|
+
end
|
15
|
+
|
16
|
+
#### Destinations
|
17
|
+
|
18
|
+
def test_destinations_all
|
19
|
+
stub_get("https://api.roomorama.com/v1.0/destinations", 'destinations/all.json')
|
20
|
+
result = @client.destinations_all
|
21
|
+
assert_equal result["result"].count, 5288
|
22
|
+
end
|
23
|
+
|
24
|
+
#### Properties
|
25
|
+
|
26
|
+
def test_properties_find
|
27
|
+
stub_get("https://api.roomorama.com/v1.0/rooms?destination=singapore&num_guests=2&num_rooms=2&max_price=300&min_price=100", 'properties/find.json')
|
28
|
+
result = @client.properties_find(destination:"singapore", num_guests:2, num_rooms:2, max_price:300, min_price:100)
|
29
|
+
assert_equal result["result"].count, 10
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_properties_get_data
|
33
|
+
stub_get("https://api.roomorama.com/v1.0/rooms/3002", 'properties/get_data.json')
|
34
|
+
result = @client.properties_get_data 3002
|
35
|
+
assert_equal result["result"]["id"], 3002
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_properties_find_similar
|
39
|
+
stub_get("https://api.roomorama.com/v1.0/rooms/3002/similar", 'properties/find_similar.json')
|
40
|
+
result = @client.properties_find_similar 3002
|
41
|
+
assert_equal result["result"].count, 5
|
42
|
+
assert_equal result["result"].first["title"], "Madison Avenue Apartment for rent on weekends"
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_properties_availabilities
|
46
|
+
stub_get("https://api.roomorama.com/v1.0/rooms/3002/availabilities?start_date=2013-12-01&end_date=2013-12-31", 'properties/availabilities.json')
|
47
|
+
result = @client.properties_availabilities 3002, start_date:"2013-12-01", end_date:"2013-12-31"
|
48
|
+
assert_equal result["result"].count, 31
|
49
|
+
assert_equal result["result"].first["available"], true
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_properties_price_check
|
53
|
+
stub_get("https://api.roomorama.com/v1.0/inquiries/new.json?room_id=60425&check_in=2013-07-01&check_out=2013-07-10", 'properties/price_check.json')
|
54
|
+
result = @client.properties_price_check 60425, check_in:"2013-07-01", check_out:"2013-07-10"
|
55
|
+
assert_equal result["result"]["total"], 9168
|
56
|
+
assert_equal result["result"]["check_in"], "2013-07-01"
|
57
|
+
assert_equal result["result"]["check_out"], "2013-07-10"
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_properties_reviews
|
61
|
+
stub_get("https://api.roomorama.com/v1.0/rooms/8582/reviews", 'properties/reviews.json')
|
62
|
+
result = @client.properties_reviews 8582
|
63
|
+
assert_equal result["result"].first["rating"], 1
|
64
|
+
assert_equal result["result"].first["room"]["id"], 8582
|
65
|
+
end
|
66
|
+
|
67
|
+
#### Favorites
|
68
|
+
|
69
|
+
def test_favorites_list
|
70
|
+
stub_get("https://api.roomorama.com/v1.0/favorites", 'favorites/list.json')
|
71
|
+
result = @client.favorites_list
|
72
|
+
assert_equal result["result"].first["title"], "[7801] STUNNING WEST VILLAGE"
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_favorites_create
|
76
|
+
stub_post("https://api.roomorama.com/v1.0/favorites", "favorites/create.json")
|
77
|
+
result = @client.favorites_create room_id: 2291
|
78
|
+
assert_equal result["room_id"], 2291
|
79
|
+
end
|
80
|
+
|
81
|
+
#### Perks
|
82
|
+
|
83
|
+
def test_perks_list
|
84
|
+
stub_get("https://api.roomorama.com/v1.0/perks?destination=singapore", "perks/list.json")
|
85
|
+
result = @client.perks_list destination: "singapore"
|
86
|
+
assert_equal result["count"], 25
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_perks_get_data
|
90
|
+
stub_get("https://api.roomorama.com/v1.0/perks/25", "perks/get_data.json")
|
91
|
+
result = @client.perks_get_data 25
|
92
|
+
assert_equal result["result"]["name"], "Mygola Trip Planning"
|
93
|
+
end
|
94
|
+
|
95
|
+
#### Users
|
96
|
+
|
97
|
+
def test_users_me
|
98
|
+
stub_get("https://api.roomorama.com/v1.0/me", "users/me.json")
|
99
|
+
result = @client.users_me
|
100
|
+
assert_equal result["result"]["id"], 1419
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_users_update_profile
|
104
|
+
stub_put("https://api.roomorama.com/v1.0/me", "users/update_profile.json")
|
105
|
+
result = @client.users_update_profile
|
106
|
+
assert_equal result["result"]["id"], 1419
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_users_get_data
|
110
|
+
stub_get("https://api.roomorama.com/v1.0/users/1900", "users/get_data.json")
|
111
|
+
result = @client.users_get_data 1900
|
112
|
+
assert_equal result["result"]["id"], 1900
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_users_register
|
116
|
+
stub_post("https://api.roomorama.com/v1.0/users", "users/register.json")
|
117
|
+
result = @client.users_register login: "test123", password: "testapi", email: "test@example.com", first_name: "Skrillex", last_name: "Avicii"
|
118
|
+
assert_equal result["result"]["login"], "test123"
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_users_reviews
|
122
|
+
stub_get("https://api.roomorama.com/v1.0/users/291/reviews", "users/reviews.json")
|
123
|
+
result = @client.users_reviews 291
|
124
|
+
assert_equal result["result"][0]["host_to_guest"], false
|
125
|
+
assert_equal result["result"][0]["host"]["id"], 291
|
126
|
+
end
|
127
|
+
|
128
|
+
#### Hosts/Properties
|
129
|
+
|
130
|
+
def test_hosts_properties_list
|
131
|
+
stub_get("https://api.roomorama.com/v1.0/host/rooms", "hosts/properties/list.json")
|
132
|
+
result = @client.hosts_properties_list
|
133
|
+
assert_equal result["result"][0]["id"], 9999
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_hosts_properties_show
|
137
|
+
stub_get("https://api.roomorama.com/v1.0/host/rooms/9999", "hosts/properties/show.json")
|
138
|
+
result = @client.hosts_properties_show 9999
|
139
|
+
assert_equal result["result"]["id"], 9999
|
140
|
+
end
|
141
|
+
|
142
|
+
# def test_get_data_for_an_empty_property
|
143
|
+
# assert_raises RoomoramaApi::NotFound do
|
144
|
+
# result = @client.properties_get_data 500
|
145
|
+
# end
|
146
|
+
# end
|
147
|
+
|
148
|
+
# def test_get_information_about_me_oauth
|
149
|
+
# result = @client.users_me
|
150
|
+
# # assert_equal
|
151
|
+
# end
|
152
|
+
|
153
|
+
#### Favorites
|
154
|
+
|
155
|
+
# def test_favorites_create
|
156
|
+
# result = @client.favorites_create room_id: 1890
|
157
|
+
# end
|
158
|
+
|
159
|
+
# def test_favorites_list
|
160
|
+
# result = @client.favorites_list
|
161
|
+
# puts result
|
162
|
+
# end
|
163
|
+
|
164
|
+
# def test_favorites_delete
|
165
|
+
# result = @client.favorites_delete 1890
|
166
|
+
# puts result
|
167
|
+
#end
|
168
|
+
|
169
|
+
#### Perks
|
170
|
+
|
171
|
+
|
172
|
+
#### Users
|
173
|
+
|
174
|
+
|
175
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: roomorama_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- TM Lee
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.8'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.8'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.7.7
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.7.7
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: fakeweb
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.3.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Ruby wrapper to call Roomorama API V1.0 at https://roomorama.com/api.
|
79
|
+
For a step by step guide on getting started with Roomorama API, refer to https://roomorama.com/api/step_by_step.
|
80
|
+
email:
|
81
|
+
- tm89lee@gmail.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .travis.yml
|
88
|
+
- CHANGELOG
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- lib/roomorama_api.rb
|
94
|
+
- lib/roomorama_api/version.rb
|
95
|
+
- roomorama_api.gemspec
|
96
|
+
- test/fixtures/destinations/all.json
|
97
|
+
- test/fixtures/favorites/create.json
|
98
|
+
- test/fixtures/favorites/list.json
|
99
|
+
- test/fixtures/hosts/properties/list.json
|
100
|
+
- test/fixtures/hosts/properties/show.json
|
101
|
+
- test/fixtures/perks/get_data.json
|
102
|
+
- test/fixtures/perks/list.json
|
103
|
+
- test/fixtures/properties/availabilities.json
|
104
|
+
- test/fixtures/properties/find.json
|
105
|
+
- test/fixtures/properties/find_similar.json
|
106
|
+
- test/fixtures/properties/get_data.json
|
107
|
+
- test/fixtures/properties/price_check.json
|
108
|
+
- test/fixtures/properties/reviews.json
|
109
|
+
- test/fixtures/users/get_data.json
|
110
|
+
- test/fixtures/users/me.json
|
111
|
+
- test/fixtures/users/register.json
|
112
|
+
- test/fixtures/users/reviews.json
|
113
|
+
- test/fixtures/users/update_profile.json
|
114
|
+
- test/minitest_helper.rb
|
115
|
+
- test/roomorama_api_test.rb
|
116
|
+
homepage: https://github.com/tmlee/roomorama_api
|
117
|
+
licenses: []
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.8.23
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Ruby wrapper to call Roomorama API V1.0
|
140
|
+
test_files:
|
141
|
+
- test/fixtures/destinations/all.json
|
142
|
+
- test/fixtures/favorites/create.json
|
143
|
+
- test/fixtures/favorites/list.json
|
144
|
+
- test/fixtures/hosts/properties/list.json
|
145
|
+
- test/fixtures/hosts/properties/show.json
|
146
|
+
- test/fixtures/perks/get_data.json
|
147
|
+
- test/fixtures/perks/list.json
|
148
|
+
- test/fixtures/properties/availabilities.json
|
149
|
+
- test/fixtures/properties/find.json
|
150
|
+
- test/fixtures/properties/find_similar.json
|
151
|
+
- test/fixtures/properties/get_data.json
|
152
|
+
- test/fixtures/properties/price_check.json
|
153
|
+
- test/fixtures/properties/reviews.json
|
154
|
+
- test/fixtures/users/get_data.json
|
155
|
+
- test/fixtures/users/me.json
|
156
|
+
- test/fixtures/users/register.json
|
157
|
+
- test/fixtures/users/reviews.json
|
158
|
+
- test/fixtures/users/update_profile.json
|
159
|
+
- test/minitest_helper.rb
|
160
|
+
- test/roomorama_api_test.rb
|
161
|
+
has_rdoc:
|