Time_Traveler 0.1.60 → 0.1.70
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/.gitignore +1 -0
- data/Gemfile +1 -12
- data/Rakefile +10 -10
- data/Time_Traveler.gemspec +0 -1
- data/apiformat.txt +37 -0
- data/bin/googleplace +19 -0
- data/bin/traffic +2 -2
- data/lib/Time_Traveler/flightInfo.rb +6 -6
- data/lib/Time_Traveler/google_api.rb +0 -4
- data/lib/Time_Traveler/google_api_inter.rb +38 -0
- data/lib/Time_Traveler/internal.rb +38 -0
- data/lib/Time_Traveler/skyscanner_api.rb +3 -5
- data/lib/Time_Traveler/trafficinfo.rb +16 -2
- data/lib/Time_Traveler/version.rb +1 -1
- data/spec/airbnbapi_spec.rb +0 -1
- data/spec/googledistanceapi_spec.rb +11 -1
- data/spec/spec_helper.rb +3 -3
- metadata +7 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c1761c1c6e755c2091fdc47f463d1c35ac169cb2
|
|
4
|
+
data.tar.gz: 11aa9f46271524f881645a3a77e569f96e81d1d4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa15a0f3b2842f537429944e3bafd5ed889288ed99955ae9482a2d6f5daca74ac295930af70714cb197a9a3ab2bfb884d5f96135f9e6d64e980a069011d72b98
|
|
7
|
+
data.tar.gz: ba9b75ee3bcf2cd6ff63fa2c8787c8c7808817fd44b57f8fecc23614830f3b6f5c03f46e99013329d8cbc3724c58f8e3a479b7b4cb1012f66b958043441b06ee
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
|
@@ -3,18 +3,18 @@ require 'rake/testtask'
|
|
|
3
3
|
|
|
4
4
|
task default: :spec
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
# end
|
|
10
|
-
|
|
11
|
-
desc 'run tests'
|
|
12
|
-
task :spec do
|
|
13
|
-
sh 'ruby spec/airbnbapi_spec.rb'
|
|
14
|
-
sh 'ruby spec/googledistanceapi_spec.rb'
|
|
15
|
-
|
|
6
|
+
desc 'Run specs'
|
|
7
|
+
Rake::TestTask.new(name=:spec) do |t|
|
|
8
|
+
t.pattern = 'spec/*_spec.rb'
|
|
16
9
|
end
|
|
17
10
|
|
|
11
|
+
# desc 'run tests'
|
|
12
|
+
# task :spec do
|
|
13
|
+
# sh 'ruby spec/airbnbapi_spec.rb'
|
|
14
|
+
# sh 'ruby spec/googledistanceapi_spec.rb'
|
|
15
|
+
#
|
|
16
|
+
# end
|
|
17
|
+
|
|
18
18
|
desc 'delete cassette fixtures'
|
|
19
19
|
task :wipe do
|
|
20
20
|
sh 'rm spec/fixtures/cassettes/*.yml' do |ok, _|
|
data/Time_Traveler.gemspec
CHANGED
|
@@ -25,7 +25,6 @@ Gem::Specification.new do |s|
|
|
|
25
25
|
s.add_development_dependency 'flog', '~> 4.4'
|
|
26
26
|
s.add_development_dependency 'flay', '~> 2.8'
|
|
27
27
|
s.add_development_dependency 'rubocop', '~> 0.42'
|
|
28
|
-
|
|
29
28
|
s.homepage = 'https://github.com/Mew-Traveler/Time_Traveler'
|
|
30
29
|
s.license = 'MIT'
|
|
31
30
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/apiformat.txt
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*google traffic
|
|
2
|
+
get duration and distance with location and mode*/
|
|
3
|
+
1. URL:
|
|
4
|
+
[GET] https://maps.googleapis.com/maps/api/distancematrix/json?origins={originlocate}&destinations={destlocate}&mode={trafficmode}&key={apikey}
|
|
5
|
+
2. header:
|
|
6
|
+
3. response:
|
|
7
|
+
{
|
|
8
|
+
"destination_addresses": [
|
|
9
|
+
"Hsinchu County, Taiwan"
|
|
10
|
+
],
|
|
11
|
+
"origin_addresses": [
|
|
12
|
+
"Taipei City, Taiwan"
|
|
13
|
+
],
|
|
14
|
+
"rows": [
|
|
15
|
+
{
|
|
16
|
+
"elements": [
|
|
17
|
+
{
|
|
18
|
+
"distance": {
|
|
19
|
+
"text": "80.4 km",
|
|
20
|
+
"value": 80393
|
|
21
|
+
},
|
|
22
|
+
"duration": {
|
|
23
|
+
"text": "2 hours 3 mins",
|
|
24
|
+
"value": 7370
|
|
25
|
+
},
|
|
26
|
+
"fare": {
|
|
27
|
+
"currency": "TWD",
|
|
28
|
+
"text": "NT$131.00",
|
|
29
|
+
"value": 131
|
|
30
|
+
},
|
|
31
|
+
"status": "OK"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"status": "OK"
|
|
37
|
+
}
|
data/bin/googleplace
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w(.. lib))
|
|
3
|
+
|
|
4
|
+
require 'Time_Traveler'
|
|
5
|
+
|
|
6
|
+
query = ARGV[0]
|
|
7
|
+
unless query
|
|
8
|
+
puts 'at least one argument is need for query method'
|
|
9
|
+
exit(1)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
unless ENV['GOOGLE_API']
|
|
13
|
+
puts 'you haven\'t set your environment variable yet'
|
|
14
|
+
exit(1)
|
|
15
|
+
end
|
|
16
|
+
google_rating = Google::GooglePlaceRating.find(query: query)
|
|
17
|
+
rating = google_rating.return_rating
|
|
18
|
+
|
|
19
|
+
puts rating
|
data/bin/traffic
CHANGED
|
@@ -6,7 +6,7 @@ require 'Time_Traveler'
|
|
|
6
6
|
origins = ARGV[0]
|
|
7
7
|
destinations = ARGV[1]
|
|
8
8
|
mode = ARGV[2]
|
|
9
|
-
unless
|
|
9
|
+
unless origins && destinations && mode
|
|
10
10
|
puts 'two arguments are need for origin, destination and traffic method'
|
|
11
11
|
exit(1)
|
|
12
12
|
end
|
|
@@ -19,4 +19,4 @@ end
|
|
|
19
19
|
traffic_load = Google::TrafficInfo.find(origins: origins, destinations: destinations,mode: mode)
|
|
20
20
|
distance_data = traffic_load.trafficAnaly
|
|
21
21
|
|
|
22
|
-
puts distance_data
|
|
22
|
+
puts distance_data
|
|
@@ -21,12 +21,12 @@ module Skyscanner
|
|
|
21
21
|
|
|
22
22
|
private
|
|
23
23
|
def getCarrierId2Carrier(originData)
|
|
24
|
-
carriers = originData[
|
|
24
|
+
carriers = originData['Carriers']
|
|
25
25
|
carrierId2Carrier = Hash.new()
|
|
26
26
|
carriers.each do |carrier|
|
|
27
|
-
carrierId2Carrier[carrier[
|
|
28
|
-
end
|
|
29
|
-
carrierId2Carrier
|
|
27
|
+
carrierId2Carrier[carrier['CarrierId']] = carrier['Name']
|
|
28
|
+
end
|
|
29
|
+
carrierId2Carrier
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
private
|
|
@@ -54,6 +54,6 @@ module Skyscanner
|
|
|
54
54
|
quote["OutboundLeg"]["DestinationId"] = placeId2Place[quote["OutboundLeg"]["DestinationId"]]
|
|
55
55
|
end
|
|
56
56
|
quotes
|
|
57
|
-
end
|
|
57
|
+
end
|
|
58
58
|
end
|
|
59
|
-
end
|
|
59
|
+
end
|
|
@@ -20,10 +20,6 @@ module Google
|
|
|
20
20
|
@config = { googlemap_id: ENV['GOOGLE_API'] }
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def self.analysis(posting_id)
|
|
24
|
-
fb_resource(posting_id)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
23
|
def self.distanceInfo(origins, dest, mode)
|
|
28
24
|
return @distance if @distance
|
|
29
25
|
distanceDetail = HTTP.get(Google_API_URL,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'http'
|
|
2
|
+
#search rating of places
|
|
3
|
+
module Google
|
|
4
|
+
# Service for all Google API calls
|
|
5
|
+
class InternalGoogleApi
|
|
6
|
+
#Setting the URL and parameters
|
|
7
|
+
Google_URL = 'https://maps.googleapis.com/maps/api/'
|
|
8
|
+
Search_Type = 'place/textsearch'
|
|
9
|
+
Return_Type = 'json'
|
|
10
|
+
Google_API_URL = URI.join(Google_URL, "#{Search_Type}/", "#{Return_Type}")
|
|
11
|
+
#Search_URL = URI.join(Google_API_URL, "#{Parms}")
|
|
12
|
+
#https://maps.googleapis.com/maps/api/place/textsearch/xml?query=清華大學&key=AIzaSyADFcZbph8b9jvV5D9zgrlOm2oMQpv6krI
|
|
13
|
+
attr_reader :google_data
|
|
14
|
+
|
|
15
|
+
def self.config=(credentials)
|
|
16
|
+
@config ? @config.update(credentials) : @config = credentials
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.config
|
|
20
|
+
return @config if @config
|
|
21
|
+
@config = { googlemap_id: ENV['GOOGLE_API'] }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.this_rating(station)
|
|
25
|
+
return @this_rating if @this_rating
|
|
26
|
+
|
|
27
|
+
station_rating = HTTP.get(Google_API_URL,
|
|
28
|
+
params:
|
|
29
|
+
{
|
|
30
|
+
key: 'AIzaSyADFcZbph8b9jvV5D9zgrlOm2oMQpv6krI',
|
|
31
|
+
query: station
|
|
32
|
+
})
|
|
33
|
+
print station_rating
|
|
34
|
+
this_station_rating = JSON.load(station_rating.to_s)['results']
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require_relative 'google_api_inter'
|
|
2
|
+
|
|
3
|
+
module Google
|
|
4
|
+
class GooglePlaceRating
|
|
5
|
+
attr_reader :rating_rawdata
|
|
6
|
+
|
|
7
|
+
def initialize(data,input)
|
|
8
|
+
@googleapi = ENV['GOOGLE_API']
|
|
9
|
+
@queryVal = input[0]
|
|
10
|
+
rating_analysis(data)
|
|
11
|
+
@info = data[0]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.find(query:)
|
|
15
|
+
rating_rawdata = InternalGoogleApi.this_rating(query)
|
|
16
|
+
@queryRating_input = {googleapi:ENV['GOOGLE_API'],queryKey:query}
|
|
17
|
+
|
|
18
|
+
new(rating_rawdata,@queryRating_input)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def return_rating
|
|
22
|
+
@info
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
def rating_analysis(queryresult)
|
|
27
|
+
queryresult.map do |place|
|
|
28
|
+
@rating = place['rating']
|
|
29
|
+
@lat = place['geometry']['location']['lat']
|
|
30
|
+
@lng = place['geometry']['location']['lng']
|
|
31
|
+
@placeid = place['place_id']
|
|
32
|
+
@types = place['types']
|
|
33
|
+
@address = place['formatted_address']
|
|
34
|
+
@placename = place['name']
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -17,13 +17,11 @@ module Skyscanner
|
|
|
17
17
|
|
|
18
18
|
def self.getOriginData(market, currency, locale, originPlace, destinationPlace, outboundPartialDate)
|
|
19
19
|
url = URI.join(Skyscanner_API_URL, market+"/", currency+"/", locale+"/", originPlace+"/", destinationPlace+"/", outboundPartialDate);
|
|
20
|
-
skyscanner_response = HTTP.get(url,
|
|
20
|
+
skyscanner_response = HTTP.get(url,
|
|
21
21
|
params: {
|
|
22
|
-
|
|
22
|
+
apiKey: config[:skyscanner_id]
|
|
23
23
|
})
|
|
24
|
-
|
|
25
24
|
originData = JSON.load(skyscanner_response.body.to_s)
|
|
26
|
-
originData
|
|
27
25
|
end
|
|
28
26
|
end
|
|
29
|
-
end
|
|
27
|
+
end
|
|
@@ -4,23 +4,36 @@ module Google
|
|
|
4
4
|
class TrafficInfo
|
|
5
5
|
attr_reader :infos
|
|
6
6
|
attr_reader :origins, :dest, :mode
|
|
7
|
+
attr_reader :anaDistance, :anaDuration, :fare
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
def initialize(distance,search)
|
|
11
|
+
|
|
10
12
|
parseSearch(search)
|
|
11
13
|
@googleapi = ENV['GOOGLE_API']
|
|
12
14
|
@infos = distance.map{ |item|
|
|
13
15
|
infos = info(item)
|
|
14
16
|
}
|
|
17
|
+
@info = distance[0]
|
|
15
18
|
end
|
|
16
19
|
|
|
17
20
|
def trafficAnaly
|
|
18
|
-
@
|
|
21
|
+
@anaDistance = @info['distance']['value']
|
|
22
|
+
@anaDuration = @info['duration']
|
|
23
|
+
if(@info['fare'])
|
|
24
|
+
@fare = @info['fare']
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
@info
|
|
28
|
+
|
|
19
29
|
end
|
|
20
30
|
|
|
21
31
|
def self.find(origins:,destinations:,mode:)
|
|
22
32
|
distance_data = GoogleApi.distanceInfo(origins,destinations,mode)
|
|
23
33
|
@search_info = {googleapi:ENV['GOOGLE_API'],originsVal:origins,destVal:destinations,modeVal:mode}
|
|
34
|
+
# @info = distance_data[0]
|
|
35
|
+
# print @info.to_s
|
|
36
|
+
|
|
24
37
|
new(distance_data,@search_info)
|
|
25
38
|
end
|
|
26
39
|
|
|
@@ -32,7 +45,8 @@ module Google
|
|
|
32
45
|
end
|
|
33
46
|
|
|
34
47
|
def info(item)
|
|
35
|
-
info = item
|
|
48
|
+
info = item
|
|
49
|
+
|
|
36
50
|
end
|
|
37
51
|
|
|
38
52
|
end
|
data/spec/airbnbapi_spec.rb
CHANGED
|
@@ -5,7 +5,6 @@ describe 'Load specifications' do
|
|
|
5
5
|
c.cassette_library_dir = CASSETTES_FOLDER
|
|
6
6
|
c.hook_into :webmock
|
|
7
7
|
|
|
8
|
-
c.filter_sensitive_data('<AIRBNB_ID>') {ENV['AIRBNB_API'] }
|
|
9
8
|
c.filter_sensitive_data('<GOOGLEMAP_ID>') {ENV['GOOGLE_API'] }
|
|
10
9
|
end
|
|
11
10
|
|
|
@@ -27,4 +26,15 @@ describe 'Load specifications' do
|
|
|
27
26
|
distance =google_load.trafficAnaly
|
|
28
27
|
distance.length.must_be :>,0
|
|
29
28
|
end
|
|
29
|
+
|
|
30
|
+
#google internal api test
|
|
31
|
+
it 'should be able to get rating from placeapi' do
|
|
32
|
+
google_rating = Google::GooglePlaceRating.find(
|
|
33
|
+
query: "清華大學 交通大學 餐廳"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
rating = google_rating.return_rating
|
|
37
|
+
rating.length.must_be :>,0
|
|
38
|
+
|
|
39
|
+
end
|
|
30
40
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -22,9 +22,9 @@ CASSETTE_FILE_SKYSCANNER = 'skyscanner_flights'
|
|
|
22
22
|
|
|
23
23
|
if File.file?('config/credentials.yml')
|
|
24
24
|
credentials = YAML.load(File.read('config/credentials.yml'))
|
|
25
|
-
ENV['AIRBNB_API'] = credentials[:
|
|
26
|
-
ENV['GOOGLE_API'] = credentials[:
|
|
27
|
-
ENV['SKYSCANNER_API'] = credentials[:
|
|
25
|
+
ENV['AIRBNB_API'] = credentials[:AIRBNB_API]
|
|
26
|
+
ENV['GOOGLE_API'] = credentials[:GOOGLE_API]
|
|
27
|
+
ENV['SKYSCANNER_API'] = credentials[:SKYSCANNER_API]
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
RESULT_FILE_AIRBNB = "#{FIXTURES_FOLDER}/airbnb_api_results.yml"
|
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.70
|
|
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-18 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: http
|
|
@@ -159,6 +159,7 @@ email:
|
|
|
159
159
|
- wtlin0711@gmail.com
|
|
160
160
|
executables:
|
|
161
161
|
- flight
|
|
162
|
+
- googleplace
|
|
162
163
|
- rent
|
|
163
164
|
- traffic
|
|
164
165
|
extensions: []
|
|
@@ -172,13 +173,17 @@ files:
|
|
|
172
173
|
- README.md
|
|
173
174
|
- Rakefile
|
|
174
175
|
- Time_Traveler.gemspec
|
|
176
|
+
- apiformat.txt
|
|
175
177
|
- bin/flight
|
|
178
|
+
- bin/googleplace
|
|
176
179
|
- bin/rent
|
|
177
180
|
- bin/traffic
|
|
178
181
|
- lib/Time_Traveler.rb
|
|
179
182
|
- lib/Time_Traveler/airbnb_api.rb
|
|
180
183
|
- lib/Time_Traveler/flightInfo.rb
|
|
181
184
|
- lib/Time_Traveler/google_api.rb
|
|
185
|
+
- lib/Time_Traveler/google_api_inter.rb
|
|
186
|
+
- lib/Time_Traveler/internal.rb
|
|
182
187
|
- lib/Time_Traveler/rentInfo.rb
|
|
183
188
|
- lib/Time_Traveler/skyscanner_api.rb
|
|
184
189
|
- lib/Time_Traveler/trafficinfo.rb
|