Module: ElephantDrive::ResponseBuilder

Included in:
BaseService
Defined in:
lib/elephant-drive-service/response_builder.rb

Instance Method Summary collapse

Instance Method Details

#generate_add_customer_response(add_extractor, password_change_extractor) ⇒ Object



12
13
14
# File 'lib/elephant-drive-service/response_builder.rb', line 12

def generate_add_customer_response add_extractor, password_change_extractor
  { installed_user_id: add_extractor[:g_user_id], reset_password_url: ElephantDriveService.user_portal_domain + ElephantDriveService.change_password_path(password_change_extractor[:message]) }
end

#generate_average_usage_report_response(extractor) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/elephant-drive-service/response_builder.rb', line 16

def generate_average_usage_report_response extractor
  {data: [], 
   total_capacity: 0.0, 
   total_active_usage: 0.0,
   total_inactive_usage: 0.0,
   total_usage_percentage: 0.0,
   total_active_usage_percentage: 0.0,
   total_inactive_usage_percentage: 0.0}.tap do |report|
    [extractor[:ds][:diffgram].fetch(:new_data_set,{}).fetch(:table,[])].flatten.select { |h| h[:str_email] }.each do |user|
      {
        display_name: user[:str_display_name],
        email: user[:str_email],
        installed_user_id: user[:g_user_id],
        status: user[:str_account_state],
        total_capacity: user[:l_capacity_b].to_f,
        total_usage: user[:l_usage_b].to_f || 0.0
      }.tap { |entry|
        entry[:usage_percentage] = entry[:total_usage] / entry[:total_capacity]

        if entry[:status] =~ /^Suspended|Active/i
          report[:total_capacity] += entry[:total_capacity]
          case entry[:status]
            when /^Active/i
              report[:total_active_usage] += entry[:total_usage]
              report[:total_active_usage_percentage] = entry[:total_usage] / entry[:total_capacity]
            when /^Suspended/i
              report[:total_inactive_usage] += entry[:total_usage]
              report[:total_inactive_usage_percentage] = entry[:total_usage] / entry[:total_capacity]
          end
        end

        report[:data] << entry
      }
    end

    report[:total_usage_percentage] = ((report[:total_active_usage] + report[:total_inactive_usage]) / report[:total_capacity]).round(2) if report[:total_capacity] > 0.0
  end
end

#generate_usage_statistics(extractor) ⇒ Object



5
6
7
8
9
10
# File 'lib/elephant-drive-service/response_builder.rb', line 5

def generate_usage_statistics extractor
  total_capacity = extractor[:l_capacity_bytes].to_f
  total_usage = [extractor[:l_active_length].to_f,extractor[:l_version_length].to_f,extractor[:l_trash_length].to_f].inject(:+)

  { total_capacity: total_capacity, total_usage: total_usage, usage_rate: total_usage/total_capacity }
end