expedia_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee2e06abd36c267bf1ab2d0a340886915496ba49
4
+ data.tar.gz: 927f042a6792ad89c34532cfd9f7c2fa11227761
5
+ SHA512:
6
+ metadata.gz: e0e857fe39eba7e119030defacb813f96cda740c22f726108a2324293919531b7b1111c28a9943b799f7d98cf06a0193ebce4a4b13aa75a3c05749c3c213a5f8
7
+ data.tar.gz: f3e64a4040786905376f2453aa41c4d1037e3d83138061a6f8fff92ce8bf6d749901541a4dbd40429a444c8651a95b64c830fb7e9eef2fea55c7c0cefebd8eaf
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in expedia_api.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Hendrik Kleinwaechter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # Expedia Api
2
+
3
+ This is a ruby wrapper for the official Expedia.com API. Please note that the Expedia.com API is a different than the one provided by the Expedia Affiliate Network. They are different companies. If you want to use the EAN Api please use [expedia gem](https://github.com/zaidakram/expedia).
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```
11
+ gem 'expedia_api'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install expedia_api
21
+
22
+ ## Usage
23
+
24
+ Create an initializer that sets your API key:
25
+
26
+ ```
27
+ config/initializers/expedia_api.rb
28
+
29
+ ````
30
+
31
+ Set the API key:
32
+
33
+ ```
34
+ Expedia.api_key = 'my_api_key'
35
+
36
+ ```
37
+
38
+ Then when using the API create a new client object:
39
+
40
+ ```
41
+ client = ExpediaApi::Client.new
42
+ client.get_list({})
43
+
44
+
45
+ ```
46
+
47
+ The parameters you can pass to `get_list` are the following:
48
+
49
+ ```
50
+ location:
51
+ example:
52
+ 40.714269,-74.005973
53
+ description:
54
+ The composition of latitude and longitude values
55
+ identifying the center point of a hotel search radius (circle). The
56
+ latitude and longitude values are joined together with a comma (,)
57
+ character.
58
+ remark:
59
+ When this parameter is used, the RADIUS parameter is required.
60
+ radius:
61
+ example:
62
+ 10km
63
+ description:
64
+ The size of the hotel search radius around the specified latitude
65
+ and longitude, along with its associated unit of measure.
66
+ The units default to kilometers if a value isn't provided in the composition.
67
+ Valid units are KM and MI.
68
+ remark:
69
+ Radius must be less than 200.0km/124.30081 miles. The radius only
70
+ applies to the LOCATION parameter.
71
+ hotelids:
72
+ example:
73
+ 28082, 11133
74
+ description:
75
+ Comma-separated list of Hotel IDs for which to return results.
76
+ regionids:
77
+ example:
78
+ 8816, 1234
79
+ description:
80
+ Comma-separated list of Expedia Region IDs. Searching is done for
81
+ all hotels in the regions.
82
+ dates:
83
+ example:
84
+ 2011-01-19,2011-01-20
85
+ description:
86
+ Comma separated list of check- in/check-out dates for hotel stay
87
+ in an ISO 8601 Date format [YYYY-MM-DD]. If this parameter is not
88
+ included, a dateless search will be conducted which returns a
89
+ featured offer for each of the hotels found.
90
+ remark:
91
+ Max advance search window is 330 days.
92
+ language:
93
+ example:
94
+ en-US
95
+ description:
96
+ language is composed of language code and country code, connected by
97
+ "-". Must be a valid language for the Point of Sale. For example,
98
+ "fr-FR"/"fr- CA" is a valid language for France/Canada site, but
99
+ could not be "fr-US". If no language is specified, a default
100
+ language will be used.
101
+ currency:
102
+ example:
103
+ USD
104
+ description:
105
+ Value should be a standard ISO. 3 letter currency code, e.g. CAD -
106
+ Canadian dollar, USD - US dollar
107
+ If not specified for dated searches, USD will be returned.
108
+ If not specified for dateless searches, the pos native currency
109
+ will be returned.
110
+ adults:
111
+ example:
112
+ 2,1
113
+ description:
114
+ Comma-separated list that specifies the number of adults staying in
115
+ each of the rooms to be requested.
116
+ remark:
117
+ Default value will be 2 if not specified. It indicates only one room
118
+ is required and there are two adults staying in the room. Up to 8
119
+ rooms can be requested at a time.
120
+ Example:
121
+ adults=2,2,2,2 (four rooms with two adults in each room))
122
+ availonly:
123
+ example:
124
+ true
125
+ description:
126
+ return available hotels only. default: true
127
+ ```
128
+
129
+ Please refer to the official API documentation by the Expedia.com team for more parameters.
130
+
131
+ You can also setup an http proxy. Expedia whitelists IPs that are able to access their API.
132
+
133
+ ```
134
+ ExpediaApi.proxy_uri = "http://proxy_uri.com:3128"
135
+ ExpediaApi.proxy_password = "foobar"
136
+ ExpediaApi.proxy_user = "foobar"
137
+ ```
138
+
139
+
140
+ ## Development
141
+
142
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
143
+
144
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
145
+
146
+ ## Contributing
147
+
148
+ Bug reports and pull requests are welcome on.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "expedia_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'expedia_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "expedia_api"
8
+ spec.version = ExpediaApi::VERSION
9
+ spec.authors = ["Hendrik Kleinwaechter"]
10
+ spec.email = ["hendrik.kleinwaechter@gmail.com"]
11
+
12
+ spec.description = "Expediacom is a lightweight flexible Ruby SDK for the official Expedia.com API"
13
+ spec.summary = "Wrapper for the Expedia.com API"
14
+ spec.homepage = "https://github.com/hendricius/expediacom"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest"
24
+ spec.add_development_dependency "webmock"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_runtime_dependency(%q<faraday>, ["~> 0.8"])
27
+ spec.add_runtime_dependency "faraday_middleware"
28
+ spec.add_runtime_dependency "activesupport"
29
+
30
+ end
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+ require 'active_support/core_ext/hash/indifferent_access'
5
+
6
+ require "expedia_api/version"
7
+ require "expedia_api/http_service"
8
+ require "expedia_api/client"
9
+ require "expedia_api/hotel_response_list"
10
+
11
+ module ExpediaApi
12
+ class << self
13
+ attr_accessor :api_key, :proxy_uri, :proxy_password, :proxy_user
14
+ end
15
+ end
@@ -0,0 +1,100 @@
1
+ module ExpediaApi
2
+ # All method naming is done in correspondence with Expedia services and ruby conventions
3
+ class Client
4
+
5
+ # parameters:
6
+ # location:
7
+ # example:
8
+ # 40.714269,-74.005973
9
+ # description:
10
+ # The composition of latitude and longitude values
11
+ # identifying the center point of a hotel search radius (circle). The
12
+ # latitude and longitude values are joined together with a comma (,)
13
+ # character.
14
+ # remark:
15
+ # When this parameter is used, the RADIUS parameter is required.
16
+ # radius:
17
+ # example:
18
+ # 10km
19
+ # description:
20
+ # The size of the hotel search radius around the specified latitude
21
+ # and longitude, along with its associated unit of measure.
22
+ # The units default to kilometers if a value isn't provided in the composition.
23
+ # Valid units are KM and MI.
24
+ # remark:
25
+ # Radius must be less than 200.0km/124.30081 miles. The radius only
26
+ # applies to the LOCATION parameter.
27
+ # hotelids:
28
+ # example:
29
+ # 28082, 11133
30
+ # description:
31
+ # Comma-separated list of Hotel IDs for which to return results.
32
+ # regionids:
33
+ # example:
34
+ # 8816, 1234
35
+ # description:
36
+ # Comma-separated list of Expedia Region IDs. Searching is done for
37
+ # all hotels in the regions.
38
+ # dates:
39
+ # example:
40
+ # 2011-01-19,2011-01-20
41
+ # description:
42
+ # Comma separated list of check- in/check-out dates for hotel stay
43
+ # in an ISO 8601 Date format [YYYY-MM-DD]. If this parameter is not
44
+ # included, a dateless search will be conducted which returns a
45
+ # featured offer for each of the hotels found.
46
+ # remark:
47
+ # Max advance search window is 330 days.
48
+ # language:
49
+ # example:
50
+ # en-US
51
+ # description:
52
+ # language is composed of language code and country code, connected by
53
+ # "-". Must be a valid language for the Point of Sale. For example,
54
+ # "fr-FR"/"fr- CA" is a valid language for France/Canada site, but
55
+ # could not be "fr-US". If no language is specified, a default
56
+ # language will be used.
57
+ # currency:
58
+ # example:
59
+ # USD
60
+ # description:
61
+ # Value should be a standard ISO. 3 letter currency code, e.g. CAD -
62
+ # Canadian dollar, USD - US dollar
63
+ # If not specified for dated searches, USD will be returned.
64
+ # If not specified for dateless searches, the pos native currency
65
+ # will be returned.
66
+ # adults:
67
+ # example:
68
+ # 2,1
69
+ # description:
70
+ # Comma-separated list that specifies the number of adults staying in
71
+ # each of the rooms to be requested.
72
+ # remark:
73
+ # Default value will be 2 if not specified. It indicates only one room
74
+ # is required and there are two adults staying in the room. Up to 8
75
+ # rooms can be requested at a time.
76
+ #
77
+ # Example:
78
+ # adults=2,2,2,2 (four rooms with two adults in each room))
79
+ # availonly:
80
+ # example:
81
+ # true
82
+ # description:
83
+ # return available hotels only. default: true
84
+ def get_list(parameters = {})
85
+ data = request(parameters: parameters)
86
+ ExpediaApi::HotelResponseList.new(response: data)
87
+ rescue Faraday::ParsingError => e
88
+ ExpediaApi::HotelResponseList.new(exception: e)
89
+ rescue Faraday::ConnectionFailed => e
90
+ ExpediaApi::HotelResponseList.new(exception: e)
91
+ end
92
+
93
+ private
94
+
95
+ def request(request_options: {}, parameters: {})
96
+ HTTPService.perform_request(request_options: request_options, parameters: parameters)
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,65 @@
1
+ module ExpediaApi
2
+ class HotelResponseList
3
+ include Enumerable
4
+ attr_reader :response, :exception
5
+
6
+ def initialize(entries: [], response: nil, exception: nil)
7
+ @response = response
8
+ self.entries = extract_entries_from_response(response)
9
+ @exception = exception
10
+ end
11
+
12
+ def each(&block)
13
+ @entries.each(&:block)
14
+ end
15
+
16
+ def map(&block)
17
+ @entries.map(&:block)
18
+ end
19
+
20
+ def entries
21
+ @entries
22
+ end
23
+
24
+ def entries=(entries)
25
+ @entries = entries.map {|e| e.with_indifferent_access }
26
+ end
27
+
28
+ def success?
29
+ exception.nil?
30
+ end
31
+
32
+ def error?
33
+ !!exception
34
+ end
35
+
36
+ def response_body
37
+ end
38
+
39
+ def extract_entries_from_response(response)
40
+ # probably an error ocurred connecting
41
+ if response.nil?
42
+ return []
43
+ end
44
+ body = nil
45
+ begin
46
+ body = JSON.parse(response.body)
47
+ rescue JSON::ParserError => e
48
+ @exception = e
49
+ return []
50
+ end
51
+ if !body.is_a?(Hash) || body.nil?
52
+ return []
53
+ end
54
+ hotel_count = body["HotelCount"].to_i
55
+ if hotel_count == 1
56
+ [body["HotelInfoList"]["HotelInfo"]]
57
+ elsif hotel_count > 1
58
+ body["HotelInfoList"]["HotelInfo"]
59
+ else
60
+ []
61
+ end
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,62 @@
1
+ module ExpediaApi
2
+ module HTTPService
3
+
4
+ API_SERVER = 'ews.expedia.com'
5
+ API_PATH = 'wsapi/rest/hotel/v1/search'
6
+
7
+ class << self
8
+
9
+
10
+ # The address of the appropriate Expedia server.
11
+ #
12
+ # return a complete server address with protocol
13
+ def server_url
14
+ "http://#{API_SERVER}"
15
+ end
16
+
17
+ def faraday_options
18
+ options = {
19
+ url: server_url
20
+ }
21
+ if use_proxy?
22
+ options[:proxy] = proxy_options
23
+ end
24
+ options
25
+ end
26
+
27
+ def perform_request(request_options: {}, parameters: {})
28
+ args = common_parameters.merge(parameters)
29
+ # figure out our options for this request
30
+ # set up our Faraday connection
31
+ connection = Faraday.new(faraday_options) do |faraday|
32
+ faraday.adapter Faraday.default_adapter
33
+ end
34
+ connection.get(API_PATH, args)
35
+ end
36
+
37
+ def use_proxy?
38
+ !!(ExpediaApi.proxy_uri && ExpediaApi.proxy_user && ExpediaApi.proxy_password)
39
+ end
40
+
41
+ def proxy_options
42
+ {
43
+ uri: ExpediaApi.proxy_uri,
44
+ user: ExpediaApi.proxy_user,
45
+ password: ExpediaApi.proxy_password
46
+ }
47
+ end
48
+
49
+
50
+
51
+ # Common Parameters required for every Call to Expedia Server.
52
+ def common_parameters
53
+ {
54
+ :format => :json,
55
+ :key => ExpediaApi.api_key
56
+ }
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module ExpediaApi
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: expedia_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hendrik Kleinwaechter
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday_middleware
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Expediacom is a lightweight flexible Ruby SDK for the official Expedia.com
126
+ API
127
+ email:
128
+ - hendrik.kleinwaechter@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - expedia_api.gemspec
142
+ - lib/expedia_api.rb
143
+ - lib/expedia_api/client.rb
144
+ - lib/expedia_api/hotel_response_list.rb
145
+ - lib/expedia_api/http_service.rb
146
+ - lib/expedia_api/version.rb
147
+ homepage: https://github.com/hendricius/expediacom
148
+ licenses: []
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.4.5
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Wrapper for the Expedia.com API
170
+ test_files: []
171
+ has_rdoc: