Class: IMS::LTI::Services::ToolProxyRegistrationService

Inherits:
Object
  • Object
show all
Defined in:
lib/ims/lti/services/tool_proxy_registration_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(registration_request) ⇒ ToolProxyRegistrationService

Returns a new instance of ToolProxyRegistrationService.



3
4
5
# File 'lib/ims/lti/services/tool_proxy_registration_service.rb', line 3

def initialize(registration_request)
  @registration_request = registration_request
end

Instance Method Details

#register_tool_proxy(tool_proxy, reregistration_confirm_url = nil, shared_secret = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ims/lti/services/tool_proxy_registration_service.rb', line 19

def register_tool_proxy(tool_proxy, reregistration_confirm_url = nil, shared_secret = nil)
  service = tool_consumer_profile.services_offered.find { |s| s.formats.include?('application/vnd.ims.lti.v2.toolproxy+json') && s.actions.include?('POST') }

  SimpleOAuth::Header::ATTRIBUTE_KEYS << :body_hash unless SimpleOAuth::Header::ATTRIBUTE_KEYS.include? :body_hash
  tool_proxy_json = tool_proxy.to_json
  body_hash = Digest::SHA1.base64digest tool_proxy_json

  if reregistration?
    consumer_key = tool_proxy.tool_proxy_guid
    consumer_secret = shared_secret
  else
    consumer_key = @registration_request.reg_key
    consumer_secret = @registration_request.reg_password
  end

  conn = Faraday.new do |conn|
    conn.request :oauth, {:consumer_key => consumer_key, :consumer_secret => consumer_secret, :body_hash => body_hash}
    conn.adapter :net_http
  end

  response = conn.post do |req|
    req.url service.endpoint
    req.headers['Content-Type'] = 'application/vnd.ims.lti.v2.toolproxy+json'
    req.headers['VND-IMS-CONFIRM-URL'] = reregistration_confirm_url if reregistration_confirm_url
    req.body = tool_proxy_json
  end

  if response.status == 201 || (response.status == 200 && reregistration?)
    IMS::LTI::Models::ToolProxy.new.from_json(tool_proxy.to_json).from_json(response.body)
  else
    raise IMS::LTI::Errors::ToolProxyRegistrationError.new(response.status, response.body)
  end
end

#remove_invalid_capabilities!(message_handler) ⇒ Object



54
55
56
57
58
59
# File 'lib/ims/lti/services/tool_proxy_registration_service.rb', line 54

def remove_invalid_capabilities!(message_handler)
  {
    invalid_capabilities: remove_capabilites!(message_handler),
    invalid_parameters: remove_params!(message_handler)
  }
end

#service_profilesObject



15
16
17
# File 'lib/ims/lti/services/tool_proxy_registration_service.rb', line 15

def service_profiles
  tool_consumer_profile.services_offered.map(&:profile)
end

#tool_consumer_profileObject



7
8
9
10
11
12
13
# File 'lib/ims/lti/services/tool_proxy_registration_service.rb', line 7

def tool_consumer_profile
  return @tool_consumer_profile if @tool_consumer_profile

  connection = Faraday.new
  response = connection.get(@registration_request.tc_profile_url)
  @tool_consumer_profile = IMS::LTI::Models::ToolConsumerProfile.new.from_json(response.body)
end