-
Notifications
You must be signed in to change notification settings - Fork 0
/
goibibo.rb
97 lines (79 loc) · 2.7 KB
/
goibibo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require 'rest_client'
class GoIbiboClient
attr_accessor :FLIGHT_URL, :MIN_FARE_URL, :BUS_URL, :BUS_SEAT_MAP_URL, :app_id, :app_key
def initialize app_id, app_key
base_URL = 'https://developer.goibibo.com/api/'
self.FLIGHT_URL = base_URL + 'search/'
self.MIN_FARE_URL = base_URL + 'stats/minfare/'
self.BUS_URL = base_URL + 'bus/search/'
self.BUS_SEAT_MAP_URL = base_URL + 'bus/seatmap/'
self.app_id = app_id
self.app_key = app_key
end
def SearchFlights source, destination, dateofdeparture, opts={}
format = opts[:format].nil? ? 'json' : opts[:format]
dateofarrival = opts[:dateofarrival].nil? ? '' : opts[:dateofarrival]
seatingclass = opts[:seatingclass].nil? ? 'E' : opts[:seatingclass]
adults = opts[:adults].nil? ? 1 : opts[:adults]
children = opts[:children].nil? ? 0 : opts[:children]
infants = opts[:infants].nil? ? 0 : opts[:infants]
params = {
"app_id" => self.app_id,
"app_key" => self.app_key,
"format" => format,
"source" => source,
"destination" => destination,
"dateofdeparture" => dateofdeparture,
"dateofarrival" => dateofarrival,
"seatingclass" => seatingclass,
"adults" => adults,
"children" => children,
"infants"=> infants
}
RestClient.get self.FLIGHT_URL, { :params => params }
end
def FetchMinFare source, destination, sdate, opts={}
format = opts[:format].nil? ? 'json' : opts[:format]
vertical = opts[:vertical].nil? ? 'flight' : opts[:vertical]
mode = opts[:mode].nil? ? 'one' : opts[:mode]
edate = opts[:edate].nil? ? sdate : opts[:edate]
travel_class = opts[:class].nil? ? 'NA' : opts[:class]
params = {
"app_id" => self.app_id,
"app_key" => self.app_key,
"format" => format,
"source" => source,
"destination" => destination,
"sdate" => sdate,
"vertical" => vertical,
"mode" => mode,
"edate" => edate,
"class" => travel_class
}
RestClient.get self.MIN_FARE_URL, { :params => params }
end
def SearchBuses source, destination, departure_date, opts={}
format = opts[:format].nil? ? 'json' : opts[:format]
arrival_date = opts[:dateofarrival].nil? ? '' : opts[:dateofarrival]
params = {
"app_id" => self.app_id,
"app_key" => self.app_key,
"format" => format,
"source" => source,
"destination" => destination,
"dateofdeparture" => departure_date,
"dateofarrival" => arrival_date
}
RestClient.get self.BUS_URL, { :params => params }
end
def FetchBusSeatMap skey, opts={}
format = opts[:format].nil? ? 'json' : opts[:format]
params = {
"app_id" => self.app_id,
"app_key" => self.app_key,
"format" => format,
"skey" => skey
}
RestClient.get self.BUS_SEAT_MAP_URL, { :params => params }
end
end