groupr 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - rbx-19mode
5
+ - jruby-19mode
6
+ - ree
data/README.rdoc CHANGED
@@ -1,3 +1,5 @@
1
+ {<img src="https://travis-ci.org/allynfolksjr/groupr.png" />}[https://travis-ci.org/allynfolksjr/groupr]
2
+
1
3
  = groupr
2
4
 
3
5
  Description goes here.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/groupr.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "groupr"
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nikky Southerland"]
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".rspec",
22
+ ".travis.yml",
22
23
  "Gemfile",
23
24
  "LICENSE.txt",
24
25
  "README.rdoc",
@@ -27,6 +28,7 @@ Gem::Specification.new do |s|
27
28
  "groupr.gemspec",
28
29
  "lib/groupr.rb",
29
30
  "spec/groupr_spec.rb",
31
+ "spec/sample_responses/view_group.html",
30
32
  "spec/spec_helper.rb"
31
33
  ]
32
34
  s.homepage = "http://github.com/allynfolksjr/groupr"
data/lib/groupr.rb CHANGED
@@ -1,76 +1,186 @@
1
1
  require 'net/http'
2
2
  require 'nokogiri'
3
3
  class Groupr
4
- attr_accessor :api_url, :certificate, :key, :uw_ca_file
5
- def initialize
6
- @api_url = "https://iam-ws.u.washington.edu:7443/group_sws/v2"
7
- @uw_ca_file = "#{ENV['HOME']}/uwca.crt"
8
- end
9
- def make_get_request
10
- options = {
11
- use_ssl: true,
12
- cert: OpenSSL::X509::Certificate.new(@certificate),
13
- key: OpenSSL::PKey::RSA.new(@key),
14
- ca_file: @uw_ca_file,
15
- verify_mode: OpenSSL::SSL::VERIFY_PEER
16
- }
17
- Net::HTTP.start(@uri.host, @uri.port, options) do |http|
18
- request = Net::HTTP::Get.new(@uri.request_uri)
19
- @response = http.request(request)
20
- end
21
- @response.body
22
- end
23
- # This method returns nil if the http request doesn't return a 200. Maybe also support for not-authorized?
24
- # def validate_response(response)
25
- # nil if get_response_code != 200
26
- # response.body if get_response_code == 200
27
- # end
28
- def get_response_code
29
- @response.code.to_i
30
- end
31
- def group_exists?(group)
32
- @uri = URI.parse("#{@api_url}/group/#{group}")
33
- make_get_request
34
- if get_response_code == 200
35
- true
36
- else
37
- false
38
- end
39
- end
40
-
41
- def view_group(group)
42
- @uri = URI.parse("#{@api_url}/group/#{group}")
43
- body = make_get_request
44
- @doc = Nokogiri::HTML(body)
45
- {
46
- title: get_title,
47
- description: get_description,
48
- name: get_name,
49
- regid: get_regid,
50
- contact: get_contact
51
- }
52
- end
53
-
54
- def get_contact
55
- @doc.xpath('//span[@class="contact"]').text
56
- end
57
-
58
- def get_title
59
- @doc.xpath('//span[@class="title"]').text
60
- end
61
- def get_description
62
- @doc.xpath('//span[@class="description"]').text
63
- end
64
- def get_name
65
- @doc.xpath('//span[@class="name"]').text
66
- end
67
- def get_regid
68
- @doc.xpath('//span[@class="regid"]').text
69
- end
70
-
71
- # def other thing to use
72
- # http.ssl_timeout
73
- # It throws TimeoutError exceptions for timeouts
74
- # http.cert_store to for.... the CA?
75
- # or maybe http.ca_file
76
- end
4
+ attr_accessor :api_url, :certificate, :key, :uw_ca_file
5
+ attr_reader :request
6
+ def initialize
7
+ @api_url = "https://iam-ws.u.washington.edu:7443/group_sws/v2"
8
+ @uw_ca_file = "#{ENV['HOME']}/uwca.crt"
9
+ end
10
+
11
+ # This method returns nil if the http request doesn't return a 200. Maybe also support for not-authorized?
12
+ # def validate_response(response)
13
+ # nil if get_response_code != 200
14
+ # response.body if get_response_code == 200
15
+ # end
16
+ def get_response_code
17
+ @response.code.to_i
18
+ end
19
+ def group_exists?(group)
20
+ @uri = URI.parse("#{@api_url}/group/#{group}")
21
+ make_get_request
22
+ if get_response_code == 200
23
+ true
24
+ else
25
+ false
26
+ end
27
+ end
28
+
29
+ ## Membership-related methods: get, get effective, update, delete
30
+
31
+
32
+ # https://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Members
33
+ def get_membership
34
+ end
35
+
36
+ # https://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Effective+Members
37
+ def get_effective_membership
38
+ end
39
+
40
+ # http://wiki.cac.washington.edu/display/infra/Groups+WebService+Update+Members
41
+ def update_membership
42
+ end
43
+
44
+ # http://wiki.cac.washington.edu/display/infra/Groups+WebService+Delete+Members
45
+ def delete_membership
46
+ end
47
+
48
+ ## Member-related methods
49
+
50
+ # http://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Member
51
+ def get_member
52
+ end
53
+
54
+ # http://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Effective+Member
55
+ def get_effective_member
56
+ end
57
+
58
+ # http://wiki.cac.washington.edu/display/infra/Groups+WebService+Add+Member
59
+ def add_member
60
+ end
61
+
62
+ # http://wiki.cac.washington.edu/display/infra/Groups+WebService+Delete+Member
63
+ def delete_member
64
+ end
65
+
66
+
67
+ ## Group-related methods. View, create, update, delete.
68
+
69
+ # https://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Group
70
+ def view_group(group)
71
+ @uri = URI.parse("#{@api_url}/group/#{group}")
72
+ body = make_get_request
73
+ @doc = Nokogiri::HTML(body)
74
+ {
75
+ title: get_title,
76
+ description: get_description,
77
+ name: get_name,
78
+ regid: get_regid,
79
+ contact: get_contact
80
+ }
81
+ end
82
+
83
+
84
+
85
+ # https://wiki.cac.washington.edu/display/infra/Groups+WebService+Create+Group
86
+ def create_group(group,description=nil)
87
+ @group = group
88
+ description.nil? ? @description = group : @description = description
89
+ @uri = URI.parse("#{@api_url}/group/#{group}")
90
+ make_put_request
91
+ get_response_code == 200 ? true : false
92
+ end
93
+
94
+ # https://wiki.cac.washington.edu/display/infra/Groups+WebService+Update+Group
95
+ def update_group
96
+ end
97
+
98
+ # https://wiki.cac.washington.edu/display/infra/Groups+WebService+Delete+Group
99
+ def delete_group
100
+ end
101
+
102
+ ## Search
103
+
104
+ # http://wiki.cac.washington.edu/display/infra/Groups+WebService+Search
105
+ def search
106
+ end
107
+
108
+ # http://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+History
109
+ def get_history
110
+ end
111
+
112
+
113
+ private
114
+ def make_get_request
115
+ options = {
116
+ use_ssl: true,
117
+ cert: OpenSSL::X509::Certificate.new(@certificate),
118
+ key: OpenSSL::PKey::RSA.new(@key),
119
+ ca_file: @uw_ca_file,
120
+ verify_mode: OpenSSL::SSL::VERIFY_PEER
121
+ }
122
+ Net::HTTP.start(@uri.host, @uri.port, options) do |http|
123
+ request = Net::HTTP::Get.new(@uri.request_uri)
124
+ @response = http.request(request)
125
+ end
126
+ @response.body
127
+ end
128
+
129
+ def make_put_request
130
+ options = {
131
+ use_ssl: true,
132
+ cert: OpenSSL::X509::Certificate.new(@certificate),
133
+ key: OpenSSL::PKey::RSA.new(@key),
134
+ ca_file: @uw_ca_file,
135
+ verify_mode: OpenSSL::SSL::VERIFY_PEER
136
+ }
137
+ Net::HTTP.start(@uri.host, @uri.port, options) do |http|
138
+ request = Net::HTTP::Put.new(@uri.request_uri)
139
+ request.body = %Q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
140
+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11/dtd">
141
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
142
+ <head>
143
+ <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
144
+ </head>
145
+ <body>
146
+ <div class="group">
147
+ <span class="description">#{@description}</span>
148
+ <ul class="names"><li class="name">#{@group}</li></ul>
149
+ <ul class="admins">
150
+ <li class="admin">nikky</li>
151
+ </ul>
152
+ </div>
153
+ </body>
154
+ </html>}
155
+ @response = http.request(request)
156
+ end
157
+ puts "Response is: #{get_response_code}"
158
+ puts "Body is: #{@response.body}"
159
+ @response.body
160
+ end
161
+
162
+ def get_response_code
163
+ @response.code.to_i
164
+ end
165
+
166
+ def get_contact
167
+ @doc.xpath('//span[@class="contact"]').text
168
+ end
169
+
170
+ def get_title
171
+ @doc.xpath('//span[@class="title"]').text
172
+ end
173
+
174
+ def get_description
175
+ @doc.xpath('//span[@class="description"]').text
176
+ end
177
+
178
+ def get_name
179
+ @doc.xpath('//span[@class="name"]').text
180
+ end
181
+
182
+ def get_regid
183
+ @doc.xpath('//span[@class="regid"]').text
184
+ end
185
+
186
+ end
data/spec/groupr_spec.rb CHANGED
@@ -2,65 +2,77 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Groupr" do
4
4
 
