lib/oversip/sip/uri.rb in oversip-1.3.8 vs lib/oversip/sip/uri.rb in oversip-1.4.0

- old
+ new

@@ -1,10 +1,18 @@ module OverSIP::SIP class Uri attr_reader :scheme, :user, :host, :host_type, :port, :params, :transport_param, :phone_context_param, :ovid_param, :headers + + def self.parse value + uri = ::OverSIP::SIP::MessageParser.parse_uri value, false + raise ::OverSIP::ParsingError, "invalid URI #{value.inspect}" unless uri.is_a? (::OverSIP::SIP::Uri) + uri + end + + def initialize scheme=:sip, user=nil, host=nil, port=nil @scheme = scheme.to_sym @user = user @host = host @host_type = ::OverSIP::Utils.ip_type(host) || :domain if host @@ -61,11 +69,17 @@ def params @params ||= {} end + def has_param? k + return nil if unknown_scheme? + params.include? k.to_s.downcase + end + def get_param k + return nil if unknown_scheme? params[k.to_s.downcase] end def set_param k, v return nil if unknown_scheme? @@ -80,9 +94,19 @@ if @params.include?(k=k.downcase) @uri_modified = true return @params.delete(k) end false + end + + def clear_params + return nil if unknown_scheme? + return false unless @params + @params.clear + @transport_param = nil + @phone_context_param = nil + @uri_modified = true + true end def transport_param= value return nil unless @scheme == :sip or @scheme == :sips if value \ No newline at end of file