Sha256: 7b910bf609c7352ea87f187a2b600bdd5cdbc487400406060294c2adcd2f13db

Contents?: true

Size: 707 Bytes

Versions: 2

Compression:

Stored size: 707 Bytes

Contents

class Restfulie::Common::Converter::OpenSearch::Descriptor
  
  def initialize(hash)
    @hash = hash["OpenSearchDescription"]
  end
  
  def urls
    uris = @hash["Url"]
    uris.kind_of?(Array) ? uris : [uris]
  end
  
  def use(content_type)
    uri = urls.find do |url|
      url["type"]==content_type
    end
    return nil if uri.nil?
    
    base_uri, params_pattern = extract_uri(uri)
    Restfulie.at(base_uri).accepts(content_type).open_search.with_pattern(params_pattern)
  end
  
  private
  def extract_uri(uri)
    uri = uri["template"]
    interrogation = uri.index("?")
    params = uri[interrogation+1..uri.size]
    base_uri = uri[0..interrogation-1]
    [base_uri, params]
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
restfulie-1.0.0.beta1 lib/restfulie/common/converter/open_search/descriptor.rb
restfulie-0.1.0.beta1 lib/restfulie/common/converter/open_search/descriptor.rb