5
- before do
6
- @group = Groupr.new
7
- @group.certificate = File.read("#{ENV['HOME']}/nikky_cac_washington_edu.cert")
8
- @group.key = File.read("#{ENV['HOME']}/nikky_cac_washington_edu.key")
9
- end
5
+ before do
6
+ @group = Groupr.new
7
+ end
10
8
 
11
- it "Checks for network connectivity"
12
- it "Should allow you to specify a custom Service API" do
13
- @group.respond_to?(:api_url).should eq true
14
- end
15
- it "Should allow you to specify your certificate" do
16
- @group.respond_to?(:certificate).should eq true
17
- end
18
- it "Should Allow you to specify your key" do
19
- @group.respond_to?(:key).should eq true
20
- end
9
+ it "Checks for network connectivity"
10
+ it "Should allow you to specify a custom Service API" do
11
+ @group.respond_to?(:api_url).should eq true
12
+ end
13
+ it "Should allow you to specify your X509 certificate" do
14
+ @group.respond_to?(:certificate).should eq true
15
+ end
16
+ it "Should Allow you to specify your RSA key" do
17
+ @group.respond_to?(:key).should eq true
18
+ end
19
+ context "group operations" do
20
+ context "#group_exists?" do
21
+ it "Should tell you that the uw_employees group exists" do
22
+ @group.should_receive(:make_get_request).and_return(nil)
23
+ @group.should_receive(:get_response_code).and_return(200)
24
+ @group.group_exists?("u_nikky_git").should be_true
25
+ end
26
+ it "Should tell you that the a_team group does not exist" do
27
+ @group.should_receive(:make_get_request).and_return(nil)
28
+ @group.should_receive(:get_response_code).and_return(404)
29
+ @group.group_exists?("a_team").should be_false
30
+ end
31
+ end
21
32
 
