Class: Groupr

Inherits:
Object
  • Object
show all
Defined in:
lib/groupr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGroupr

Returns a new instance of Groupr.



6
7
8
9
# File 'lib/groupr.rb', line 6

def initialize
  @api_url = "https://iam-ws.u.washington.edu:7443/group_sws/v2"
  @uw_ca_file = "#{ENV['HOME']}/uwca.crt"
end

Instance Attribute Details

#api_urlObject

Returns the value of attribute api_url.



4
5
6
# File 'lib/groupr.rb', line 4

def api_url
  @api_url
end

#certificateObject

Returns the value of attribute certificate.



4
5
6
# File 'lib/groupr.rb', line 4

def certificate
  @certificate
end

#keyObject

Returns the value of attribute key.



4
5
6
# File 'lib/groupr.rb', line 4

def key
  @key
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/groupr.rb', line 5

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/groupr.rb', line 5

def status
  @status
end

#uw_ca_fileObject

Returns the value of attribute uw_ca_file.



4
5
6
# File 'lib/groupr.rb', line 4

def uw_ca_file
  @uw_ca_file
end

Instance Method Details

#create_group(group, description = nil) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/groupr.rb', line 98

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

#delete_group(group) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/groupr.rb', line 127

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

#get_effective_membership(group) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/groupr.rb', line 41

def get_effective_membership(group)
  @uri = URI.parse("#{@api_url}/group/#{group}/effective_member")
  body = make_get_request
  doc = Nokogiri::HTML(body)
  members = []
  doc.xpath('//a[@class="effective_member"]').each do |m|
    members << m.text
  end
  members
end

#get_membership(group) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/groupr.rb', line 29

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

#get_response_codeObject



12
13
14
# File 'lib/groupr.rb', line 12

def get_response_code
  @response.code.to_i
end

#group_exists?(group) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
# File 'lib/groupr.rb', line 15

def group_exists?(group)
  @uri = URI.parse("#{@api_url}/group/#{group}")
  make_get_request
  if get_response_code == 200
    true
  else
    false
  end
end

#update_groupObject



123
124
# File 'lib/groupr.rb', line 123

def update_group
end

#view_group(group) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/groupr.rb', line 82

def view_group(group)
  @uri = URI.parse("#{@api_url}/group/#{group}")
  body = make_get_request
  @doc = Nokogiri::HTML(body)
  {
    title: get_title,
    description: get_description,
    name: get_name,
    regid: get_regid,
    contact: get_contact
  }
end