Class: CompanyHelper

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

Instance Method Summary collapse

Instance Method Details

#update_companies_batch(api_controller, debug, company_profiles) ⇒ Object



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
54
55
# File 'lib/moesif_aws_lambda/update_company.rb', line 27

def update_companies_batch(api_controller, debug, company_profiles)
    companyModels = []
    company_profiles.each { |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
    }

    if companyModels.any?
        begin
            api_controller.update_companies_batch(companyModels)
            if debug
            puts "Update Companies Successfully"
            end
        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
24
25
# File 'lib/moesif_aws_lambda/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))
            if debug
                puts "Update Company Successfully"
            end
            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