Class: Toolhound::Client
- Inherits:
-
Object
- Object
- Toolhound::Client
- Includes:
- Authentication, Projects, Configurable, Util
- Defined in:
- lib/toolhound-ruby/client.rb,
lib/toolhound-ruby/client/users.rb,
lib/toolhound-ruby/client/projects.rb
Defined Under Namespace
Constant Summary collapse
- DB_TYPE_REGEX =
/^(int|dec|var|bol|dte|bin)/
Instance Attribute Summary collapse
-
#connection ⇒ Object
def projects.
-
#dataserver ⇒ Object
def projects.
-
#password ⇒ Object
def projects.
-
#port ⇒ Object
def projects.
-
#username ⇒ Object
def projects.
Attributes included from Configurable
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#inspect ⇒ Object
:nodoc:.
- #inventory ⇒ Object
- #inventory_item ⇒ Object
- #job ⇒ Object
- #manufacturer ⇒ Object
-
#nearmiss_warn(*message) ⇒ nil
Wrapper around Kernel#warn to print warnings unless TOOLHOUND_SILENT is set to true.
- #project ⇒ Object
- #purchase_order ⇒ Object
- #purchase_receipt ⇒ Object
- #query(query, options = {}) ⇒ Object
- #rental ⇒ Object
- #rental_charge ⇒ Object
- #rental_item ⇒ Object
- #reset_connection ⇒ Object
-
#same_options?(opts) ⇒ Boolean
Compares client options to a Hash of requested options.
- #transaction ⇒ Object
-
#transform_attribute_key(key) ⇒ Object
“SELECT MAX(dteStartDate) AS max_date, MIN(dteStartDate) AS min_date FROM tblRentalCharge WHERE intEntityID = 100044”.
- #transform_attributes(attrs) ⇒ Object
- #vendor ⇒ Object
Methods included from Projects
Methods included from Util
#acronym_regex, #acronyms, #camelize, #demodulize, #underscore
Methods included from Configurable
#configure, keys, #options, #reset!
Methods included from Authentication
#authenticatable?, #reconnect, #sign_in, #sign_out
Constructor Details
#initialize(options = {}) ⇒ Client
40 41 42 43 44 45 46 47 48 |
# File 'lib/toolhound-ruby/client.rb', line 40 def initialize( = {}) # Use options passed in, but fall back to module defaults Toolhound::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", [key] || Toolhound.instance_variable_get(:"@#{key}")) end sign_in if authenticatable? end |
Instance Attribute Details
#connection ⇒ Object
def projects
end attr_accessor :access_token, :client_id, :uid, :expiry, :me
38 39 40 |
# File 'lib/toolhound-ruby/client.rb', line 38 def connection @connection end |
#dataserver ⇒ Object
def projects
end attr_accessor :access_token, :client_id, :uid, :expiry, :me
38 39 40 |
# File 'lib/toolhound-ruby/client.rb', line 38 def dataserver @dataserver end |
#password ⇒ Object
def projects
end attr_accessor :access_token, :client_id, :uid, :expiry, :me
38 39 40 |
# File 'lib/toolhound-ruby/client.rb', line 38 def password @password end |
#port ⇒ Object
def projects
end attr_accessor :access_token, :client_id, :uid, :expiry, :me
38 39 40 |
# File 'lib/toolhound-ruby/client.rb', line 38 def port @port end |
#username ⇒ Object
def projects
end attr_accessor :access_token, :client_id, :uid, :expiry, :me
38 39 40 |
# File 'lib/toolhound-ruby/client.rb', line 38 def username @username end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/toolhound-ruby/client.rb', line 59 def inspect # :nodoc: inspected = super # mask password inspected = inspected.gsub! @password, "*******" if @password # Only show last 4 of token, secret # if @access_token # inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}" # end # if @client_secret # inspected = inspected.gsub! @client_secret, "#{'*'*36}#{@client_secret[36..-1]}" # end inspected end |
#inventory ⇒ Object
112 113 114 |
# File 'lib/toolhound-ruby/client.rb', line 112 def inventory @inventory ||= Toolhound::Inventory.new(self) end |
#inventory_item ⇒ Object
116 117 118 |
# File 'lib/toolhound-ruby/client.rb', line 116 def inventory_item @inventory_item ||= Toolhound::InventoryItem.new(self) end |
#job ⇒ Object
104 105 106 |
# File 'lib/toolhound-ruby/client.rb', line 104 def job @job ||= Toolhound::Job.new(self) end |
#manufacturer ⇒ Object
142 143 144 |
# File 'lib/toolhound-ruby/client.rb', line 142 def manufacturer @vendor ||= Toolhound::Manufacturer.new(self) end |
#nearmiss_warn(*message) ⇒ nil
Wrapper around Kernel#warn to print warnings unless TOOLHOUND_SILENT is set to true.
209 210 211 212 213 |
# File 'lib/toolhound-ruby/client.rb', line 209 def nearmiss_warn(*) unless ENV['TOOLHOUND_SILENT'] warn end end |
#project ⇒ Object
124 125 126 |
# File 'lib/toolhound-ruby/client.rb', line 124 def project @project ||= Toolhound::Project.new(self) end |
#purchase_order ⇒ Object
145 146 147 |
# File 'lib/toolhound-ruby/client.rb', line 145 def purchase_order @vendor ||= Toolhound::PurchaseOrder.new(self) end |
#purchase_receipt ⇒ Object
120 121 122 |
# File 'lib/toolhound-ruby/client.rb', line 120 def purchase_receipt @purchase_receipt ||= Toolhound::PurchaseReceipt.new(self) end |
#query(query, options = {}) ⇒ Object
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/toolhound-ruby/client.rb', line 151 def query(query, = {}) klass = self results = connection.execute(query) results.map do |row| transform_attributes(row) end end |
#rental ⇒ Object
128 129 130 |
# File 'lib/toolhound-ruby/client.rb', line 128 def rental @rental ||= Toolhound::Rental.new(self) end |
#rental_charge ⇒ Object
135 136 137 |
# File 'lib/toolhound-ruby/client.rb', line 135 def rental_charge @rental_charge ||= Toolhound::RentalCharge.new(self) end |
#rental_item ⇒ Object
132 133 134 |
# File 'lib/toolhound-ruby/client.rb', line 132 def rental_item @rental_item ||= Toolhound::RentalItem.new(self) end |
#reset_connection ⇒ Object
100 101 102 |
# File 'lib/toolhound-ruby/client.rb', line 100 def reset_connection @connection = nil end |
#same_options?(opts) ⇒ Boolean
Compares client options to a Hash of requested options
54 55 56 |
# File 'lib/toolhound-ruby/client.rb', line 54 def (opts) opts.hash == .hash end |
#transaction ⇒ Object
108 109 110 |
# File 'lib/toolhound-ruby/client.rb', line 108 def transaction @transaction ||= Toolhound::Transaction.new(self) end |
#transform_attribute_key(key) ⇒ Object
“SELECT MAX(dteStartDate) AS max_date, MIN(dteStartDate) AS min_date FROM tblRentalCharge WHERE intEntityID = 100044”
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/toolhound-ruby/client.rb', line 186 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) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/toolhound-ruby/client.rb', line 162 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 |
#vendor ⇒ Object
139 140 141 |
# File 'lib/toolhound-ruby/client.rb', line 139 def vendor @vendor ||= Toolhound::Vendor.new(self) end |