How To Query A Basic API In Ruby

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
it is a Simon bacchanal quick video and this time on how you can query an API what is an API an API is basically a way for you to access the database of another application so for example if I want to retrieve all my recent status updates from a Facebook I can use the Facebook API to query the database and get the data back from Facebook the same thing with Twitter Pinterest Amazon as an API everything that's really popular has an API these days so you can actually access several parts of the database so for this video I'm going to query the Pokemon API which is that poky API or some query this which is basically an application programming interface we can query all the berries come testing counter-revolutions a Pokemon locations different moves each Pokemon has and so forth so that's exactly what we're gonna do with a ruby so to start up we're going to go to our command line we're gonna open up pride or IRB but I prefer pry is its color Tech we're going to require the open URI library this will allow us to send different requests to the API so our get requests or I post requests but this API only supports get requests for now we're going to require the GC library which will allow us to parse the JSON response they will get from the API so one query this thing for example pop upon the evolution chain of let's see if we go to the link we should get a JSON response back which is basically a index of all the evolution chain so when we passed another argument like the idea of the Aleutian chain which is probably the evolution chain of the first Pokemon which is Bulbasaur's coral or Charmander I think we get the turn baby trigger I have no idea I have a sort of hitter sir so he probably got the leaf one during the grass block much was the car bob lazar thing is Bulbasaur Roseate here Bulbasaur so Bob sir it holds it the Ivysaur which evolved into venus sir that's pretty cool so you want to query this with Ruby so we're gonna do OOP OOP deposit link wheat and then we'll get a JSON response back from the server which is basically our object let's underscore the underscore character is actually pretty cool it allows you to set to access the last calculated methods you've inputted so for example I've gotten this response but I didn't a pass in a variable here I didn't set it to a variable but I can still do it afterwards by setting it to the underscore variable which is basically the previous thing so now we got response which is our cheese all right I think it's a string now we get a string variable of our seesaw response the Ruby we can do JSON that bars of our response which we can set as a cheese sound variable and so now we got our evolution chain of doubles or basically we can do different methods on the JSON object let's see what it responds to if you call methods on any object see all the things that response to just pretty cool so it responds to the basic [Music] hash hash objects hash bolts in Ruby so we got Jason Marquis Jason up keys Jason our keys so all those main keys we have our baby baby trigger ID and chain so if you want to access the chain we can do J some chain involves - let's see what the keys are for the chain so we got evolution details of all Stewie's baby species that's pretty cool so let's say you want to query something else like the new pokémon we can access different endpoints so so we got the access point which is basically our this point so this is our access point which is the black API so this is our blank access point in which we can pass different access point I mean not access points but but resource points over article so you got various contests and counters so after each you can put in Pokemon for example then the index number like the 15 Pokemon which will return the 15 pokemons visual for example let's say you want to query the last Pokemon form from the original series which is mu 2 or you my childhood is coming back right now so you got mu and gives you all its abilities and basically we can parse that into JSON again so the square this link real quick which will return our new object and we can parse it again just not part a response I didn't set it to elastic so this thing quick response equals this thing and now we can parse the response again like JSON object and we got you for example if you want to retrieve all the abilities of I mean all the moves that us we can do chase sum equals lost and you can see all the different moves it has like level up that's not really move is it mega punch we need also for each different game they got a different level I think from when they learned the boo for example in Coliseum view only loads the move mega punch at level 20 and in black - why - it learns level 10 for example okay so it works like that so what if you just want the name of all the moves that view isn't able to learn when he levels up oh it shouldn't include the zero thing of course cuz we're not calling the first one were just this should be yep so now we got an array of all the different moves you wish able to learn it's pretty cool if you want you can pause it in us for example same moves now we'll get a collection of moves so we got moves class dismissed fury pretty cool this is the last move that he alerts and that's basically a short demonstration of how you can query different api's so you can apply this to Twitter Pinterest Amazon Google Maps for example and all the other ones that are freely available some will require you to have a key to add identify you you so for example if you go to the Facebook Graph API and you try to query it with me or dick nope what is the endpoint again this yep so if you try to curry it with yourself you have to have an access token to identify yourself but the Pokemon API is just freed used for anyone which is pretty cool so there was was a video if you liked it thumbs it up leave a comment and so forth
Info
Channel: Simon Somlai
Views: 5,852
Rating: undefined out of 5
Keywords:
Id: yUkv1pinlmg
Channel Id: undefined
Length: 11min 13sec (673 seconds)
Published: Sat Apr 15 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.