Class: XporterOnDemand::Registration
- Inherits:
-
Object
- Object
- XporterOnDemand::Registration
- Includes:
- Utils
- Defined in:
- lib/xporter_on_demand/registration.rb
Defined Under Namespace
Classes: School
Constant Summary collapse
- SCHOOL_ATTRIBUTES =
i( lea_code dfes_code school_name school_contact_first_name school_contact_last_name school_contact_email school_contact_phone school_contact school_technical_contact_name school_technical_contact_email school_technical_contact_phone partner_application_id partner_name partner_registered_email we_accept_groupcall_usage_policy )
Instance Attribute Summary collapse
-
#app_management_secret ⇒ Object
Returns the value of attribute app_management_secret.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#partner_id ⇒ Object
Returns the value of attribute partner_id.
-
#registration_type ⇒ Object
Returns the value of attribute registration_type.
-
#schools ⇒ Object
readonly
Returns the value of attribute schools.
Instance Method Summary collapse
- #add_school(param_hash = {}) ⇒ Object
- #generate_hash(secret: @app_management_secret, timestamp:, content: to_json) ⇒ Object
- #get_school(lea, dfes) ⇒ Object
-
#initialize(args = {}) ⇒ Registration
constructor
A new instance of Registration.
- #register ⇒ Object
- #to_json ⇒ Object
Methods included from Utils
#assign_attributes, #configure_request, #create_result, #dont_raise_exception, #handle_exceptions, #parameterize, #unwrap
Constructor Details
#initialize(args = {}) ⇒ Registration
46 47 48 49 50 51 52 53 54 55 56 |
# 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 |
Instance Attribute Details
#app_management_secret ⇒ Object
Returns the value of attribute app_management_secret.
10 11 12 |
# File 'lib/xporter_on_demand/registration.rb', line 10 def app_management_secret @app_management_secret end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
9 10 11 |
# File 'lib/xporter_on_demand/registration.rb', line 9 def end |
#partner_id ⇒ Object
Returns the value of attribute partner_id.
10 11 12 |
# File 'lib/xporter_on_demand/registration.rb', line 10 def partner_id @partner_id end |
#registration_type ⇒ Object
Returns the value of attribute registration_type.
10 11 12 |
# File 'lib/xporter_on_demand/registration.rb', line 10 def registration_type @registration_type end |
#schools ⇒ Object (readonly)
Returns the value of attribute schools.
9 10 11 |
# File 'lib/xporter_on_demand/registration.rb', line 9 def schools @schools end |
Instance Method Details
#add_school(param_hash = {}) ⇒ Object
58 59 60 61 62 63 64 |
# 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) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# 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 + + secret) sha256 = OpenSSL::Digest.new('sha256') OpenSSL::HMAC.hexdigest(sha256, secret, b64).upcase end |
#get_school(lea, dfes) ⇒ Object
96 97 98 |
# 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 ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/xporter_on_demand/registration.rb', line 66 def register = DateTime.current.strftime("%FT%T%z") auth = generate_hash(timestamp: ) args = { url: REGISTRATION_PATH, headers: { 'ApplicationId': @partner_id, 'DateTime': , '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. = school['Message'] school['Status'] == 'OK' end else = response['Message'] false end end |
#to_json ⇒ Object
100 101 102 |
# File 'lib/xporter_on_demand/registration.rb', line 100 def to_json { Schools: @schools.map(&:camelize), RegistrationType: @registration_type }.to_json end |