All Files
(69.71%
covered at
0.85
hits/line)
10 files in total.
175 relevant lines.
122 lines covered and
53 lines missed
-
1
files = Dir.glob(File.join(File.dirname(__FILE__), 'VIAJERO/*.rb'))
-
10
files.each { |lib| require_relative lib }
-
1
require 'http'
-
-
1
module Airbnb
-
# Service for all Airbnb API calls
-
1
class AirbnbApi
-
#Setting the URL and parameters
-
1
Airbnb_URL = 'https://api.airbnb.com/'
-
1
API_VER = 'v2'
-
1
Airbnb_API_URL = URI.join(Airbnb_URL, "#{API_VER}/")
-
1
Search_URL = URI.join(Airbnb_API_URL, "search_results")
-
-
1
def self.config=(credentials)
-
@config ? @config.update(credentials) : @config = credentials
-
end
-
-
1
def self.config
-
return @config if @config
-
@config = { airbnb_id: ENV['AIRBNB_API'] }
-
end
-
-
1
def self.rooms_info(location)
-
rooms_response = HTTP.get(Search_URL,
-
params: { client_id: config[:airbnb_id],
-
location: location
-
})
-
roomsinfo = JSON.load(rooms_response.to_s)['search_results']
-
-
end
-
-
end
-
end
-
1
require_relative 'skyscanner_api'
-
-
1
module Skyscanner
-
1
class FlightInfo
-
1
attr_reader :flightInfo
-
-
1
def initialize(originData)
-
carrierId2Carrier = getCarrierId2Carrier(originData)
-
placeId2Place = getPlaceId2Place(originData)
-
@flightInfo = extractFlightInfo(carrierId2Carrier, placeId2Place, originData)
-
end
-
-
1
def flightInfo
-
@flightInfo
-
end
-
-
1
def self.find(market:, currency:, locale:, originPlace:, destinationPlace:, outboundPartialDate:)
-
originData = SkyscannerApi.getOriginData(market, currency, locale, originPlace, destinationPlace, outboundPartialDate)
-
new(originData)
-
end
-
-
1
private
-
1
def getCarrierId2Carrier(originData)
-
carriers = originData['Carriers']
-
carrierId2Carrier = Hash.new()
-
carriers.each do |carrier|
-
carrierId2Carrier[carrier['CarrierId']] = carrier['Name']
-
end
-
carrierId2Carrier
-
end
-
-
1
private
-
1
def getPlaceId2Place(originData)
-
places = originData["Places"]
-
placeId2Place = Hash.new()
-
places.each do |place|
-
if place["Type"] == "Station"
-
placeId2Place[place["PlaceId"]] = place["Name"] #+","+place["CountryName"]
-
end
-
end
-
placeId2Place
-
end
-
-
1
private
-
1
def extractFlightInfo(carrierId2Carrier, placeId2Place, originData)
-
quotes = originData["Quotes"]
-
quotes.each do |quote|
-
if(quote["OutboundLeg"]["CarrierIds"].empty? == false)
-
for i in 0..quote["OutboundLeg"]["CarrierIds"].length
-
quote["OutboundLeg"]["CarrierIds"][i] = carrierId2Carrier[quote["OutboundLeg"]["CarrierIds"][i]]
-
end
-
end
-
quote["OutboundLeg"]["OriginId"] = placeId2Place[quote["OutboundLeg"]["OriginId"]]
-
quote["OutboundLeg"]["DestinationId"] = placeId2Place[quote["OutboundLeg"]["DestinationId"]]
-
end
-
quotes
-
end
-
end
-
end
-
1
require 'http'
-
-
1
module Google
-
# Service for all Google API calls
-
1
class GoogleApi
-
#Setting the URL and parameters
-
1
Google_URL = 'https://maps.googleapis.com/maps/api/'
-
1
Search_Type = 'distancematrix'
-
1
Return_Type = 'json'
-
1
Google_API_URL = URI.join(Google_URL, "#{Search_Type}/", "#{Return_Type}")
-
#Search_URL = URI.join(Google_API_URL, "#{Parms}")
-
1
attr_reader :google_data
-
-
1
def self.config=(credentials)
-
@config ? @config.update(credentials) : @config = credentials
-
end
-
-
1
def self.config
-
1
return @config if @config
-
1
@config = { googlemap_id: ENV['GOOGLE_API'] }
-
end
-
-
1
def self.distanceInfo(origins, dest, mode)
-
1
return @distance if @distance
-
1
distanceDetail = HTTP.get(Google_API_URL,
-
params:
-
{
-
key: config['googlemap_id'],
-
origins: origins,
-
destinations: dest,
-
mode: mode
-
})
-
1
distance_data = JSON.load(distanceDetail.to_s)['rows'][0]['elements']
-
end
-
-
end
-
end
-
1
require 'http'
-
#search rating of places
-
1
module Google
-
# Service for all Google API calls
-
1
class InternalGoogleApi
-
#Setting the URL and parameters
-
1
Google_URL = 'https://maps.googleapis.com/maps/api/'
-
1
Search_Type = 'place/textsearch'
-
1
Return_Type = 'json'
-
1
Google_API_URL = URI.join(Google_URL, "#{Search_Type}/", "#{Return_Type}")
-
#Search_URL = URI.join(Google_API_URL, "#{Parms}")
-
#https://maps.googleapis.com/maps/api/place/textsearch/xml?query=清華大學&key=AIzaSyADFcZbph8b9jvV5D9zgrlOm2oMQpv6krI
-
1
attr_reader :google_data
-
-
1
def self.config=(credentials)
-
@config ? @config.update(credentials) : @config = credentials
-
end
-
-
1
def self.config
-
return @config if @config
-
@config = { googlemap_id: ENV['GOOGLE_API'] }
-
end
-
-
1
def self.this_rating(station)
-
1
return @this_rating if @this_rating
-
-
1
station_rating = HTTP.get(Google_API_URL,
-
params:
-
{
-
key: 'AIzaSyADFcZbph8b9jvV5D9zgrlOm2oMQpv6krI',
-
query: station
-
})
-
1
this_station_rating = JSON.load(station_rating.to_s)['results']
-
end
-
-
end
-
end
-
1
require_relative 'google_api_inter'
-
-
1
module Google
-
1
class GooglePlaceRating
-
1
attr_reader :rating_rawdata,:attracs
-
-
1
def initialize(data,input)
-
1
@googleapi = ENV['GOOGLE_API']
-
1
@queryVal = input[0]
-
1
@attracs = rating_analysis(data)
-
# @info = data[0]
-
end
-
-
1
def self.find(query:)
-
1
rating_rawdata = InternalGoogleApi.this_rating(query)
-
1
@queryRating_input = {googleapi:ENV['GOOGLE_API'],queryKey:query}
-
-
1
new(rating_rawdata,@queryRating_input)
-
end
-
-
1
def return_rating
-
@info
-
end
-
-
1
private
-
1
def rating_analysis(queryresult)
-
1
queryresult.map do |place|
-
{
-
rating: place['rating'],
-
lat: place['geometry']['location']['lat'],
-
lng: place['geometry']['location']['lng'],
-
placeid: place['place_id'],
-
types: place['types'],
-
address: place['formatted_address'],
-
placename: place['name'],
-
id: place['id'],
-
icon: place['icon'],
-
opening_hours: place['opening_hours']
-
20
}
-
end
-
end
-
end
-
end
-
1
require_relative 'airbnb_api'
-
-
1
module Airbnb
-
1
class RentInfo
-
1
attr_reader :location
-
1
attr_reader :infos
-
-
1
def initialize(rooms,info)
-
@infos = rooms.map { |item|
-
rooms = room(item)
-
}
-
searchVal(info)
-
end
-
-
1
def infos
-
@infos
-
end
-
-
1
def self.find(location:)
-
@search_info = {api:ENV['AIRBNB_API'],locate:location}
-
rooms_data = AirbnbApi.rooms_info(location)
-
new(rooms_data,@search_info)
-
end
-
-
1
private
-
1
def room(item)
-
#item = item['listing']
-
room = {
-
city: item['listing']['city'],
-
name: item['listing']['name'],
-
pic_url: item['listing']['picture_url'],
-
id: item['listing']['id']
-
}
-
end
-
-
1
def searchVal(oriSearch)
-
@location = oriSearch['locate']
-
@airbnbapi = oriSearch['api']
-
end
-
-
end
-
end
-
1
require 'http'
-
-
1
module Skyscanner
-
1
class SkyscannerApi
-
1
Skyscanner_URL = 'http://partners.api.skyscanner.net/apiservices/browseroutes/'
-
1
API_VER = 'v1.0'
-
1
Skyscanner_API_URL = URI.join(Skyscanner_URL, "#{API_VER}/")
-
-
1
def self.config=(credentials)
-
@config ? @config.update(credentials) : @config = credentials
-
end
-
-
1
def self.config
-
return @config if @config
-
@config = { skyscanner_id: ENV['SKYSCANNER_API'] }
-
end
-
-
1
def self.getOriginData(market, currency, locale, originPlace, destinationPlace, outboundPartialDate)
-
url = URI.join(Skyscanner_API_URL, market+"/", currency+"/", locale+"/", originPlace+"/", destinationPlace+"/", outboundPartialDate);
-
skyscanner_response = HTTP.get(url,
-
params: {
-
apiKey: config[:skyscanner_id]
-
})
-
print skyscanner_response
-
originData = JSON.load(skyscanner_response.to_s)
-
end
-
end
-
end
-
1
require_relative 'google_api'
-
-
1
module Google
-
1
class TrafficInfo
-
1
attr_reader :infos
-
1
attr_reader :origins, :dest, :mode
-
1
attr_reader :anaDistance, :anaDuration, :fare
-
-
-
1
def initialize(distance,search)
-
-
1
parseSearch(search)
-
1
@googleapi = ENV['GOOGLE_API']
-
1
@infos = distance.map{ |item|
-
1
infos = info(item)
-
}
-
1
@info = distance[0]
-
end
-
-
1
def trafficAnaly
-
1
@anaDistance = @info['distance']['value']
-
1
@anaDuration = @info['duration']
-
1
if(@info['fare'])
-
@fare = @info['fare']
-
end
-
-
1
@info
-
-
end
-
-
1
def self.find(origins:,destinations:,mode:)
-
1
distance_data = GoogleApi.distanceInfo(origins,destinations,mode)
-
1
@search_info = {googleapi:ENV['GOOGLE_API'],originsVal:origins,destVal:destinations,modeVal:mode}
-
# @info = distance_data[0]
-
# print @info.to_s
-
-
1
new(distance_data,@search_info)
-
end
-
-
1
private
-
1
def parseSearch(sear)
-
1
@origins = sear[:originsVal]
-
1
@dest = sear[:destVal]
-
1
@mode = sear[:modeVal]
-
end
-
-
1
def info(item)
-
1
info = item
-
-
end
-
-
end
-
end
-
1
module VIAJERO
-
1
VERSION = '0.1.73'
-
end