Module: Unfuddler
- Defined in:
- lib/unfuddler.rb
Defined Under Namespace
Class Attribute Summary collapse
-
.http ⇒ Object
Returns the value of attribute http.
-
.password ⇒ Object
Returns the value of attribute password.
-
.subdomain ⇒ Object
Returns the value of attribute subdomain.
-
.username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
- .authenticate(info) ⇒ Object
- .handle_response(response) ⇒ Object
- .request(type, url, data = nil) ⇒ Object
Class Attribute Details
.http ⇒ Object
Returns the value of attribute http.
12 13 14 |
# File 'lib/unfuddler.rb', line 12 def http @http end |
.password ⇒ Object
Returns the value of attribute password.
12 13 14 |
# File 'lib/unfuddler.rb', line 12 def password @password end |
.subdomain ⇒ Object
Returns the value of attribute subdomain.
12 13 14 |
# File 'lib/unfuddler.rb', line 12 def subdomain @subdomain end |
.username ⇒ Object
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 |