PROTON-781: Added the URL class to the Ruby core APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/afd25a61 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/afd25a61 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/afd25a61 Branch: refs/heads/PROTON-781-ruby-reactor-apis Commit: afd25a612268ae7d891bb25dc4d831bdc52331f3 Parents: ac46b78 Author: Darryl L. Pierce <mcpie...@gmail.com> Authored: Wed Mar 4 16:36:39 2015 -0500 Committer: Darryl L. Pierce <mcpie...@gmail.com> Committed: Thu Jun 18 09:27:21 2015 -0400 ---------------------------------------------------------------------- proton-c/bindings/ruby/lib/core/url.rb | 77 ++++++++++++++++++++++++++ proton-c/bindings/ruby/lib/qpid_proton.rb | 1 + 2 files changed, 78 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/afd25a61/proton-c/bindings/ruby/lib/core/url.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/core/url.rb b/proton-c/bindings/ruby/lib/core/url.rb new file mode 100644 index 0000000..a68811a --- /dev/null +++ b/proton-c/bindings/ruby/lib/core/url.rb @@ -0,0 +1,77 @@ +#-- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +#++ + +module Qpid::Proton + + class URL + + attr_reader :scheme + attr_reader :username + attr_reader :password + attr_reader :host + attr_reader :port + attr_reader :path + + def initialize(url = nil, options = {}) + options[:defaults] = true + + if url + @url = Cproton.pn_url_parse(url) + if @url.nil? + raise ArgumentError.new("invalid url: #{url}") + end + else + @url = Cproton.pn_url + end + @scheme = Cproton.pn_url_get_scheme(@url) + @username = Cproton.pn_url_get_username(@url) + @password = Cproton.pn_url_get_password(@url) + @host = Cproton.pn_url_get_host(@url) + @port = Cproton.pn_url_get_port(@url) + @path = Cproton.pn_url_get_path(@url) + defaults + end + + def port=(port) + if port.nil? + Cproton.pn_url_set_port(@url, nil) + else + Cproton.pn_url_set_port(@url, port) + end + end + + def port + Cproton.pn_url_get_port(@url).to_i + end + + def to_s + "#{@scheme}://#{@username.nil? ? '' : @username}#{@password.nil? ? '' : '@' + @password + ':'}#{@host}:#{@port}/#{@path}" + end + + private + + def defaults + @scheme = @scheme || "ampq" + @host = @host || "0.0.0.0" + @port = @port || 5672 + end + + end + +end http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/afd25a61/proton-c/bindings/ruby/lib/qpid_proton.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/qpid_proton.rb b/proton-c/bindings/ruby/lib/qpid_proton.rb index 33fe9b6..11a555f 100644 --- a/proton-c/bindings/ruby/lib/qpid_proton.rb +++ b/proton-c/bindings/ruby/lib/qpid_proton.rb @@ -78,6 +78,7 @@ require "core/ssl_details" require "core/ssl" require "core/transport" require "core/base_handler" +require "core/url" # Messenger API classes require "messenger/subscription" --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org