skyscanner 0.1

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: afa3e386540526da0ca3cc32b865324308da8281
4
+ data.tar.gz: 5fd2a877d72e668e0750eb401cb1cd8717841bcc
5
+ SHA512:
6
+ metadata.gz: d19e4b0748824b1157964e7c7407e47280459478b8a4546d87072d3a1c3fc2486ff53192e4f1f34ca5c7eef7f99fd7f159ca42edb913c81dbd27f201cc2413be
7
+ data.tar.gz: d5251bc5c84755f3b5064da6eaaad76dae1f2bfc7195a6f47e006b363570ccd324ee6b48250057af91797d451b77731ac03d2e481a85d9c7fb12a8f98f6bf831
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2012 Dan Matthews / Ticket Evolution (http://ticketevolution.com)
4
+ Copyright (c) 2013 Alex Beregszaszi
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ the Software, and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ skyscanner
2
+ ==========
3
+
4
+ A Ruby wrapper for the Skyscanner API.
5
+
6
+
7
+ Installation
8
+ ------------
9
+
10
+ **With Bundler**
11
+
12
+ In your Gemfile, add the following line
13
+
14
+ gem 'skyscanner', :require => 'skyscanner'
15
+
16
+ **Without Bundler**
17
+
18
+ gem install skyscanner
19
+
20
+ Usage
21
+ -----
22
+
23
+ At the moment the interface is very simple and it only supports the Browse Cache Service API. Feel free to submit pull requests for more features.
24
+
25
+ Each of the four endpoints can be accessed with a class method reflecting the endpoint's name.
26
+
27
+ Skyscanner::Connection.browse_dates
28
+ Skyscanner::Connection.browse_grid
29
+ Skyscanner::Connection.browse_routes
30
+ Skyscanner::Connection.browse_quotes
31
+ Skyscanner::Connection.site_redirect
32
+
33
+ Options can be passed in a hash to these methods and they will be included in the request.
34
+
35
+ ## Example from: http://www.skyscanneraffiliate.net/portal/en-GB/US/BrowseCache/BrowseQuotes
36
+ Skyscanner::Conneciton.browse_quotes({ :country => "GB", :curency => "GBP", :locale => "en-GB", :originPlace => "UK", :destinationPlace => "anywhere", :outboundPartialDate => "anytime", :inboundPartialDate => "anytime" })
37
+ # => GET http://partners.api.skyscanner.net/apiservices/browsequotes/v1.0/GB/GBP/en-GB/UK/anywhere/anytime/anytime?apiKey=prtl6749387986743898559646983194
38
+
39
+ There are a number of class level options that can be overridden.
40
+
41
+ Skyscanner::Connection.adapter # the Faraday adapter to use (default: :net_http)
42
+ Skyscanner::Connection.logger # a Logger object for logging requests (default: nil)
43
+ Skyscanner::Connection.protocol # http or https (default: :http)
44
+ Skyscanner::Connection.response_format # ruby, json, jsonp or xml (default: ruby)
45
+ Skyscanner::Connection.url # partners.api.skyscanner.net/apiservices/
46
+ Skyscanner::Connection.version # v.10
47
+
48
+ Example:
49
+
50
+ Skyscanner::Connection.protocol
51
+ # => :http
52
+ Skyscanner::Connection.protocol = :https
53
+ # => :https
54
+
55
+ These options can also be overridden during instantiation of a Skyscanner::Connection
56
+
57
+ @secure = Skyscanner::Connection.new({:protocol => :https})
58
+
59
+
60
+ Copyright
61
+ ---------
62
+
63
+ Made for Soundtravel (http://soundtravel.co/).
64
+
65
+ Copyright (c) 2013 Alex Beregszaszi. See LICENSE for details.
66
+
67
+ Based on the SeatGeek Ruby API (https://github.com/bluefocus/seatgeek/) which is:
68
+ Copyright (c) 2012 Dan Matthews / Ticket Evolution ([http://ticketevolution.com](http://ticketevolution.com))
@@ -0,0 +1,214 @@
1
+ require 'faraday'
2
+ require 'multi_json'
3
+
4
+ module Skyscanner
5
+ class Connection
6
+ class << self; self; end.class_eval do
7
+ def adapter; @@adapter ||= :net_http; end
8
+ def adapter=(input); @@adapter = input; end
9
+
10
+ def site_redirect(*args); new.site_redirect(*args); end
11
+ def browse_quotes(*args); new.browse_quotes(*args); end
12
+ def browse_grid(*args); new.browse_grid(*args); end
13
+ def browse_routes(*args); new.browse_routes(*args); end
14
+ def browse_dates(*args); new.browse_dates(*args); end
15
+
16
+ def events(*args); new.events(*args); end
17
+
18
+ def logger; @@logger ||= nil; end
19
+ def logger=(input); @@logger = input; end
20
+
21
+ def options
22
+ {
23
+ :adapter => adapter,
24
+ :logger => logger,
25
+ :protocol => protocol,
26
+ :response_format => response_format,
27
+ :url => url,
28
+ :version => version,
29
+ :api_key => apikey
30
+ }
31
+ end
32
+
33
+ def performers(*args); new.performers(*args); end
34
+
35
+ def protocol; @@protocol ||= :http; end
36
+ def protocol=(input); @@protocol = input; end
37
+
38
+ def response_format; @@response_format ||= :ruby; end
39
+ def response_format=(input); @@response_format = input; end
40
+
41
+ def taxonomies(*args); new.taxonomies(*args); end
42
+
43
+ def url; @@url ||= "partners.api.skyscanner.net/apiservices"; end
44
+ def url=(input); @@url = input; end
45
+
46
+ def venues(*args); new.venues(*args); end
47
+
48
+ def version; @@version ||= "v1.0"; end
49
+ def version=(input); @@version = input; end
50
+
51
+ def apikey; @@api_key end
52
+ def apikey=(input); @@api_key = input; end
53
+ end
54
+
55
+ def initialize(options = {})
56
+ @options = self.class.options.merge({}.tap do |opts|
57
+ options.each do |k, v|
58
+ opts[k.to_sym] = v
59
+ end
60
+ end)
61
+ end
62
+
63
+ def handle_response(response)
64
+ if response_format == :ruby and response.status == 200
65
+ MultiJson.decode(response.body)
66
+ else
67
+ { :status => response.status, :body => response.body }
68
+ end
69
+ end
70
+
71
+ # Ruby 1.8.7 / ree compatibility
72
+ def id
73
+ @options[:id]
74
+ end
75
+
76
+ def request(url, segments, params)
77
+ handle_response(Faraday.new(*builder(url, segments_to_path(segments, params), params.clone)) do |build|
78
+ build.adapter adapter
79
+ # build.use Faraday::Response::VerboseLogger, logger unless logger.nil?
80
+ end.get)
81
+ end
82
+
83
+ def response_format
84
+ @options[:response_format].to_sym
85
+ end
86
+
87
+ def api_key
88
+ @options[:api_key]
89
+ end
90
+
91
+ def segments_to_path(segments, params)
92
+ out = []
93
+ segments.each do |k, v|
94
+ value = params[k]
95
+ if value then
96
+ out << value
97
+ elsif v then
98
+ raise ArgumentError.new("Mandatory parameter (#{k}) missing")
99
+ end
100
+ end
101
+ out.join('/')
102
+ end
103
+
104
+ def site_redirect(params = {})
105
+ segments = {
106
+ :country => true,
107
+ :currency => true,
108
+ :locale => true,
109
+ :originPlace => true,
110
+ :destinationPlace => true,
111
+ :outboundPartialDate => true,
112
+ :inboundPartialDate => false,
113
+ :associateID => false,
114
+ :utm_source => false,
115
+ :utm_medium => false,
116
+ :utm_name => false
117
+ }
118
+
119
+ # request('skyscannerredirect', segments, params)
120
+ # Life isn't that easy - in this case the constructed URL is what we return
121
+ ret = builder("skyscannerredirect", segments_to_path(segments, params), params.clone)
122
+ "#{ret[0]}?apiKey=#{api_key}"
123
+ end
124
+
125
+ def browse_quotes(params = {})
126
+ segments = {
127
+ :country => true,
128
+ :currency => true,
129
+ :locale => true,
130
+ :originPlace => true,
131
+ :destinationPlace => true,
132
+ :outboundPartialDate => true,
133
+ :inboundPartialDate => false
134
+ }
135
+ request('browsequotes', segments, params)
136
+ end
137
+
138
+ def browse_grid(params = {})
139
+ segments = {
140
+ :country => true,
141
+ :currency => true,
142
+ :locale => true,
143
+ :originPlace => true,
144
+ :destinationPlace => true,
145
+ :outboundPartialDate => true,
146
+ :inboundPartialDate => false
147
+ }
148
+ request('browsegrid', segments, params)
149
+ end
150
+
151
+ def browse_routes(params = {})
152
+ segments = {
153
+ :country => true,
154
+ :currency => true,
155
+ :locale => true,
156
+ :originPlace => true,
157
+ :destinationPlace => true,
158
+ :outboundPartialDate => true,
159
+ :inboundPartialDate => false
160
+ }
161
+ request('browseroutes', segments, params)
162
+ end
163
+
164
+ def browse_dates(params = {})
165
+ segments = {
166
+ :country => true,
167
+ :currency => true,
168
+ :locale => true,
169
+ :originPlace => true,
170
+ :destinationPlace => true,
171
+ :outboundPartialDate => true,
172
+ :inboundPartialDate => false
173
+ }
174
+ request('browsedates', segments, params)
175
+ end
176
+
177
+ def endpoint_uri(method)
178
+ "#{protocol}://#{url}/#{method}/#{version}/"
179
+ end
180
+
181
+ def uri(path)
182
+ "#{protocol}://#{url}/#{path}/#{version}"
183
+ end
184
+
185
+ private
186
+
187
+ def method_missing(method, *params)
188
+ @options.keys.include?(method.to_sym) && params.first.nil? ? @options[method.to_sym] : super
189
+ end
190
+
191
+ def builder(uri_segment, path, params)
192
+ return [
193
+ [].tap do |part|
194
+ part << endpoint_uri(uri_segment)
195
+ part << path
196
+ part << "/#{params.delete(:id)}" unless params[:id].nil?
197
+ end.join,
198
+ {
199
+ :params => custom_options.merge(([:jsonp, :xml].include?(response_format) ? \
200
+ params.merge(:format => response_format) : params)).merge(:apiKey => api_key)
201
+ }
202
+ ]
203
+ end
204
+
205
+ def custom_options
206
+ @custom_options ||= {}.tap do |opts|
207
+ ignore = self.class.options.keys
208
+ @options.each do |k, v|
209
+ opts[k] = v unless ignore.include?(k)
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "skyscanner"
5
+ gem.version = "0.1"
6
+ gem.authors = ["Alex Beregszaszi"]
7
+ gem.email = ["alex@rtfs.hu"]
8
+ gem.description = "A Ruby wrapper for the Skyscanner API. See http://www.skyscanneraffiliate.net/portal/en-GB/US/api/overview for the official documentation."
9
+ gem.summary = "A Ruby wrapper for the Skyscanner API."
10
+ gem.homepage = "http://github.com/axic/skyscanner"
11
+ gem.license = "MIT"
12
+
13
+ gem.add_dependency "faraday"
14
+ gem.add_dependency "multi_json"
15
+
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.extra_rdoc_files = [
22
+ "LICENSE",
23
+ "README.md"
24
+ ]
25
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: skyscanner
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Alex Beregszaszi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A Ruby wrapper for the Skyscanner API. See http://www.skyscanneraffiliate.net/portal/en-GB/US/api/overview
42
+ for the official documentation.
43
+ email:
44
+ - alex@rtfs.hu
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files:
48
+ - LICENSE
49
+ - README.md
50
+ files:
51
+ - .gitignore
52
+ - LICENSE
53
+ - README.md
54
+ - lib/skyscanner.rb
55
+ - skyscanner.gemspec
56
+ homepage: http://github.com/axic/skyscanner
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.0.3
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A Ruby wrapper for the Skyscanner API.
80
+ test_files: []