22
- context "#group_exists?" do
23
- it "Should tell you that the uw_employees group exists" do
24
- @group.should_receive(:make_get_request).and_return(nil)
25
- @group.should_receive(:get_response_code).and_return(200)
26
- @group.group_exists?("u_nikky_git").should be_true
27
- end
28
- it "Should tell you that the a_team group does not exist" do
29
- @group.should_receive(:make_get_request).and_return(nil)
30
- @group.should_receive(:get_response_code).and_return(404)
31
- @group.group_exists?("a_team").should be_false
32
- end
33
- end
33
+ context "#view_group" do
34
+ before do
35
+ @group.should_receive(:make_get_request).and_return(File.open('spec/sample_responses/view_group.html'))
36
+ @results = @group.view_group("u_nikky_git")
37
+ end
38
+ it "Should tell you the group name" do
39
+ @results[:name].should eq "u_nikky_git"
40
+ end
41
+ it "Should tell you the group description" do
42
+ @results[:description].should_not == ""
43
+ end
44
+ it "Should tell you the group contact" do
45
+ @results[:contact].should eq "nikky"
46
+ end
47
+ it "Should tell you the group title" do
48
+ @results[:title].should eq "nikky git"
49
+ end
50
+ end
51
+ context "#create_group" do
52
+ before do
53
+ @group.should_receive(:make_put_request).and_return(nil)
54
+ end
55
+ it "Should create a new group" do
56
+ @group.should_receive(:get_response_code).and_return(200)
57
+ @group.create_group("u_test_hi").should eq true
58
+ end
59
+ it "Should fail to create a new group if the response code is non-200" do
60
+ @group.should_receive(:get_response_code).and_return(419)
61
+ @group.create_group("u_test_hi").should eq false
62
+ end
34
63
 
