Module: Unfuddler

Defined in:
lib/unfuddler.rb

Defined Under Namespace

Classes: Project, Ticket

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.httpObject

Returns the value of attribute http.



11
12
13
# File 'lib/unfuddler.rb', line 11

def http
  @http
end

.passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/unfuddler.rb', line 11

def password
  @password
end

.subdomainObject

Returns the value of attribute subdomain.



11
12
13
# File 'lib/unfuddler.rb', line 11

def subdomain
  @subdomain
end

.usernameObject

Returns the value of attribute username.



11
12
13
# File 'lib/unfuddler.rb', line 11

def username
  @username
end

Class Method Details

.authenticate(info) ⇒ Object



13
14
15
16
# File 'lib/unfuddler.rb', line 13

def authenticate(info)
  @username, @password, @subdomain = info[:username] || info["username"], info[:password] || info["password"], info[:subdomain] || info["subdomain"]
  @http = Net::HTTP.new("#{@subdomain}.unfuddle.com", 80)
end

.handle_response(response) ⇒ Object



26
27
28
29
30
# File 'lib/unfuddler.rb', line 26

def handle_response(response)
  valid_codes = [201, 200, 302]
  raise "Server returned response code: " + response.code unless valid_codes.include?(response.code.to_i)
  Crack::XML.parse(response.body)
end

.request(type, url, data = nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/unfuddler.rb', line 18

def request(type, url, data = nil)
  request = eval("Net::HTTP::#{type.to_s.capitalize}").new("/api/v1/#{url}", {'Content-type' => "application/xml"})
  request.basic_auth @username, @password

  request.body = data if data
  handle_response(@http.request(request))
end