Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use curl to connect to Fogbugz, instead of open-uri or Net::HTTP.

This ensures SSL is properly taken care of:  Ruby on Mac OS X 10.5 failed with an SSL verification error.
  • Loading branch information...
commit 23d792ab64ab2331223d3ab936bad6097ce69a97 1 parent ef550d0
@francois francois authored
View
16 fogbugz_service.rb
@@ -1,5 +1,4 @@
require "uri"
-require "open-uri"
require "rexml/document"
require "rexml/xpath"
require "activesupport"
@@ -12,8 +11,9 @@ class BadCredentials < FogbugzError; end
attr_reader :root_uri, :api_uri
- def initialize(root)
+ def initialize(root, curl)
@root_uri = root.respond_to?(:scheme) ? root : URI.parse(root)
+ @curl = curl
end
def validate!
@@ -34,7 +34,9 @@ def connect
def logon(email, password)
params = {"cmd" => "logon", "email" => email, "password" => password}
- document = get(@api_uri.merge("?#{params.to_query}"))
+ uri = @api_uri.dup
+ uri.query = params.to_query
+ document = get(uri)
bad_logon = REXML::XPath.first(document.root, "//error")
raise BadCredentials, "Bad credentials supplied to Fogbugz: #{bad_logon}" unless bad_logon.blank?
REXML::XPath.first(document.root, "//token/text()").to_s
@@ -43,11 +45,13 @@ def logon(email, password)
protected
# Returns an REXML::Document to the specified URI
def get(uri)
- data = open(uri)
+ cmd = "#{@curl} --silent '#{uri.to_s}'"
+ puts cmd
+ data = `#{cmd}`
begin
- REXML::Document.new(data.read)
+ REXML::Document.new(data)
rescue REXML::ParseException
- raise BadXml, "Could not parse response data:\n#{data.read}"
+ raise BadXml, "Could not parse response data:\n#{data}"
end
end
end
View
5 test/fogbugz_service_logon_test.rb
@@ -4,14 +4,15 @@
class FogbugzServiceLogonTest < Test::Unit::TestCase
def setup
@service_uri = URI.parse("http://fogbugz.my-service.com/")
- @service = FogbugzService.new(@service_uri)
+ @service = FogbugzService.new(@service_uri, "/path/to/curl")
@service.stubs(:get).returns(REXML::Document.new(VALID_API_RESPONSE))
@uri = @service.validate!
end
def test_logon_calls_fogbugz_to_retrieve_token
params = {"cmd" => "logon", "email" => "me@my-domain.com", "password" => "my-super-duper-password"}.to_query
- @service.expects(:get).with(@uri.merge("?#{params}")).returns(REXML::Document.new(VALID_LOGON_RESPONSE))
+ @uri.query = params
+ @service.expects(:get).with(@uri).returns(REXML::Document.new(VALID_LOGON_RESPONSE))
@service.logon("me@my-domain.com", "my-super-duper-password")
end
View
2  test/fogbugz_service_test.rb
@@ -4,7 +4,7 @@
class FogbugzServiceTest < Test::Unit::TestCase
def setup
@service_uri = URI.parse("http://fogbugz.my-service.com/")
- @service = FogbugzService.new(@service_uri)
+ @service = FogbugzService.new(@service_uri, "/path/to/curl")
end
def test_validate_connects_to_fogbugz_and_retrieves_the_api_url
Please sign in to comment.
Something went wrong with that request. Please try again.