Class: Sbuilder::Interfaces::Salesforce::Reader

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/sbuilder/reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#logger

Constructor Details

#initialize(options = {}) ⇒ Reader


constructore



24
25
26
27
28
# File 'lib/sbuilder/reader.rb', line 24

def initialize( options={} )
  @describes = {}
  # init logger
  logger(options).info "initialized"
end

Instance Attribute Details

#describesObject (readonly)

Hash:SObjectName->Describe


15
16
17
# File 'lib/sbuilder/reader.rb', line 15

def describes
  @describes
end

Instance Method Details

#clientObject



46
47
48
# File 'lib/sbuilder/reader.rb', line 46

def client
  connect
end

#connectRestforce

Create connection object to sales force

Returns:

  • (Restforce)

    client object



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