Exemple #1
0
        public override async Task <ResolveResultDTO <DogData> > ResolveAsync(
            ResolveRequestDTO req
            )
        {
            var path = DogAPI.GetDogUrl(req.key);

            try {
                // using BeatThat.Requests.WebRequest here, just an easy way
                // to make a one-line HTTP request and get a typed result
                var data = await new WebRequest <DogData>(path).ExecuteAsync();

                return(ResolveResultDTO <DogData> .ResolveSucceeded(
                           req, data.id, data
                           ));
            }
            catch (Exception e) {
                return(ResolveResultDTO <DogData> .ResolveError(
                           req, e.Message
                           ));
            }
        }
Exemple #2
0
        public override Request <ResolveResultDTO <DogData> > Resolve(ResolveRequestDTO req, Action <Request <ResolveResultDTO <DogData> > > callback = null)
        {
            var key     = req.key;
            var path    = DogAPI.GetDogUrl(key);
            var promise = new Promise <ResolveResultDTO <DogData> >((resolve, reject) =>
            {
                new WebRequest <DogData>(path).Execute(r => {
                    if (r.hasError)
                    {
                        reject(ResolveResultDTO <DogData> .ResolveError(req, r.error));
                        return;
                    }

                    resolve(ResolveResultDTO <DogData> .ResolveSucceeded(
                                req, r.item.id, r.item
                                ));
                });
            });

            promise.Execute(callback);
            return(promise);
        }