Source

Linq2vk / src / UserAPI / Common / Query.fs

Full commit
namespace Linq2vk.Core.Implementation

open System.Collections.Generic
open Linq2vk.Core

module Query =
    
    let init (sid:string) =
        [("sid", sid)]
        
    let add (k:string) (v:'a) q =
        (k, v.ToString()) :: q
        
    let toUrl q =
        let prefix = "http://userapi.com/data?"
        let makepair (k, v) =
            sprintf "%s=%s" k v
        let urlQuery = q |> (Seq.map makepair >> Seq.toArray >> (fun xs -> System.String.Join("&", xs)))
        prefix + urlQuery

    let addAction (act:Action) =
        add "act" <|
            match act with
            | Friends               -> "friends"
            | UpdatesActivity       -> "updates_activity"
            | UpdatesFriends        -> "updates_friends"
            | UpdatesPhotos         -> "updates_photos"
            | UpdatesTaggedPhotos   -> "updates_tagged_photos"
            | Profile               -> "profile"
            | Inbox                 -> "inbox"
            | Outbox                -> "outbox"
            | _                     -> failwith "Not implemented"
            
    // TODO: why does not point-free style work here?
    let addId id = add "id" id
    let addTo toVal = add "to" toVal
    let addFrom from = add "from" from