Method: Azure::Table::TableService#entities_uri

Defined in:
lib/azure/table/table_service.rb

#entities_uri(table_name, partition_key = nil, row_key = nil, query = {}) ⇒ Object



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/azure/table/table_service.rb', line 510

def entities_uri(table_name, partition_key=nil, row_key=nil, query={})
  return table_name if table_name.kind_of? ::URI

  path = if partition_key && row_key
    "%s(PartitionKey='%s',RowKey='%s')" % [
      table_name.encode("UTF-8"), encodeODataUriValue(partition_key.encode("UTF-8")), encodeODataUriValue(row_key.encode("UTF-8"))
    ]
  else
    "%s()" % table_name.encode("UTF-8")
  end

  uri = generate_uri(path)
  qs = []
  if query
    query.each do | key, val |
      key = key.encode("UTF-8")
      val = val.encode("UTF-8")

      if key[0] == "$"
        qs.push "#{key}#{::URI.encode_www_form(""=>val)}"
      else
        qs.push ::URI.encode_www_form(key=>val)
      end
    end
  end
  uri.query = qs.join '&' if qs.length > 0
  uri
end