diff --git a/lib/hyperclient/link.rb b/lib/hyperclient/link.rb index c660ed5..fa98cf8 100644 --- a/lib/hyperclient/link.rb +++ b/lib/hyperclient/link.rb @@ -1,6 +1,7 @@ require 'hyperclient/resource' require 'uri_template' require 'futuroscope' +require_relative '../uri_template/rfc6570/expression' module Hyperclient # Internal: The Link is used to let a Resource interact with the API. diff --git a/lib/uri_template/rfc6570/expression.rb b/lib/uri_template/rfc6570/expression.rb new file mode 100644 index 0000000..1e20351 --- /dev/null +++ b/lib/uri_template/rfc6570/expression.rb @@ -0,0 +1,24 @@ +require 'uri_template/rfc6570/expression' + +class URITemplate::RFC6570 + class Expression < Token + def expand(vars) + unused_vars = vars.keys.dup + result = [] + @variable_specs.each do |var, expand, max_length| + if Utils.def?(vars[var]) + result.push(*expand_one(var, vars[var], expand, max_length)) + end + unused_vars.delete(var) + end + unused_vars.each do |k| + result.push(*expand_one(k, vars[k], false, 0)) + end + if result.any? + return (self.class::PREFIX + result.join(self.class::SEPARATOR)) + else + return '' + end + end + end +end