Class: Linkshare::CustomReports

Inherits:
Object
  • Object
show all
Defined in:
lib/linkshare/custom_reports.rb

Instance Method Summary collapse

Instance Method Details

#fetchReports(reportname, bdate, edate, network, tz = "America%2FNew_York", date_type = 'transaction', include_summary = "N") ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/linkshare/custom_reports.rb', line 16

def fetchReports(reportname, bdate, edate, network, tz="America%2FNew_York", date_type='transaction', include_summary="N")
   token = Linkshare.custom_report_token
   url = Linkshare::API_URIS[:custom_reports]+'/'+reportname+'/filters?start_date='+bdate+'&end_date='+edate+'&include_summary='+include_summary+'&network='+network.to_s+'&tz='+tz+'&date_type='+date_type+'&token='+token
   @reportsRows = []
   @reportsCSV = open(url).read()
   reportsrows = @reportsCSV.force_encoding("UTF-8").gsub("\"",'').split(/\n/)
   if reportsrows[1].match(/^\{code\:.*\}$/)
     raise 'Linkshare Error (custom report): ' + reportsrows[1]
   end
   @cols = reportsrows[0].split(/,/)
   reportsrows.shift
   reportsrows.each { |row|
     r = {}
     split_row = row.split(/,/)
     @cols.each_with_index { | o, i|
       r[@cols[i]]=split_row[i]
     }
     @reportsRows.push(r)
   }
   @reportsRows
end

#getCSVObject



9
10
11
# File 'lib/linkshare/custom_reports.rb', line 9

def getCSV
  @reportsCSV
end

#getReportsObject



13
14
15
# File 'lib/linkshare/custom_reports.rb', line 13

def getReports
  @reportsRows
end

#initilizeObject



4
5
6
7
8
# File 'lib/linkshare/custom_reports.rb', line 4

def initilize()
  @reportsCSV = ''
  @reportsRows = []
  @cols = []
end