groupr 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/groupr.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "groupr"
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
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"]
12
- s.date = "2012-12-05"
12
+ s.date = "2012-12-07"
13
13
  s.description = "Gem used to interact with University of Washington Groups Service"
14
14
  s.email = "nikky@uw.edu"
15
15
  s.extra_rdoc_files = [
data/lib/groupr.rb CHANGED
@@ -1,2 +1,76 @@
1
+ require 'net/http'
2
+ require 'nokogiri'
1
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
2
76
  end
data/spec/groupr_spec.rb CHANGED
@@ -1,8 +1,66 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Groupr" do
4
- it "Instantiates a new instance of groupr" do
4
+
5
+ before do
5
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
10
+
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
21
+
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
34
+
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
53
+
54
+
55
+ context "#get_members" do
56
+ it "Gets the members of a group"
57
+ end
58
+
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"
6
65
  end
7
- it "Loads a certificate"
8
66
  end
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.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-05 00:00:00.000000000 Z
12
+ date: 2012-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -141,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  segments:
143
143
  - 0
144
- hash: 3825900658999057012
144
+ hash: -2323866880024639544
145
145
  required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  none: false
147
147
  requirements: