Class: Reporting

Inherits:
Object
  • Object
show all
Includes:
ConfigReader
Defined in:
lib/reporting.rb

Constant Summary collapse

@@instance =
nil

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConfigReader

#config_dir, #config_file, #mkdir, #param, #user_file

Constructor Details

#initialize ⇒ Reporting

Returns a new instance of Reporting.



25
26
27
28
29
30
31
32
# File 'lib/reporting.rb', line 25

def initialize
  rest_base_url = param("rest_base_url")
  if (rest_base_url.nil? || rest_base_url.length == 0)
    raise "configuration file does not contain expected parameters -- try config init"
  end
  @common = CommonRestUtils.new(rest_base_url + "reporting/")
  @uri_customers_segment = "customers/" + param("acct-num") + "/"
end

Class Method Details

.do ⇒ Object



21
22
23
# File 'lib/reporting.rb', line 21

def self.do
  @@instance ? @@instance : @@instance = Reporting.new
end

Instance Method Details

#customer_suffix(word) ⇒ Object



54
55
56
# File 'lib/reporting.rb', line 54

def customer_suffix(word)
  @uri_customers_segment + word
end

#get_all_data_transferred(begin_time, end_time, *pops) ⇒ Object



66
67
68
# File 'lib/reporting.rb', line 66

def get_all_data_transferred(begin_time, end_time, *pops)
  @common.callMethod(interval_suffix("bytestransferred", begin_time, end_time) + to_csv("&pops=", pops), :get)
end

#get_asset_activity(media_type, begin_time, end_time) ⇒ Object



70
71
72
# File 'lib/reporting.rb', line 70

def get_asset_activity(media_type, begin_time, end_time)
  @common.callMethod(media_suffix(media_type, "filestats", begin_time, end_time), :get)
end

#get_billing_regions ⇒ Object



74
75
76
# File 'lib/reporting.rb', line 74

def get_billing_regions
  @common.callMethod("billing/regions", :get)
end

#get_cache_status_activity(media_type, begin_time, end_time) ⇒ Object



78
79
80
# File 'lib/reporting.rb', line 78

def get_cache_status_activity(media_type, begin_time, end_time)
  @common.callMethod(media_suffix(media_type, "cachestats", begin_time, end_time), :get)
end

#get_current_storage_usage ⇒ Object



82
83
84
# File 'lib/reporting.rb', line 82

def get_current_storage_usage
  @common.callMethod(customer_suffix("lateststorageusage"), :get)
end

#get_customer_account_number(custom_id) ⇒ Object



86
87
88
# File 'lib/reporting.rb', line 86

def (custom_id)
  @common.callMethod("customers/accountnumber?customercustomid=" + custom_id, :get)
end

#get_customer_name ⇒ Object



90
91
92
# File 'lib/reporting.rb', line 90

def get_customer_name
  @common.callMethod(customer_suffix("customername"), :get)
end

#get_data_transferred_and_hits_by_custom_report_codes(media_type, begin_time, end_time) ⇒ Object



94
95
96
# File 'lib/reporting.rb', line 94

def get_data_transferred_and_hits_by_custom_report_codes(media_type, begin_time, end_time)
  @common.callMethod(media_suffix(media_type, "cnamereportcodes", begin_time, end_time), :get)
end

#get_data_transferred_by_platform(media_type, begin_time, end_time, *pops) ⇒ Object



98
99
100
# File 'lib/reporting.rb', line 98

def get_data_transferred_by_platform(media_type, begin_time, end_time, *pops)
  @common.callMethod(media_suffix(media_type, "bytestransferred", begin_time, end_time) + to_csv("&pops=", pops), :get)
end

#get_data_transferred_by_platform_and_interval(media_type, begin_time, end_time, region_id, interval_id, *pops) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/reporting.rb', line 102

def get_data_transferred_by_platform_and_interval(media_type, begin_time, end_time, region_id, interval_id, *pops)
  suffix = interval_suffix("bytestransferred/interval", begin_time, end_time);
  if (media_type)
    suffix = suffix + "&mediatypeid=" + media_type.to_s
  end
  if (interval_id)
    suffix = suffix + "&intervalid=" + interval_id.to_s
  end
  suffix = suffix + to_csv("&pops=", pops)
  if (region_id)
    suffix = suffix + "&regionid=" + region_id.to_s
  end
  puts "suffix: " + suffix
  @common.callMethod(suffix, :get)
end

#get_directory_activity(media_type, begin_time, end_time) ⇒ Object



118
119
120
# File 'lib/reporting.rb', line 118

def get_directory_activity(media_type, begin_time, end_time)
  @common.callMethod(media_suffix(media_type, "directorystats", begin_time, end_time), :get)
end

#get_download_activity(media_type, begin_time, end_time) ⇒ Object



122
123
124
# File 'lib/reporting.rb', line 122

def get_download_activity(media_type, begin_time, end_time)
  @common.callMethod(media_suffix(media_type, "completedownloads", begin_time, end_time), :get)
end

#get_maximum_storage_usage(begin_time, end_time) ⇒ Object



126
127
128
# File 'lib/reporting.rb', line 126

def get_maximum_storage_usage(begin_time, end_time)
  @common.callMethod(interval_suffix("maxstorageusage", begin_time, end_time), :get)
end

#get_report_codes(media_type) ⇒ Object



130
131
132
133
134
135
136
# File 'lib/reporting.rb', line 130

def get_report_codes(media_type)
  suffix = customer_suffix("reportcodes")
  if (media_type)
    suffix = suffix + "?mediatypeid=" + media_type.to_s
  end
  @common.callMethod(suffix, :get)
end

#get_traffic_usage(media_type, region_id, units, billing_month) ⇒ Object



138
139
140
141
142
143
# File 'lib/reporting.rb', line 138

def get_traffic_usage(media_type, region_id, units, billing_month)
  suffix = @uri_customers_segment +
    "media/" + media_type.to_s + "/region/" + region_id.to_s + "/units/" + units.to_s + "/trafficusage" +
    "?begindate=" + billing_month.strftime("%Y-%m-01")
  @common.callMethod(suffix, :get)
end

#interval(begin_time, end_time) ⇒ Object



50
51
52
# File 'lib/reporting.rb', line 50

def interval(begin_time, end_time)
  "?begindate=" + time_to_q(begin_time) + "&enddate=" + time_to_q(end_time)
end

#interval_suffix(word, begin_time, end_time) ⇒ Object



58
59
60
# File 'lib/reporting.rb', line 58

def interval_suffix(word, begin_time, end_time)
  @uri_customers_segment + word + interval(begin_time, end_time)
end

#media_suffix(media_type, word, begin_time, end_time) ⇒ Object



62
63
64
# File 'lib/reporting.rb', line 62

def media_suffix(media_type, word, begin_time, end_time)
  @uri_customers_segment + "media/" + media_type.to_s + "/" + word + interval(begin_time, end_time)
end

#time_to_q(time) ⇒ Object



46
47
48
# File 'lib/reporting.rb', line 46

def time_to_q(time)
  time.strftime("%Y-%m-%dT%H:%M:%S")
end

#to_csv(prefix, pops_list) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/reporting.rb', line 34

def to_csv(prefix, pops_list)
  result = ""
  if (pops_list.count > 0)
    result = prefix + pops_list[0]
    pops_list.shift
    pops_list.each { |pop|
      result = result + "," + pop
    }
  end
  result
end