class XporterOnDemand::Registration
Constants
- SCHOOL_ATTRIBUTES
Attributes
app_management_secret[RW]
message[R]
partner_id[RW]
registration_type[RW]
schools[R]
Public Class Methods
new(args = {}) { |self| ... }
click to toggle source
# File lib/xporter_on_demand/registration.rb, line 46 def initialize(args = {}) @schools = Set.new if block_given? yield self else @registration_type = args[:registration_type] || 'Live' @partner_id = args[:partner_id] @app_management_secret = args[:app_management_secret] end end
Public Instance Methods
add_school(param_hash = {})
click to toggle source
# File lib/xporter_on_demand/registration.rb, line 58 def add_school(param_hash = {}) attributes = SCHOOL_ATTRIBUTES.each_with_object({}) do |key, hash| hash[key] = param_hash[key] end @schools << School.new(attributes) end
generate_hash(secret: @app_management_secret, timestamp:, content: to_json)
click to toggle source
# File lib/xporter_on_demand/registration.rb, line 104 def generate_hash(secret: @app_management_secret, timestamp:, content: to_json) raise ArgumentError, 'Must supply your App Management Secret' unless secret raise ArgumentError, 'Must supply at least one school' if @schools.empty? b64 = Base64.strict_encode64(content + timestamp + secret) sha256 = OpenSSL::Digest.new('sha256') OpenSSL::HMAC.hexdigest(sha256, secret, b64).upcase end
get_school(lea, dfes)
click to toggle source
# File lib/xporter_on_demand/registration.rb, line 96 def get_school(lea, dfes) @schools.find{ |sch| sch.lea_code == lea && sch.dfes_code == dfes } end
register()
click to toggle source
# File lib/xporter_on_demand/registration.rb, line 66 def register timestamp = DateTime.current.strftime("%FT%T%z") auth = generate_hash(timestamp: timestamp) args = { url: REGISTRATION_PATH, headers: { 'ApplicationId': @partner_id, 'DateTime': timestamp, 'Authorization': "Groupcall #{auth}", }, body: to_json, } response = post(args) if response['Schools'] response['Schools'].all? do |school| s = get_school(school['LeaCode'], school['DfesCode']) s.status = school['Status'] s.message = school['Message'] school['Status'] == 'OK' end else @message = response['Message'] false end end
to_json()
click to toggle source
# File lib/xporter_on_demand/registration.rb, line 100 def to_json { Schools: @schools.map(&:camelize), RegistrationType: @registration_type }.to_json end