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
Returns a new instance of 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
111 112 113 |
# File 'lib/toolhound-ruby/client.rb', line 111 def inventory @inventory ||= Toolhound::Inventory.new(self) end |
#inventory_item ⇒ Object
115 116 117 |
# File 'lib/toolhound-ruby/client.rb', line 115 def inventory_item @inventory_item ||= Toolhound::InventoryItem.new(self) end |
#job ⇒ Object
103 104 105 |
# File 'lib/toolhound-ruby/client.rb', line 103 def job @job ||= Toolhound::Job.new(self) end |
#manufacturer ⇒ Object
141 142 143 |
# File 'lib/toolhound-ruby/client.rb', line 141 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.
208 209 210 211 212 |
# File 'lib/toolhound-ruby/client.rb', line 208 def nearmiss_warn(*) unless ENV['TOOLHOUND_SILENT'] warn end end |
#project ⇒ Object
123 124 125 |
# File 'lib/toolhound-ruby/client.rb', line 123 def project @project ||= Toolhound::Project.new(self) end |
#purchase_order ⇒ Object
144 145 146 |
# File 'lib/toolhound-ruby/client.rb', line 144 def purchase_order @vendor ||= Toolhound::PurchaseOrder.new(self) end |
#purchase_receipt ⇒ Object
119 120 121 |
# File 'lib/toolhound-ruby/client.rb', line 119 def purchase_receipt @purchase_receipt ||= Toolhound::PurchaseReceipt.new(self) end |
#query(query, options = {}) ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/toolhound-ruby/client.rb', line 150 def query(query, = {}) klass = self results = connection.execute(query) results.map do |row| transform_attributes(row) end end |
#rental ⇒ Object
127 128 129 |
# File 'lib/toolhound-ruby/client.rb', line 127 def rental @rental ||= Toolhound::Rental.new(self) end |
#rental_charge ⇒ Object
134 135 136 |
# File 'lib/toolhound-ruby/client.rb', line 134 def rental_charge @rental_charge ||= Toolhound::RentalCharge.new(self) end |
#rental_item ⇒ Object
131 132 133 |
# File 'lib/toolhound-ruby/client.rb', line 131 def rental_item @rental_item ||= Toolhound::RentalItem.new(self) end |
#reset_connection ⇒ Object
99 100 101 |
# File 'lib/toolhound-ruby/client.rb', line 99 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
107 108 109 |
# File 'lib/toolhound-ruby/client.rb', line 107 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”
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# 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) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 |
# 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 |