roomorama_api 0.1.0
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.
- 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
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
## v0.1.0
|
2
|
+
|
3
|
+
* Initial release
|
4
|
+
* Supports the following API calls
|
5
|
+
* destinations_all
|
6
|
+
* properties_find
|
7
|
+
* properties_get_data
|
8
|
+
* properties_find_similar
|
9
|
+
* properties_availabilities
|
10
|
+
* properties_price_check
|
11
|
+
* properties_reviews
|
12
|
+
* favorites_list
|
13
|
+
* favorites_create
|
14
|
+
* favorites_delete
|
15
|
+
* perks_list
|
16
|
+
* perks_get_data
|
17
|
+
* users_me
|
18
|
+
* users_update_profile
|
19
|
+
* users_get_data
|
20
|
+
* users_register
|
21
|
+
* users_reviews
|
22
|
+
* hosts_properties_list
|
23
|
+
* hosts_properties_show
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TM Lee
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
[](https://travis-ci.org/tmlee/roomorama_api)
|
2
|
+
|
3
|
+
# RoomoramaApi
|
4
|
+
|
5
|
+
RoomoramaApi is a Ruby gem that wraps the Roomorama API V1.0 documented at https://roomorama.com/api.
|
6
|
+
|
7
|
+
For a step by step guide on getting started with Roomorama API, refer to https://roomorama.com/api/step_by_step.
|
8
|
+
|
9
|
+
This gem does not handle OAuth authentication or token generation. You may want to use https://github.com/intridea/omniauth and the Roomorama OAuth strategy at https://github.com/roomorama/omniauth-roomorama
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'roomorama_api', :git => 'git@github.com:tmlee/roomorama_api.git'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Currently this gem does not handle any oauth authentication yet. Host and Guest API calls are not support yet in this version.
|
25
|
+
|
26
|
+
### Initialize a client
|
27
|
+
|
28
|
+
client = RoomoramaApi::Client.new
|
29
|
+
|
30
|
+
### Initialize a client with OAuth token
|
31
|
+
|
32
|
+
client = RoomoramaApi::Client.new '<OAUTH TOKEN>'
|
33
|
+
|
34
|
+
### Get all destinations
|
35
|
+
|
36
|
+
client.destinations_all
|
37
|
+
|
38
|
+
### Search for properties/rooms
|
39
|
+
|
40
|
+
client.properties_find destination: 'singapore'
|
41
|
+
client.properties_find destination: 'singapore', order: 'title_asc'
|
42
|
+
|
43
|
+
### Get data for a give property/room
|
44
|
+
|
45
|
+
client.properties_get_data 500, strip_html: 'false'
|
46
|
+
|
47
|
+
|
48
|
+
### Make OAuth calls - get information about myself
|
49
|
+
|
50
|
+
client.user_me
|
51
|
+
|
52
|
+
### Supported API Calls
|
53
|
+
|
54
|
+
destinations_all
|
55
|
+
properties_find
|
56
|
+
properties_get_data
|
57
|
+
properties_find_similar
|
58
|
+
properties_availabilities
|
59
|
+
properties_price_check
|
60
|
+
properties_reviews
|
61
|
+
favorites_list
|
62
|
+
favorites_create
|
63
|
+
favorites_delete
|
64
|
+
perks_list
|
65
|
+
perks_get_data
|
66
|
+
users_me
|
67
|
+
users_update_profile
|
68
|
+
users_get_data
|
69
|
+
users_register
|
70
|
+
users_reviews
|
71
|
+
hosts_properties_list
|
72
|
+
hosts_properties_show
|
73
|
+
|
74
|
+
### Can't find the API Call you want?
|
75
|
+
|
76
|
+
Submit an issue or a pull request.
|
77
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
require "roomorama_api/version"
|
2
|
+
require "faraday"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module RoomoramaApi
|
6
|
+
|
7
|
+
class Client
|
8
|
+
|
9
|
+
def initialize(oauth_token=nil)
|
10
|
+
@oauth_token == ''
|
11
|
+
@oauth_token = oauth_token if oauth_token
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
BASE_URL = 'https://api.roomorama.com/'
|
16
|
+
API_VERSION = 'v1.0'
|
17
|
+
|
18
|
+
### Destinations
|
19
|
+
|
20
|
+
def destinations_all(options={})
|
21
|
+
api_call "destinations", options
|
22
|
+
end
|
23
|
+
|
24
|
+
#### Properties
|
25
|
+
|
26
|
+
def properties_find(options={})
|
27
|
+
api_call "rooms", options
|
28
|
+
end
|
29
|
+
|
30
|
+
def properties_get_data(room_id, options={})
|
31
|
+
api_call "rooms/" + room_id.to_s, options
|
32
|
+
end
|
33
|
+
|
34
|
+
def properties_find_similar(room_id, options={})
|
35
|
+
api_call "rooms/" + room_id.to_s + "/similar", options
|
36
|
+
end
|
37
|
+
|
38
|
+
def properties_availabilities(room_id, options={})
|
39
|
+
api_call "rooms/" + room_id.to_s + "/availabilities", options
|
40
|
+
end
|
41
|
+
|
42
|
+
def properties_price_check(room_id, options={})
|
43
|
+
api_call "inquiries/new.json", options.merge(room_id: room_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
def properties_reviews(room_id, options={})
|
47
|
+
api_call "rooms/" + room_id.to_s + "/reviews", options
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
#### Favorites
|
52
|
+
|
53
|
+
def favorites_list(options = {})
|
54
|
+
api_call "favorites", options
|
55
|
+
end
|
56
|
+
|
57
|
+
def favorites_create(options = {})
|
58
|
+
api_call "favorites", options, :post
|
59
|
+
end
|
60
|
+
|
61
|
+
def favorites_delete(id, options = {})
|
62
|
+
api_call "favorites/" + id.to_s, options, :delete
|
63
|
+
end
|
64
|
+
|
65
|
+
#### Perks
|
66
|
+
|
67
|
+
def perks_list(options={})
|
68
|
+
api_call "perks", options
|
69
|
+
end
|
70
|
+
|
71
|
+
def perks_get_data(perk_id, options={})
|
72
|
+
api_call "perks/" + perk_id.to_s, options
|
73
|
+
end
|
74
|
+
|
75
|
+
#### Users
|
76
|
+
|
77
|
+
def users_me(options={})
|
78
|
+
api_call "me", options
|
79
|
+
end
|
80
|
+
|
81
|
+
def users_update_profile(options={})
|
82
|
+
api_call "me", options, :put
|
83
|
+
end
|
84
|
+
|
85
|
+
def users_get_data(user_id, options={})
|
86
|
+
api_call "users/" + user_id.to_s, options
|
87
|
+
end
|
88
|
+
|
89
|
+
def users_register(options={})
|
90
|
+
api_call "users", options, :post
|
91
|
+
end
|
92
|
+
|
93
|
+
def users_reviews(user_id, options={})
|
94
|
+
api_call "users/" + user_id.to_s + "/reviews", options
|
95
|
+
end
|
96
|
+
|
97
|
+
#### Hosts/Properties
|
98
|
+
|
99
|
+
def hosts_properties_list(options={})
|
100
|
+
api_call "host/rooms", options
|
101
|
+
end
|
102
|
+
|
103
|
+
def hosts_properties_show(room_id, options={})
|
104
|
+
api_call "host/rooms/" + room_id.to_s, options
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def api_url
|
111
|
+
BASE_URL + API_VERSION + '/'
|
112
|
+
end
|
113
|
+
|
114
|
+
def api_call(method_name, options, verb=:get)
|
115
|
+
response = connection(method_name, options, verb)
|
116
|
+
parse_response response
|
117
|
+
end
|
118
|
+
|
119
|
+
def parse_response(response)
|
120
|
+
raise_errors response
|
121
|
+
if response.body == " "
|
122
|
+
{}
|
123
|
+
else
|
124
|
+
JSON.parse response.body
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def connection(method_name, options, verb)
|
129
|
+
|
130
|
+
conn = Faraday.new(:url => api_url) do |faraday|
|
131
|
+
faraday.request :url_encoded
|
132
|
+
#faraday.response :logger
|
133
|
+
faraday.adapter Faraday.default_adapter
|
134
|
+
faraday.headers['Authorization'] = "Bearer " + @oauth_token
|
135
|
+
end
|
136
|
+
|
137
|
+
if verb == :put
|
138
|
+
response = conn.put(method_name, options)
|
139
|
+
elsif verb == :post
|
140
|
+
response = conn.post(method_name, options)
|
141
|
+
elsif verb == :delete
|
142
|
+
response = conn.delete(method_name)
|
143
|
+
else
|
144
|
+
response = conn.get(method_name + "?" + to_query_params(options))
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
def to_query_params(options)
|
150
|
+
options.collect { |key, value| "#{key}=#{value}" }.join('&')
|
151
|
+
end
|
152
|
+
|
153
|
+
def raise_errors(response)
|
154
|
+
message = "(#{response.status})"
|
155
|
+
|
156
|
+
case response.status.to_i
|
157
|
+
when 400
|
158
|
+
raise BadRequest, message
|
159
|
+
when 401
|
160
|
+
raise Unauthorized, message
|
161
|
+
when 403
|
162
|
+
raise General, message
|
163
|
+
when 404
|
164
|
+
raise NotFound, message
|
165
|
+
when 500
|
166
|
+
raise InternalError, "An internal error is thrown."
|
167
|
+
when 502..503
|
168
|
+
raise Unavailable, message
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
class BadRequest < StandardError; end
|
176
|
+
class Unauthorized < StandardError; end
|
177
|
+
class General < StandardError; end
|
178
|
+
class Unavailable < StandardError; end
|
179
|
+
class InternalError < StandardError; end
|
180
|
+
class NotFound < StandardError; end
|
181
|
+
|
182
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/roomorama_api/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["TM Lee"]
|
6
|
+
gem.email = ["tm89lee@gmail.com"]
|
7
|
+
gem.description = %q{Ruby wrapper to call Roomorama API V1.0 at https://roomorama.com/api. For a step by step guide on getting started with Roomorama API, refer to https://roomorama.com/api/step_by_step.}
|
8
|
+
gem.summary = %q{Ruby wrapper to call Roomorama API V1.0}
|
9
|
+
gem.homepage = "https://github.com/tmlee/roomorama_api"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "roomorama_api"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = RoomoramaApi::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency('faraday', '~> 0.8')
|
19
|
+
gem.add_dependency('json', '~> 1.7.7')
|
20
|
+
gem.add_development_dependency('fakeweb', "~> 1.3.0")
|
21
|
+
gem.add_development_dependency('rake')
|
22
|
+
|
23
|
+
end
|