|
| 1 | +module Restforce |
| 2 | + class << self |
| 3 | + attr_writer :log |
| 4 | + |
| 5 | + # Returns the current Configuration |
| 6 | + # |
| 7 | + # Example |
| 8 | + # |
| 9 | + # Restforce.configuration.username = "username" |
| 10 | + # Restforce.configuration.password = "password" |
| 11 | + def configuration |
| 12 | + @configuration ||= Configuration.new |
| 13 | + end |
| 14 | + |
| 15 | + # Yields the Configuration |
| 16 | + # |
| 17 | + # Example |
| 18 | + # |
| 19 | + # Restforce.configure do |config| |
| 20 | + # config.username = "username" |
| 21 | + # config.password = "password" |
| 22 | + # end |
| 23 | + def configure |
| 24 | + yield configuration |
| 25 | + end |
| 26 | + |
| 27 | + def log? |
| 28 | + @log ||= false |
| 29 | + end |
| 30 | + |
| 31 | + def log(message) |
| 32 | + return unless Restforce.log? |
| 33 | + Restforce.configuration.logger.send :debug, message |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + class Configuration |
| 38 | + attr_accessor :api_version |
| 39 | + # The username to use during login. |
| 40 | + attr_accessor :username |
| 41 | + # The password to use during login. |
| 42 | + attr_accessor :password |
| 43 | + # The security token to use during login. |
| 44 | + attr_accessor :security_token |
| 45 | + # The OAuth client id |
| 46 | + attr_accessor :client_id |
| 47 | + # The OAuth client secret |
| 48 | + attr_accessor :client_secret |
| 49 | + # Set this to true if you're authenticating with a Sandbox instance. |
| 50 | + # Defaults to false. |
| 51 | + attr_accessor :host |
| 52 | + |
| 53 | + attr_accessor :oauth_token |
| 54 | + attr_accessor :refresh_token |
| 55 | + attr_accessor :instance_url |
| 56 | + |
| 57 | + def initialize |
| 58 | + @api_version ||= '24.0' |
| 59 | + @host ||= 'login.salesforce.com' |
| 60 | + end |
| 61 | + |
| 62 | + def logger |
| 63 | + @logger ||= ::Logger.new STDOUT |
| 64 | + end |
| 65 | + end |
| 66 | +end |
0 commit comments