Class: Echo360::Echo360
- Inherits:
-
Object
- Object
- Echo360::Echo360
- Defined in:
- lib/echo-connector.rb
Instance Method Summary collapse
- #createUser(user_id, password, first_name, last_name, role, email) ⇒ Object
- #get_user(user_id) ⇒ Object
- #get_users ⇒ Object
-
#initialize(site, consumer_key, consumer_secret, organisation = 0) ⇒ Echo360
constructor
A new instance of Echo360.
Constructor Details
#initialize(site, consumer_key, consumer_secret, organisation = 0) ⇒ Echo360
Returns a new instance of Echo360.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/echo-connector.rb', line 7 def initialize(site, consumer_key, consumer_secret, organisation = 0) consumer = OAuth::Consumer.new consumer_key, consumer_secret, { :site => site, :request_token_path => "", :authorize_path => "", :access_token_path => "", :http_method => :get } @access_token = OAuth::AccessToken.new consumer @organisation = getOrganizations[organisation][:id] end |
Instance Method Details
#createUser(user_id, password, first_name, last_name, role, email) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/echo-connector.rb', line 43 def createUser user_id, password, first_name, last_name, role, email builder = Nokogiri::XML::Builder.new do |xml| xml.person { xml.send(:"first-name", first_name) xml.send(:"last-name", last_name) xml.send(:"email-address", email) xml.role role xml.credentials { xml.send(:"user-name", user_id) xml.password password } xml.send(:"organization-roles") { xml.send(:"organization-role") { xml.send(:"organization-id", @organisation) xml.role role } } } end rsp = @access_token.post("/ess/scheduleapi/v1/people", builder.to_xml,{ 'Accept' => 'application/xml', 'Content-Type' => 'application/xml' }) !rsp.value end |
#get_user(user_id) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/echo-connector.rb', line 32 def get_user user_id users_xml = get_users_xml person = users_xml.xpath("/people/person[user-name/text() = \"#{user_id}\"]")[0] raise "User not found: #{user_id}" if person.nil? id = person.search('id')[0].content first_name = person.search('first-name')[0].content last_name = person.search('last-name')[0].content user_id = person.search('user-name')[0].content { id: id, first_name: first_name, last_name: last_name, user_id: user_id } end |
#get_users ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/echo-connector.rb', line 19 def get_users users_xml = get_users_xml users = Array.new users_xml.xpath("/people/person").each do |person| id = person.search('id')[0].content first_name = person.search('first-name')[0].content last_name = person.search('last-name')[0].content user_id = person.search('user-name')[0].content users << { id: id, first_name: first_name, last_name: last_name, user_id: user_id } end users end |