Class: MetaProject::Project::XForge::XForgeBase

Inherits:
Base
  • Object
show all
Defined in:
lib/meta_project/project/xforge/xforge_base.rb

Direct Known Subclasses

RubyForge, SourceForge

Instance Attribute Summary

Attributes inherited from Base

#name, #scm, #scm_web, #tracker

Instance Method Summary collapse

Constructor Details

#initialize(host, unix_name, cvs_mod) ⇒ XForgeBase

Returns a new instance of XForgeBase.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 6

def initialize(host, unix_name, cvs_mod)
  @host = host
  @unix_name = unix_name
  @name = unix_name

  @tracker = tracker_class.new(group_id_uri("tracker"), self)

  unless(cvs_mod.nil?)
    @scm = create_cvs(unix_name, cvs_mod)
    @scm_web = create_view_cvs(unix_name, cvs_mod)
  end
end

Instance Method Details

#group_idObject

The group_id of this project



42
43
44
45
46
47
48
49
50
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 42

def group_id
  unless(@group_id)
    html = better_open(xforge_project_url).read
    group_id_pattern = /project\/memberlist.php\?group_id=(\d+)/
    @group_id = html[group_id_pattern, 1]
    raise "Couldn't get group_id from #{xforge_project_url}. I was looking for /#{group_id_pattern.source}/" unless @group_id
  end
  @group_id
end

#group_id_uri(path, postfix = "") ⇒ Object



56
57
58
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 56

def group_id_uri(path, postfix="")
  "http://#{@host}/#{path}/?group_id=#{group_id}#{postfix}"
end

#home_pageObject

The home page of this project



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 61

def home_page
  unless(@home_page)
    html = better_open(xforge_project_url).read
    @home_page = html[home_page_regexp, 1]
    unless @home_page
      STDERR.puts "WARNING: Couldn't get home_page from #{xforge_project_url}. I was looking for /#{home_page_regexp.source}/"
      STDERR.puts "Will use #{xforge_project_url} as home page instead."
      @home_page = xforge_project_url
    end
  end
  @home_page
end

#login(user_name, password) ⇒ Object

Logs in and returns a Session



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 24

def (user_name, password)
  http = Net::HTTP.new(@host, 80)

   = http.start do |http|
    data = [
      "login=1",
      "form_loginname=#{user_name}",
      "form_pw=#{password}"
    ].join("&")
    http.post("/account/login.php", data)
  end

  cookie = ["set-cookie"]
  raise "Login failed" unless cookie
  Session.new(@host, self, cookie)
end

#to_yaml_propertiesObject



19
20
21
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 19

def to_yaml_properties
  ["@host", "@unix_name"]
end

#xforge_project_urlObject



52
53
54
# File 'lib/meta_project/project/xforge/xforge_base.rb', line 52

def xforge_project_url
  "http://#{@host}/projects/#{@unix_name}/"
end