class RestforceMock::Client
Public Class Methods
new(opts = {})
click to toggle source
# File lib/restforce_mock/client.rb, line 11 def initialize(opts = {}) end
Public Instance Methods
api_get(url, attrs = nil)
click to toggle source
# File lib/restforce_mock/client.rb, line 18 def api_get(url, attrs = nil) url=~/sobjects\/(.+)\/(.+)/ object=$1 id=$2 if !attrs.nil? && url == 'query' query = attrs.values.first response = get_object_from_query(query) return Body.new(response, url) else response = get_object(object, id) return Body.new(response) end end
api_patch(url, attrs)
click to toggle source
# File lib/restforce_mock/client.rb, line 33 def api_patch(url, attrs) url=~/sobjects\/(.+)\/(.+)/ object=$1 id=$2 validate_schema!(object) validate_presence!(object, id) update_object(object, id, attrs) end
api_post(url, attrs)
click to toggle source
# File lib/restforce_mock/client.rb, line 42 def api_post(url, attrs) url=~/sobjects\/(.+)/ sobject = $1 id = ::SecureRandom.urlsafe_base64(13) #duplicates possible validate_schema!(sobject) validate_requires!(sobject, attrs) add_object(sobject, id, attrs) return Body.new(id) end
mashify?()
click to toggle source
# File lib/restforce_mock/client.rb, line 14 def mashify? true end
validate_presence!(object, id)
click to toggle source
# File lib/restforce_mock/client.rb, line 69 def validate_presence!(object, id) unless RestforceMock::Sandbox.storage[object][id] msg = "Provided external ID field does not exist or is not accessible: #{id}" raise Faraday::Error::ResourceNotFound.new(msg) end end
validate_requires!(sobject, attrs)
click to toggle source
# File lib/restforce_mock/client.rb, line 52 def validate_requires!(sobject, attrs) return unless RestforceMock.configuration.schema_file return unless RestforceMock.configuration.error_on_required object_schema = schema[sobject] required = object_schema. select{|k,v|v[:required]}. collect{|k,v|k}. collect(&:to_sym) missing = required - attrs.keys - RestforceMock.configuration.required_exclusions if missing.length > 0 raise Faraday::Error::ResourceNotFound.new( "REQUIRED_FIELD_MISSING: Required fields are missing: #{missing}") end end
validate_schema!(object)
click to toggle source
# File lib/restforce_mock/client.rb, line 76 def validate_schema!(object) if RestforceMock.configuration.raise_on_schema_missing unless schema[object] raise RestforceMock::Error.new("No schema for Salesforce object #{object}") end end end
Private Instance Methods
schema()
click to toggle source
# File lib/restforce_mock/client.rb, line 86 def schema @schema ||= begin manager = RestforceMock::SchemaManager.new begin manager.load_schema(RestforceMock.configuration.schema_file) rescue Errno::ENOENT raise RestforceMock::Error.new("No schema for Salesforce object is available") end end end