コード例 #1
0
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";
            System.Diagnostics.Trace.WriteLine("In Home Controller");

            // accessing developer.marvel.com

            //HTTP GET
            // http://gateway.marvel.com/v1/public/comics?ts=1&apikey=1234&hash=ffd275c5130566a2916217b101f26150


            // randomize which of the 50 retrieved characters will be displayed
            int characterIndex = new Random().Next(0, 99);


            var marvelClient = new MarvelRestClient(pb_key, pr_key);
            var filter       = new CharacterRequestFilter
            {
                Limit = 100
            };

            var response = marvelClient.FindCharacters(filter);
            var imageUrl = response.Data.Results[characterIndex].Thumbnail.Path + "." +
                           response.Data.Results[characterIndex].Thumbnail.Extension;

            if (imageUrl.Contains("image_not_available"))
            {
                imageUrl = "https://www.writeups.org/wp-content/uploads/Spider-Man-Marvel-Comics-Peter-Parker-Profile.jpg";
            }
            ViewBag.imageUrl = imageUrl;


            return(View());
        }
コード例 #2
0
        private static List <Personagem> BaixarPersonagens(MarvelRestClient client)
        {
            int offset      = 0;
            int limit       = 100;
            int total       = int.MaxValue;
            var personagens = new List <Personagem>();

            while (offset < total)
            {
                var filtro = new CharacterRequestFilter()
                {
                    Limit  = limit,
                    Offset = offset
                };

                var response = client.FindCharacters(filtro);

                total   = Convert.ToInt32(response.Data.Total);
                offset += limit;

                foreach (var character in response.Data.Results)
                {
                    var personagem = new Personagem()
                    {
                        IdPersonagem    = character.Id,
                        Nome            = character.Name,
                        QuantQuadrinhos = character.Comics.Items.Count
                    };

                    personagens.Add(personagem);
                }
            }

            return(personagens);
        }
コード例 #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            try
            {
                MarvelRestClient client     = new MarvelRestClient(publicKey, privateKey);
                var response                = client.FindCharacters();
                List <Character> Characters = new List <Character>();
                foreach (var character in response.Data.Results)
                {
                    Characters.Add(new Character()
                    {
                        Name     = character.Name,
                        ImageUrl = string.Format("{0}.{1}", character.Thumbnail.Path, character.Thumbnail.Extension)
                    });
                }

                ListView lstSuperHero = FindViewById <ListView>(Resource.Id.lstSuperHeroes);
                _adapter             = new SuperHeroAdapter(this, Characters);
                lstSuperHero.Adapter = _adapter;
            }
            catch (Exception ex)
            {
            }
        }
コード例 #4
0
        public List <ComicBook> GetFilteredComics(string filteredString)
        {
            var client = new MarvelRestClient(publicKey, privateKey);
            var filter = new ComicRequestFilter();

            filter.TitleStartsWith = filteredString;
            var response = client.FindComics(filter);
            List <ComicBook> comicList = new List <ComicBook>();

            if (response != null && response.Data != null)
            {
                foreach (var comic in response.Data.Results)
                {
                    var book = new ComicBook();
                    book.SeriesTitle = comic.Title;
                    book.Description = SetDescription(comic);//comic.Description;
                    book.IssueNumber = comic.IssueNumber;
                    var thumbNail = new Thumbnail();
                    thumbNail.Path      = comic.Thumbnail.Path;
                    thumbNail.Extension = comic.Thumbnail.Extension;
                    book.Thumbnail      = thumbNail;
                    List <ComicImage> images = new List <ComicImage>();
                    for (int i = 0; i < comic.Images.Count; i++)
                    {
                        ComicImage image = new ComicImage();
                        image.Extension = comic.Images[i].Extension;
                        image.Path      = comic.Images[i].Path;
                        images.Add(image);
                    }
                    comicList.Add(book);
                }
            }
            return(comicList);
        }
コード例 #5
0
ファイル: Character.cs プロジェクト: sully-emoney/marvel-api
        public static List <Character> FindByName(string name)
        {
            var creds  = new Credentials();
            var client = new MarvelRestClient(creds.PublicKey, creds.PrivateKey);

            var filter = new CharacterRequestFilter();

            filter.NameStartsWith = name;

            var response = client.FindCharacters(filter);

            return(ResultsToList(response));
        }
コード例 #6
0
ファイル: Comic.cs プロジェクト: sully-emoney/marvel-api
        /// <summary>
        /// Limited to the top 5 comics ordered by Name Ascending
        /// </summary>
        /// <param name="character"></param>
        /// <returns></returns>
        public static List <Comic> GetComics(Character character)
        {
            var creds  = new Credentials();
            var client = new MarvelRestClient(creds.PublicKey, creds.PrivateKey);

            var filter = new ComicRequestFilter();

            filter.OrderBy(OrderResult.NameAscending);
            filter.Limit = 5;

            var comicResponse = client.FindCharacterComics(character.Id.ToString(), filter);

            return(ResultsToList(comicResponse));
        }
コード例 #7
0
ファイル: Comic.cs プロジェクト: sully-emoney/marvel-api
        /// <summary>
        /// Limited to the 1 comic ordered by Name Ascending
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>
        public static Comic GetComic(string title)
        {
            var creds  = new Credentials();
            var client = new MarvelRestClient(creds.PublicKey, creds.PrivateKey);

            var filter = new ComicRequestFilter();

            filter.OrderBy(OrderResult.NameAscending);
            filter.Limit           = 1;
            filter.TitleStartsWith = title;

            var comicResponse = client.FindComics(filter);

            return(ResultsToList(comicResponse)[0]);
        }
コード例 #8
0
        public static void Main()
        {
            // Initialize the API client
            //
            var client = new MarvelRestClient(publicKey, privateKey);

            // First 20 characters
            //
            var response = client.FindCharacters();

            // Iterate through the results and print them out.
            //
            response.Data.Results.ForEach(c => Console.WriteLine($"{c.Name} : {c.Description}"));
            Console.ReadLine();
        }
コード例 #9
0
ファイル: HomeController.cs プロジェクト: rroa/marvel-csharp
        public JsonResult SomeActionMethod(NameViewModel postdata)
        {
            const string apiKey     = "YOUR API PUBLIC KEY";
            const string privateKey = "YOUR API PRIVATE KEY";

            var client = new MarvelRestClient(apiKey, privateKey);
            List <ResultViewModel> results = null;

            if (postdata.Type.ToLower() == "character")
            {
                var filter = new CharacterRequestFilter {
                    NameStartsWith = postdata.Name
                };
                filter.OrderBy(OrderResult.NameAscending);
                filter.Limit = 40;

                var response = client.GetCharacters(filter);

                if (response.Code == "200")
                {
                    results =
                        response.Data.Results.Select(res =>
                                                     new ResultViewModel {
                        Id = res.Id, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
                    }).ToList();
                }
            }
            else
            {
                var filter = new ComicRequestFilter {
                    TitleStartsWith = postdata.Name
                };
                filter.OrderBy(OrderResult.NameAscending);
                filter.Limit = 40;

                var response = client.GetComics(filter);

                if (response.Code == "200")
                {
                    results =
                        response.Data.Results.Select(res =>
                                                     new ResultViewModel {
                        Id = res.Id, Name = res.Title, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
                    }).ToList();
                }
            }
            return(Json(results));
        }
コード例 #10
0
        public override async Task <FunctionResponse> ProcessMessageAsync(FunctionRequest request)
        {
            // Initialize the marvel api client
            var client = new MarvelRestClient(PUBLICKEY, PRIVATEKEY);

            // Initialize an avengers team
            var team = new Types.AvengerTeam();

            // Initialize character request filter
            var characterRequestFilter = new CharacterRequestFilter();

            // Query marvel api for desired avengers
            // TODO: refine this logic to assemble stronger team
            characterRequestFilter.OrderBy(OrderResult.NameAscending);
            characterRequestFilter.Limit = 1;
            var characterResponse = client.FindCharacters(characterRequestFilter);

            foreach (var character in characterResponse.Data.Results)
            {
                // Initialize a comic listing filter to determine power for each avenger
                var comicRequestFilter = new ComicRequestFilter();
                comicRequestFilter.AddCharacter(character.Id);

                // Form avenger object
                var currentAvenger = new Types.Avenger();
                currentAvenger.name  = character.Name;
                currentAvenger.id    = character.Id;
                currentAvenger.power = client.FindCharacterComics(character.Id.ToString(), comicRequestFilter).Data.Total;

                // Add avenger to team
                team.AddAvengerToTeam(currentAvenger);
            }

            var message = GameLogic.Methods.FormatBattlefieldId(request.RoundNumber, DateTime.UtcNow.ToString(), "AVENGERS", "DEFEND");

            await Methods.PostBattlefield(new Types.Item
            {
                Id    = message,
                Value = JsonConvert.SerializeObject(team.avengerTeam)
            });

            return(new FunctionResponse());
        }
コード例 #11
0
        public ActionResult Atualizar()
        {
            var client = new MarvelRestClient(publicKey, privateKey);

            List <Personagem> personagens = BaixarPersonagens(client);

            using (var ctx = new Contexto())
            {
                if (ctx.Personagens.Count() > 0)
                {
                    ctx.Personagens.RemoveRange(ctx.Personagens.ToList());
                    ctx.SaveChanges();
                }

                ctx.Personagens.AddRange(personagens);
                ctx.SaveChanges();
            }

            return(View(personagens));
        }
コード例 #12
0
 public MainActivity()
 {
     client = new MarvelRestClient(publicKey, privateKey);
 }
コード例 #13
0
ファイル: ApiHelper.cs プロジェクト: CoyCoding/Comix
 public static void InitializeClient()
 {
     MarvelClient = new MarvelRestClient(MarvelpublicKey, MarvelprivateKey);
     HeroContext  = new PowerLevelApiClient(HeroKey);
 }
コード例 #14
0
 public ApiMarvel()
 {
     client = new MarvelRestClient(publickey, privatekey);
 }
コード例 #15
0
        public IActionResult Index(/*RestResponse restResponse*//*RestRequest request*//*NameViewModel postdata*/)
        {
            const string apiKey     = "1f8c669bfb6d6b86aa65400c8f3ad03d";
            const string privateKey = "b7e37b0815b570c2f84f0267060b0637698ed06a";

            var client = new MarvelRestClient(apiKey, privateKey);
            //List<ResultViewModel> results = null;
            List <CharactersInResultViewModel> results = null;
            List <CharactersInResultViewModel> resultsCharactersInAStory = null;



            //NameViewModel postdata = "hulk";

            //if (postdata.Type.ToLower() == "character")
            //{
            var filter = new CharacterRequestFilter {
                NameStartsWith = "hulk"
            };

            filter.OrderBy(OrderResult.NameAscending);
            //filter.Limit = 40;
            filter.Limit = 1;


            var response = client.FindCharacters(filter);

            //if (response.Code == "200")
            //{
            //    results =
            //    response.Data.Results.Select(res =>
            //        new CharactersInResultViewModel { Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
            //}


            results =
                response.Data.Results.Select(res =>
                                             new CharactersInResultViewModel {
                StoryID = /*res.Stories.Items.Equals(*/ "1009351" /*).ToString()*/, /**StoryID = res.Stories. */ Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
            }).ToList();



            //            else
            //            {

            //                    if (response.Code == "200")
            //            {
            //            results =
            //            response.Data.Results.Select(res =>
            //                new CharactersInResultViewModel { Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
            //    }).ToList();
            //}


            //results =
            //            response.Data.Results.Select(res =>
            //                new CharactersInResultViewModel { StoryID = /*res.Stories.Items.Equals(*/"1009351"/*).ToString()*/,/**StoryID = res.Stories. */Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();


            List <ResultViewModel> realresults = new List <ResultViewModel>();

            //ResultViewModel realresults;


            realresults =
                response.Data.Results.Select(res =>
                                             new ResultViewModel {
                Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
            }).ToList();

            realresults.FirstOrDefault();



            //else
            //{

            //if (response.Code == "200")
            //{
            //results =
            //response.Data.Results.Select(res =>
            //    new ResultViewModel { Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
            //    }


            //results =
            //response.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { StoryID = /*res.Stories.Items.Equals(*/"1009351"/*).ToString()*/,/**StoryID = res.Stories. */Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();


            //}
            //else
            //{

            FindStoryCharacters();

            //ViewBag.Message = (List<CharactersInResultViewModel>)request;

            /*ViewBag.Message =*/ /*(List<CharactersInResultViewModel>)*//*request;*/

            /* ViewBag.Message =*/ /*(List<CharactersInResultViewModel>)*//*restResponse;*/


            //ViewBag.Message = results;



            //var comicFilter = new ComicRequestFilter { TitleStartsWith = "hulk" };
            //comicFilter.OrderBy(OrderResult.NameAscending);
            //comicFilter.Limit = 40;
            ////comicFilter.Limit = 1;

            //var comicFilterresponse = client.FindComics(comicFilter);

            ////if (response.Code == "200")
            ////{
            //results =
            //response.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { /*Characters = Marvel.Api.Model.DomainObjects.Story.*/ Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
            ////}
            //var firstResultDescription = results.FirstOrDefault();

            //var characterList =

            //var characterList = firstResultDescription.Description.

            //var Filter = new StoryRequestFilter { };
            //Filter.OrderBy(OrderResult.NameAscending);
            //Filter.Limit = 40;
            ////filter.Limit = 1;

            //StoryResult storyFilterresponse = client.FindStory("1009351");  /*client.FindStoryCharacters("1009351");*/

            //resultsCharactersInAStory =
            //storyFilterresponse.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { /*Characters = res.Stories., */Id = res.Id, Description = res.Description/*, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL */}).ToList();
            ////    }



            //storyFilterresponse.Data.Results.

            //resultsCharactersInAStory =
            //storyFilterresponse.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { /*Characters = res.Stories., */Id = res.Id, Description = res.Description/*, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL */}).ToList();
            ////    }

            //if (response.Code == "200")
            //{
            //results =
            //response.Data.Results.Select(res =>
            //    new ResultViewModel { Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
            ////    }
            ////}

            List <CharactersInResultViewModel> charactersResults = null;

            charactersResults =
                response.Data.Results.Select(res =>
                                             new CharactersInResultViewModel {
                Name = res.Name
            }).ToList();
            //    }
            //}

            var storyFilterresponseCharacterList = charactersResults;

            var baseAddress = new Uri("http://importmarvel.com/");

            using (var httpClient = new HttpClient
            {
                BaseAddress = baseAddress
            })
            {
                using (var allCharactersInAStory = /*await */ httpClient.GetAsync("api/characters"))
                {
                    string allCharactersInAStoryData = allCharactersInAStory.Result.ToString();

                    ViewBag.Message = allCharactersInAStoryData;

                    return(View(allCharactersInAStoryData));
                }

                //ViewBag.Message = allCharactersInAStoryData;

                //ViewBag.Message = realresults;

                //return View(allCharactersInAStoryData);

                //return View(realresults);



                //ViewBag.Message = results;


                //return View(results);



                //ViewBag.Message = resultsCharactersInAStory;


                //return View(resultsCharactersInAStory);



                //return View(storyFilterresponse);


                //ViewBag.Message = storyFilterresponseCharacterList;

                //return Json(storyFilterresponseCharacterList);

                //return View("Index", restResponse);

                //return View(storyFilterresponseCharacterList);

                //return Json(results);



                //[HttpPost]
                //[HttpGet]
                //public IActionResult Index(/*NameViewModel postdata*/)
                //{

                //    const string apiKey = "1f8c669bfb6d6b86aa65400c8f3ad03d";
                //    const string privateKey = "b7e37b0815b570c2f84f0267060b0637698ed06a";

                //    const string characterName = "hulk";

                //    var client = new MarvelRestClient(apiKey, privateKey);
                //    List<ResultViewModel> results = null;

                //    //if (postdata.Type.ToLower() == "character")
                //    //{
                //    var filter = new StoryRequestFilter { /*Characters.Equals == The Hulk*//*NameStartsWith = postdata.Name*/ };
                //    filter.OrderBy(OrderResult.NameAscending);
                //    //filter.Comics.Contains("hulk");
                //    //filter.Comics.Where(res.Id == 30)
                //    //filter.Series.
                //    filter.Limit = 1;

                //    //var response = client.FindCharacters(filter);

                //    var response = client.FindStories(filter);

                //    //if (response.Code == "200")
                //    //    {
                //    //results =
                //    //response.Data.Results./*Where(results.*//*Where(response.Data.Results.).*/Select(res =>
                //    //                //new ResultViewModel { Id = 30/*res.Id*/, Description = res.Description,  Name = "The second volume containing the Hulk\u0027s early adventures with appearances by the Sub-Mariner, the Mandarin, Ka-Zar and Nick Fury" /*res.Title*/, Url = "http://gateway.marvel.com/v1/public/stories/30" /*res.ResourceURI*/ })./*Where(response.Data.Results.Id*//*.Where(res.Id == 30)*//*.*/ToList()/*.Where(Id == 30)*//*.FirstOrDefault*//*(*//*t => t.Type == "detail").URL }).ToList(*//*)*/;
                //    //                new ResultViewModel { Id = 30, Description = res.Description, Name = res.Title, Url = "http://gateway.marvel.com/v1/public/stories/30/" })./*Where(response.Data.Results.Id*//*.Where(res.Id == 30)*//*.*/ToList()/*.Where(Id == 30)*//*.FirstOrDefault*//*(*//*t => t.Type == "detail").URL }).ToList(*//*)*/;

                //    results =
                //            response.Data.Results.Select(res =>
                //                new ResultViewModel { Id = res.Id, Description = res.Description, Name = res.Title, Url = res.ResourceURI.FirstOrDefault().ToString() }).ToList();



                //    //}.

                //    //results.Where()

                //    //else
                //    //{
                //    //    var filter = new ComicRequestFilter { TitleStartsWith = postdata.Name };
                //    //    filter.OrderBy(OrderResult.NameAscending);
                //    //    filter.Limit = 40;

                //    //    var response = client.FindComics(filter);

                //    //    if (response.Code == "200")
                //    //    {
                //    //        results =
                //    //        response.Data.Results.Select(res =>
                //    //            new ResultViewModel { Id = res.Id, Name = res.Title, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
                //    //    }
                //    //}
                //    return Json(results/*.ToList()*/);
                //    //return View(results);
                //}

                //return View();



                //[HttpPost]
                //public JsonResult SomeActionMethod(NameViewModel postdata)
                //{
                //    const string apiKey = "1f8c669bfb6d6b86aa65400c8f3ad03d";
                //    const string privateKey = "b7e37b0815b570c2f84f0267060b0637698ed06a";


                //    var client = new MarvelRestClient(apiKey, privateKey);
                //    List<ResultViewModel> results = null;

                //    if (postdata.Type.ToLower() == "character")
                //    {
                //        var filter = new CharacterRequestFilter { NameStartsWith = postdata.Name };
                //        filter.OrderBy(OrderResult.NameAscending);
                //        filter.Limit = 40;

                //        var response = client.FindCharacters(filter);

                //        if (response.Code == "200")
                //        {
                //            results =
                //            response.Data.Results.Select(res =>
                //                new ResultViewModel { Id = res.Id, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
                //        }
                //    }
                //    else
                //    {
                //        var filter = new ComicRequestFilter { TitleStartsWith = postdata.Name };
                //        filter.OrderBy(OrderResult.NameAscending);
                //        filter.Limit = 40;

                //        var response = client.FindComics(filter);

                //        if (response.Code == "200")
                //        {
                //            results =
                //            response.Data.Results.Select(res =>
                //                new ResultViewModel { Id = res.Id, Name = res.Title, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
                //        }
                //    }
                //    return Json(results);
                //}

                //public IActionResult Privacy()
                //{
                //    return View();
                //}
            }
        }