Sha256: 96099caeb5757ad2a85e2377d5f34dba7ef969d5343bb605ae862311830ce35e

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require 'mongo'

#class for communication with mongo database for iot API
class MongoIot

  attr_accessor :mongoip, :mongoport, :client, :database

  def initialize(mongoip, mongoport, iotip, database)
    @database = database
    @mongoip = mongoip
    @mongoport = mongoport
    @iotip = iotip
    client_host = [mongoip + ":" + mongoport]
    @client = Mongo::Client.new(client_host, :database => database)
  end

  def audit_logger(proc_name)
    begin
    collection = client[:audit]
    doc = {
        proc_name: proc_name,
        hobbies: [ 'hiking', 'tennis', 'fly fishing' ],
        siblings: {
            brothers: 0,
            sisters: 1
        }
    }
    result = collection.insert_one(doc)
    p result
    rescue
      continue
    end
  end

  def ttt
    p "111111"
    begin
      puts(client.cluster.inspect)
      puts('Collection Names: ')
      puts(client.database.collection_names)
      puts('Connected!')
      collection = client[:audit]
      doc = {
          name: 'Steve',
          hobbies: [ 'hiking', 'tennis', 'fly fishing' ],
          siblings: {
              brothers: 0,
              sisters: 1
          }
      }
      result = collection.insert_one(doc)
      p result
      client.close
    rescue StandardError => err
      puts('Error: ')
      puts(err)
    end



  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
imperituroard-0.1.9 lib/imperituroard/projects/iot/mongoconnector.rb