Class: AdobeConnect::Service
- Inherits:
-
Object
- Object
- AdobeConnect::Service
- Defined in:
- lib/adobe_connect/service.rb
Overview
Public: Manages calls to the Connect API.
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#password ⇒ Object
readonly
private
Returns the value of attribute password.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#authenticated? ⇒ Boolean
Public: Get the current authentication status.
-
#client ⇒ Object
Public: Get the HTTP client used to make requests.
-
#initialize(options = AdobeConnect::Config) ⇒ Service
constructor
Public: Create a new AdobeConnect::Service.
-
#log_in ⇒ Object
Public: Authenticate against the currently configured Connect service.
-
#method_missing(method, *args) ⇒ Object
Public: Forward any missing methods to the Connect instance.
-
#request(action, params = {}, use_session = true) ⇒ Object
private
Public: Execute a call against the Adobe Connect instance.
Constructor Details
#initialize(options = AdobeConnect::Config) ⇒ Service
Public: Create a new AdobeConnect::Service.
options - An AdobeConnect::Config object or a hash with the keys:
:username - An Adobe Connect username.
:password - The Connect user's password.
:domain - The domain for the Connect instance (with protocol
prepended).
14 15 16 17 18 19 20 |
# File 'lib/adobe_connect/service.rb', line 14 def initialize( = AdobeConnect::Config) @username = [:username] @password = [:password] @domain = URI.parse([:domain]) @authenticated = false @client = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Public: Forward any missing methods to the Connect instance.
method - The name of the method called. *args - An array of arguments passed to the method.
Examples
service = AdobeConnect::Service.new
service.sco_by_url(url_path: '/example/') #=> calls service.request.
Returns an AdobeConnect::Response.
66 67 68 69 70 71 |
# File 'lib/adobe_connect/service.rb', line 66 def method_missing(method, *args) action = method.to_s.dasherize params = args.first request(action, params) end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
5 6 7 |
# File 'lib/adobe_connect/service.rb', line 5 def domain @domain end |
#password ⇒ Object (readonly, private)
Returns the value of attribute password.
74 75 76 |
# File 'lib/adobe_connect/service.rb', line 74 def password @password end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
5 6 7 |
# File 'lib/adobe_connect/service.rb', line 5 def session @session end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
5 6 7 |
# File 'lib/adobe_connect/service.rb', line 5 def username @username end |
Instance Method Details
#authenticated? ⇒ Boolean
Public: Get the current authentication status.
Returns a boolean.
39 40 41 |
# File 'lib/adobe_connect/service.rb', line 39 def authenticated? @authenticated end |
#client ⇒ Object
Public: Get the HTTP client used to make requests.
Returns a Net::HTTP instance.
46 47 48 49 50 51 52 53 |
# File 'lib/adobe_connect/service.rb', line 46 def client if @client.nil? @client = Net::HTTP.new(domain.host, domain.port) @client.use_ssl = (domain.scheme == 'https') end @client end |
#log_in ⇒ Object
Public: Authenticate against the currently configured Connect service.
Returns a boolean.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/adobe_connect/service.rb', line 25 def log_in response = request('login', { :login => username, :password => password }, false) if response.at_xpath('//status').attr('code') == 'ok' session_regex = /BREEZESESSION=([^;]+)/ @session = response.fetch('set-cookie').match(session_regex)[1] @authenticated = true else false end end |
#request(action, params = {}, use_session = true) ⇒ Object (private)
Public: Execute a call against the Adobe Connect instance.
action - The name of the API action to call. params - A hash of params to pass in the request. The value of the :extra_query_string param will be
appended to the request URL. This is sometimes necessary because the API allows for repeated
parameters and sometimes the order of the parameters is important.
use_session - If true, require an active session (default: true).
Returns an AdobeConnect::Response.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/adobe_connect/service.rb', line 85 def request(action, params={}, use_session = true) if use_session log_in unless authenticated? params[:session] = session end if params[:extra_query_string] extra_query_string = params[:extra_query_string] raise 'Invalid argument. extra_query_string should start with &.' unless extra_query_string.start_with?('&') params.delete :extra_query_string end query_string = ParamFormatter.new(params).format response = client.get("/api/xml?action=#{action}#{query_string}#{extra_query_string}") AdobeConnect::Response.new(response) end |