Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

Allow connections to non-hosted servers that have a path in their URI #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/ridley/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,16 @@ def initialize(server_url, client_name, client_key, options = {})
b.adapter :net_http_persistent
end

uri_hash = Ridley::Helpers.options_slice(Addressable::URI.parse(server_url).to_hash, :scheme, :host, :port)
uri_hash = Ridley::Helpers.options_slice(Addressable::URI.parse(server_url).to_hash, :scheme, :host, :port, :path)

unless uri_hash[:port]
uri_hash[:port] = (uri_hash[:scheme] == "https" ? 443 : 80)
end

if org_match = server_url.match(/.*\/organizations\/(.*)/)
if org_match = uri_hash[:path].match(/^\/organizations\/(.*)/)
@organization = org_match[1]
end

unless @organization.nil?
uri_hash[:path] = "/organizations/#{@organization}"
end

super(Addressable::URI.new(uri_hash), options)
@headers[:user_agent] = "Ridley v#{Ridley::VERSION}"
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/ridley/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
describe "parsing the 'server_url' option" do
its(:host) { should eql("api.opscode.com") }
its(:scheme) { should eql("https") }
its(:path_prefix) { should eql("/") }
its(:path_prefix) { should eql("/some_path") }
end

describe "with a server_url containing an organization" do
Expand All @@ -51,7 +51,7 @@
subject.organization.should eql(organization)
end

it "sets the 'path_prefix' of the connection the organization sub URI" do
it "sets the 'path_prefix' of the connection to the organization sub URI" do
subject.path_prefix.should eql("/organizations/#{organization}")
end
end
Expand Down