lib/groupr.rb in groupr-0.2.1 vs lib/groupr.rb in groupr-0.2.2
- old
+ new
@@ -1,10 +1,10 @@
require 'net/http'
require 'nokogiri'
class Groupr
attr_accessor :api_url, :certificate, :key, :uw_ca_file
- attr_reader :request
+ attr_reader :request, :status
def initialize
@api_url = "https://iam-ws.u.washington.edu:7443/group_sws/v2"
@uw_ca_file = "#{ENV['HOME']}/uwca.crt"
end
@@ -24,11 +24,19 @@
## Membership-related methods: get, get effective, update, delete
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Members
- def get_membership
+ def get_membership(group)
+ @uri = URI.parse("#{@api_url}/group/#{group}/member")
+ body = make_get_request
+ doc = Nokogiri::HTML(body)
+ members = []
+ doc.css('li').each do |m|
+ members << m.text
+ end
+ members
end
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Effective+Members
def get_effective_membership
end
@@ -106,11 +114,20 @@
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Update+Group
def update_group
end
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Delete+Group
- def delete_group
+ def delete_group(group)
+ @uri = URI.parse("#{@api_url}/group/#{group}")
+ make_delete_request
+ if get_response_code == 200
+ @status = "Group deleted or not found"
+ true
+ else
+ @status = "No authorization"
+ false
+ end
end
## Search
# http://wiki.cac.washington.edu/display/infra/Groups+WebService+Search
@@ -132,9 +149,24 @@
ca_file: @uw_ca_file,
verify_mode: OpenSSL::SSL::VERIFY_PEER
}
Net::HTTP.start(@uri.host, @uri.port, options) do |http|
request = Net::HTTP::Get.new(@uri.request_uri)
+ @response = http.request(request)
+ end
+ @response.body
+ end
+ # This makes a delete request against the groups service, used for uh, deleting things
+ def make_delete_request
+ options = {
+ use_ssl: true,
+ cert: OpenSSL::X509::Certificate.new(@certificate),
+ key: OpenSSL::PKey::RSA.new(@key),
+ ca_file: @uw_ca_file,
+ verify_mode: OpenSSL::SSL::VERIFY_PEER
+ }
+ Net::HTTP.start(@uri.host, @uri.port, options) do |http|
+ request = Net::HTTP::Delete.new(@uri.request_uri)
@response = http.request(request)
end
@response.body
end
# This makes a put request against the groups service, useful for pushing information