tripit 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/Gemfile +13 -0
  2. data/Gemfile.lock +20 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +157 -0
  5. data/Rakefile +53 -0
  6. data/VERSION +1 -0
  7. data/lib/trip_it/base.rb +105 -0
  8. data/lib/trip_it/classes/address.rb +18 -0
  9. data/lib/trip_it/classes/flight_status.rb +27 -0
  10. data/lib/trip_it/classes/group.rb +12 -0
  11. data/lib/trip_it/classes/image.rb +10 -0
  12. data/lib/trip_it/classes/invitee.rb +14 -0
  13. data/lib/trip_it/classes/objects/activity_object.rb +45 -0
  14. data/lib/trip_it/classes/objects/air_object.rb +39 -0
  15. data/lib/trip_it/classes/objects/base_object.rb +31 -0
  16. data/lib/trip_it/classes/objects/car_object.rb +43 -0
  17. data/lib/trip_it/classes/objects/cruise_object.rb +44 -0
  18. data/lib/trip_it/classes/objects/directions_object.rb +27 -0
  19. data/lib/trip_it/classes/objects/lodging_object.rb +34 -0
  20. data/lib/trip_it/classes/objects/map_object.rb +26 -0
  21. data/lib/trip_it/classes/objects/note_object.rb +43 -0
  22. data/lib/trip_it/classes/objects/rail_object.rb +39 -0
  23. data/lib/trip_it/classes/objects/reservation_object.rb +43 -0
  24. data/lib/trip_it/classes/objects/restaurant_object.rb +34 -0
  25. data/lib/trip_it/classes/objects/transport_object.rb +39 -0
  26. data/lib/trip_it/classes/objects/weather_object.rb +32 -0
  27. data/lib/trip_it/classes/points_program.rb +28 -0
  28. data/lib/trip_it/classes/points_program_activity.rb +15 -0
  29. data/lib/trip_it/classes/points_program_expiration.rb +12 -0
  30. data/lib/trip_it/classes/profile.rb +68 -0
  31. data/lib/trip_it/classes/profile_email_address.rb +15 -0
  32. data/lib/trip_it/classes/segments/air_segment.rb +56 -0
  33. data/lib/trip_it/classes/segments/cruise_segment.rb +28 -0
  34. data/lib/trip_it/classes/segments/rail_segment.rb +25 -0
  35. data/lib/trip_it/classes/segments/transport_segment.rb +34 -0
  36. data/lib/trip_it/classes/tp_date_time.rb +11 -0
  37. data/lib/trip_it/classes/traveler.rb +16 -0
  38. data/lib/trip_it/classes/trip.rb +230 -0
  39. data/lib/trip_it/classes/trip_crs_remark.rb +12 -0
  40. data/lib/trip_it/enums/activity_detail_type.rb +8 -0
  41. data/lib/trip_it/enums/cruise_detail_type.rb +5 -0
  42. data/lib/trip_it/enums/flight_status_code.rb +15 -0
  43. data/lib/trip_it/enums/note_detail_type.rb +5 -0
  44. data/lib/trip_it/enums/transport_detail_type.rb +6 -0
  45. data/lib/trip_it/oauth.rb +77 -0
  46. data/lib/trip_it/util/param_util.rb +235 -0
  47. data/lib/tripit.rb +45 -0
  48. data/test/fixtures/air_info.json +0 -0
  49. data/test/helper.rb +18 -0
  50. data/test/test_tripit.rb +7 -0
  51. data/test/unit/base_test.rb +16 -0
  52. data/test/unit/classes/address_test.rb +0 -0
  53. data/test/unit/classes/flight_status_test.rb +0 -0
  54. data/test/unit/classes/group_test.rb +0 -0
  55. data/test/unit/classes/image_test.rb +0 -0
  56. data/test/unit/classes/invitee_test.rb +0 -0
  57. data/test/unit/classes/objects/activity_object_test.rb +0 -0
  58. data/test/unit/classes/objects/air_object_test.rb +0 -0
  59. data/test/unit/classes/objects/base_object_test.rb +0 -0
  60. data/test/unit/classes/objects/car_object_test.rb +0 -0
  61. data/test/unit/classes/objects/cruise_object_test.rb +0 -0
  62. data/test/unit/classes/objects/directions_object_test.rb +0 -0
  63. data/test/unit/classes/objects/lodging_object_test.rb +0 -0
  64. data/test/unit/classes/objects/map_object_test.rb +0 -0
  65. data/test/unit/classes/objects/note_object_test.rb +0 -0
  66. data/test/unit/classes/objects/rail_object_test.rb +0 -0
  67. data/test/unit/classes/objects/reservation_object_test.rb +0 -0
  68. data/test/unit/classes/objects/restaurant_object_test.rb +0 -0
  69. data/test/unit/classes/objects/transport_object_test.rb +0 -0
  70. data/test/unit/classes/objects/weather_object_test.rb +0 -0
  71. data/test/unit/classes/points_program_activity_test.rb +0 -0
  72. data/test/unit/classes/points_program_expiration_test.rb +0 -0
  73. data/test/unit/classes/points_program_test.rb +0 -0
  74. data/test/unit/classes/profile_email_address_test.rb +0 -0
  75. data/test/unit/classes/profile_test.rb +0 -0
  76. data/test/unit/classes/segments/air_segment_test.rb +0 -0
  77. data/test/unit/classes/segments/cruise_segment_test.rb +0 -0
  78. data/test/unit/classes/segments/rail_segment_test.rb +0 -0
  79. data/test/unit/classes/segments/transport_segment_test.rb +0 -0
  80. data/test/unit/classes/traveler_test.rb +0 -0
  81. data/test/unit/classes/trip_crs_remark_test.rb +0 -0
  82. data/test/unit/classes/trip_test.rb +0 -0
  83. data/test/unit/enums/activity_detail_type_test.rb +0 -0
  84. data/test/unit/enums/cruise_detail_type_test.rb +0 -0
  85. data/test/unit/enums/flight_status_type_test.rb +0 -0
  86. data/test/unit/enums/note_detail_type_test.rb +0 -0
  87. data/test/unit/enums/transport_detail_type_test.rb +0 -0
  88. data/test/unit/oauth_test.rb +0 -0
  89. data/test/unit/util/param_util_test.rb +0 -0
  90. data/tripit.gemspec +188 -0
  91. metadata +284 -0
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+ rcov (0.9.9)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.5.2)
19
+ rcov
20
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Alex Kremer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # tripit
2
+
3
+ A very high-level abstraction library providing objects to interact with the TripIt API. It is essentially a multi-user wrapper with each object being bound to a client. This library's methodology of dealing with API data was heavily influenced by [Mike Richards' Dopplr gem](http://github.com/mikeric/dopplr).
4
+
5
+ Every object in this library mirrors the official TripIt API's properties as closely as possible. Each TripIt API object and its properties have been converted into a Ruby object. To get a list of all the objects and their properties, please see the [TripIt API XML Schema](https://api.dev.tripit.com/xsd/tripit-api-obj-v1.xsd) and the List of usable Objects below. You can also read the [TripIt API Documentation](http://github.com/tripit/api/downloads) for further details or check out the much more lightweight official [TripIt Ruby Binding](http://github.com/tripit/ruby_binding_v1)
6
+
7
+ ## Install
8
+
9
+ gem install tripit
10
+
11
+ ## Usage
12
+
13
+ Here are some examples of how to use a few of the objects available.
14
+
15
+ ### TripIt::OAuth
16
+
17
+ Create a **TripIt::OAuth** instance with your consumer token and secret. Authorize the client using your access token, provided that you've already obtained one.
18
+
19
+ client = TripIt::OAuth.new('1a2b3c4d5e', '2a3b4c5d6e')
20
+ client.authorize_from_access('3a4b5c6d7e', '4a5b6c7d8e')
21
+
22
+ ### TripIt::Profile
23
+
24
+ **TripIt::Profile** is used for viewing and creating objects related to the TripIt user you authenticated with **TripIt::OAuth**.
25
+
26
+ client = TripIt::OAuth.new('1a2b3c4d5e', '2a3b4c5d6e')
27
+ client.authorize_from_access('3a4b5c6d7e', '4a5b6c7d8e')
28
+
29
+ # Instantiate the user by loading his profile -- pass the client object so Profile knows how to authenticate.
30
+ myuser = TripIt::Profile.new(client)
31
+
32
+ # Get the user's public display name
33
+ myuser.public_display_name => "Test User"
34
+
35
+ # Get the user's screen name
36
+ myuser.screen_name => "test_user"
37
+
38
+ # Get a list of the user's registered e-mail addresses
39
+ # (returns Array of TripIt::ProfileEmailAddress objects)
40
+ myuser.profile_email_addresses => [TripIt::ProfileEmailAddress]
41
+
42
+ # Get a list of the user's trips
43
+ # (returns Array of TripIt::Trip objects. As you use them, they will lazy-load their children.)
44
+ myuser.trips => [TripIt::Trip]
45
+
46
+ # Get a list of the user's trips, and populate all child objects in one call
47
+ # (returns Array of populated TripIt::Trip objects)
48
+ myuser.trips(:include_objects => true) => [TripIt::Trip]
49
+
50
+ # Check if the user is a TripIt Pro user, and then get an
51
+ # array of his registered TripIt::PointsProgram objects
52
+ if myuser.is_pro?
53
+ myuser.points_programs => [TripIt::PointsProgram]
54
+ end
55
+
56
+ ### TripIt::Trip
57
+
58
+ **TripIt::Trip** is used for viewing and creating objects related to a Trip. As previously, you must be authenticated with **TripIt::OAuth**.
59
+
60
+ client = TripIt::OAuth.new('1a2b3c4d5e', '2a3b4c5d6e')
61
+ client.authorize_from_access('3a4b5c6d7e', '4a5b6c7d8e')
62
+
63
+ # Load a known Trip ID. If you don't know this, and are looking
64
+ # for a user's trips, see TripIt::Profile.trips
65
+ trip_id = 12345678
66
+ mytrip = TripIt::Trip.new(client, trip_id)
67
+
68
+ # Get the Trip's primary location
69
+ mytrip.primary_location => "Happy, Texas"
70
+
71
+ # Get a list of nearby users (returns Array of TripIt::Profile objects)
72
+ mytrip.closeness_matches => [TripIt::Profile]
73
+
74
+ # Get the screen name of the first closeness match
75
+ mytrip.closeness_matches.first.screen_name => "traveling_friend"
76
+
77
+ # Get a list of the AirObjects for this trip
78
+ # (returns Array of TripIt::AirObject objects)
79
+ mytrip.air => [TripIt::AirObject]
80
+
81
+ # Get a list of segments for the trip's first TripIt::AirObject
82
+ # (returns Array of TripIt::AirSegment objects)
83
+ mytrip.air.first.segment => [TripIt::AirSegment]
84
+
85
+ # Get some segment information for the first segment
86
+ nyclhr = mytrip.air.first.segment.first
87
+ nyclhr.start_city_name => "New York, NY"
88
+ nyclhr.end_city_name => "London, United Kingdom"
89
+ nyclhr.marketing_airline => "British Airways"
90
+
91
+ # Get a list of Hotels for this Trip
92
+ # (returns Array of TripIt::LodgingObject objects)
93
+ mytrip.lodging => [TripIt::LodgingObject]
94
+
95
+ # Get some info on the first hotel stay of this trip
96
+ hot = mytrip.lodging.first
97
+ hot.supplier_name => "Westin Times Square"
98
+ hot.room_type => "Presidential Suite"
99
+
100
+ # DateTime properties always return native Ruby DateTime objects
101
+ hot.start_date_time => 2011-03-01T11:37:00+00:00
102
+
103
+ # Address properties always return TripIt::Address objects
104
+ hot.address => TripIt::Address
105
+ hot.address.city => "New York"
106
+
107
+ ## List of usable Objects
108
+
109
+ * TripIt::Address
110
+ * TripIt::FlightStatus
111
+ * TripIt::Group
112
+ * TripIt::Image
113
+ * TripIt::Invitee
114
+ * TripIt::PointsProgram
115
+ * TripIt::PointsProgramActivity
116
+ * TripIt::PointsProgramExpiration
117
+ * TripIt::Profile
118
+ * TripIt::ProfileEmailAddress
119
+ * TripIt::Traveler
120
+ * TripIt::Trip
121
+ * TripIt::TripCrsRemark
122
+
123
+ * TripIt::ActivityObject
124
+ * TripIt::AirObject
125
+ * TripIt::AirSegment
126
+ * TripIt::CarObject
127
+ * TripIt::CruiseObject
128
+ * TripIt::CruiseSegment
129
+ * TripIt::DirectionsObject
130
+ * TripIt::LodgingObject
131
+ * TripIt::MapObject
132
+ * TripIt::NoteObject
133
+ * TripIt::RailObject
134
+ * TripIt::RailSegment
135
+ * TripIt::RestaurantObject
136
+ * TripIt::TransportObject
137
+ * TripIt::TransportSegment
138
+ * TripIt::WeatherObject
139
+
140
+ ## Unofficial Library
141
+
142
+ This library is used for interaction with the TripIt API but is not endorsed or certified by TripIt. If you're looking for a more lightweight library, check out their official [Ruby Binding](http://github.com/tripit/ruby_binding_v1)
143
+
144
+ ## Contributing to tripit
145
+
146
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
147
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
148
+ * Fork the project
149
+ * Start a feature/bugfix branch
150
+ * Commit and push until you are happy with your contribution
151
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
152
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
153
+
154
+ ## Copyright
155
+
156
+ Copyright (c) 2011 Alex Kremer. See LICENSE.txt for further details.
157
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "tripit"
16
+ gem.homepage = "http://github.com/flextrip/tripit"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{A Ruby library for talking to the TripIt API}
19
+ gem.description = %Q{The entire TripIt API encapsulated in Ruby objects}
20
+ gem.email = "dev@flextrip.com"
21
+ gem.authors = ["Alex Kremer"]
22
+ gem.add_runtime_dependency 'oauth'
23
+ gem.add_runtime_dependency 'json'
24
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
25
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "tripit #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.2
@@ -0,0 +1,105 @@
1
+ module TripIt
2
+ class Base
3
+ extend TripIt::ParamUtil
4
+
5
+ def chkAndPopulate(iVar, objType, prop)
6
+ return if prop.nil?
7
+ if prop.is_a?(Array)
8
+ prop.each do |value|
9
+ iVar << objType.new(value)
10
+ end
11
+ else
12
+ iVar << objType.new(prop)
13
+ end
14
+ end
15
+
16
+ def chkObjAndPopulate(client, iVar, objType, prop)
17
+ return if prop.nil?
18
+ if prop.is_a?(Array)
19
+ prop.each do |value|
20
+ iVar << objType.new(client, value["id"], value)
21
+ end
22
+ else
23
+ iVar << objType.new(client, prop["id"], prop)
24
+ end
25
+ end
26
+
27
+ # Convert a TripIt DateTime Object to a Ruby DateTime Object
28
+ def convertDT(tpitDT)
29
+ return nil if tpitDT.nil?
30
+ date = tpitDT["date"]
31
+ time = tpitDT["time"]
32
+ offset = tpitDT["utc_offset"]
33
+ if time.nil?
34
+ # Just return a date
35
+ Date.parse(tpitDT["date"])
36
+ else
37
+ DateTime.parse(tpitDT["date"] + "T" + tpitDT["time"] + tpitDT["utc_offset"])
38
+ end
39
+ end
40
+
41
+ # Convert object to (crude) XML for create (API does not seem to accept JSON)
42
+ def to_xml
43
+ self.class.name == "TripIt::TpDateTime" ? xmlstr = "<DateTime>" : xmlstr = "<#{self.class.name.split("::").last}>"
44
+ self.respond_to?("sequence") ? arr = self.sequence : arr = self.instance_variables
45
+ arr.each do |key|
46
+ next if key == "@client" # Skip the OAuth client
47
+ value = self.instance_variable_get(key)
48
+ next if value.nil?
49
+ if value.is_a?(Array)
50
+ next if value.empty?
51
+ # We have an array of objects. First get the type of class
52
+ objectType = value.first.class.name.split("::").last
53
+ # Now get all of the objects' to_xml values
54
+ xmlArr = value.map { |mem| mem.to_xml }
55
+ xmlstr << "<#{camelize(key[1..-1])}>#{xmlArr}</#{camelize(key[1..-1])}>"
56
+ elsif value.class.name.split("::").first == "TripIt"
57
+ # If it's a single one of our objects, call its to_xml method
58
+ xmlstr << value.to_xml
59
+ elsif key=~/date_/
60
+ xmlstr << TripIt::TpDateTime.new(value).to_xml
61
+ else
62
+ xmlstr << "<#{key[1..-1]}>#{value}</#{key[1..-1]}>"
63
+ end
64
+ end
65
+ self.class.name == "TripIt::TpDateTime" ? xmlstr << "</DateTime>" : xmlstr << "</#{self.class.name.split("::").last}>"
66
+ end
67
+
68
+ def to_json
69
+ { self.class.name.split("::").last => self.to_hash.to_json }
70
+ end
71
+
72
+ def to_hash
73
+ hash = {}
74
+ self.instance_variables.each do |key|
75
+ next if key == "@client"
76
+ value = self.instance_variable_get(key)
77
+ if value.is_a?(Array)
78
+ # We have an array of objects. First get the type of class
79
+ objectType = value.first.class.name.split("::").last
80
+ # Now get all of the objects' to_hash values
81
+ hashArr = value.map {|mem| mem.to_hash}
82
+ hash[camelize(key[1..-1]).to_sym] = { objectType => hashArr }
83
+ elsif value.class.name.split("::").first == "TripIt"
84
+ # If it's a single one of our objects, call its to_hash method
85
+ hash[camelize(key[1..-1]).to_sym] = value.to_hash
86
+ elsif key=~/date_/
87
+ hash[camelize(key[1..-1]).to_sym] = TripIt::TpDateTime.new(value).to_hash
88
+ else
89
+ hash[key[1..-1].to_sym] = value
90
+ end
91
+ end
92
+ hash
93
+ end
94
+
95
+ def Boolean(string)
96
+ return true if string == true || string =~ /^true$/i
97
+ return false if string == false || string.nil? || string =~ /^false$/i
98
+ raise ArgumentError.new("Invalid value for Boolean: \"#{string}\"")
99
+ end
100
+
101
+ def camelize(word)
102
+ word.split(/[^a-z0-9]/i).map{|w| w.capitalize}.join
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,18 @@
1
+ module TripIt
2
+ class Address < Base
3
+ string_param :address, :addr1, :addr2, :city, :state, :zip, :country
4
+ attr_reader :latitude, :longitude
5
+
6
+ def initialize(params = {})
7
+ @address = params["address"]
8
+ @addr1 = params["addr1"]
9
+ @addr2 = params["addr2"]
10
+ @city = params["city"]
11
+ @state = params["state"]
12
+ @zip = params["zip"]
13
+ @country = params["country"]
14
+ @latitude = params["latitude"]
15
+ @longitude = params["longitude"]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ module TripIt
2
+ class FlightStatus < Base
3
+ attr_reader :scheduled_departure_date_time, :estimated_departure_date_time, :scheduled_arrival_date_time, :estimated_arrival_date_time, \
4
+ :departure_terminal, :departure_gate, :arrival_terminal, :arrival_gate, :layover_minutes, :baggage_claim, \
5
+ :flight_status, :airport_code, :last_modified
6
+ boolean_read_param :is_connection_at_risk
7
+
8
+ def initialize(params = {})
9
+ raise ArgumentError, "FlightStatus created with empty parameters" if params.empty?
10
+
11
+ @scheduled_departure_date_time = convertDT(params["ScheduledDepartureDateTime"])
12
+ @estimated_departure_date_time = convertDT(params["EstimatedDepartureDateTime"])
13
+ @scheduled_arrival_date_time = convertDT(params["ScheduledArrivalDateTime"])
14
+ @estimated_arrival_date_time = convertDT(params["EstimatedArrivalDateTime"])
15
+ @is_connection_at_risk = Boolean(params["is_connection_at_risk"])
16
+ @departure_terminal = params["departure_terminal"]
17
+ @departure_gate = params["departure_gate"]
18
+ @arrival_terminal = params["arrival_terminal"]
19
+ @arrival_gate = params["arrival_gate"]
20
+ @layover_minutes = params["layover_minutes"]
21
+ @baggage_claim = params["baggage_claim"]
22
+ @flight_status = params["flight_status"]
23
+ @airport_code = params["airport_code"]
24
+ @last_modified = params["last_modified"]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ module TripIt
2
+ class Group < Base
3
+ attr_reader :display_name, :url
4
+
5
+ def initialize(params = {})
6
+ raise ArgumentError, "Group created with empty parameters" if params.empty?
7
+
8
+ @display_name = params["display_name"]
9
+ @url = params["url"]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module TripIt
2
+ class Image < Base
3
+ string_param :caption, :url
4
+
5
+ def initialize(params = {})
6
+ @caption = params["caption"]
7
+ @url = params["url"]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ module TripIt
2
+ class Invitee < Base
3
+ attr_reader :profile
4
+ boolean_read_param :is_read_only, :is_traveler
5
+
6
+ def initialize(params, profile)
7
+ raise ArgumentError, "Invitee created with empty parameters" if params.empty?
8
+
9
+ @is_read_only = Boolean(params['is_read_only'])
10
+ @is_traveler = Boolean(params['is_traveler'])
11
+ @profile = profile
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,45 @@
1
+ module TripIt
2
+ class ActivityObject < ReservationObject
3
+ datetime_param :start_date_time
4
+ time_param :end_time
5
+ address_param :address
6
+ traveler_array_param :participant
7
+ string_param :location_name
8
+
9
+ def initialize(client, obj_id = nil, source = nil)
10
+ @client = client
11
+ unless obj_id.nil?
12
+ @obj_id = obj_id
13
+ populate(source)
14
+ end
15
+ end
16
+
17
+ def populate(source)
18
+ info = source || @client.get("/activity", :id => @obj_id)["ActivityObject"]
19
+ super(info)
20
+ @start_date_time = convertDT(info["StartDateTime"])
21
+ @end_time = Time.parse(info["end_time"]) unless info["end_time"].nil?
22
+ @address = TripIt::Address.new(info["Address"]) unless info["Address"].nil?
23
+ @location_name = info["location_name"]
24
+ @detail_type_code = info["detail_type_code"]
25
+ @participant = []
26
+ chkAndPopulate(@participant, TripIt::Traveler, info["Participant"])
27
+ end
28
+
29
+ def detail_type_code
30
+ @detail_type_code
31
+ end
32
+ def detail_type_code=(val)
33
+ if ACTIVITY_DETAIL_TYPE_CODE.has_key?(val)
34
+ @detail_type_code = val
35
+ else
36
+ raise ArgumentError, "detail_type_code must have a valid ACTIVITY_DETAIL_TYPE_CODE"
37
+ end
38
+ end
39
+
40
+ def sequence
41
+ arr = super
42
+ arr + ["@start_date_time", "@end_time", "@address", "@participant", "@detail_type_code", "@location_name"]
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,39 @@
1
+ module TripIt
2
+ class AirObject < ReservationObject
3
+ traveler_array_param :traveler
4
+
5
+ def initialize(client, obj_id = nil, source = nil)
6
+ @client = client
7
+ unless obj_id.nil?
8
+ @obj_id = obj_id
9
+ populate(source)
10
+ end
11
+ end
12
+
13
+ def populate(source)
14
+ info = source || @client.get("/air", :id => @obj_id)["AirObject"]
15
+ super(info)
16
+ @segment = []
17
+ @traveler = []
18
+ chkAndPopulate(@segment, TripIt::AirSegment, info["Segment"])
19
+ chkAndPopulate(@traveler, TripIt::Traveler, info["Traveler"])
20
+ @segment = @segment.sort_by {|seg| seg.start_date_time } unless @segment.empty?
21
+ end
22
+
23
+ def segment
24
+ @segment
25
+ end
26
+ def segment=(val)
27
+ if val.is_a?(Array) && val.all? { |e| AirSegment === e }
28
+ @segment = val
29
+ else
30
+ raise ArgumentError, "Segment must be an Array of AirSegments"
31
+ end
32
+ end
33
+
34
+ def sequence
35
+ arr = super
36
+ arr + ["@segment", "@traveler"]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,31 @@
1
+ module TripIt
2
+ class BaseObject < Base
3
+ attr_reader :id, :relative_url, :is_client_traveler
4
+ integer_param :trip_id
5
+ string_param :display_name
6
+ array_param :image
7
+
8
+ def populate(info)
9
+ return if info.nil? # Make sure we don't raise an error if info is nil
10
+ @id = info["id"]
11
+ @relative_url = info["relative_url"]
12
+ @trip_id = info["trip_id"]
13
+ @is_client_traveler = Boolean(info["is_client_traveler"])
14
+ @display_name = info["display_name"]
15
+ @image = []
16
+ chkAndPopulate(@image, TripIt::Image, info["Image"])
17
+ end
18
+
19
+ def save
20
+ if @obj_id.nil?
21
+ @client.create(self.to_xml)
22
+ else
23
+ @client.replace("/#{self.class.name.split("::").last.gsub("Object","").downcase}/id/#{@obj_id}", self.to_xml)
24
+ end
25
+ end
26
+
27
+ def sequence
28
+ ["@trip_id","@display_name", "@image"]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ module TripIt
2
+ class CarObject < ReservationObject
3
+ datetime_param :start_date_time, :end_date_time
4
+ address_param :start_location_address, :end_location_address
5
+ string_param :start_location_hours, :start_location_name, :start_location_phone, :end_location_hours, :end_location_name, :end_location_phone, \
6
+ :car_description, :car_type, :mileage_charges
7
+ traveler_param :driver
8
+
9
+ def initialize(client, obj_id = nil, source = nil)
10
+ @client = client
11
+ unless obj_id.nil?
12
+ @obj_id = obj_id
13
+ populate(source)
14
+ end
15
+ end
16
+
17
+ def populate(source)
18
+ info = source || @client.get("/car", :id => @obj_id)["CarObject"]
19
+ super(info)
20
+ @start_date_time = convertDT(info["StartDateTime"])
21
+ @end_date_time = convertDT(info["EndDateTime"])
22
+ @start_location_address = TripIt::Address.new(info["start_location_address"]) unless info["start_location_address"].nil?
23
+ @end_location_address = TripIt::Address.new(info["end_location_address"]) unless info["end_location_address"].nil?
24
+ @start_location_hours = info["start_location_hours"]
25
+ @start_location_name = info["start_location_name"]
26
+ @start_location_phone = info["start_location_phone"]
27
+ @end_location_hours = info["end_location_hours"]
28
+ @end_location_name = info["end_location_name"]
29
+ @end_location_phone = info["end_location_phone"]
30
+ @car_description = info["car_description"]
31
+ @car_type = info["car_type"]
32
+ @mileage_charges = info["mileage_charges"]
33
+ @driver = TripIt::Traveler.new(info["Driver"]) unless info["Driver"].nil?
34
+ end
35
+
36
+ def sequence
37
+ arr = super
38
+ arr + ["@start_date_time", "@end_date_time", "@start_location_address", "@end_location_address", "@driver",
39
+ "@start_location_hours", "@start_location_name", "@start_location_phone", "@end_location_hours",
40
+ "@end_location_name", "@end_location_phone", "@car_description", "@car_type", "@mileage_charges"]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,44 @@
1
+ module TripIt
2
+ class CruiseObject < ReservationObject
3
+ traveler_array_param :traveler
4
+ string_param :cabin_number, :cabin_type, :dining, :ship_name
5
+
6
+ def initialize(client, obj_id = nil, source = nil)
7
+ @client = client
8
+ unless obj_id.nil?
9
+ @obj_id = obj_id
10
+ populate(source)
11
+ end
12
+ end
13
+
14
+ def populate(source)
15
+ info = source || @client.get("/cruise", :id => @obj_id)["CruiseObject"]
16
+ super(info)
17
+ @segment = []
18
+ @traveler = []
19
+ @cabin_number = info["cabin_number"]
20
+ @cabin_type = info["cabin_type"]
21
+ @dining = info["dining"]
22
+ @ship_name = info["ship_name"]
23
+ chkAndPopulate(@segment, TripIt::CruiseSegment, info["Segment"])
24
+ chkAndPopulate(@traveler, TripIt::Traveler, info["Traveler"])
25
+ @segment = @segment.sort_by {|seg| seg.start_date_time } unless @segment.empty?
26
+ end
27
+
28
+ def segment
29
+ @segment
30
+ end
31
+ def segment=(val)
32
+ if val.is_a?(Array) && val.all? { |e| CruiseSegment === e }
33
+ @segment = val
34
+ else
35
+ raise ArgumentError, "Segment must be an Array of CruiseSegments"
36
+ end
37
+ end
38
+
39
+ def sequence
40
+ arr = super
41
+ arr + ["@segment", "@traveler", "@cabin_number", "@cabin_type", "@dining", "@ship_name"]
42
+ end
43
+ end
44
+ end