Method: Condensr#initialize

Defined in:
lib/condensr.rb

#initialize(client_options) ⇒ Condensr

Returns a new instance of Condensr.



12
13
14
15
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
# File 'lib/condensr.rb', line 12

def initialize(client_options)
  # for a rails application, we should have this config in initializers/condensr.rb as follows
  # CONDENSR = Condensr.new(  {
  # aws: {
  #     access_key_id: 'akid',
  #     secret_access_key: 'secret',
  #     region: 'us-west-1',
  #     bucket: bucket_name
  # },
  # gcloud: {
  #     project_id:project_Id,
  #     key_file: path to key.json relative from the present working dir,
  #     bucket: bucket_name
  # }
  # })
  # so we can call the object CONDENSR from any part of the application
  fail ArgumentError.new("client options are missing") if client_options.empty?
  @client_options = client_options
  if (@client_options[:aws])
    Aws.config.update({
                          region: @client_options[:aws][:region],
                          credentials: Aws::Credentials.new(@client_options[:aws][:access_key_id], @client_options[:aws][:secret_access_key])
                      })
  end

  if (@client_options[:gcloud])
    key_file =  Pathname.pwd + @client_options[:gcloud][:key_file] if  @client_options[:gcloud][:key_file]
    @gcloud = Gcloud.new(@client_options[:gcloud][:project_id],  @client_options[:gcloud][:key] || key_file)
  end
end