Class: Sbuilder::Interfaces::Salesforce::Reader
- Inherits:
-
Object
- Object
- Sbuilder::Interfaces::Salesforce::Reader
- Includes:
- Logger
- Defined in:
- lib/sbuilder/reader.rb
Instance Attribute Summary collapse
-
#describes ⇒ Object
readonly
[Hash:SObjectName->Describe].
Instance Method Summary collapse
- #client ⇒ Object
-
#connect ⇒ Restforce
Create connection object to sales force.
-
#describe(sObject, &blk) ⇒ Object
cache ‘sObject’ describes, use ‘&blk’ to read if given (allow file cache).
-
#initialize(options = {}) ⇒ Reader
constructor
—————————————————————— constructore.
Methods included from Logger
Constructor Details
#initialize(options = {}) ⇒ Reader
constructore
24 25 26 27 28 |
# File 'lib/sbuilder/reader.rb', line 24 def initialize( ={} ) @describes = {} # init logger logger().info "initialized" end |
Instance Attribute Details
#describes ⇒ Object (readonly)
- Hash:SObjectName->Describe
15 16 17 |
# File 'lib/sbuilder/reader.rb', line 15 def describes @describes end |
Instance Method Details
#client ⇒ Object
46 47 48 |
# File 'lib/sbuilder/reader.rb', line 46 def client connect end |
#connect ⇒ Restforce
Create connection object to sales force
36 37 38 39 40 41 42 43 |
# File 'lib/sbuilder/reader.rb', line 36 def connect( ) @client ||= Restforce.new :username => Config.configuration.username, :password => Config.configuration.password, :security_token => Config.configuration.security_token, :client_id => Config.configuration.client_id, :client_secret => Config.configuration.client_secret, :api_version => Config.configuration.api_version # "34.0" end |
#describe(sObject, &blk) ⇒ Object
cache ‘sObject’ describes, use ‘&blk’ to read if given (allow file cache)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sbuilder/reader.rb', line 55 def describe( sObject, &blk ) logger.info "#{__method__}: sObject=#{sObject}" # object cache? return describes[ sObject] unless describes[ sObject].nil? logger.info "#{__method__}: not cached - sObject=#{sObject}" # try file cachke if block_ive if block_given? logger.info "#{__method__}: block given, does yield have a cache for sObject=#{sObject}" describes[ sObject] = yield( sObject ) end if describes[sObject] logger.info "#{__method__}: yield did return cached object=#{sObject}" return describes[ sObject] end # access salesforce logger.info "#{__method__}: not cached - read start=#{sObject}" describes[ sObject] = client.describe( sObject ) logger.info "#{__method__}: not cached - read done=#{sObject}" return describes[ sObject] end |