Class: CompanyHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/moesif_rack/update_company.rb

Instance Method Summary collapse

Instance Method Details

#update_companies_batch(api_controller, debug, company_profiles) ⇒ Object



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
# File 'lib/moesif_rack/update_company.rb', line 25

def update_companies_batch(api_controller, debug, company_profiles)
  companyModels = []
  company_profiles.each do |company|
    if company.key?('company_id')
      companyModels << MoesifApi::CompanyModel.from_hash(company)
    else
      puts 'To update a company, a company_id field is required'
    end
  end

  if companyModels.any?
    begin
      api_controller.update_companies_batch(companyModels)
      puts 'Update Companies Successfully' if debug
    rescue MoesifApi::APIException => e
      if e.response_code.between?(401, 403)
        puts 'Unathorized accesss updating companies to Moesif. Please verify your Application Id.'
      end
      if debug
        puts 'Error updating companies to Moesif, with status code: '
        puts e.response_code
      end
    end
  else
    puts 'Expecting the input to be of the type - Array of hashes while updating companies in batch'
  end
end

#update_company(api_controller, debug, company_profile) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/moesif_rack/update_company.rb', line 2

def update_company(api_controller, debug, company_profile)
  if company_profile.any?
    if company_profile.key?('company_id')
      begin
        api_controller.update_company(MoesifApi::CompanyModel.from_hash(company_profile))
        puts 'Update Company Successfully' if debug
      rescue MoesifApi::APIException => e
        if e.response_code.between?(401, 403)
          puts 'Unathorized accesss updating company to Moesif. Please verify your Application Id.'
        end
        if debug
          puts 'Error updating company to Moesif, with status code: '
          puts e.response_code
        end
      end
    else
      puts 'To update a company, a company_id field is required'
    end
  else
    puts 'Expecting the input to be of the type - dictionary while updating user'
  end
end