Created
          December 27, 2013 11:23 
        
      - 
      
- 
        Save hodzanassredin/8145754 to your computer and use it in GitHub Desktop. 
    vk api type providers way
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | type getter = string->seq<string * string> -> Async<string> | |
| type ResponseWallGet = JsonProvider<"./wall.get.json"> | |
| type Api(acess_token : string) = class | |
| let create (acess_token:string) : getter = | |
| fun method_name parameters -> | |
| async { | |
| let url = sprintf "https://api.vkontakte.ru/method/%s" method_name | |
| let query = seq { | |
| yield ("acess_token", acess_token) | |
| yield! parameters | |
| } | |
| let! html = Http.AsyncRequest( url, | |
| query=query, | |
| meth="GET", | |
| headers = [ "accept", "application/json" ]) | |
| return html | |
| } | |
| let api = create acess_token | |
| let unix_time seonds = (new DateTime(1970, 1, 1)).AddSeconds((float)seonds) | |
| member x.WallGet(owner_id:int, count:int) = async { | |
| let! json = api "wall.get" ["owner_id", owner_id.ToString(); "count" , count.ToString()] | |
| return ResponseWallGet.Parse(json).Response | |
| } | |
| member x.WallGetAsync(owner_id:int, count:int) = Async.StartAsTask(x.WallGet(owner_id, count)) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment