echo-connector 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/echo-connector.rb +88 -0
  2. metadata +47 -0
@@ -0,0 +1,88 @@
1
+ require "oauth"
2
+ require "nokogiri"
3
+
4
+ module Echo360
5
+
6
+ class Echo360
7
+ def initialize(site, consumer_key, consumer_secret, organisation = 0)
8
+ consumer=OAuth::Consumer.new consumer_key, consumer_secret,
9
+ { :site => site,
10
+ :request_token_path => "",
11
+ :authorize_path => "",
12
+ :access_token_path => "",
13
+ :http_method => :get }
14
+
15
+ @access_token = OAuth::AccessToken.new consumer
16
+ @organisation = getOrganizations[organisation][:id]
17
+ end
18
+
19
+ def getUsers
20
+ users_xml = getUsersXML
21
+ users = Array.new
22
+ users_xml.xpath("/people/person").each do |person|
23
+ id = person.search('id')[0].content
24
+ first_name = person.search('first-name')[0].content
25
+ last_name = person.search('last-name')[0].content
26
+ user_id = person.search('user-name')[0].content
27
+ users << { id: id, first_name: first_name, last_name: last_name, user_id: user_id }
28
+ end
29
+ return users
30
+ end
31
+
32
+ def getUser user_id
33
+ users_xml = getUsersXML
34
+ person = users_xml.xpath("/people/person[user-name/text() = \"#{user_id}\"]")[0]
35
+ raise "User not found: #{user_id}" if person.nil?
36
+ id = person.search('id')[0].content
37
+ first_name = person.search('first-name')[0].content
38
+ last_name = person.search('last-name')[0].content
39
+ user_id = person.search('user-name')[0].content
40
+ { id: id, first_name: first_name, last_name: last_name, user_id: user_id }
41
+ end
42
+
43
+ def createUser user_id, password, first_name, last_name, role, email
44
+ builder = Nokogiri::XML::Builder.new do |xml|
45
+ xml.person {
46
+ xml.send(:"first-name", first_name)
47
+ xml.send(:"last-name", last_name)
48
+ xml.send(:"email-address", email)
49
+ xml.role role
50
+ xml.credentials {
51
+ xml.send(:"user-name", user_id)
52
+ xml.password password
53
+ }
54
+ xml.send(:"organization-roles") {
55
+ xml.send(:"organization-role") {
56
+ xml.send(:"organization-id", @organisation)
57
+ xml.role role
58
+ }
59
+ }
60
+ }
61
+ end
62
+ rsp = @access_token.post("/ess/scheduleapi/v1/people", builder.to_xml,{ 'Accept' => 'application/xml', 'Content-Type' => 'application/xml' })
63
+ !rsp.value
64
+ end
65
+
66
+ private
67
+
68
+ def getUsersXML
69
+ Nokogiri.XML @access_token.get("/ess/scheduleapi/v1/people").body
70
+ end
71
+
72
+ def getOrganizations
73
+ response = @access_token.get "/ess/scheduleapi/v1/organizations"
74
+ org_xml = Nokogiri.XML response.body
75
+
76
+ orgs = Array.new
77
+
78
+ org_xml.search('organization').each do |org|
79
+ id = org.search('id')[0].content
80
+ name = org.search('name')[0].content
81
+ orgs << { name: name, id: id }
82
+ end
83
+
84
+ return orgs
85
+ end
86
+ end
87
+
88
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: echo-connector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Beresford
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-19 00:00:00.000000000 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+ description: Echo360 API Connector for Ruby
16
+ email: beezly@beez.ly
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/echo-connector.rb
22
+ has_rdoc: true
23
+ homepage: http://github.com/beezly/echo-connector
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.6.2
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: Echo360 API Connector
47
+ test_files: []