<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Peter Papadimitropoulos on Medium]]></title>
        <description><![CDATA[Stories by Peter Papadimitropoulos on Medium]]></description>
        <link>https://medium.com/@peterpapadimitropoulos?source=rss-768bcaa3ab90------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Hd6ad10rtGsC5RtG.</url>
            <title>Stories by Peter Papadimitropoulos on Medium</title>
            <link>https://medium.com/@peterpapadimitropoulos?source=rss-768bcaa3ab90------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 07:01:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@peterpapadimitropoulos/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Facebook Authentication in a React App]]></title>
            <link>https://medium.com/front-end-weekly/facebook-authorization-in-a-react-app-b7a9176aacb6?source=rss-768bcaa3ab90------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7a9176aacb6</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[facebook]]></category>
            <dc:creator><![CDATA[Peter Papadimitropoulos]]></dc:creator>
            <pubDate>Tue, 17 Oct 2017 00:10:39 GMT</pubDate>
            <atom:updated>2017-11-21T20:01:12.781Z</atom:updated>
            <content:encoded><![CDATA[<p>The Facebook API documentation is a great source of information for accomplishing most Facebook partnered related tasks.</p><p>The most popular being user authentication. Having a Facebook user sign into your app and using their basic information to perform user related tasks.</p><p>Looking at the documentation, you can see that there are different implementation solutions for different mediums such as iOS, Android and Web. We will be looking at Web.</p><p>The Web solution is tailored to plain Javascript. Let’s see how we can take what is there and tailor it closer to a React application.</p><p>The first step is to log into the Facebook developers website using your Facebook login:</p><p><a href="http://t.umblr.com/redirect?z=https%3A%2F%2Fdevelopers.facebook.com%2F&amp;t=M2M0Mjk2MDExYzY5MjQ0YTYxYzA5ZjhhNzgyMjY3MmUxNGJmYzc3NyxWWlVlOHhBSg%3D%3D&amp;b=t%3Aerpxo-rYPTtKfNgc4xAgiA&amp;p=https%3A%2F%2Fpeterpapadim.tumblr.com%2Fpost%2F164788886766%2Ffacebook-authorization-in-a-react-app&amp;m=1">https://developers.facebook.com/</a></p><p>Doing this will provide you with a App ID which we will be using to connect Facebook to our App.</p><p>This App ID will look like a string of numbers and will be available under “My Apps” when logged in.</p><p>Let’s look at the quick start with Javascript instructions to get started:</p><p><a href="http://t.umblr.com/redirect?z=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fjavascript%2Fquickstart&amp;t=OTI5Y2VmOGZiYjlkMTliMjY4ZTIyMTg1NDRiNGEzYmRlZDBkZDhhNixWWlVlOHhBSg%3D%3D&amp;b=t%3Aerpxo-rYPTtKfNgc4xAgiA&amp;p=https%3A%2F%2Fpeterpapadim.tumblr.com%2Fpost%2F164788886766%2Ffacebook-authorization-in-a-react-app&amp;m=1">https://developers.facebook.com/docs/javascript/quickstart</a></p><p>We need to begin by including Facebooks SDK into our app.</p><p>The documentation provides us with a script that should be included into our html files we’d like this incorporated into. This shouldn’t be so bad right? We are using React and just have a single paged application, so that would mean we would just have to include this script into one file.</p><p>Here is what the script to be included looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/0*e99B7hrIBuqwiC03.png" /></figure><p>There is just one minor adjustment we need to make to the code. Notice in the <strong>#fbAsyncInit </strong>function there is a object which includes a key-value pair with appId as its key. We will have to adjust the value so that instead of ‘your-app-id’, we have our new Facebook App ID listed. This will get our App talking to Facebook.</p><p>There are a couple of things to note before we go any further.</p><p>This script is ran asynchronously. What does this mean for us.</p><p>We are using React and not manipulating the DOM directly, so we want to tie this into a component and its lifecycle methods in order to fully predict the use and readiness of our new functions. The script being ran async also surfaces an issue of how will we know when these new functions are ready for use in our App.</p><p>Therefore, when building a React App, it may be best to break this script apart a bit and pull it into a components life cycle.</p><p>We have a new AuthComponent now created.</p><p>Let’s define a <strong>#componentDidMount </strong>method. Why componentDidMount? We want the ability to predict that once our new component is mounted, we are ready to use the tools provided to us from the SDK.</p><p>Look at the newly defined componentDidMount in our AuthComponent:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K1PK66OBJupETk4T.png" /></figure><p>It should look pretty familiar. We extracted our given functions from the provided script and put them at the top and bottom of our method. That shouldn’t look any different. There is something different here that I’ve included right in the center that should look unfamiliar. <strong>window.FB.Event.subscribe. </strong>What is this and how does it help up.</p><p>The Facebook SDK provides us with something called Event Subscriptions. They are like event listeners that are tied to Facebook actions. Facebook provides us with something called auth. auth is returned JSON that notes if a user is logged in or not and included some related information. Here we are subscribing to auth.statusChange which is a method provided by Facebook. Whenever a statusChange occurs (User logging in or a User logging out) we will perform the condition defined along with the response returned as a result of the statusChange. authResponse will only be available if a user is logged in. It includes information such as the returned access token and the user id. Therefore we are asking that our App perform a certain action if a user logged in and another if a user logged out. A log in and log out with trigger the method calls due to our Event Subscription.</p><p>In order to give a user the ability to log in and out within our app we have to somehow give them a way to click a button that redirects them to a Facebook authentication screen, allowing them to log into their Facebook using their Facebook credentials.</p><p>Facebook us a super easy way to do this. They have pre-built buttons that we can render into our codebase that do just that! It is not anything super fancy! It is just a div wrapped in unique class names and attributes that you can customize. You can customize the button and be provided with the code using the documentation below. Render that button into your app and watch the magic happen!</p><p><a href="http://t.umblr.com/redirect?z=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Ffacebook-login%2Fweb%2Flogin-button&amp;t=ZWI3NmQ1YmZkM2I3ZmIzMmM5OTkwYzdhYzE0ZTEzOWE4YTIwOGZmMixWWlVlOHhBSg%3D%3D&amp;b=t%3Aerpxo-rYPTtKfNgc4xAgiA&amp;p=https%3A%2F%2Fpeterpapadim.tumblr.com%2Fpost%2F164788886766%2Ffacebook-authorization-in-a-react-app&amp;m=1">https://developers.facebook.com/docs/facebook-login/web/login-button</a></p><p>Play around with the event subscription to watch different actions take place following a log in or log out. Try just <strong>console.log(‘You’re logged in’)</strong> and <strong>console.log(‘You’re logged out’) </strong>for starters to make sure your event subscription and new button are working properly!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7a9176aacb6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/facebook-authorization-in-a-react-app-b7a9176aacb6">Facebook Authentication in a React App</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux in React.]]></title>
            <link>https://medium.com/@peterpapadimitropoulos/redux-in-react-ace433d1942e?source=rss-768bcaa3ab90------2</link>
            <guid isPermaLink="false">https://medium.com/p/ace433d1942e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Peter Papadimitropoulos]]></dc:creator>
            <pubDate>Tue, 17 Oct 2017 00:08:32 GMT</pubDate>
            <atom:updated>2017-10-17T00:08:32.245Z</atom:updated>
            <content:encoded><![CDATA[<p>You may have ended up in a similar place as myself. You just learned all about React but can’t go one google search without seeing the word Redux in all the results that come up. <strong><em>The intent of this post is not to teach you all about Redux, but to help provide a high level overview of how to two work together in a working, usable application.</em></strong></p><p>Redux is a Javascript library.<br>There is absolutely no intrinsic connection between React and Redux. They are separate libraries.</p><p>What is it?</p><ul><li>Redux documentation definition: “Is a predictable state container for javascript applications”</li><li>What does this mean?</li><li>What do we gain by using it?</li></ul><p>Let’s say we want to build an application that displays a list of movies and when a list item is selected, we get a detailed view related to that specific item. Using Redux and React, we can build a model for our app that looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i3-N1iN-d08MPewg.png" /></figure><p>Redux manages the data contained inside our application.<br>React manages the views contained inside our application.</p><p>When Redux describes itself as a state container, it really means a collection of all the data that describes the app. This does not just mean hard data such as the list of movies in the diagram above but also includes more meta level data properties such as which movie is currently selected.</p><p>Imagine our Application state looked something like this:</p><blockquote><strong><em>{<br></em></strong><em> </em><strong><em>movies</em></strong><em>:</em><strong><em> [</em></strong><em> {title: ‘Harry Potter’}, {title: ‘Lord of the Rings’}, {title: ‘Taken’}, {title: ‘Titanic’}</em></blockquote><blockquote><strong><em>]</em></strong><em>,</em></blockquote><blockquote><strong><em>activeMovie</em></strong><em>: {title: ‘Harry Potter’}<br></em><strong><em> }</em></strong></blockquote><p>We can break that active state into what redux would call <strong><em>reducers</em></strong>.</p><blockquote><em>A reducer is a function that returns a piece of the application state.</em></blockquote><p>For example, based on that application state and our modeled react/redux application above, we can create the following reducers.</p><p>We will be looking at what it looks like to get started with our movies reducer and see how we can tie it to a react component. Our goal is to simply render our list of movies onto our page!</p><p>We would adjust our file structure just a bit to now accommodate our newly introduced reducers. We would create a reducers directory and add two new files:</p><p>src <strong>=&gt;</strong> reducers <strong>=&gt;</strong> movies.js<br> <strong>=&gt;</strong> index.js</p><p>We will start looking at these files in more details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/0*H6j9bKICVvCzNbIG.png" /></figure><p>movies.js within our reducers directory will contain our Application state! It will simply look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*TjzCSFuW8HSwzwHJ.png" /></figure><p>It exports our array of objects containing the list of movies (activeMovie has been removed from the state for the purpose of this walk-through.)</p><p>So what does our secondary file index.js within the reducers directory contain? Let’s take a look because this will look a bit funky:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*BtBOj8nxtO2wDyuv.png" /></figure><p>Notice the two imports on top. We are bringing in a function called combineReducers from the Redux library and we are also bringing in our list of movies object.</p><p>As your app grows more complex, you’ll want to split your <a href="http://t.umblr.com/redirect?z=http%3A%2F%2Fredux.js.org%2Fdocs%2FGlossary.html%23reducer&amp;t=ZTY0ZDUxYzYxMjY2ZjllNTUwMjIxNGNjMTA0M2JmYzkwYmE1ZTNhOSxHNmJubTFIYg%3D%3D&amp;b=t%3Aerpxo-rYPTtKfNgc4xAgiA&amp;p=https%3A%2F%2Fpeterpapadim.tumblr.com%2Fpost%2F164274295671%2Fredux-in-react&amp;m=1">reducing function</a> into separate functions, each managing independent parts of the <a href="http://t.umblr.com/redirect?z=http%3A%2F%2Fredux.js.org%2Fdocs%2FGlossary.html%23state&amp;t=OTI4OGY0MmRjNWE2MmE4MWY0OTY5YTBlOTFjYjZhNjc5Y2RiYWViOCxHNmJubTFIYg%3D%3D&amp;b=t%3Aerpxo-rYPTtKfNgc4xAgiA&amp;p=https%3A%2F%2Fpeterpapadim.tumblr.com%2Fpost%2F164274295671%2Fredux-in-react&amp;m=1">state</a>. That is what #combineReducers will do for us. You can read more in redux’s documentation <a href="http://t.umblr.com/redirect?z=http%3A%2F%2Fredux.js.org%2Fdocs%2Fapi%2FcombineReducers.html&amp;t=YjdkZWM1NGZiMDk3YjAzYTdlNGFiNjc4YTM1NzI2Y2QzMTUyYTc5OSxHNmJubTFIYg%3D%3D&amp;b=t%3Aerpxo-rYPTtKfNgc4xAgiA&amp;p=https%3A%2F%2Fpeterpapadim.tumblr.com%2Fpost%2F164274295671%2Fredux-in-react&amp;m=1">here</a>. For the purpose of this high level breakdown we won’t be looking too deep into this. Just know that had we had more functions within our MoviesReducers, we’d be able to break it down into individual functions tied to different keys. Here we are just taking what we have and tying it to the movies key.</p><p>Lets briefly talk about containers.</p><blockquote><em>A container is a react component that has a direct connection to the state managed by redux. Containers are sometimes called smart components and you may see smart component being used in the redux documentation.</em></blockquote><p>At what point do components get promoted to containers?<br>We only create containers for components that care about a particular piece of state.</p><p>Let’s look at the exciting part of our app. We created this container called MovieList. We put this in our container because it is directly tied with a piece of state as we will walk through now. Take a look at the code below. It shouldn’t look too foreign.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GFlRGM3JwKg7nap7.png" /></figure><p>We are importing another new library. react-redux is a library that helps us connect out redux states to our react components. This library is not a part of React or Redux. We are importing<br>import { connect } from react-redux</p><p>In our container, we will use a function that becomes available to us from our newly imported react-redux library. mapStateToProps — Takes in one arg (state). — to take app state as an arg</p><p>- what the function returns will be accessible within the container via ‘props’ (usually an object)</p><p>the connect function is what actually says take this component and this mapStateToProps and return a container and that is what we export.<br> export default connect(mapStateToProps)(BookList)</p><p>** if state changes, the component will re-render</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ace433d1942e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[APIs in Javascript]]></title>
            <link>https://medium.com/@peterpapadimitropoulos/apis-in-javascript-3f4568a7b78?source=rss-768bcaa3ab90------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f4568a7b78</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ajax]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[jquery]]></category>
            <dc:creator><![CDATA[Peter Papadimitropoulos]]></dc:creator>
            <pubDate>Mon, 16 Oct 2017 23:57:03 GMT</pubDate>
            <atom:updated>2017-10-16T23:57:03.310Z</atom:updated>
            <content:encoded><![CDATA[<p>When looking into APIs for the first time, it was difficult to grasp a general understanding of what an API is as how it can be used. For starters, the acronym definition made things even more confusing for me and I can understand why someone would stop there and never turn back.</p><h3>API — Application programming interface.</h3><p>I don’t think i’ve ever seen 3 words seem more unclear together. Most simply put, an API is used as a standard way to exchange information between different things. A software company releases its API to the public so that other software developers can design products that are powered by its service. Think of one of your favorite songs that has a featured artist in it. That artist was interested in collaborating with that specific artist with the intent of enhancing their music. As developers we are constantly looking for opportunities to enhance our applications with the intent of making the a great experience for our users. We will look at an simple example API below using javascript along with the jQuery library. We will be looking at the GIPHY API. Imagine you have a web app and within your app you’d like to be able to search by keyword for a funny gif. GIPHY has provided to developers the tools needed to accomplish such a task. Let’s think about what we are doing in the process of creating this feature. We discovered an existing software that has a feature we think our web app can benefit from by integrating with it.</p><p><strong>Step 1. </strong>API Documentation!</p><p>You just bought your brand new ikea dinning room table and it is time to get it up and standing on all four legs. You won’t get anywhere without reading the included 25 pages of instructions. Just like your new table, an API comes with a very structured set of instructions designed and documented by the creators of that software themselves. When using an API, there’s no room for a loose screw that you might be able to get away with when building your table. An API documentation is not a guideline, nor a template for you to build on. It is a strict set of instructions you must follow in order to have the API cooperate as desired. Like most different manufacturers selling tables out there, all APIs have unique documentation that must be followed precisely. Sometimes this documentation may be more unclear for one than it was for another. After looking into all the resources that software has provided, some further research may be required if things are still unclear. Google tends to solve any further confusion. You can’t be the only person trying to utilize that API.</p><p>Let’s look at the documentation of the GIPHY api we are looking to use: <a href="http://t.umblr.com/redirect?z=https%3A%2F%2Fdevelopers.giphy.com%2Fdocs%2F&amp;t=YWI1YjEzMTRmMDM4MWVkOWY0NjBlYWUyMjM3MmIwNmM2MDVkZjFkZix6cnFKUWN1Sw%3D%3D&amp;b=t%3Aerpxo-rYPTtKfNgc4xAgiA&amp;p=https%3A%2F%2Fpeterpapadim.tumblr.com%2Fpost%2F163635238211%2Fapis-in-javascript&amp;m=1">https://developers.giphy.com/docs/</a></p><p>For this example in particular, it looks like we need a “API key” to get started with GIPHY. This can easily be obtained by signing up for a free developers account with them!</p><p>Let’s see what’s written for us in this documentation and based on what we see, let’s figure out which pieces we will need to to build out our feature in our web app!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IQ5aTFGUnD0kQftF.png" /></figure><p>I think this is what we’d like to use. Search for a gif by keyword! That would be perfect. But what does all this mean? Well when utilizing an API, we will be sending an HTTP request to the server such as a GET or POST request. For our example, we are GET-ting gif from GIPHY which is why this will be a GET request. We are looking to receive information from our server and use it in some way. When the time comes and we receive the information we are requesting, it will be sent in JSON format. JSON stands for Javascript Object Notation. It is essentially a large object with key/value pairs with all the information crammed in. We will shortly see how somewhere inside the JSON object we receive will be the links to the gifs we requested!</p><p>What other instructions do we have at our Endpoint above (Endpoint is the destination we are looking to receive or send information to/from). HOST is where we will be requesting our information from and PATH narrows down the task we are looking to accomplish. Similar to a mailing address, think of the HOST as the City/State and the PATH as the unique address. <br>Now that we have our HOST and the unique PATH to request information from, lets put them together. We will be requesting information via a GET request from:</p><p><a href="http://t.umblr.com/redirect?z=http%3A%2F%2Fapi.giphy.com%2Fv1%2Fgifs%2Fsearch&amp;t=NjU3YjM1OWJhOWMxNWEyNDM4YTBlNmExZmI5NDJkMzUzMWQ1NDE3ZSx6cnFKUWN1Sw%3D%3D&amp;b=t%3Aerpxo-rYPTtKfNgc4xAgiA&amp;p=https%3A%2F%2Fpeterpapadim.tumblr.com%2Fpost%2F163635238211%2Fapis-in-javascript&amp;m=1">http://api.giphy.com/v1/gifs/search</a></p><p>Sounds pretty good so far, but as you may have noticed, our url says we are requesting information via a search but doesn’t say what we are searching for! I want gifs of kittens so lets make sure to mention that to the server!</p><p>Luckily we have our documentation to teach us how to request what we are looking for using parameters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UM5nun5MwGgfz1cc.png" /></figure><p>This is pretty cool. Our url <a href="http://t.umblr.com/redirect?z=http%3A%2F%2Fapi.giphy.com%2Fv1%2Fgifs%2Fsearch&amp;t=NjU3YjM1OWJhOWMxNWEyNDM4YTBlNmExZmI5NDJkMzUzMWQ1NDE3ZSx6cnFKUWN1Sw%3D%3D&amp;b=t%3Aerpxo-rYPTtKfNgc4xAgiA&amp;p=https%3A%2F%2Fpeterpapadim.tumblr.com%2Fpost%2F163635238211%2Fapis-in-javascript&amp;m=1">http://api.giphy.com/v1/gifs/search</a> can accept different parameters after the /search to help us customize our search. It looks like there are two required parameters in our example that we need to include, so lets just worry about those two for now. When adding parameters to the end of your url, they must be in a specific format in order for the request to understand what we are asking for. Parameters are added using a ‘?’ but if you have multiple parameters to add, the first parameter will be added using a ‘?’ and any parameters that follow will use a ‘&amp;’. Let’s see what that looks like in our example. We need to add the search term or phrase along with our API key we now have after signing up. The documentation mentions that our phrase will be added using the <strong>q </strong>variable and our API key will be added using the <strong>api_key</strong> variable. Still wanting to see gifs of kittens, our url should now look like this:</p><p><a href="http://t.umblr.com/redirect?z=http%3A%2F%2Fapi.giphy.com%2Fv1%2Fgifs%2Fsearch%3Fq%3Dkittens%26api_key%3D5e43d3b89ae74dd5931c27cce50d5f6e&amp;t=ZDk4MzA0YWRhNDk3ODNhNjY1OTc4N2Y3MGEwOWZjZGZiZGNhYzdkNSx6cnFKUWN1Sw%3D%3D&amp;b=t%3Aerpxo-rYPTtKfNgc4xAgiA&amp;p=https%3A%2F%2Fpeterpapadim.tumblr.com%2Fpost%2F163635238211%2Fapis-in-javascript&amp;m=1"><strong>http://api.giphy.com/v1/gifs/search?q=kittens&amp;api_key=5e43d3b89ae74dd5931c27cce50d5f6e</strong></a></p><p>Notice the <strong>?</strong> before our first <strong>q</strong> parameter and the <strong>&amp;</strong> before our second <strong>api_key</strong> parameter. Now our request should understand exactly what we want and we are granted permission for our request using our API key!</p><p>The only thing left for us to do make the request in our javascript application. To do this, we will be using ajax, provided to us by the jQuery library. We have simple index.js and index.html files ready to get us started. In our index.js file, we will be working directly in our document ready.</p><p>So how does ajax work? Ajax is pretty cool. We will be calling the ajax method from jQuery using the following notation:</p><p><strong>$.ajax( { } )</strong></p><p>ajax takes in a object as an argument. This object will include our url that we are making a request to along with and any ajax settings we are providing to configure the request. Like all javascript objects, the url and any settings will be sent in a key value pair notation. jQuery provides many different settings that can be used to configure the request. For our example, we will only be using url, method, and success. Feel free to check out the jQuery documentation for information on all the settings available: <a href="http://t.umblr.com/redirect?z=http%3A%2F%2Fapi.jquery.com%2Fjquery.ajax%2F&amp;t=ODkxM2IxYTQzMTk4YTRlYjE1MTI1YWQ0YTEzY2U4ODM0ZGY4OWE2MCx6cnFKUWN1Sw%3D%3D&amp;b=t%3Aerpxo-rYPTtKfNgc4xAgiA&amp;p=https%3A%2F%2Fpeterpapadim.tumblr.com%2Fpost%2F163635238211%2Fapis-in-javascript&amp;m=1">http://api.jquery.com/jquery.ajax/</a></p><p>Let’s fill in our request a little more.</p><p><strong>$.ajax( { url: , method: , success: ,</strong></p><p><strong>} )</strong></p><p><em>url</em> will just be a string value with our full url:</p><p><strong>$.ajax( {</strong></p><p><strong>url: </strong>‘http://api.giphy.com/v1/gifs/search? q=kittens&amp;api_key=5e43d3b89ae74dd5931c27cce50d5f6e’,<br><strong> method: ,</strong><br><strong> success: ,</strong></p><p><strong>} )</strong></p><p><em>method </em>will be the type of HTTP request we are making. We mentioned it being a GET because we are requesting data from the interface (also wrapped in a string):</p><p><strong>$.ajax( {</strong></p><p><strong>url: </strong>‘<a href="http://t.umblr.com/redirect?z=http%3A%2F%2Fapi.giphy.com%2Fv1%2Fgifs%2Fsearch%3Fq%3Dkittens%26api_key%3D5e43d3b89ae74dd5931c27cce50d5f6e&amp;t=ZDk4MzA0YWRhNDk3ODNhNjY1OTc4N2Y3MGEwOWZjZGZiZGNhYzdkNSx6cnFKUWN1Sw%3D%3D&amp;b=t%3Aerpxo-rYPTtKfNgc4xAgiA&amp;p=https%3A%2F%2Fpeterpapadim.tumblr.com%2Fpost%2F163635238211%2Fapis-in-javascript&amp;m=1">http://api.giphy.com/v1/gifs/search?q=kittens&amp;api_key=5e43d3b89ae74dd5931c27cce50d5f6e’</a>,</p><p><strong>method: </strong>‘GET’<strong> </strong>,<br><strong> success: ,</strong></p><p><strong>} )</strong></p><p><em>success </em>will be how we use the data we receive! For our example, lets just get all the gifs to display in the body of our index.html. The value for success will be a function that takes one parameter which will be our requested data if the request was successful. That data should be our JSON object. But how do we know what is in that data in order for us to navigate to the appropriate keys to get the data we are looking for? One way is to take our url we are using to make a request and just copy and paste it into our browsers address bar. That will display to us what that object looks like and all the key value pairs nested within. It may look a little messy. There are Chrome extensions and softwares available such as Postman which can help clean that view up for you. When we look at our object we will see that there are 25 objects within our object! This is because the Search Endpoint defaults to providing 25 gifs for us (unless otherwise configured in the url parameters). There is a key nested in each of our 25 gif objects called images: which contains all the gif url’s (contains different fixed sizes for small or larger use). We will iterate all 25 objects and append that url to our index.html body! On each object we will need to map through:</p><p>gif &gt;&gt; images &gt;&gt; fixed_height &gt;&gt; url</p><p>in order to get the desired image appended to our body. Let’s add this function as a value to our success key in our ajax request:</p><p>$( document ).ready( function(){</p><p>$.ajax({ url: ‘http://api.giphy.com/v1/gifs/search?q=kittens&amp;api_key=5e43d3b89ae74dd5931c27cce50d5f6e’,</p><p>method: ‘GET’,</p><p>success: function(giphy){</p><p>giphy.data.forEach(function(gif){</p><p>$(‘body’).append(`&lt;img src=’${gif.images.fixed_height.url}’&gt;`)</p><p>})</p><p>}</p><p>})</p><p>})</p><p>Save and open index.html in your browser and you should see 25 gif of kittens!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*riKrJBjQFGoaessk.png" /></figure><p>The fun part about watching the magic happen and getting your request to run successfully is customizing the way you view and request the data. For example, we don’t want to just see kittens in our app right? I mean, you might. But what you can do is create a simple form in your index.html and take in the string that was entered. You can take that string of a keyword or phrase and interpolate it into you url request! How cool is that? Making your new API integration dynamic within your application!</p><p>The best way to learn more on how to use API’s and understand their use is to play with more of them. Think of some of your favorite websites and look up their API documentation and the cool things they allow you to do with it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f4568a7b78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails Generate]]></title>
            <link>https://medium.com/@peterpapadimitropoulos/rails-generate-d15d1909d760?source=rss-768bcaa3ab90------2</link>
            <guid isPermaLink="false">https://medium.com/p/d15d1909d760</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Peter Papadimitropoulos]]></dc:creator>
            <pubDate>Mon, 16 Oct 2017 23:49:48 GMT</pubDate>
            <atom:updated>2017-10-16T23:49:48.951Z</atom:updated>
            <content:encoded><![CDATA[<p>Rails is big, abstract and powerful. There are a variety of built in tools that are provided by Rails straight out of the box that make the developing experience polished and efficient. A few that come in handy are the Rails <strong>Generate</strong> commands. Generate will help expedite the set up of resources needed for your app. An example would be creating a model or controller file for your app straight from your terminal using <strong>Generate</strong>. When researching different Rails concepts, there were a few generators being used interchangeably and I couldn’t quite tell exactly what they were providing or how they were different. I’ll be briefly covering the following generators along with what they provide to your Rails app:</p><ul><li>rails<strong> generate</strong> model</li><li>rails<strong> generate</strong> resource</li><li>rails<strong> generate </strong>scaffold</li></ul><p><strong>g </strong>is an alias of <strong>generate </strong>and the above can also be written as:</p><ul><li>rails <strong>g</strong> model</li><li>rails <strong>g </strong>resource</li><li>rails <strong>g</strong> scaffold</li></ul><p>Suppose we have a Rails app called dog_app and we are currently in the root directory within our Terminal. Let’s look into what each of the following would provide for us:</p><blockquote><em>1. rails </em><strong><em>g</em></strong><em> model Dog breed:string<br>2. rails </em><strong><em>g </em></strong><em>resource Dog breed:string<br>3. rails </em><strong><em>g</em></strong><em> scaffold Dog breed:string</em></blockquote><p>Let’s take it from the top-</p><p><strong>1. (model)</strong> — This would generate 2 things for us:</p><ul><li>A model file (dog.rb) <strong>=&gt;</strong> inside app/models directory.</li><li>A migration file (xxxxxx_create_dogs.rb) <strong>=&gt;</strong> inside db/migrate directory.</li></ul><p><strong>2.</strong> <strong>(resource)</strong> — This would generate a few things for us:</p><ul><li>A model file (dog.rb) <strong>=&gt;</strong> inside app/models directory.</li><li>A migration file (xxxxxx_create_dogs.rb) <strong>=&gt;</strong> inside db/migrate directory.</li><li>A empty controller file (dogs_controller.rb) <strong>=&gt;</strong> inside app/controllers directory.</li><li>resources :dogs routes <strong>=&gt;</strong> in routes.rb file.</li></ul><p>Pretty cool! We get quite a bit set up for us in that one command!</p><p><strong>3.</strong> <strong>(scaffold)</strong> — This would generate properties similar to resource with some extra additions to your controller along with corresponding view files!:</p><ul><li>A model file (dog.rb) <strong>=&gt;</strong> inside app/models directory.</li><li>A migration file (xxxxxx_create_dogs.rb) <strong>=&gt;</strong> inside db/migrate directory.</li><li>A controller file (dogs_controller.rb) <strong>=&gt;</strong> inside app/controllers directory.</li><li>resources :dogs routes <strong>=&gt;</strong> in routes.rb file.</li><li>7 View files <strong>=&gt; </strong>views/dogs</li></ul><p>With scaffold, the controller is no longer created empty! 7 public methods and 2 private methods are added to the controller! If you’ve created a rails app before using CRUD, then these methods will look familiar to you. The only difference here being you didn’t write these methods and the boilerplate code is templated out for you :) The 7 public methods are your common CRUD related methods defined such as <em>#index, #edit, #create,</em> etc. More exciting are the 2 private methods defined. Lets take a peek below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P8rYavwR3yRcokST.png" /></figure><p>A dog setter and strong params method has been defined and is ready for use!</p><p>Of course there is a time and place for using any of the generators mentioned. You never want to abuse or clutter your directories with files you don’t need. It’s also not very fun to still need many associated files that need to be manually created following let’s say a <em>generate model</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d15d1909d760" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Be Lazy — The Beginners Guide.]]></title>
            <link>https://medium.com/@peterpapadimitropoulos/how-to-be-lazy-the-beginners-guide-1f5fc28b03?source=rss-768bcaa3ab90------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f5fc28b03</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <dc:creator><![CDATA[Peter Papadimitropoulos]]></dc:creator>
            <pubDate>Mon, 16 Oct 2017 23:45:01 GMT</pubDate>
            <atom:updated>2017-10-16T23:45:01.105Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first began my journey as a programmer, there were a few new habits I had to acquire (and continue to acquire) in order to be efficient and successful.</p><p>There was one in particular that was highly encouraged in the coding community and was a little confusing to me at a first glance. It was even more confusing when I read it 5 times and heard it another 10. To be a good programmer, you have to be lazy. Us programmers are lazy and must embrace it apparently. So what exactly does this mean? I can tell you when I first read it, I naturally got defensive. I thought I was being called lazy for wanting to become a programmer. Don’t be discouraged! As I began my studies and dipped my toe in the foreign waters, I learned a little bit more of what exactly this means.</p><p>Let me break this down into two parts:</p><p>The technical side of being a programmer consists of the code you write and the tools used in the process. Turns out you can be lazy and efficient with both!</p><p>Let’s take a look at some code to see what being lazy with your code means. I’ll be using Ruby in the short examples below. If you are not familiar with Ruby syntax or have never looked at a snippet of code, just have a lazy state of mind when you start looking into learning how to code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/0*52tNy3su5vE-mwE9.png" /></figure><p>If you can’t tell what these 5 simple lines of code will do when interpreted by the Ruby language, it is going to print <strong>Hello, World!</strong> on <em>5</em> separate lines. Sure it may be simple and yes maybe we intended to print out <em>5</em> repeating lines, but what if it was your best friends birthday and you wanted to print <strong>Happy Birthday!</strong> <em>1,000 </em>times for them on your screen? Sure you can use copy and paste, but we are even lazier than that.</p><p>Look at the following snippet of code that does just that, but using just one line of code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*SLsA7r6DvsU-2vU7.png" /></figure><p>This brings up what we call looking for opportunities to “<strong>DRY</strong>.” <strong>DRY</strong> meaning <strong>Don’t Repeat Yourself</strong>. If we can accomplish something without having to repeat ourselves, then lets take that route. Keeps us sane, keeps our code clean, and give any reader of our code less to read.</p><p>Lets look at another example that is specific to method definitions in Ruby. Just a tiny bit more complicated (and not very practical, but for visual purposes.) The code shown below has a class with 3 unique instance methods that are short and each have one line in common which confirms the instance variable assignment in the form of a short string message which gets outputted. Remember, we are lazy, which means we can find an easier way to put that repeating “puts” code into all our methods. If we know that we will be creating many methods that share something particular, it is best to remove that method quality and create a new method that can be called within every method that will share that feature:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/0*BoZ2H7H99VtQI4Xt.png" /></figure><p>In these two snippets you will notice the only thing that changed was we created a new method that will be used for printing out our confirmation message. It didn’t make our code much shorter, but since we are lazy, we don’t have to remember to type out<strong> “All set to…”</strong> at the end of any method we create that needs that confirmation output. Instead, all we need to do is remember to call the confirmation instance method which is responsible for holding that code we don’t want to re-type. Again, not very practical, but imagine if that text was over a paragraph long. One, it would be annoying copying and pasting it in every method definition. And two, we wouldn’t want that paragraph showing up multiple times throughout our code and flooding our code, <strong>yuk!</strong></p><p>Our code is not the only place to be lazy! Let’s take a look at some of the tools we use as programmers regularly and how we can be more efficient. The following is less technical but just some neat tips and tricks to keep handy, and with practice can go a long way. You’ve probably been staring at your text editor and your terminal for some time now. If you haven’t, you will be one day. The amazing part about most text editors and your terminal is that the creators of them, thought only about the programmers and enriching our experience. There are a ton of keyboard shortcuts available to help create a better programming experience. The cool part about all the different shortcuts available is that as they become second nature to you, you get to strictly focus on the code you are writing and not consume time and energy on navigating your interface. I highly recommend playing around with them and coming up with a nice lazy set up! The images below include some useful terminal shortcuts and some shortcuts for the Atom text editor (you can do a quick google search for shortcuts available for any text editor you are using, but they tend to be universal.)</p><p><strong>Terminal:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5bKKGiif8KryHuew.png" /></figure><p><strong>Atom Text Editor:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pavqWrXv6NwaH4WZ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f5fc28b03" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>