|
2 | 2 | require 'cgi' |
3 | 3 | require 'rexml/document' |
4 | 4 | require 'digest/sha1' |
| 5 | +require 'digest/sha2' |
5 | 6 | require 'rubygems' |
6 | 7 | require 'bigbluebutton_hash_to_xml' |
7 | 8 | require 'bigbluebutton_exception' |
8 | 9 | require 'bigbluebutton_formatter' |
9 | 10 | require 'bigbluebutton_modules' |
10 | | -require 'bigbluebutton_config_xml' |
11 | | -require 'bigbluebutton_config_layout' |
12 | 11 | require 'logger' |
13 | 12 |
|
14 | 13 | module BigBlueButton |
@@ -68,13 +67,17 @@ class BigBlueButtonApi |
68 | 67 | # url:: URL to a BigBlueButton server (e.g. http://demo.bigbluebutton.org/bigbluebutton/api) |
69 | 68 | # secret:: Shared secret for this server |
70 | 69 | # version:: API version e.g. 0.81 |
71 | | - def initialize(url, secret, version=nil, logger=nil) |
| 70 | + # logger:: Logger object to log actions (so apps can use their own loggers) |
| 71 | + # sha256:: Flag to use sha256 when hashing url contents for checksum |
| 72 | + def initialize(url, secret, version=nil, logger=nil, sha256=false) |
72 | 73 | @supported_versions = ['0.8', '0.81', '0.9', '1.0'] |
73 | | - @url = url |
| 74 | + @url = url.chomp('/') |
74 | 75 | @secret = secret |
75 | 76 | @timeout = 10 # default timeout for api requests |
76 | 77 | @request_headers = {} # http headers sent in all requests |
77 | 78 | @logger = logger |
| 79 | + @sha256 = sha256 |
| 80 | + # If logger is not informed, it defaults to STDOUT with INFO level |
78 | 81 | if logger.nil? |
79 | 82 | @logger = Logger.new(STDOUT) |
80 | 83 | @logger.level = Logger::INFO |
@@ -545,88 +548,10 @@ def delete_recordings(recordIDs, options={}) |
545 | 548 | send_api_request(:deleteRecordings, params) |
546 | 549 | end |
547 | 550 |
|
548 | | - |
549 | | - # |
550 | | - # API calls since 0.81 |
551 | | - # |
552 | | - |
553 | | - # Retrieves the default config.xml file from the server. |
554 | | - # Returns the XML as a string by default, but if `asObject` is set to true, returns the XML |
555 | | - # parsed as an XmlSimple object (). |
556 | | - # asObject (Hash):: If true, returns the XML parsed as an XmlSimple object, using: |
557 | | - # data = XmlSimple.xml_in(response, { 'ForceArray' => false, 'KeepRoot' => true }) |
558 | | - # You can then parse it back into an XML string using: |
559 | | - # XmlSimple.xml_out(data, { 'RootName' => nil, 'XmlDeclaration' => true }) |
560 | | - # If set to false, returns the XML as a string. |
561 | | - # options (Hash):: Hash with additional parameters. This method doesn't accept additional |
562 | | - # parameters, but if you have a custom API with more parameters, you |
563 | | - # can simply pass them in this hash and they will be added to the API call. |
564 | | - def get_default_config_xml(asObject=false, options={}) |
565 | | - response = send_api_request(:getDefaultConfigXML, options, nil, true) |
566 | | - if asObject |
567 | | - XmlSimple.xml_in(response, { 'ForceArray' => false, 'KeepRoot' => true }) |
568 | | - else |
569 | | - response |
570 | | - end |
571 | | - end |
572 | | - |
573 | | - # Sets a config.xml file in the server. |
574 | | - # Returns the token returned by the server (that can be later used in a 'join' call) in case |
575 | | - # of success. |
576 | | - # meeting_id (string):: The ID of the meeting where this config.xml will be used. |
577 | | - # xml (string|BigBlueButtonConfigXml):: The XML that should be sent as a config.xml. |
578 | | - # It will usually be an edited output of the default config.xml: |
579 | | - # xml = api.get_default_config_xml |
580 | | - # Or you can use directly a BigBlueButtonConfigXml object: |
581 | | - # BigBlueButtonConfigXml.new(xml) |
582 | | - # options (Hash):: Hash with additional parameters. This method doesn't accept additional |
583 | | - # parameters, but if you have a custom API with more parameters, you |
584 | | - # can simply pass them in this hash and they will be added to the API call. |
585 | | - # TODO: Right now we are sending the configXML parameters in the URL and in the body of the POST |
586 | | - # request. It works if left only in the URL, but the documentation of the API claims that it has |
587 | | - # to be in the body of the request. So it's no clear yet and this might change in the future. |
588 | | - def set_config_xml(meeting_id, xml, options={}) |
589 | | - if xml.instance_of?(BigBlueButton::BigBlueButtonConfigXml) |
590 | | - data = xml.as_string |
591 | | - else |
592 | | - data = xml |
593 | | - end |
594 | | - params = { :meetingID => meeting_id, :configXML => data }.merge(options) |
595 | | - response = send_api_request(:setConfigXML, params, data) |
596 | | - response[:configToken] |
597 | | - end |
598 | | - |
599 | | - |
600 | 551 | # |
601 | 552 | # Helper functions |
602 | 553 | # |
603 | 554 |
|
604 | | - # Returns an array with the name of all layouts available in the server. |
605 | | - # Will fetch the config.xml file (unless passed in the arguments), fetch the |
606 | | - # layout definition file, and return the layouts. |
607 | | - # If something goes wrong, returns nil. Otherwise returns the list of layout |
608 | | - # names or an empty array if there's no layout defined. |
609 | | - def get_available_layouts(config_xml=nil) |
610 | | - config_xml = get_default_config_xml if config_xml.nil? |
611 | | - config_xml = BigBlueButton::BigBlueButtonConfigXml.new(config_xml) |
612 | | - layout_config = config_xml.get_attribute("LayoutModule", "layoutConfig", true) |
613 | | - unless layout_config.nil? |
614 | | - response = send_request(layout_config) |
615 | | - layout_config = BigBlueButton::BigBlueButtonConfigLayout.new(response.body) |
616 | | - layout_config.get_available_layouts |
617 | | - else |
618 | | - nil |
619 | | - end |
620 | | - end |
621 | | - |
622 | | - # Returns an array with the layouts that exist by default in a BigBlueButton |
623 | | - # server. If you want to query the server to get a real list of layouts, use |
624 | | - # <tt>get_available_layouts</tt>. |
625 | | - def get_default_layouts |
626 | | - # this is the list for BigBlueButton 0.81 |
627 | | - ["Default", "Video Chat", "Meeting", "Webinar", "Lecture assistant", "Lecture"] |
628 | | - end |
629 | | - |
630 | 555 | # Make a simple request to the server to test the connection. |
631 | 556 | def test_connection |
632 | 557 | response = send_api_request(:index) |
@@ -680,17 +605,12 @@ def get_url(method, params={}) |
680 | 605 | # checksum calc |
681 | 606 | checksum_param = params_string + @secret |
682 | 607 | checksum_param = method.to_s + checksum_param |
683 | | - checksum = Digest::SHA1.hexdigest(checksum_param) |
| 608 | + checksum = @sha256 ? Digest::SHA256.hexdigest(checksum_param) : Digest::SHA1.hexdigest(checksum_param) |
684 | 609 |
|
685 | | - if method == :setConfigXML |
686 | | - params_string = "checksum=#{checksum}&#{params_string}" |
687 | | - return "#{@url}/#{method}", params_string |
688 | | - else |
689 | | - url = "#{@url}/#{method}?" |
690 | | - url += "#{params_string}&" unless params_string.empty? |
691 | | - url += "checksum=#{checksum}" |
692 | | - return url, nil |
693 | | - end |
| 610 | + url = "#{@url}/#{method}?" |
| 611 | + url += "#{params_string}&" unless params_string.empty? |
| 612 | + url += "checksum=#{checksum}" |
| 613 | + return url, nil |
694 | 614 | end |
695 | 615 |
|
696 | 616 | # Performs an API call. |
|
0 commit comments