35
- context "#view_group" do
36
- before do
37
- @group.should_receive(:make_get_request).and_return(File.open('view_group.html'))
38
- @results = @group.view_group("u_nikky_git")
39
- end
40
- it "Should tell you the group name" do
41
- @results[:name].should eq "u_nikky_git"
42
- end
43
- it "Should tell you the group description" do
44
- @results[:description].should_not == ""
45
- end
46
- it "Should tell you the group contact" do
47
- @results[:contact].should eq "nikky"
48
- end
49
- it "Should tell you the group title" do
50
- @results[:title].should eq "nikky git"
51
- end
52
- end
64
+ end
53
65
 
66
+ context "#get_members" do
67
+ it "Gets the members of a group"
68
+ end
54
69
 
55
- context "#get_members" do
56
- it "Gets the members of a group"
57
- end
70
+ context "#add_member" do
71
+ it "Adds a member to a group"
72
+ end
58
73
 
59
- context "#add_member" do
60
- it "Adds a member to a group"
61
- end
62
-
63
- context "#remove_member" do
64
- it "Removes a member from a group"
65
- end
74
+ context "#remove_member" do
75
+ it "Removes a member from a group"
76
+ end
77
+ end
66
78
  end
@@ -0,0 +1,87 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3
+ <head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"></head>
4
+ <body>
5
+
6
+
7
+
8
+
9
+ <div class="group" version="2">
10
+
11
+ Regid: <span class="regid">ddd677bfea054b2191fd7bcdf4d715e4</span>
12
+ <br><span class="names">
13
+ Name: <span class="name">u_nikky_git</span>
14
+ </span>
15
+ <br>
16
+ Title: <span class="title">nikky git</span>
17
+ <br>
18
+ Description: <span class="description">List to restrict access to my "public" git repository to CAC and other campus support staff as needed.</span>
19
+ <br>
20
+
21
+ Group contact: <span class="contact">nikky</span>
22
+ <br>
23
+
24
+ Created: <span class="createtime">1292452356669</span>
25
+ <br>
26
+ Modified: <span class="modifytime">1292452357055</span>
27
+ <br>
28
+ Membership modified: <span class="membermodifytime">1301805036473</span>
29
+ <br>
30
+ Authn factor: <span class="authnfactor">1</span>
31
+ <br>
32
+ Classification: <span class="classification">u</span>
33
+ <br>
34
+ Membership dependency group: <span class="dependson"></span>
35
+
36
+
37
+
38
+ Email Enabled: <span class="emailenabled">disabled</span>
39
+ <br>
40
+
41
+ Published email address: <span class="publishemail"></span>
42
+ <br>
43
+
44
+ Report to owner:
45
+ <span class="reporttoowner">no</span>
46
+ <br>
47
+
48
+ Allowed senders: <ul class="authorigs">
49
+ <li class="authorig" type="none">dc=none</li>
50
+ </ul>
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+ Administrators:
59
+ <ul class="admins">
60
+ <li class="admin" type="uwnetid">nikky</li>
61
+ </ul>
62
+ Updaters:
63
+ <ul class="updaters"></ul>
64
+ Creators:
65
+ <ul class="creators"></ul>
66
+ Readers:
67
+ <ul class="readers">
68
+ <li class="reader" type="none">dc=all</li>
69
+ </ul>
70
+
71
+ Optins:
72
+ <ul class="optins"></ul>
73
+ Optouts:
74
+ <ul class="optouts"></ul>
75
+ <br>
76
+
77
+ Membership: <a rel="members" href="/group_sws/v2/group/ddd677bfea054b2191fd7bcdf4d715e4/member">Membership</a>
78
+
79
+ </div>
80
+
81
+ <div class="status"></div>
82
+
83
+
84
+
85
+
86
+ </body>
87
+ </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groupr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -117,6 +117,7 @@ extra_rdoc_files:
117
117
  files:
118
118
  - .document
119
119
  - .rspec
120
+ - .travis.yml
120
121
  - Gemfile
121
122
  - LICENSE.txt
122
123
  - README.rdoc
@@ -125,6 +126,7 @@ files:
125
126
  - groupr.gemspec
126
127
  - lib/groupr.rb
127
128
  - spec/groupr_spec.rb
129
+ - spec/sample_responses/view_group.html
128
130
  - spec/spec_helper.rb
129
131
  homepage: http://github.com/allynfolksjr/groupr
130
132
  licenses:
@@ -141,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
143
  version: '0'
142
144
  segments:
143
145
  - 0
144
- hash: -2323866880024639544
146
+ hash: 4214034756816010912
145
147
  required_rubygems_version: !ruby/object:Gem::Requirement
146
148
  none: false
147
149
  requirements: