Class: ConcurConnect::ItineraryFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/concur_connect/itinerary_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ ItineraryFinder

Returns a new instance of ItineraryFinder.



7
8
9
# File 'lib/concur_connect/itinerary_finder.rb', line 7

def initialize(session)
  self.session = session
end

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



5
6
7
# File 'lib/concur_connect/itinerary_finder.rb', line 5

def session
  @session
end

Instance Method Details

#build_itineraries(data) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/concur_connect/itinerary_finder.rb', line 20

def build_itineraries(data)
  list = []
  if data['ItineraryInfoList'] && data['ItineraryInfoList']['ItineraryInfo']
    data['ItineraryInfoList']['ItineraryInfo'].each do |datum|
      itinerary = Itinerary.new
      itinerary.concur_id = datum['id']
      itinerary.name = datum['TripName']
      itinerary.start_date = datum['StartDateLocal']
      itinerary.end_date = datum['EndDateLocal']
      list << itinerary
    end
  end
  list
end

#find(user_id, start_date = nil) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/concur_connect/itinerary_finder.rb', line 11

def find(user_id, start_date = nil)
  url = 'travel/trip/v1.0/'
  url += "?startDate=#{start_date.strftime('%Y-%m-%d')}" if start_date
  response = session.get url do |g|
    g.headers['X-UserID'] = user_id
  end
  build_itineraries response.body
end