class OpenStax::Exchange::FakeClient

Public Class Methods

configuration() click to toggle source
# File lib/openstax/exchange/fake_client/fake_client.rb, line 15
def self.configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/openstax/exchange/fake_client/fake_client.rb, line 11
def self.configure
  yield configuration
end
new(exchange_configuration) click to toggle source
# File lib/openstax/exchange/fake_client/fake_client.rb, line 19
def initialize(exchange_configuration)
  @client_config_platform_id     = exchange_configuration.client_platform_id
  @client_config_platform_secret = exchange_configuration.client_platform_secret
  @client_config_server_url      = exchange_configuration.client_server_url
  @client_config_api_version     = exchange_configuration.client_api_version

  @server_registered_platforms   = self.class.configuration.registered_platforms
  @server_server_url             = self.class.configuration.server_url

  raise "invalid server url" \
    unless @client_config_server_url == @server_server_url

  raise "invalid platform credentials" \
    unless @server_registered_platforms.fetch(@client_config_platform_id) == @client_config_platform_secret

  @token = SecureRandom.hex(64)
  @multiple_choice_responses = {}
  @grades = {}
end

Public Instance Methods

create_identifiers() click to toggle source
# File lib/openstax/exchange/fake_client/fake_client.rb, line 47
def create_identifiers
  Hashie::Mash.new(
    'read' => SecureRandom.hex(64),
    'write' => SecureRandom.hex(64)
  )
end
is_real_client?() click to toggle source
# File lib/openstax/exchange/fake_client/fake_client.rb, line 39
def is_real_client?
  false
end
record_grade(identifier, resource, trial, grade, grader) click to toggle source
# File lib/openstax/exchange/fake_client/fake_client.rb, line 71
def record_grade(identifier, resource, trial, grade, grader)
  host = URI(resource).host
  raise "invalid resource" unless host =~ /openstax\.org\z|localhost\z/

  @grades[identifier] ||= {}
  @grades[identifier][resource] ||= {}
  @grades[identifier][resource][trial] ||= []
  @grades[identifier][resource][trial] << {grade: grade, grader: grader}

  return {
    'identifier' => identifier,
    'resource'   => resource,
    'trial'      => trial,
    'grade'      => grade,
    'grader'     => grader
  }
end
record_multiple_choice_answer(identifier, resource, trial, answer) click to toggle source
# File lib/openstax/exchange/fake_client/fake_client.rb, line 54
def record_multiple_choice_answer(identifier, resource, trial, answer)
  host = URI(resource).host
  raise "invalid resource" unless host =~ /openstax\.org\z|localhost\z/

  @multiple_choice_responses[identifier] ||= {}
  @multiple_choice_responses[identifier][resource] ||= {}
  @multiple_choice_responses[identifier][resource][trial] ||= []
  @multiple_choice_responses[identifier][resource][trial] << answer

  return {
    'identifier' => identifier,
    'resource'   => resource,
    'trial'      => trial,
    'answer'     => answer
  }
end
token() click to toggle source
# File lib/openstax/exchange/fake_client/fake_client.rb, line 43
def token
  @token
end