Class: ConcurConnect::ExpenseReportFinder

Inherits:
Object
  • Object
show all
Includes:
Finder
Defined in:
lib/concur_connect/expense_report_finder.rb

Constant Summary collapse

STATUSES =
%w{RECENT UNSUBMITTED PENDING APPROVED PROCESSED PAID
PAYMENTCONFIRMED FORTHISMONTH FORLASTMONTH FORTHISQUARTER
FORLASTQUARTER FORTHISYEAR FORLASTYEAR TOAPPROVE APPROVEDTHISMONTH
APPROVEDLASTMONTH APPROVEDTHISQUARTER APPROVEDLASTQUARTER
APPROVEDTHISYEAR APPROVEDLASTYEAR}

Instance Attribute Summary

Attributes included from Finder

#session

Instance Method Summary collapse

Methods included from Finder

#initialize

Instance Method Details

#build_expense_reports(data) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/concur_connect/expense_report_finder.rb', line 26

def build_expense_reports(data)
  list = []
  if data['ReportsList'] && data['ReportsList']['ReportSummary']
    items = data['ReportsList']['ReportSummary']
    items = [items] unless items.is_a?(Array)
    items.each do |datum|
      expense_report = ExpenseReport.new
      expense_report.id = datum['ReportId']
      expense_report.name = datum['ReportName']
      expense_report.date = datum['ReportDate']
      expense_report.details_url = datum['Report_Details_Url']
      expense_report.session = session
      list << expense_report
    end
  end
  list
end

#find(user_id = nil, status = 'APPROVED', date = nil) ⇒ Object

status: status string defined in STATUSES date: a Date/Time object for filtering



17
18
19
20
21
22
23
24
# File 'lib/concur_connect/expense_report_finder.rb', line 17

def find(user_id = nil, status = 'APPROVED', date = nil)
  url = "/api/expense/expensereport/v1.1/reportslist/#{status}"
  url += "/LastModified?date=#{date.strftime('%Y-%m-%d')}" if date
  response = session.get url do |g|
    g.headers['X-UserID'] = user_id if user_id
  end
  build_expense_reports response.body
end