Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added reports
ij committed Sep 14, 2017
1 parent e1a81d4 commit 728e06c
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/sf.rb
@@ -20,6 +20,7 @@
require "sf/venue"
require "sf/opportunity"
require "sf/service_institution"
require "sf/report"
module Sf
class << self
def client
40 changes: 40 additions & 0 deletions lib/sf/report.rb
@@ -0,0 +1,40 @@
class Sf::Report
include Sf::Base

def self.eduroam_subscribers
rpt_url = "#{ENV['SF_RPT_BASE_URL']}/#{ENV['SF_RPT_EDUROAM_SUBSCRIBERS']}?includeDetails=true"
result = Sf.client.get(rpt_url)
report = {}
if content = result.body
# data, error, meta
data_rows = content.factMap["T!T"]["rows"]
rpt_metadata = content.reportMetadata
report[:meta] = {
name: rpt_metadata.name,
columns: rpt_metadata.detailColumns,
count: data_rows.size,
id: rpt_metadata.id,
}
report[:data] = data_rows_to_hash(data_rows, report[:meta])
report[:error] = {}
else
report[:data] = []
report[:meta] = {}
report[:error] = {err: "Error"}
end
report
end

private

def self.data_rows_to_hash(data_rows, meta)
columns = meta[:columns]
data_rows.map do |row|
item = {}
0.upto(columns.size - 1) do |i|
item[columns[i]] = row.dataCells[i].label
end
item
end
end
end
2 changes: 1 addition & 1 deletion lib/sf/version.rb
@@ -1,3 +1,3 @@
module Sf
VERSION = "0.1.51"
VERSION = "0.1.52"
end

0 comments on commit 728e06c

Please sign in to comment.