lib/groupr.rb in groupr-0.2.0 vs lib/groupr.rb in groupr-0.2.1
- old
+ new
@@ -6,15 +6,11 @@
def initialize
@api_url = "https://iam-ws.u.washington.edu:7443/group_sws/v2"
@uw_ca_file = "#{ENV['HOME']}/uwca.crt"
end
- # This method returns nil if the http request doesn't return a 200. Maybe also support for not-authorized?
- # def validate_response(response)
- # nil if get_response_code != 200
- # response.body if get_response_code == 200
- # end
+ public
def get_response_code
@response.code.to_i
end
def group_exists?(group)
@uri = URI.parse("#{@api_url}/group/#{group}")
@@ -85,10 +81,26 @@
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Create+Group
def create_group(group,description=nil)
@group = group
description.nil? ? @description = group : @description = description
@uri = URI.parse("#{@api_url}/group/#{group}")
+ @request_text = %Q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11/dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+ <head>
+ <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
+ </head>
+ <body>
+ <div class="group">
+ <span class="description">#{@description}</span>
+ <ul class="names"><li class="name">#{@group}</li></ul>
+ <ul class="admins">
+ <li class="admin">nikky</li>
+ </ul>
+ </div>
+ </body>
+ </html>}
make_put_request
get_response_code == 200 ? true : false
end
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Update+Group
@@ -109,10 +121,11 @@
def get_history
end
private
+ # This makes a get request against the groups service, useful for getting information
def make_get_request
options = {
use_ssl: true,
cert: OpenSSL::X509::Certificate.new(@certificate),
key: OpenSSL::PKey::RSA.new(@key),
@@ -123,63 +136,44 @@
request = Net::HTTP::Get.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
def make_put_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::Put.new(@uri.request_uri)
- request.body = %Q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
- "http://www.w3.org/TR/xhtml11/DTD/xhtml11/dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
- <head>
- <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
- </head>
- <body>
- <div class="group">
- <span class="description">#{@description}</span>
- <ul class="names"><li class="name">#{@group}</li></ul>
- <ul class="admins">
- <li class="admin">nikky</li>
- </ul>
- </div>
- </body>
- </html>}
+ request.body = @request_text
@response = http.request(request)
end
puts "Response is: #{get_response_code}"
puts "Body is: #{@response.body}"
@response.body
end
-
- def get_response_code
- @response.code.to_i
- end
-
+ # Returns the contact information of a group
def get_contact
@doc.xpath('//span[@class="contact"]').text
end
-
+ # Returns the group title
def get_title
@doc.xpath('//span[@class="title"]').text
end
-
+ # Returns the group description
def get_description
@doc.xpath('//span[@class="description"]').text
end
-
+ # Returns the group name
def get_name
@doc.xpath('//span[@class="name"]').text
end
-
+ # Returns the unique group regid
def get_regid
@doc.xpath('//span[@class="regid"]').text
end
end