Class: XForge::Project

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

Overview

A Project is an interface to a hosted project.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, unix_name) ⇒ Project

Returns a new instance of Project.



12
13
14
15
# File 'lib/xforge/project.rb', line 12

def initialize(host, unix_name)
  @host = host
  @unix_name = unix_name
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/xforge/project.rb', line 10

def host
  @host
end

#unix_nameObject (readonly)

Returns the value of attribute unix_name.



10
11
12
# File 'lib/xforge/project.rb', line 10

def unix_name
  @unix_name
end

Instance Method Details

#group_idObject

The group_id of this project



49
50
51
52
53
54
55
56
57
# File 'lib/xforge/project.rb', line 49

def group_id
  unless(@group_id)
    regexp = /stats\/[?&]group_id=(\d+)/
    html = open(project_uri) { |data| data.read }
    @group_id = html[regexp, 1]
    raise "Couldn't get group_id" unless @group_id
  end
  @group_id
end

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



68
69
70
# File 'lib/xforge/project.rb', line 68

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

#home_page_uriObject

The home page of this project



73
74
75
76
77
78
79
80
# File 'lib/xforge/project.rb', line 73

def home_page_uri
  unless(@home_page)
    html = open(project_uri) { |data| data.read }
    @home_page = html[@host.home_page_regexp, 1]
    raise "Couldn't get home_page" unless @home_page
  end
  @home_page
end

#login(user_name, password) ⇒ Object

Logs in and returns a Session



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/xforge/project.rb', line 22

def (user_name, password)
  http = Net::HTTP.new(@host.name, host.)
  
  # Can't get this to work, so login doesn't work on SourceForge yet!
  # http://www.ruby-lang.org/ja/man/index.cgi?cmd=view;name=net%2Fhttps.rb
  if(host. == 443)
    http.use_ssl = true
    http.ca_file = '/usr/share/ssl/cert.pem'
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    http.verify_depth = 5
  end

   = 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

#project_uriObject



64
65
66
# File 'lib/xforge/project.rb', line 64

def project_uri
  "http://#{@host.name}/projects/#{@unix_name}/"
end

#scm_webObject

The scm browser of this project



60
61
62
# File 'lib/xforge/project.rb', line 60

def scm_web
  @scm_web ||= host.scm_web(self)
end

#to_yaml_propertiesObject



17
18
19
# File 'lib/xforge/project.rb', line 17

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

#trackerObject



82
83
84
# File 'lib/xforge/project.rb', line 82

def tracker
  @tracker ||= @host.tracker(self)
end