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 ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ - rbx-19mode
7
+ # uncomment this line if your project needs to run something other than `rake`:
8
+ script: bundle exec rake test
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
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in roomorama_api.gemspec
4
+ gemspec
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
+ [![Build Status](https://travis-ci.org/tmlee/roomorama_api.png)](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,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'lib'
7
+ t.libs << 'test'
8
+ t.test_files = FileList['test/*_test.rb']
9
+ t.verbose = true
10
+ end
11
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module RoomoramaApi
2
+ VERSION = "0.1.0"
3
+ end
@@ -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