wego 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cf46dc4b0a7a44dd041075de9c69e6aaad65eb50
4
+ data.tar.gz: aca751f9789113cfb6e792a4d9d309cf7b7c2cf0
5
+ SHA512:
6
+ metadata.gz: 260d8b61becff250c8faa972ebfaccbc6fc8d64183c5bde6c65b0c27581243c93ff78de9d65db76db1f04f59d067054066507b3504c8e4347ce577f310322f8b
7
+ data.tar.gz: 01e2aa77e129eb031a34b768f1a832bd198bb75757bf6e8c9c2bdcf1c648c53414bd6ab3a9e9e92ee6a5a2c94dcdaab6ee1fc82ed55673beb3875fc161f078cd
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /.pryrc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
@@ -0,0 +1,4 @@
1
+ Wego.configure do |config|
2
+ config.api_key = WEGO_API_KEY
3
+ config.api_code = WEGO_API_CODE
4
+ end
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ - 2.2.0
6
+ - 2.1.9
7
+ before_install: gem install bundler -v 1.12.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wego.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Abu Nashir
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,208 @@
1
+ # Wego Hotels API
2
+
3
+ [![Build
4
+ Status](https://travis-ci.org/abunashir/wego.svg?branch=master)](https://travis-ci.org/abunashir/wego)
5
+ [![Code
6
+ Climate](https://codeclimate.com/github/abunashir/wego/badges/gpa.svg)](https://codeclimate.com/github/abunashir/wego)
7
+
8
+ The Wego Hotels API allows developers to interact with the Hotels product of
9
+ Wego.com programmatically via HTTP requests. This is the interface to the Wego
10
+ Hotels API and responses are parsed to `OpenStruct` object.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem "wego", github: "abunashir/wego"
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```sh
23
+ $ bundle install
24
+ ```
25
+
26
+ ## Configure
27
+
28
+ Once you are approved and you got your API key from Wego.com, then you can add
29
+ an initializer to set your API keys
30
+
31
+ ```ruby
32
+ Wego.configure do |config|
33
+ config.api_key = "WEGO_API_KEY"
34
+ config.api_code = "WEGO_TS_CODE"
35
+ end
36
+ ```
37
+
38
+ ## Usages
39
+
40
+ ### Locations
41
+
42
+ Use this to map user location queries to Wego location IDs. E.g. you will
43
+ probably provide your users with a text field for entering the location when
44
+ searching for hotels. The Locations API allows you to lookup text queries like
45
+ "sydney" to get a list of matching locations and their IDs.
46
+
47
+ ```ruby
48
+ Wego::Location.find(
49
+ "sydney", lang: "en", page: 1, per_page: 10
50
+ )
51
+ ```
52
+
53
+ Complete list of options: [Wego Location API].
54
+
55
+ ### Search
56
+
57
+ To perform a real-time search on Wego's partners' sites for rates in a given
58
+ location and date range, you need to pass the search terms with the user's ip.
59
+ For example: create new search for hotels in Sydney (location ID 7046)
60
+
61
+ ```ruby
62
+ Wego::Search.create(
63
+ location_id: "7046",
64
+ rooms: 1,
65
+ guests: 2,
66
+ check_in: "2016-07-15",
67
+ check_out: "2016-07-20",
68
+ user_ip: end_user_ip
69
+ )
70
+ ```
71
+
72
+ Complete list of parameters: [Wego Search API].
73
+
74
+ ### Results
75
+
76
+ Once user created a new search and they have the `search_id` then they can
77
+ retrieve that search results very easily. Wego suggests to wait at least
78
+ 10 seconds after starting the search
79
+
80
+ ```ruby
81
+ Wego::Result.find(
82
+ search_id,
83
+ lang: "en",
84
+ page: 1,
85
+ per_page: 20,
86
+ order: "asc",
87
+ sort: "popularity",
88
+ currency_code: "USD"
89
+ )
90
+ ```
91
+
92
+ Complete list of options: [Wego Search Results API].
93
+
94
+ ### Hotel Details
95
+
96
+ Get details of a hotel, like its address, amenities, photos.
97
+
98
+ ```ruby
99
+ Wego::Result.find(
100
+ search_id, hotel_id: hotel_id, lang: "en", currency: "USD"
101
+ )
102
+ ```
103
+
104
+ Complete list of parameters: [Wego Search Result API].
105
+
106
+ ### Booking
107
+
108
+ The Wego API doesn't support the shopping cart or e-commerce process either, but
109
+ using the API you can take users to continue the booking process at one of
110
+ their partners' sites.
111
+
112
+ ```ruby
113
+ Wego::Booking.url_for(
114
+ search_id, hotel_id: hotel_id, room_rate_id: room_rate_id
115
+ )
116
+ ```
117
+
118
+ ## Development
119
+
120
+ We are following Sandi Metz's Rules for this gem, you can read the
121
+ [description of the rules here]
122
+ (http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers). All new code should follow these rules. If you make changes in a pre-existing
123
+ file that violates these rules you should fix the violations as part of
124
+ your contribution.
125
+
126
+ ### Setup
127
+
128
+ * Clone the repository.
129
+
130
+ ```sh
131
+ git clone https://github.com/abunashir/wego.git
132
+ ```
133
+
134
+ * Setup your environment.
135
+
136
+ ```sh
137
+ bin/setup
138
+ ```
139
+
140
+ * Run the test suite
141
+
142
+ ```sh
143
+ bin/rake
144
+ ```
145
+
146
+ ### PlayBox
147
+
148
+ * Setup API keys.
149
+
150
+ ```sh
151
+ cp .sample.pryrc .pryrc
152
+ vim .pryrc
153
+ ```
154
+
155
+ * Start your console.
156
+
157
+ ```sh
158
+ bin/console
159
+ ```
160
+
161
+ * Start playing with it.
162
+
163
+ ```sh
164
+ Wego::Location.find "sydney"
165
+ ```
166
+
167
+ ## Testing
168
+
169
+ ### RSpec
170
+
171
+ This gem provides an easier way to test Wego API Responses. Simply include the
172
+ following line in your `spec_helper` and you should have access to all of the
173
+ test helpers.
174
+
175
+ ```ruby
176
+ require "wego/rspec"
177
+ ```
178
+
179
+ ## Contributing
180
+
181
+ First, thank you for contributing! We love pull requests from everyone. By
182
+ participating in this project, you hereby grant the right to grant or transfer
183
+ an unlimited number of non exclusive licenses or sub-licenses to third parties,
184
+ under the copyright covering the contribution to use the contribution by all
185
+ means.
186
+
187
+ Here are a few technical guidelines to follow:
188
+
189
+ 1. Open an [issue][issues] to discuss a new feature.
190
+ 1. Write tests to support your new feature.
191
+ 1. Make sure the entire test suite passes locally and on CI.
192
+ 1. Open a Pull Request.
193
+ 1. [Squash your commits][squash] after receiving feedback.
194
+ 1. Party!
195
+
196
+ [issues]: https://github.com/abunashir/wego/issues
197
+ [squash]: https://github.com/thoughtbot/guides/tree/master/protocol/git#write-a-feature
198
+
199
+
200
+ ## License
201
+
202
+ The gem is available as open source under the terms of
203
+ the [MIT License](http://opensource.org/licenses/MIT).
204
+
205
+ [Wego Location API]: http://support.wan.travel/hc/en-us/articles/200713154#api_locations_search
206
+ [Wego Search API]: http://support.wan.travel/hc/en-us/articles/200713154#api_search_new
207
+ [Wego Search Results API]: http://support.wan.travel/hc/en-us/articles/200713154#api_search_search_id
208
+ [Wego Search Result API]: http://support.wan.travel/hc/en-us/articles/200713154#api_show_hotel_id
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wego"
5
+ require "pry"
6
+
7
+ Pry.start
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,9 @@
1
+ require "wego/version"
2
+ require "wego/client"
3
+ require "wego/location"
4
+ require "wego/search"
5
+ require "wego/result"
6
+ require "wego/booking"
7
+
8
+ module Wego
9
+ end
@@ -0,0 +1,11 @@
1
+ module Wego
2
+ class Booking
3
+ def self.url_for(search_id, hotel_id:, room_rate_id:)
4
+ Wego::Client.new(
5
+ "search/redirect/#{search_id}",
6
+ hotel_id: hotel_id,
7
+ room_rate_id: room_rate_id
8
+ ).url
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ require "rest-client"
2
+ require "wego/response"
3
+ require "wego/configuration"
4
+
5
+ module Wego
6
+ class Client
7
+ attr_reader :end_point, :attributes
8
+
9
+ def initialize(end_point, attributes = {})
10
+ @end_point = end_point
11
+ @attributes = attributes
12
+ end
13
+
14
+ def get
15
+ RestClient.get api_path, params: api_params
16
+ end
17
+
18
+ def url
19
+ params = api_params.map { |key, value| "#{key}=#{value}" }.join("&")
20
+ [api_path, params].join("?")
21
+ end
22
+
23
+ private
24
+
25
+ def api_path
26
+ [Wego.configuration.api_host, end_point].join("/")
27
+ end
28
+
29
+ def api_params
30
+ Wego.configuration.api_keys.merge attributes
31
+ end
32
+ end
33
+
34
+ def self.get_resource(end_point, api_params = {})
35
+ Wego::Response.parse_json(
36
+ Client.new(end_point, api_params).get
37
+ )
38
+ rescue RestClient::ResourceNotFound, RestClient::BadRequest
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ module Wego
2
+ class Configuration
3
+ attr_accessor :api_host
4
+ attr_accessor :api_key
5
+ attr_accessor :api_code
6
+
7
+ def initialize
8
+ @api_host = "http://api.wego.com/hotels/api"
9
+ end
10
+
11
+ def api_keys
12
+ { key: api_key, ts_code: api_code }
13
+ end
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def self.configuration=(config)
21
+ @configuration = config
22
+ end
23
+
24
+ def self.configure
25
+ yield configuration
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ module Wego
2
+ class Location
3
+ def self.find(location, options = {})
4
+ Wego.get_resource(
5
+ "locations/search",
6
+ options.merge(q: location)
7
+ )
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module Wego
2
+ class Response
3
+ def self.parse_json(response)
4
+ JSON.parse(response, object_class: Wego::OpenStruct)
5
+ end
6
+ end
7
+
8
+ class OpenStruct < ::OpenStruct
9
+ alias :read_attribute_for_serialization :send
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Wego
2
+ class Result
3
+ def self.find(search_id, options = {})
4
+ Wego.get_resource "search/#{search_id}", options
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path("../../../spec/support/fake_wego_api", __FILE__)
2
+
3
+ RSpec.configure do |config|
4
+ config.include FakeWegoApi
5
+ end
@@ -0,0 +1,16 @@
1
+ require "wego/result"
2
+
3
+ module Wego
4
+ class Search
5
+ def self.create(search_terms)
6
+ search_terms[:check_in] = Wego.format_date(search_terms[:check_in])
7
+ search_terms[:check_out] = Wego.format_date(search_terms[:check_out])
8
+
9
+ Wego.get_resource "search/new", search_terms
10
+ end
11
+ end
12
+
13
+ def self.format_date(date)
14
+ DateTime.parse(date).strftime("%Y-%m-%d")
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Wego
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "wego/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "wego"
7
+ spec.version = Wego::VERSION
8
+ spec.authors = ["Abu Nashir"]
9
+ spec.email = ["abunashir@gmail.com"]
10
+
11
+ spec.summary = "Wego API wrapper in Ruby"
12
+ spec.description = %q{This Ruby interface to the Wego Hotels API}
13
+ spec.homepage = "http://www.wan.travel/api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ["lib"]
18
+ spec.test_files = `git ls-files -- {spec}/*`.split("\n")
19
+
20
+ spec.add_dependency "rest-client", "~> 1.8"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "webmock", "~> 2.0"
26
+ spec.add_development_dependency "pry", "~> 0.10.3"
27
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wego
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Abu Nashir
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.10.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.10.3
97
+ description: This Ruby interface to the Wego Hotels API
98
+ email:
99
+ - abunashir@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".sample.pryrc"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/rake
113
+ - bin/setup
114
+ - lib/wego.rb
115
+ - lib/wego/booking.rb
116
+ - lib/wego/client.rb
117
+ - lib/wego/configuration.rb
118
+ - lib/wego/location.rb
119
+ - lib/wego/response.rb
120
+ - lib/wego/result.rb
121
+ - lib/wego/rspec.rb
122
+ - lib/wego/search.rb
123
+ - lib/wego/version.rb
124
+ - wego.gemspec
125
+ homepage: http://www.wan.travel/api
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.6.4
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Wego API wrapper in Ruby
149
+ test_files: []