Top Level Namespace

Defined Under Namespace

Modules: Provisional

Instance Method Summary collapse

Instance Method Details

#create_repository(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/provisional/unfuddle_common.rb', line 23

def create_repository(options)
  begin
    http = Net::HTTP.new("#{options['domain']}.unfuddle.com", 80)
    request = Net::HTTP::Post.new('/api/v1/repositories.xml', 'Content-Type' => 'application/xml')
    request.basic_auth(options['username'], options['password'])
    request.body = xml_payload(options)
    response, data = http.request(request)
    unless response.code == "201"
      raise RuntimeError, "Repository not created on Unfuddle due to HTTP error: #{response.code}"
    end
  rescue
    raise RuntimeError, "Repository not created on Unfuddle due to exception: #{$!}"
  end
end

#ensure_required_options(options) ⇒ Object



4
5
6
7
8
# File 'lib/provisional/unfuddle_common.rb', line 4

def ensure_required_options(options)
  %w(username password domain id).each do |opt|
    raise ArgumentError, "#{opt} must be specified" unless options[opt]
  end
end

#rescuing_exceptions(&block) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/provisional.rb', line 5

def rescuing_exceptions(&block)
  begin
    yield
  rescue
    raise RuntimeError, "Repository not created due to exception: #{$!}"
  end
end

#xml_payload(options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/provisional/unfuddle_common.rb', line 10

def xml_payload(options)
  xml = Builder::XmlMarkup.new
  xml.repository do
    xml.abbreviation options['name']
    xml.title options['name']
    xml.system options['scm']
    xml.projects do
      xml.project(:id => options['id'])
    end
  end
  return xml.target!
end