From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id D072E7EE25 for ; Mon, 28 Oct 2013 23:26:07 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of kosmo.zb@gmail.com) identity=pra; client-ip=209.85.217.179; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="kosmo.zb@gmail.com"; x-sender="kosmo.zb@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of kosmo.zb@gmail.com designates 209.85.217.179 as permitted sender) identity=mailfrom; client-ip=209.85.217.179; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="kosmo.zb@gmail.com"; x-sender="kosmo.zb@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-lb0-f179.google.com) identity=helo; client-ip=209.85.217.179; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="kosmo.zb@gmail.com"; x-sender="postmaster@mail-lb0-f179.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArgCAArkblLRVdmzlGdsb2JhbABZDoMxVKwGB5JdgSMIFg4BAQEBBwsLCRIqgiUBAQQBQAEsAQsBAwELAQUFBwQNDSEiEgEFAQoSGQgKh2MDCQYNmXCPYIRXJwMKV4kOAQUMjHOBAhmBCIRmA5gKgS+ObBgpgWSCLj88 X-IPAS-Result: ArgCAArkblLRVdmzlGdsb2JhbABZDoMxVKwGB5JdgSMIFg4BAQEBBwsLCRIqgiUBAQQBQAEsAQsBAwELAQUFBwQNDSEiEgEFAQoSGQgKh2MDCQYNmXCPYIRXJwMKV4kOAQUMjHOBAhmBCIRmA5gKgS+ObBgpgWSCLj88 X-IronPort-AV: E=Sophos;i="4.93,588,1378850400"; d="scan'208";a="32297636" Received: from mail-lb0-f179.google.com ([209.85.217.179]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 28 Oct 2013 23:26:07 +0100 Received: by mail-lb0-f179.google.com with SMTP id w6so3462756lbh.10 for ; Mon, 28 Oct 2013 15:26:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=oCgO3scGNkB20lC6pBZkGsC27s1rMj4ZAD0QU3N0NuM=; b=oYo6zm31PrePO35wOyhpqBe9BH5vGqQuf3JmHFiIEoU2pPKAHD4BcYEJsB+em2sXNB BYCbVbwN0YpoFvitGg/J6J+YTz04pYSGR2303i7fPkfNWb9GRqERRmiZ71gutsuVNNCK 63eKDtRUYG0DM2zlsfCNb+Z0nZNhsleY/RyLw9XLUO0Zsi1dVzJLR3DksKhqqa80ZA7/ T3aokEjCwm+4IWHhwQjmjytIAkkjX13vGr7IDGV4VkYfk7DcSgw9pzbtxH/Wla4LDRMt oz2LFHzDzayc0dSdIv+Z+cIYLEATYqVVMdaNo0/d0X3U/wpSWVKrS8Gd3SXW+vQ+4Tkl JEQQ== MIME-Version: 1.0 X-Received: by 10.152.116.109 with SMTP id jv13mr3339083lab.30.1382999166060; Mon, 28 Oct 2013 15:26:06 -0700 (PDT) Sender: kosmo.zb@gmail.com Received: by 10.112.61.130 with HTTP; Mon, 28 Oct 2013 15:26:06 -0700 (PDT) In-Reply-To: References: Date: Mon, 28 Oct 2013 22:26:06 +0000 X-Google-Sender-Auth: K08dWk7yALLeXZuUWE5x9cct4jI Message-ID: From: David Sheets To: ollie.frolovs.2012@my.bristol.ac.uk Cc: O Caml Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Using Uri with Google Distance Matrix API On Mon, Oct 28, 2013 at 9:58 PM, O Frolovs wrote: > Hello Hi Ollie, > I'm learning OCaml and currently trying to use it for my project at uni. > > Specifically, i=92m trying to use Uri [1] to create a Google Distance > Matrix request and i find it a bit awkward since the API uses pipe > character "|" for separating parameter values but Uri uses commas "," > and i could not find a way to override it: Unfortunately, the Google Distance Matrix API does not conform to the Internet Standard for URIs. Specifically, the pipe character "|" is not allowed in a well-formed URI. I'm not sure why Google has decided to use this character out of the very many separators available to them. > utop # open Core.Std;; > utop # #require "uri";; > > utop # let x =3D Uri.of_string "http://www.github.com/";; > val x : Uri.t =3D > > utop # let y =3D Uri.add_query_param x ("origins", ["Bristol"; > "Cambridge"; "Plymouth"; "London"]);; > val y : Uri.t =3D > > utop # Uri.to_string y;; > - : string =3D "http://www.github.com/?origins=3DBristol,Cambridge,Plymou= th,London" > > This is not what the API expects. > > I also tried concatenating the origins values before passing it to Uri > but as you can see below, Uri performed character escape on pipe > characters. So besides not looking elegant, it did not work: > > utop # String.concat ~sep:"|" ["Bristol"; "Cambridge"; "Plymouth"; "Londo= n"];; > - : string =3D "Bristol|Cambridge|Plymouth|London" > > utop # let y =3D Uri.add_query_param x ("origins", [c]);; > val y : Uri.t =3D > > utop # Uri.to_string y;; > - : string =3D "http://www.github.com/?origins=3DBristol%7CCambridge%7CPl= ymouth%7CLondon" > > I am wondering > > (a) if there is a way to make Uri do what i want, that is to use pipe > character to separate the origins values. I do not believe there is a way to accomplish this in Uri 1.3.8. Have you tried submitting the percent-encoded query string to the API to see if Google properly interprets the escaping of invalid characters? Uri is designed to take as input any string and produce as output only those strings that are conformant to RFC 3986. > (b) why Uri does not have an optional ~sep parameter, like Jane > Street's Core.String.concat does? No one has implemented it yet. :-) There has been discussion about significantly changing this API feature for 1.4 as well. If you are not manipulating the URIs heavily and are not in need of input sanitation, using Uri may not be necessary unless another library requires input of Uri.t values. If none of this helps you, please create an issue at and we may end up adding something to help you in the next revision (could be later this week depending on how persuasive you are and how extensive the feature). Hope this helps, David > Help?! > > -- Ollie > > [1] http://www.cl.cam.ac.uk/projects/ocamllabs/pkg/uri/1.3.8/index.html > [2] https://developers.google.com/maps/documentation/distancematrix/ > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs