Time_Traveler 0.1.50 → 0.1.60
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/flight +25 -0
- data/bin/rent +2 -2
- data/bin/traffic +1 -1
- data/lib/Time_Traveler/flightInfo.rb +59 -0
- data/lib/Time_Traveler/skyscanner_api.rb +29 -0
- data/lib/Time_Traveler/version.rb +1 -1
- data/spec/skyscanner_spec.rb +25 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f518bde9a49f760ccbcb5ba41adf0063c3cd3b3
|
4
|
+
data.tar.gz: aea965240713cb65f93f929ba0f5935f3eb314e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daa2c9d5a40915c2769c4e3548b32bd1c1c3d36709a841a0cadee2b1080fd43aab40aa07983ee1edec3c0f5a32994dd4d69757056016d61a2ecf21c2d0a12d52
|
7
|
+
data.tar.gz: c27878967fdb34aff5405dda6519af6e2a85bc3eb1e8109b5ba016ec525ac8cf63f08015b5e949504d6312e81138e9f7e6d5cdf556016455906806ff367f56a0
|
data/README.md
CHANGED
@@ -23,5 +23,5 @@ Please setup your aribnb & google developer credentials by creating an app profi
|
|
23
23
|
Require Time_Traveler gem in your code: `require 'Time_Traveler'`
|
24
24
|
|
25
25
|
Supply your Time_Traveler credentials to our library in one of two ways:
|
26
|
-
- Setup environment variables: `ENV['AIRBNB_API']`
|
26
|
+
- Setup environment variables: `ENV['AIRBNB_API']` , `ENV['GOOGLE_API']` and `ENV['SKYSCANNER_API']`
|
27
27
|
|
data/bin/flight
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w(.. lib))
|
3
|
+
|
4
|
+
require 'Time_Traveler'
|
5
|
+
|
6
|
+
market = ARGV[0]
|
7
|
+
currency = ARGV[1]
|
8
|
+
locale = ARGV[2]
|
9
|
+
originPlace = ARGV[3]
|
10
|
+
destinationPlace = ARGV[4]
|
11
|
+
outboundPartialDate = ARGV[5]
|
12
|
+
unless market && currency && locale && originPlace && destinationPlace && outboundPartialDate
|
13
|
+
puts 'arguments are need for skyscanner method(market currency locale originPlace destinationPlace outboundPartialDate)'
|
14
|
+
exit(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
unless ENV['SKYSCANNER_API']
|
18
|
+
puts 'you haven\'t set your environment variable yet'
|
19
|
+
exit(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
flight = Skyscanner::FlightInfo.find(market: market, currency: currency, locale: locale, originPlace: originPlace, destinationPlace: destinationPlace, outboundPartialDate: outboundPartialDate)
|
23
|
+
flightInfo = flight.flightInfo
|
24
|
+
|
25
|
+
puts flightInfo
|
data/bin/rent
CHANGED
data/bin/traffic
CHANGED
@@ -16,7 +16,7 @@ unless ENV['GOOGLE_API']
|
|
16
16
|
exit(1)
|
17
17
|
end
|
18
18
|
|
19
|
-
traffic_load =
|
19
|
+
traffic_load = Google::TrafficInfo.find(origins: origins, destinations: destinations,mode: mode)
|
20
20
|
distance_data = traffic_load.trafficAnaly
|
21
21
|
|
22
22
|
puts distance_data
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative 'skyscanner_api'
|
2
|
+
|
3
|
+
module Skyscanner
|
4
|
+
class FlightInfo
|
5
|
+
attr_reader :flightInfo
|
6
|
+
|
7
|
+
def initialize(originData)
|
8
|
+
carrierId2Carrier = getCarrierId2Carrier(originData)
|
9
|
+
placeId2Place = getPlaceId2Place(originData)
|
10
|
+
@flightInfo = extractFlightInfo(carrierId2Carrier, placeId2Place, originData)
|
11
|
+
end
|
12
|
+
|
13
|
+
def flightInfo
|
14
|
+
@flightInfo
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.find(market:, currency:, locale:, originPlace:, destinationPlace:, outboundPartialDate:)
|
18
|
+
originData = SkyscannerApi.getOriginData(market, currency, locale, originPlace, destinationPlace, outboundPartialDate)
|
19
|
+
new(originData)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def getCarrierId2Carrier(originData)
|
24
|
+
carriers = originData["Carriers"]
|
25
|
+
carrierId2Carrier = Hash.new()
|
26
|
+
carriers.each do |carrier|
|
27
|
+
carrierId2Carrier[carrier["CarrierId"]] = carrier["Name"]
|
28
|
+
end
|
29
|
+
carrierId2Carrier
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def getPlaceId2Place(originData)
|
34
|
+
places = originData["Places"]
|
35
|
+
placeId2Place = Hash.new()
|
36
|
+
places.each do |place|
|
37
|
+
if place["Type"] == "Station"
|
38
|
+
placeId2Place[place["PlaceId"]] = place["Name"] #+","+place["CountryName"]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
placeId2Place
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def extractFlightInfo(carrierId2Carrier, placeId2Place, originData)
|
46
|
+
quotes = originData["Quotes"]
|
47
|
+
quotes.each do |quote|
|
48
|
+
if(quote["OutboundLeg"]["CarrierIds"].empty? == false)
|
49
|
+
for i in 0..quote["OutboundLeg"]["CarrierIds"].length
|
50
|
+
quote["OutboundLeg"]["CarrierIds"][i] = carrierId2Carrier[quote["OutboundLeg"]["CarrierIds"][i]]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
quote["OutboundLeg"]["OriginId"] = placeId2Place[quote["OutboundLeg"]["OriginId"]]
|
54
|
+
quote["OutboundLeg"]["DestinationId"] = placeId2Place[quote["OutboundLeg"]["DestinationId"]]
|
55
|
+
end
|
56
|
+
quotes
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'http'
|
2
|
+
|
3
|
+
module Skyscanner
|
4
|
+
class SkyscannerApi
|
5
|
+
Skyscanner_URL = 'http://partners.api.skyscanner.net/apiservices/browseroutes/'
|
6
|
+
API_VER = 'v1.0'
|
7
|
+
Skyscanner_API_URL = URI.join(Skyscanner_URL, "#{API_VER}/")
|
8
|
+
|
9
|
+
def self.config=(credentials)
|
10
|
+
@config ? @config.update(credentials) : @config = credentials
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.config
|
14
|
+
return @config if @config
|
15
|
+
@config = { skyscanner_id: ENV['SKYSCANNER_API'] }
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.getOriginData(market, currency, locale, originPlace, destinationPlace, outboundPartialDate)
|
19
|
+
url = URI.join(Skyscanner_API_URL, market+"/", currency+"/", locale+"/", originPlace+"/", destinationPlace+"/", outboundPartialDate);
|
20
|
+
skyscanner_response = HTTP.get(url,
|
21
|
+
params: {
|
22
|
+
apiKey: config[:skyscanner_id]
|
23
|
+
})
|
24
|
+
|
25
|
+
originData = JSON.load(skyscanner_response.body.to_s)
|
26
|
+
originData
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe 'Load specifications' do
|
4
|
+
VCR.configure do |c|
|
5
|
+
c.cassette_library_dir = CASSETTES_FOLDER
|
6
|
+
c.hook_into :webmock
|
7
|
+
|
8
|
+
c.filter_sensitive_data('<SKYSCANNER_ID>') {ENV['SKYSCANNER_API'] }
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
VCR.insert_cassette CASSETTE_FILE_SKYSCANNER, record: :new_episodes
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
VCR.eject_cassette
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should be able to get the data from Skyscanner' do
|
20
|
+
skyscanner_load = Skyscanner::FlightInfo.find(market: 'TW', currency: 'TWD', locale: 'en-GB', originPlace: 'TW', destinationPlace: 'UK', outboundPartialDate: '2016-11-20')
|
21
|
+
flightInfo = skyscanner_load.flightInfo
|
22
|
+
flightInfo.length.must_be :>,0
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Time_Traveler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.60
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yvonne Shih
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-11-
|
13
|
+
date: 2016-11-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: http
|
@@ -158,6 +158,7 @@ email:
|
|
158
158
|
- q2221252@gmail.com
|
159
159
|
- wtlin0711@gmail.com
|
160
160
|
executables:
|
161
|
+
- flight
|
161
162
|
- rent
|
162
163
|
- traffic
|
163
164
|
extensions: []
|
@@ -171,17 +172,21 @@ files:
|
|
171
172
|
- README.md
|
172
173
|
- Rakefile
|
173
174
|
- Time_Traveler.gemspec
|
175
|
+
- bin/flight
|
174
176
|
- bin/rent
|
175
177
|
- bin/traffic
|
176
178
|
- lib/Time_Traveler.rb
|
177
179
|
- lib/Time_Traveler/airbnb_api.rb
|
180
|
+
- lib/Time_Traveler/flightInfo.rb
|
178
181
|
- lib/Time_Traveler/google_api.rb
|
179
182
|
- lib/Time_Traveler/rentInfo.rb
|
183
|
+
- lib/Time_Traveler/skyscanner_api.rb
|
180
184
|
- lib/Time_Traveler/trafficinfo.rb
|
181
185
|
- lib/Time_Traveler/version.rb
|
182
186
|
- spec/.load_spec.rb.swp
|
183
187
|
- spec/airbnbapi_spec.rb
|
184
188
|
- spec/googledistanceapi_spec.rb
|
189
|
+
- spec/skyscanner_spec.rb
|
185
190
|
- spec/spec_helper.rb
|
186
191
|
homepage: https://github.com/Mew-Traveler/Time_Traveler
|
187
192
|
licenses:
|
@@ -203,11 +208,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
208
|
version: '0'
|
204
209
|
requirements: []
|
205
210
|
rubyforge_project:
|
206
|
-
rubygems_version: 2.
|
211
|
+
rubygems_version: 2.6.8
|
207
212
|
signing_key:
|
208
213
|
specification_version: 4
|
209
214
|
summary: Gets room content from Airbnb
|
210
215
|
test_files:
|
211
216
|
- spec/airbnbapi_spec.rb
|
212
217
|
- spec/googledistanceapi_spec.rb
|
218
|
+
- spec/skyscanner_spec.rb
|
213
219
|
- spec/spec_helper.rb
|