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.



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

def http
  @http
end

.passwordObject

Returns the value of attribute password.



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

def password
  @password
end

.subdomainObject

Returns the value of attribute subdomain.



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

def subdomain
  @subdomain
end

.usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Class Method Details

.authenticate(info) ⇒ Object



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

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

.handle_response(response) ⇒ Object



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

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



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

def request(type, url, data = nil)
  request = eval("Net::HTTP::#{type.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