class Toolhound::Client

Constants

DB_TYPE_REGEX

Attributes

connection[RW]

def projects

end attr_accessor :access_token, :client_id, :uid, :expiry, :me

dataserver[RW]

def projects

end attr_accessor :access_token, :client_id, :uid, :expiry, :me

password[RW]

def projects

end attr_accessor :access_token, :client_id, :uid, :expiry, :me

port[RW]

def projects

end attr_accessor :access_token, :client_id, :uid, :expiry, :me

username[RW]

def projects

end attr_accessor :access_token, :client_id, :uid, :expiry, :me

Public Class Methods

new(options = {}) click to toggle source
# File lib/toolhound-ruby/client.rb, line 40
def initialize(options = {})

  # Use options passed in, but fall back to module defaults
  Toolhound::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", options[key] || Toolhound.instance_variable_get(:"@#{key}"))
  end

  sign_in if authenticatable?
end

Public Instance Methods

inventory() click to toggle source
# File lib/toolhound-ruby/client.rb, line 111
def inventory
  @inventory ||= Toolhound::Inventory.new(self)
end
inventory_item() click to toggle source
# File lib/toolhound-ruby/client.rb, line 115
def inventory_item
  @inventory_item ||= Toolhound::InventoryItem.new(self)
end
job() click to toggle source
# File lib/toolhound-ruby/client.rb, line 103
def job
  @job ||= Toolhound::Job.new(self)
end
manufacturer() click to toggle source
# File lib/toolhound-ruby/client.rb, line 141
def manufacturer
  @vendor ||= Toolhound::Manufacturer.new(self)
end
nearmiss_warn(*message) click to toggle source

Wrapper around Kernel#warn to print warnings unless TOOLHOUND_SILENT is set to true.

@return [nil]

# File lib/toolhound-ruby/client.rb, line 208
def nearmiss_warn(*message)
  unless ENV['TOOLHOUND_SILENT']
    warn message
  end
end
password=(value) click to toggle source

Set password for authentication

@param value [String] Toolhound-field password

# File lib/toolhound-ruby/client.rb, line 94
def password=(value)
  reset_connection
  @password = value
end
project() click to toggle source
# File lib/toolhound-ruby/client.rb, line 123
def project
  @project ||= Toolhound::Project.new(self)
end
purchase_order() click to toggle source
# File lib/toolhound-ruby/client.rb, line 144
def purchase_order
  @vendor ||= Toolhound::PurchaseOrder.new(self)
end
purchase_receipt() click to toggle source
# File lib/toolhound-ruby/client.rb, line 119
def purchase_receipt
  @purchase_receipt ||= Toolhound::PurchaseReceipt.new(self)
end
query(query, options = {}) click to toggle source
# File lib/toolhound-ruby/client.rb, line 150
def query(query, options = {})
  klass = self



  results = connection.execute(query)
  results.map do |row|
    transform_attributes(row)
  end
end
rental() click to toggle source
# File lib/toolhound-ruby/client.rb, line 127
def rental
  @rental ||= Toolhound::Rental.new(self)
end
rental_charge() click to toggle source
# File lib/toolhound-ruby/client.rb, line 134
def rental_charge
  @rental_charge ||= Toolhound::RentalCharge.new(self)
end
rental_item() click to toggle source
# File lib/toolhound-ruby/client.rb, line 131
def rental_item
  @rental_item ||= Toolhound::RentalItem.new(self)
end
reset_connection() click to toggle source
# File lib/toolhound-ruby/client.rb, line 99
def reset_connection
  @connection = nil
end
same_options?(opts) click to toggle source

Compares client options to a Hash of requested options

@param opts [Hash] Options to compare with current client options @return [Boolean]

# File lib/toolhound-ruby/client.rb, line 54
def same_options?(opts)
  opts.hash == options.hash
end
transaction() click to toggle source
# File lib/toolhound-ruby/client.rb, line 107
def transaction
  @transaction ||= Toolhound::Transaction.new(self)
end
transform_attribute_key(key) click to toggle source

“SELECT MAX(dteStartDate) AS max_date, MIN(dteStartDate) AS min_date FROM tblRentalCharge WHERE intEntityID = 100044”

# File lib/toolhound-ruby/client.rb, line 185
def transform_attribute_key(key)
  # renamed = self.class.renamed_attributes
  # if renamed.include? key
  #   renamed[key].to_sym
  # elsif key == self.class.primary_key
  #   :id
  # else
  # # "varTransferReceiptPrefix"
  #   word = key[3..key.length]
  #   word.underscore.to_sym
  # end
  word = key
  if DB_TYPE_REGEX =~ key
    word = key[3..key.length]
  end
  underscore(word).to_sym
end
transform_attributes(attrs) click to toggle source
# File lib/toolhound-ruby/client.rb, line 161
def transform_attributes(attrs)
  hash = {}
  attrs.each do |k, v|
    key = transform_attribute_key(k)
    if hash.include? key
      hash[:"#{key}1"] = v
    else
      hash[key] = v
    end
  end
  hash
end
username=(value) click to toggle source

Set username for authentication

@param value [String] Toolhound-field username

# File lib/toolhound-ruby/client.rb, line 86
def username=(value)
  reset_connection
  @email = value
end
vendor() click to toggle source
# File lib/toolhound-ruby/client.rb, line 138
def vendor
  @vendor ||= Toolhound::Vendor.new(self)
end