expedia_api 0.1.6 → 0.1.7
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/lib/expedia_api/entities/package.rb +5 -0
- data/lib/expedia_api/entities/package_flight.rb +6 -26
- data/lib/expedia_api/entities/package_flight_leg.rb +111 -0
- data/lib/expedia_api/entities/package_flight_leg_segment.rb +126 -0
- data/lib/expedia_api/entities/package_hotel.rb +10 -0
- data/lib/expedia_api/version.rb +1 -1
- data/lib/expedia_api.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00c0cba3e1f70e0d30b927589783bf263ec9e4c8
|
4
|
+
data.tar.gz: 8bc3717b0d80eae5ebb27494ab4f1af29d47a0b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69e61b3e88dbee6ec9aafea1224e6d17b75099c5dbd113fb04c85ee86807637c1d595b7f646691fd0753294c7693cd11a6548c7ad770b0142210c3b821bad219
|
7
|
+
data.tar.gz: 371056c4370c0216119f7ffa2d5167d865e0ae7a10a30026497147f4a63ce8e1b285f8e4e4aca9f6ceb7403125870311665ad0fd06a459b1c693b4493104278f
|
@@ -1,47 +1,27 @@
|
|
1
1
|
module ExpediaApi
|
2
2
|
module Entities
|
3
3
|
class PackageFlight
|
4
|
-
attr_reader :raw_data
|
5
|
-
|
6
4
|
def initialize(raw_data)
|
7
5
|
@raw_data = raw_data || {}
|
8
6
|
end
|
9
7
|
|
8
|
+
# returns the flight identifier for the given flight.
|
10
9
|
def index
|
11
|
-
raw_data[:FlightIndex].to_i
|
10
|
+
@raw_data[:FlightIndex].to_i
|
12
11
|
end
|
13
12
|
|
13
|
+
# returns an array of flight legs for the given flight
|
14
14
|
def flight_legs
|
15
15
|
extract_flightlegs.map do |leg|
|
16
|
-
|
16
|
+
PackageFlightLeg.new(leg)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
# extracts the json of the flight legs from the data.
|
20
21
|
def extract_flightlegs
|
21
|
-
raw_data.fetch(:FlightItinerary, {}).fetch(:FlightLeg, {})
|
22
|
-
end
|
23
|
-
|
24
|
-
class FlightLeg
|
25
|
-
def initialize(raw_data)
|
26
|
-
@raw_data = raw_data || {}
|
27
|
-
end
|
28
|
-
|
29
|
-
def segments
|
30
|
-
extract_segments.map do |segment|
|
31
|
-
FlightLegSegment.new(segment)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def extract_segments
|
36
|
-
@raw_data[:FlightSegment] || []
|
37
|
-
end
|
22
|
+
@raw_data.fetch(:FlightItinerary, {}).fetch(:FlightLeg, {})
|
38
23
|
end
|
39
24
|
|
40
|
-
class FlightLegSegment
|
41
|
-
def initialize(raw_data)
|
42
|
-
@raw_data = raw_data || {}
|
43
|
-
end
|
44
|
-
end
|
45
25
|
end
|
46
26
|
end
|
47
27
|
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module ExpediaApi
|
2
|
+
module Entities
|
3
|
+
# wrapper class for each of the flight legs
|
4
|
+
class PackageFlightLeg
|
5
|
+
|
6
|
+
# The raw data by the API looks like this:
|
7
|
+
#
|
8
|
+
# {
|
9
|
+
# "FlightDuration": "PT21H50M",
|
10
|
+
# "FlightLegIndex": "1",
|
11
|
+
# "FlightSegment": [
|
12
|
+
# {
|
13
|
+
# "ArrivalAirportCode": "DUS",
|
14
|
+
# "ArrivalDateTime": "2016-09-07T08:30:00",
|
15
|
+
# "CarrierCode": "AB",
|
16
|
+
# "DepartureAirportCode": "HAM",
|
17
|
+
# "DepartureDateTime": "2016-09-07T07:30:00",
|
18
|
+
# "FlightDuration": "PT1H0M",
|
19
|
+
# "FlightNumber": "6743",
|
20
|
+
# "FlightSegmentIndex": "1"
|
21
|
+
# },
|
22
|
+
# {
|
23
|
+
# "ArrivalAirportCode": "AUH",
|
24
|
+
# "ArrivalDateTime": "2016-09-07T20:20:00",
|
25
|
+
# "CarrierCode": "AB",
|
26
|
+
# "DepartureAirportCode": "DUS",
|
27
|
+
# "DepartureDateTime": "2016-09-07T11:30:00",
|
28
|
+
# "FlightDuration": "PT6H50M",
|
29
|
+
# "FlightNumber": "4008",
|
30
|
+
# "FlightSegmentIndex": "2"
|
31
|
+
# },
|
32
|
+
# {
|
33
|
+
# "ArrivalAirportCode": "SYD",
|
34
|
+
# "ArrivalDateTime": "2016-09-08T17:55:00",
|
35
|
+
# "CarrierCode": "AB",
|
36
|
+
# "DepartureAirportCode": "AUH",
|
37
|
+
# "DepartureDateTime": "2016-09-07T21:55:00",
|
38
|
+
# "FlightDuration": "PT14H0M",
|
39
|
+
# "FlightNumber": "4070",
|
40
|
+
# "FlightSegmentIndex": "3"
|
41
|
+
# }
|
42
|
+
# ]
|
43
|
+
# }
|
44
|
+
def initialize(raw_data)
|
45
|
+
@raw_data = raw_data || {}
|
46
|
+
end
|
47
|
+
|
48
|
+
# returns the flight segments of the flight
|
49
|
+
def segments
|
50
|
+
@segments ||= begin
|
51
|
+
segments = extract_segments.map do |segment|
|
52
|
+
PackageFlightLegSegment.new(segment)
|
53
|
+
end
|
54
|
+
segments.each do |segment|
|
55
|
+
segment.sibling_segments = segments
|
56
|
+
end
|
57
|
+
segments
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# extracts the segments of the flight from the json
|
62
|
+
def extract_segments
|
63
|
+
@raw_data[:FlightSegment] || []
|
64
|
+
end
|
65
|
+
|
66
|
+
# returns the total time it will in seconds.
|
67
|
+
#
|
68
|
+
# format by expedia: "PT21H50M"
|
69
|
+
def total_duration_seconds
|
70
|
+
hours = hours_all_segments
|
71
|
+
minutes = minutes_all_segments
|
72
|
+
if hours && minutes
|
73
|
+
hours * 3600 + minutes * 60
|
74
|
+
else
|
75
|
+
0
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# returns the hours of the flight, if nor parsable, returns nil
|
80
|
+
def hours_all_segments
|
81
|
+
stamp = @raw_data[:FlightDuration].split("PT")[1]
|
82
|
+
stamp.split("H")[0].to_i
|
83
|
+
rescue
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
|
87
|
+
# returns the minutes of the flight, if nor parsable, returns nil
|
88
|
+
def minutes_all_segments
|
89
|
+
stamp = @raw_data[:FlightDuration].split("PT")[1]
|
90
|
+
stamp.split("H")[1].split("M")[0].to_i
|
91
|
+
rescue
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
|
95
|
+
# returns the index of the flight leg
|
96
|
+
def index
|
97
|
+
@raw_data[:FlightLegIndex].to_i
|
98
|
+
end
|
99
|
+
|
100
|
+
# returns true if we have a to flight
|
101
|
+
def is_to_flight?
|
102
|
+
index == 1
|
103
|
+
end
|
104
|
+
|
105
|
+
# returns true if we have a return flight leg.
|
106
|
+
def is_return_flight?
|
107
|
+
index == 2
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module ExpediaApi
|
2
|
+
module Entities
|
3
|
+
# class handling each of the flight legs segments
|
4
|
+
#
|
5
|
+
# receives data in this format:
|
6
|
+
# {
|
7
|
+
# "FlightSegmentIndex"=>"2",
|
8
|
+
# "DepartureAirportCode"=>"SAW",
|
9
|
+
# "ArrivalAirportCode"=>"DXB",
|
10
|
+
# "DepartureDateTime"=>"2016-05-31T21:45:00",
|
11
|
+
# "ArrivalDateTime"=>"2016-06-01T03:20:00",
|
12
|
+
# "CarrierCode"=>"PC",
|
13
|
+
# "FlightNumber"=>"5660",
|
14
|
+
# "FlightDuration"=>"PT4H35M"
|
15
|
+
# }
|
16
|
+
class PackageFlightLegSegment
|
17
|
+
|
18
|
+
attr_accessor :sibling_segments
|
19
|
+
|
20
|
+
def initialize(raw_data)
|
21
|
+
@raw_data = raw_data || {}
|
22
|
+
@sibling_segments = []
|
23
|
+
end
|
24
|
+
|
25
|
+
# returns a departure datetime for the departure time of the segment
|
26
|
+
def departure_time
|
27
|
+
DateTime.parse(@raw_data[:DepartureDateTime])
|
28
|
+
end
|
29
|
+
|
30
|
+
# returns a datetime for the arrival date of the segment
|
31
|
+
def arrival_time
|
32
|
+
DateTime.parse(@raw_data[:ArrivalDateTime])
|
33
|
+
end
|
34
|
+
|
35
|
+
# returns the index of the segment
|
36
|
+
def index
|
37
|
+
@raw_data[:FlightSegmentIndex].to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
# returns the carrier code of the segment
|
41
|
+
def carrier_code
|
42
|
+
@raw_data[:CarrierCode]
|
43
|
+
end
|
44
|
+
|
45
|
+
# returns the departure airport code of the segment
|
46
|
+
def departure_airport_code
|
47
|
+
@raw_data[:DepartureAirportCode]
|
48
|
+
end
|
49
|
+
|
50
|
+
# returns the arrival airport code of the segment
|
51
|
+
def arrival_airport_code
|
52
|
+
@raw_data[:ArrivalAirportCode]
|
53
|
+
end
|
54
|
+
|
55
|
+
# returns the time between this segment and the next one.
|
56
|
+
def stay_duration_seconds
|
57
|
+
return 0 unless next_segment
|
58
|
+
# when we arrive at the next airport, minus when we arrived at this
|
59
|
+
# airport.
|
60
|
+
(next_segment.departure_time.to_time - arrival_time.to_time).to_i
|
61
|
+
end
|
62
|
+
|
63
|
+
# returns the duration how long the segment takes. returns 0 if it can
|
64
|
+
# not be identified.
|
65
|
+
def duration_seconds
|
66
|
+
hours = hours_flight
|
67
|
+
minutes = minutes_flight
|
68
|
+
if hours && minutes
|
69
|
+
hours * 3600 + minutes * 60
|
70
|
+
else
|
71
|
+
0
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# returns the hours of the flight, if nor parsable, returns nil
|
76
|
+
def hours_flight
|
77
|
+
stamp = @raw_data[:FlightDuration].split("PT")[1]
|
78
|
+
stamp.split("H")[0].to_i
|
79
|
+
rescue
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
|
83
|
+
# returns the minutes of the flight, if nor parsable, returns nil
|
84
|
+
def minutes_flight
|
85
|
+
stamp = @raw_data[:FlightDuration].split("PT")[1]
|
86
|
+
stamp.split("H")[1].split("M")[0].to_i
|
87
|
+
rescue
|
88
|
+
nil
|
89
|
+
end
|
90
|
+
|
91
|
+
# returns the flight number of the flight
|
92
|
+
def flight_number
|
93
|
+
@raw_data[:FlightNumber]
|
94
|
+
end
|
95
|
+
|
96
|
+
# returns true if it is the last segment of the flight
|
97
|
+
def is_last_segment_of_flight?
|
98
|
+
return true if sibling_segments.empty?
|
99
|
+
sibling_segments.sort_by {|segment| segment.index }.reverse.first == self
|
100
|
+
end
|
101
|
+
|
102
|
+
# returns true if it is the first segment of the flight
|
103
|
+
def is_first_segment_of_flight?
|
104
|
+
return true if sibling_segments.empty?
|
105
|
+
sibling_segments.sort_by {|segment| segment.index }.first == self
|
106
|
+
end
|
107
|
+
|
108
|
+
# returns the next segment followed by this segment
|
109
|
+
def next_segment
|
110
|
+
return nil if sibling_segments.empty?
|
111
|
+
sibling_segments[sibling_segments.sort_by(&:index).index(self) + 1]
|
112
|
+
end
|
113
|
+
|
114
|
+
# returns the previous segment preceeded by this segment
|
115
|
+
def previous_segment
|
116
|
+
return nil if sibling_segments.empty?
|
117
|
+
index = sibling_segments.sort_by(&:index).index(self)
|
118
|
+
if index && index >= 1
|
119
|
+
sibling_segments[index - 1]
|
120
|
+
else
|
121
|
+
nil
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/lib/expedia_api/version.rb
CHANGED
data/lib/expedia_api.rb
CHANGED
@@ -11,6 +11,8 @@ require "expedia_api/entities"
|
|
11
11
|
require "expedia_api/entities/search_entity"
|
12
12
|
require "expedia_api/entities/package"
|
13
13
|
require "expedia_api/entities/package_flight"
|
14
|
+
require "expedia_api/entities/package_flight_leg"
|
15
|
+
require "expedia_api/entities/package_flight_leg_segment"
|
14
16
|
require "expedia_api/entities/package_hotel"
|
15
17
|
require "expedia_api/response_lists"
|
16
18
|
require "expedia_api/response_lists/base_response_list"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expedia_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hendrik Kleinwaechter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -158,6 +158,8 @@ files:
|
|
158
158
|
- lib/expedia_api/entities.rb
|
159
159
|
- lib/expedia_api/entities/package.rb
|
160
160
|
- lib/expedia_api/entities/package_flight.rb
|
161
|
+
- lib/expedia_api/entities/package_flight_leg.rb
|
162
|
+
- lib/expedia_api/entities/package_flight_leg_segment.rb
|
161
163
|
- lib/expedia_api/entities/package_hotel.rb
|
162
164
|
- lib/expedia_api/entities/search_entity.rb
|
163
165
|
- lib/expedia_api/http_service.rb
|