<?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 Nurudeen Ibrahim on Medium]]></title>
        <description><![CDATA[Stories by Nurudeen Ibrahim on Medium]]></description>
        <link>https://medium.com/@noordean?source=rss-d114f84e2a57------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Jh1FZPqzgO3pM5huXW1sjw.jpeg</url>
            <title>Stories by Nurudeen Ibrahim on Medium</title>
            <link>https://medium.com/@noordean?source=rss-d114f84e2a57------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 08:57:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@noordean/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[Understanding Ruby Blocks]]></title>
            <link>https://medium.com/@noordean/understanding-ruby-blocks-3a45d16891f1?source=rss-d114f84e2a57------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a45d16891f1</guid>
            <category><![CDATA[block]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Nurudeen Ibrahim]]></dc:creator>
            <pubDate>Sat, 09 Mar 2019 17:06:25 GMT</pubDate>
            <atom:updated>2019-03-09T17:06:25.614Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kTBEx777DtQQRk3N" /></figure><p>Ruby blocks are anonymous functions that can be passed into methods. Blocks are enclosed in a <strong>do-end</strong> statement or curly braces <strong>{}. </strong>do-end is usually used for blocks that span through multiple lines while {} is used for single line blocks. Blocks can have arguments which should be defined between two pipe <strong>|</strong> characters.</p><p>Here is a basic example:</p><pre>1. [1, 2, 3].each { |n| puts n }</pre><pre>2. [1, 2, 3].each do |n|<br>     puts n<br>   end</pre><p>These two above examples would output the same result:</p><pre>1<br>2<br>3</pre><p>In this example, the block’s argument is <strong>n</strong> and the block’s body is <strong>puts n. </strong>The block is passed to the <strong>each</strong> method of an <strong>array</strong> object. So if you have used the <strong>each</strong> method before, you’ve definitely used Ruby blocks.</p><p>To demonstrate how important Ruby blocks are, let’s start from here:</p><pre>def say_my_age<br>  puts 10<br>end</pre><p>This is a Ruby basic method that outputs 10. What if we want to make this more flexible? Okay we can rewrite the method to accept an argument, and have something like this:</p><pre>def say_my_age(age)<br>  puts age<br>end</pre><p>This is better, but we can still do better. We can give the caller of this method the total flexibility of passing in some code, not just the argument <strong>age, </strong>and the responsibility of our method would be to execute the code. This is where <strong>blocks</strong> come in.</p><h4><strong>The yield Keyword</strong></h4><p>In order to create a method that accepts blocks, you need to understand how the <strong>yield</strong> keyword works.</p><pre>def say_my_age<br>  yield<br>end</pre><p>And we can use the method like this:</p><pre>say_my_age { puts &quot;Ten&quot; }</pre><pre>// Ten</pre><p>We can now call our method, passing in some code and <strong>yield</strong> would execute it for us. That is how powerful the <strong>yield</strong> keyword is.</p><p>Wait, what if the method is called without passing in any block? Then we would have an error saying <strong><em>no block given (yield). </em></strong>This is because yield actually expects a block to be passed. To prevent this kind of error, Ruby provides us with a <strong>Kernel</strong> method called <strong>block_given? </strong>which returns <strong>true</strong> if a block is passed into a method and <strong>false</strong> otherwise. We can now rewrite the method as:</p><pre>def say_my_age<br>  if block_given?<br>    yield<br>  else<br>    &quot;You didn&#39;t give me your age&quot;<br>  end<br>end</pre><p>With this in place, we’ll get <em>“You didn’t give me your age”</em> if <strong>say_my_age</strong> is invoked without a block.</p><p>As mentioned in the beginning of this tutorial, a block can have arguments. So when we <strong>yield</strong> to the block, we need to provide values for its arguments. To understand this, let’s write own our “each” method for Array objects.</p><pre>class Array<br>  def our_own_each<br>    for i in self<br>      yield i<br>    end<br>  end<br>end</pre><p>Here we are using Ruby for-loop to get each element of the current Array instance and yielding each element to the given block. This method can be used like the normal(built-in) <strong>each</strong> method:</p><pre>[1, 2, 3].our_own_each { |n| puts n * 2 }</pre><pre>// Outputs<br>2<br>4<br>6</pre><h4>The call Method</h4><p>We can explicitly pass in a block as method parameter and invoke the block right inside our method.</p><pre>def say_my_age(&amp;block)<br>  block.call<br>end</pre><p>The <strong>&amp;</strong> denotes that the parameter is a block and should be treated as such. This method would give the same result as the first example under “The yield Keyword”.</p><p>We can also supply block arguments to the call method. So another version of our_own_each array method can be written like this:</p><pre>class Array<br>  def our_own_each(&amp;block)<br>    for i in self<br>      block.call i<br>    end<br>  end<br>end</pre><h4>The instance_exec and instance_eval Methods</h4><p>Blocks can also be invoked by using these two methods, and they come in handy in building Ruby DSLs such as <strong>FactoryBot</strong> when combined with some Ruby metaprogramming techniques such as <strong>method_missing, define_method, </strong>etc<strong>.</strong></p><p>Let’s first see how <em>instance_exec</em> can be used to write another version of our_own_each method:</p><pre>class Array<br>  def our_own_each(&amp;block)<br>    for i in self<br>      instance_exec(i, &amp;block)<br>    end<br>  end<br>end</pre><p>Let’s check another example to show how important these two methods are.</p><pre>class Cat<br>  def do_something(&amp;block)<br>    instance_exec(&amp;block)<br>  end<br>  <br>  def sit<br>    &quot;I am sitting&quot;<br>  end<br>end</pre><p>We can then use this class as shown below:</p><pre>cat = Cat.new<br>cat.do_something { puts cat.sit }</pre><pre>// &quot;I am sitting&quot;</pre><p>Wait, we can also achieve the same thing with the previous ways we mentioned(I mean “yield” and “call”).</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3o6nV2WHO8ZIbpGGwU%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3o6nV2WHO8ZIbpGGwU%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3o6nV2WHO8ZIbpGGwU%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/0785f4d92f27b7c25ea934ff88f5f44c/href">https://medium.com/media/0785f4d92f27b7c25ea934ff88f5f44c/href</a></iframe><p>But what if we could change that to:</p><pre>cat = Cat.new<br>cat.do_something { puts sit }</pre><pre>// &quot;I am sitting&quot;</pre><p>Notice that I’ve removed the reference to the <strong>cat</strong> object. <strong>instance_exec</strong> and <strong>instance_eval</strong> can do this but <em>yield</em> and <em>call</em> can’t. This comes in handy when you want to make a lot of references to an object from your block.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FB2MTuzDezeEqBKm76A%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FB2MTuzDezeEqBKm76A%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FB2MTuzDezeEqBKm76A%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb60ab85b0de443227bfc0b7b20c4218/href">https://medium.com/media/bb60ab85b0de443227bfc0b7b20c4218/href</a></iframe><p>There’s a great application of this in Rails routing where you see something like:</p><pre>Rails.application.routes.draw <strong>do<br>  </strong>resources :products <strong>do<br>    </strong>resources :comments<br>  <strong>end<br>end</strong></pre><p>This allows you to write neater and less code.</p><p>Note: The major difference between <em>instance_exec</em> and <em>instance_eval</em> is that <em>instance_exec</em> can take in other arguments apart from <em>&amp;block</em>, while <em>instance-eval</em> takes in only <em>&amp;block</em>. Trying to pass in other arguments to instance_eval results in “<em>wrong number of arguments” error.</em></p><p>For any suggestion or correction about this article, please feel free to put it as a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a45d16891f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Querying By Timestamps]]></title>
            <link>https://medium.com/@noordean/querying-by-timestamps-3da3ff9fe2bd?source=rss-d114f84e2a57------2</link>
            <guid isPermaLink="false">https://medium.com/p/3da3ff9fe2bd</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[timestamp]]></category>
            <category><![CDATA[activerecord]]></category>
            <dc:creator><![CDATA[Nurudeen Ibrahim]]></dc:creator>
            <pubDate>Thu, 07 Feb 2019 08:22:40 GMT</pubDate>
            <atom:updated>2019-02-07T08:22:40.061Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I came across this strange behavior with querying by created_at field in Rails/Postgres. I was working around two tables; versions and updates.</p><pre>Version.last.created_at<br>=&gt; Tue, 05 Feb 2019 20:08:31 UTC +00:00</pre><pre>Update.last.created_at<br>=&gt; Tue, 05 Feb 2019 20:08:31 UTC +00:00</pre><p>Then I tried to query the versions table by the update’s created_at.</p><pre>Version.where(created_at: Update.last.created_at)<br>=&gt; []</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FYkLMX7jrGHN7PX5XqX%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fbublywater-bubly-water-aparna-nancherla-YkLMX7jrGHN7PX5XqX&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FYkLMX7jrGHN7PX5XqX%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c38ad0a96cef662c37cb6a354631c00/href">https://medium.com/media/2c38ad0a96cef662c37cb6a354631c00/href</a></iframe><p>I was surprised by this result because I was actually expecting the above query to return an array containing the last version. This prompted me to do another check.</p><pre>Version.last.created_at == Update.last.created_at<br>=&gt; false</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FNTkPcydaGnuvu%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fwhat-kobe-bryant-wut-NTkPcydaGnuvu&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FNTkPcydaGnuvu%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="314" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9a195001608e3a056a575f7c09e0c4d/href">https://medium.com/media/b9a195001608e3a056a575f7c09e0c4d/href</a></iframe><p>I decided to make some research, then I realized that doing a direct comparison with timestamps does not always give expected results, and the best way to ensure an accurate result is giving is by casting them to integer. Then I did:</p><pre>Version.last.created_at.to_i == Update.last.created_at.to_i<br>=&gt; true</pre><p>Yeah <strong>true</strong>!</p><p>In order to achieve what I wanted, I discovered a Postgres CAST method which helps in types casting. So I ended up with something similar to this:</p><pre>Version.where(&quot;CAST(extract(epoch from created_at) AS INT) = ?&quot;, Update.last.created_at.to_i)</pre><pre>=&gt; {id: 5800287, created_at: Tue, 05 Feb 2019 20:08:31 UTC +00:00, ...}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxT0xex6lga2LBrjhHq%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Flatenightseth-seth-meyers-lnsm-xT0xex6lga2LBrjhHq&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FxT0xex6lga2LBrjhHq%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/6830ad710a2b291520f1ee39346090e4/href">https://medium.com/media/6830ad710a2b291520f1ee39346090e4/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3da3ff9fe2bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Today I Learned (TIL)]]></title>
            <link>https://medium.com/@noordean/today-i-learned-til-dcae10ef49d3?source=rss-d114f84e2a57------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcae10ef49d3</guid>
            <category><![CDATA[til]]></category>
            <category><![CDATA[2019]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nurudeen Ibrahim]]></dc:creator>
            <pubDate>Mon, 31 Dec 2018 07:08:55 GMT</pubDate>
            <atom:updated>2018-12-31T07:08:55.855Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*Otb15fd6UlpKPBUSkZ2Fyg.jpeg" /><figcaption>TIL</figcaption></figure><p>Over the last couple of months, I have found it really difficult to keep publishing articles on this platform, due to the following reasons:</p><ol><li>I have been seriously busy since I started my new job, and never had time to put things together.</li><li>I have learnt some pretty cool stuff but combining these pieces together into articles has been a serious issue for me.</li></ol><p>Moving forward:</p><p>I have decided to start a TIL series where I will be writing short articles about what I learn, not necessarily on a daily basis but whenever I come across a new knowledge or new solutions to a problem. Getting about 15–20mins to write short articles shouldn’t be a problem for me, and with this, I believe I will be able to share my little knowledge with others.</p><p>This is my plan for 2019 and I’m sure it’s going to be fun.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcae10ef49d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Rails API with Pragma (Part 1)]]></title>
            <link>https://medium.com/backticks-tildes/building-a-rails-api-with-pragma-part-1-61c1097ff506?source=rss-d114f84e2a57------2</link>
            <guid isPermaLink="false">https://medium.com/p/61c1097ff506</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[pragma]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Nurudeen Ibrahim]]></dc:creator>
            <pubDate>Sat, 14 Apr 2018 00:39:51 GMT</pubDate>
            <atom:updated>2018-04-14T16:40:42.333Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XpdJFSgWDguT9oJIFmGjyg.jpeg" /></figure><p>Recently I was tasked with leveling up on a not so popular <em>gem, </em>or let me say a <em>meta-gem</em> called Pragma. Calling Pragma a gem would be an understatement as it does more than just a gem, and depends on several other gems. Pragma can be used to build a complete API within a very short time, it’s described on its documentation as:</p><blockquote>An expressive, opinionated ecosystem for building beautiful RESTful APIs with Ruby. It creates a solid foundation for your API so that you can focus on the stuff that matters.</blockquote><p>In this tutorial, I’m going to show you how you can get started with Pragma. I believe this tutorial will save you a lot of headache which I had while trying to get things done with Pragma, as I couldn’t get enough resources on this gem apart from its simple and basic documentation.</p><p>First and foremost, I would like you to go through this <a href="https://chunksofco.de/pragma-a-new-way-to-build-rails-rest-apis-part-1-937538dee774">tutorial</a> by <a href="https://chunksofco.de/@timigod?source=post_header_lockup">Timi Ajiboye</a>. It’s the fundamental to really understand what we will be dealing with here.</p><p>We are going to be building a very simple application called Mini-Mart.This is going to be a simple e-commerce API that will have product, user, order and review resources. Kindly note that we may not complete the app in this post, as I always try to avoid my posts from getting too long, therefore this may get split into parts.</p><p>To create an app with pragma, we just need to clone pragma’s starter repository.</p><pre>git clone https://github.com/pragmarb/pragma-rails-starter.git mini-mart</pre><p>This would create a Pragma app ready to go into the mini-mart directory. cd mini-mart to enter the app’s directory and take a look at the files generated. If you go through the README file, you would see that we have to run the following commands to setup our app and the database.</p><pre>cp config/database.example.yml config/database.yml<br>cp config/application.example.yml config/application.yml</pre><p>These would automatically copy the contents from the examples configuration to our application and database configuration files. Note that you might have to tweak parts of these files so as to fit your development setting, especially the database.yml file. I changed the username, password, and database for both the development and test environments in my database.yml file to look exactly like this:</p><pre>default: &amp;default<br>  adapter: postgresql<br>  pool: 5<br>  timeout: 5000</pre><pre>development:<br>  &lt;&lt;: *default<br>  host: localhost<br>  username: &#39;&#39;<br>  password: &#39;&#39;<br>  database: mini_mart_development</pre><pre>test:<br>  &lt;&lt;: *default<br>  host: localhost<br>  username: &#39;&#39;<br>  password: &#39;&#39;<br>  database: mini_mart_test</pre><pre>production:<br>  &lt;&lt;: *default<br>  url: &lt;%= ENV[&#39;DATABASE_URL&#39;] %&gt;</pre><p>As you can see, my postgres has empty as both username and password, kindly enter yours accordingly. I have also decided to rename the databases to mini_mart_development and mini_mart_test instead of api_development and api_test respectively.</p><p>Now we can safely run rake db:setup to have our database created. Let’s first create the products table, we need to generate a Product model for that.</p><pre>rails g model Product name:string description:text number_in_store:integer</pre><pre>rails db:migrate</pre><p>Running these two commands would create the products table in our database, having the columns id, name, description, number_in_store, created_at and updated_at. We should not worry about having any associated tables for now, as we can easily create a migration for that when the need arises.</p><p>If you’ve gone through the tutorial I mentioned earlier, you should now know that Pragma pulls in the following pieces:</p><ul><li><a href="https://github.com/pragmarb/pragma-operation">Pragma::Operation</a></li><li><a href="https://github.com/pragmarb/pragma-policy">Pragma::Policy</a></li><li><a href="https://github.com/pragmarb/pragma-decorator">Pragma::Decorator</a></li><li><a href="https://github.com/pragmarb/pragma-contract">Pragma::Contract</a></li></ul><p>To reiterate what you should have read in the tutorial; Decorator handles your json presentation, Contract handles validation, Policy deals with authorization while Operation handles the main business logic. It’s also worth mentioning that Pragma was built on <a href="http://trailblazer.to/">Trailblazer</a>, and you should have also seen the difference between Pragma and Trailblazer in the first tutorial. So if you want to dig deeper on any of the parts mentioned above, it would make sense to check it out on Trailblazer.</p><p>Let’s generate the resource for the Product model we created.</p><pre>rails g pragma:resource product</pre><p>This command can be seen as the rails g scaffold for Pragma. It will automatically generate a product folder containing all the necessary files, and place it inside the resources folder. It also creates the necessary routes and spec files as well. Your folder structure should now look similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*crwPPB1yNWSoSTiCOymZng.png" /><figcaption>The product resource generated inside the app/resources directory</figcaption></figure><p>Right now we already have all endpoints for product in place, we just need to do some tweaking to make it work effectively. Run rails routes to see all your present available routes, and try and access some of them with postman, you would get some funny responses.</p><p>Let’s start by creating some real products, to do that, we need to put some validation in place. Open the base.rb file inside the contract folder and let’s put some validation in there.</p><pre># app/resources/api/product/contract/base.rb</pre><pre>module API<br>  module V1<br>    module Product<br>      module Contract<br>        class Base &lt; Pragma::Contract::Base<br>          property :name<br>          property :description<br>          property :number_in_store</pre><pre>          validation do<br>            required(:name).filled<br>            required(:description).filled<br>            required(:number).filled<br>          end<br>        end<br>      end<br>    end<br>  end<br>end</pre><p>The property method allows us to specify different columns we would like to manipulate, and the validation takes in a block which allows us to specify the kind of validation we want to put on each attribute. Since Pragma::Contract was built on Reform, you are strongly advised to check its <a href="https://github.com/trailblazer/reform">documentation</a> for all the available methods. This basic validation we’ve written will make sure that we can’t create a product without specifying all the three attributes.</p><p>Now let’s move to the decorator, there are two files inside this folder; collection.rb and instance.rb. The instance.rb file handles presentation for a single record while collection.rb handles for a collection of records. Let’s put the following in the instance.rb.</p><pre># app/resources/api/product/decorator/instance.rb</pre><pre>module API<br>  module V1<br>    module Product<br>      module Decorator<br>        class Instance &lt; Pragma::Decorator::Base<br>          feature Pragma::Decorator::Type<br>          feature Pragma::Decorator::Timestamp</pre><pre>          property :id<br>          property :name<br>          property :description<br>          property :number</pre><pre>          timestamp :created_at<br>          timestamp :updated_at<br>        end<br>      end<br>    end<br>  end<br>end</pre><p>Here we are featuring the timestamp helper from Pragma::Decorator, which helps us to convert datetime object of created_at and updated_at to UNIX timestamp which is the preferred way of presenting times in an API. We also use property to list the attributes we would like to display in the json response. You can dig deeper on this through the Pragma::Decorator’s <a href="https://github.com/pragmarb/pragma-decorator">README</a>.</p><p>Don’t forget that I said instance.rb is for presenting a single record, but it is referenced by default from the collection.rb, so you may not need to edit the collection.rb. Though you can open the file to see what’s going on there.</p><p>At this point we should be able to create a new product. Go to postman and send a POST request to this route <a href="http://localhost:3000/api/v1/products/">http://localhost:3000/api/v1/products/</a> with the necessary request body. You should obviously get a response message that says</p><blockquote>You are not authorized to access the requested resource.</blockquote><p>This is because we’ve not authorized any user to be able to create product. So open the policy.rb file and change the create? method to the following:</p><pre># app/resources/api/product/policy.rb</pre><pre>def create?<br>  true<br>end</pre><p>This means we have given access to any user to create product. Test with postman again and everything should work fine. Send more requests so that we can have more products in our database.</p><p>Let’s assume that we only want to have products of unique names on our products table. That is. we do not want to have multiple products having the same name. In ActiveModel, simply specifying unique: true on the attribute name would solve this problem for us. But here in Pragma::Contract, it requires more codes and I have not been able to get that to work. My work around for now, is to specify a step in the create operation that checks the records against the new one, and write a response message into the response object.</p><p>Inside the create.rb file of operation, let’s put the following:</p><pre># app/resources/api/product/operation/create.rb</pre><pre>module API<br>  module V1<br>    module Product<br>      module Operation<br>        class Create &lt; Pragma::Operation::Create<br>          step :unique?, before: &#39;persist.save&#39;<br>          failure :log_error!</pre><pre>          def unique?(options, params:, **)<br>            ::Product.find_by(name: params[&quot;name&quot;]).nil?<br>          end</pre><pre>          def log_error!(options)<br>            options[&#39;result.response&#39;] =<br>                 Pragma::Operation::Response.new( status: 409,<br>                   entity: {<br>                     message: &quot;Record already exists&quot;<br>                   }<br>                 )<br>          end<br>        end<br>      end<br>    end<br>  end<br>end</pre><p>We have basically two methods inside this class. The unique? method that checks our products table against the new record and then return true or false. The log_error! method that adds our error message into the result.response object, instantiating the Response class from Pragma::Operation makes that possible. Kindly note that every method in operation files takes options as parameter, and maybe with some other optional parameters. The options is so important as it contains some keys as related to every request being made.</p><p>Pragma::Operation provides us with some methods such as step, failure and success that we can use to control the execution of the methods written. This is another beautiful part of Pragma that allows us to control codes’ execution without using If-condition. We specified the unique? step, and also specified a before-hook that this should be executed before saving the record into the database. What the log_error! failure means is that once the unique? step fails, the execution should come to log_error!. If step had been used for this, the execution won’t bother coming to log_error! if unique? fails.</p><p>Now try sending a request to create a new product using an already existing name, and you should get an appropriate error message. I will also strongly advise that you check documentation on <a href="https://github.com/pragmarb/pragma-operation">Pragma::Operation</a> and that of <a href="http://trailblazer.to/guides/trailblazer/2.0/01-operation-basics">Trailblazer</a> to have a better understanding, as this is the heart of Pragma, and you must know your way around it.</p><p>Let’s now grant access to get all the products in our database, open policy.rb and change the resolve method inside the Scope class to the following:</p><pre>def resolve<br>  scope.all<br>end</pre><p>This gives us access to all the product records in our application. If you send a GET request to <a href="http://localhost:3000/api/v1/products">http://localhost:3000/api/v1/products</a>, you should have a response containing all your products.</p><p>Also if you want to get a particular product, sending a GET request to <a href="http://localhost:3000/api/v1/products">http://localhost:3000/api/v1/products</a>/id_of_the_product will return the product, but we will also have to grant access for this by specifying true in the show? method inside policy.rb.</p><pre>def show?<br>  true<br>end</pre><p>You should have gotten the flow by now, if you want to be able to update and delete a product, you will also have to tweak both update and destroy methods to return true respectively.</p><p>Looking at what we have right now, the way we have exposed our app by specifying true as return values of all our authorization methods is not actually ideal. We will need to protect some parts by the time we have the user resource and put authentication in place, which we are going to be doing in the next part of this tutorial.</p><p>If you have any suggestion/comment /question as regards this tutorial, kindly post as comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61c1097ff506" width="1" height="1" alt=""><hr><p><a href="https://medium.com/backticks-tildes/building-a-rails-api-with-pragma-part-1-61c1097ff506">Building a Rails API with Pragma (Part 1)</a> was originally published in <a href="https://medium.com/backticks-tildes">Backticks &amp; Tildes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authentication with JWT in Rails API]]></title>
            <link>https://medium.com/@noordean/authentication-with-jwt-in-rails-api-71102387c0b0?source=rss-d114f84e2a57------2</link>
            <guid isPermaLink="false">https://medium.com/p/71102387c0b0</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[jwt]]></category>
            <dc:creator><![CDATA[Nurudeen Ibrahim]]></dc:creator>
            <pubDate>Thu, 08 Mar 2018 14:32:23 GMT</pubDate>
            <atom:updated>2018-11-18T07:37:58.441Z</atom:updated>
            <content:encoded><![CDATA[<p>Authentication is one of the vital parts of any web application, and there are many libraries that provide various options to perform authentication in one way or another. The most prominent gem for authentication in Ruby on Rails is devise which is considered to be an overkill for API-based systems.</p><p>For the fact that JWT(JSON web token) gives me total control over my whole authentication process, I prefer using it when it comes to building APIs. In this tutorial, we are going to be talking about how JWT can be used for authenticating Rails API, and at the same time touching a bit of authorization to make it more explanatory and interesting.</p><p>Note: This tutorial focuses only on authentication in Rails and not how API is built in Rails. If you are looking for an extensive tutorial on Rails API, kindly check this out <a href="https://scotch.io/tutorials/build-a-restful-json-api-with-rails-5-part-one">https://scotch.io/tutorials/build-a-restful-json-api-with-rails-5-part-one</a>. Now let’s get started.</p><ol><li>Add jwt and dotenv-rails to your Gemfile:</li></ol><pre>gem &#39;jwt&#39;<br>gem &#39;dotenv-rails&#39;</pre><p>jwt is the main gem that handles tokens encoding and decoding. dotenv-rails will help us keep our jwt secret key as an environmental variable.</p><p>Then run bundle install</p><p>2. Create a .env file in the root directory and add your jwt secret key:</p><pre>JWT_SECRET=&#39;yoursecretkey&#39;</pre><p>3. We will create our JsonWebToken class which will contain the logic to encode and decode tokens. So create a jwt folder inside your app folder and add a json_web_token.rb file.</p><p>app/jwt/json_web_token.rb:</p><pre>class JsonWebToken<br>  JWT_SECRET = ENV[&quot;JWT_SECRET&quot;]</pre><pre>  def self.encode(payload, exp = 24.hours.from_now)<br>    payload[:exp] = exp.to_i</pre><pre>    JWT.encode(payload, JWT_SECRET)<br>  end</pre><pre>  def self.decode(token)<br>    body = JWT.decode(token, JWT_SECRET)[0]<br>    HashWithIndifferentAccess.new body<br>  rescue JWT::ExpiredSignature, JWT::VerificationError =&gt; e<br>    raise ExceptionHandler::ExpiredSignature, e.message<br>  rescue JWT::DecodeError, JWT::VerificationError =&gt; e<br>    raise ExceptionHandler::DecodeError, e.message<br>  end<br>end</pre><p>We are declaring the constant JWT_SECRET in the first line of the class which had already been defined in the .env file. This class contains essentially two class methods, encode and decode.</p><p>The encode method accepts two parameters, a payload which is a hash containing key-value you are encoding with, and the token expiry time which we’ve set to a default value of 24hrs. This method relies on the encode method from the JWT class.</p><p>The decode method accepts token as the only parameter, and also relies on the provided decode method from JWT class. HashWithIndifferentAccess gives permission to refer to the keys in the decoded body as both symbol and string. We are also raising ExpiredSignature and DecodeError exceptions which are going to be rescued soon to display appropriate custom messages.</p><p>4. Let’s create an exception class where we will rescue and provide custom messages for the JWT exceptions we’ve raised.</p><p>app/controllers/concerns/exception_handler.rb:</p><pre>module ExceptionHandler<br>  extend ActiveSupport::Concern</pre><pre>  class DecodeError &lt; StandardError; end<br>  class ExpiredSignature &lt; StandardError; end</pre><pre>  included do<br>    rescue_from ExceptionHandler::DecodeError do |_error|<br>      render json: {<br>        message: &quot;Access denied!. Invalid token supplied.&quot;<br>      }, status: :unauthorized<br>    end</pre><pre>    rescue_from ExceptionHandler::ExpiredSignature do |_error|<br>      render json: {<br>        message: &quot;Access denied!. Token has expired.&quot;<br>      }, status: :unauthorized<br>    end<br>  end<br>end</pre><p>The included method which takes a block of code makes our rescue logic available as soon as this module is included into any class. We then created the exception classes, inheriting from StandardError. Each of the exception classes are rescued by responding with appropriate custom messages.</p><p>5. Let’s include the ExceptionClass to the application_controller so that it can be made visible to all our controllers.</p><p>app/controllers/application_controller.rb:</p><pre>class ApplicationController &lt; ActionController::API<br>  include ExceptionHandler</pre><pre>end</pre><p>6. Now it’s time to create our authentication and authorization files.</p><p>app/auth/authentication.rb:</p><pre>class Authentication<br>  def initialize(user_object)<br>    @username = user_object[:username]<br>    @password = user_object[:password]<br>    @user = User.find_by(username: @username)<br>  end</pre><pre>  def authenticate<br>    @user &amp;&amp; @user.authenticate(@password)<br>  end</pre><pre>  def generate_token<br>    JsonWebToken.encode(user_id: @user.id)<br>  end<br>end</pre><p>Our Authentication constructor accepts user_object as a parameter, this is a hash containing both the username and password of the user. The authenticate method simply checks if the user is valid by comparing the username with the hashed password. The generate_token calls the encode method of our JsonWebToken class, and supplies a hash of the user’s id.</p><p>app/auth/authorization.rb:</p><pre>class Authorization<br>  def initialize(request)<br>    @token = request.headers[:HTTP_TOKEN]<br>  end</pre><pre>  def current_user<br>    JsonWebToken.decode(@token)[:user_id] if @token<br>  end<br>end</pre><p>Our Authorization constructor accepts the request object as a parameter, and from there, extracts the supplied token. The current_user method decodes and gets user_id from the decoded token.</p><p>7. The Authentication and Authorization classes are now available for use in any of our controllers. Firstly, let’s see how we can use the Authentication class to control login action inside the users_controller.</p><p>app/controllers/users_controller.rb:</p><pre>class UsersController &lt; ApplicationController</pre><pre>  def login<br>    auth_object = Authentication.new(login_params)<br>    if auth_object.authenticate<br>      render json: {<br>        message: &quot;Login successful!&quot;, token: auth_object.generate_token }, status: :ok<br>    else<br>      render json: {<br>        message: &quot;Incorrect username/password combination&quot;}, status: :unauthorized<br>    end<br>  end</pre><pre>  private</pre><pre>  def login_params<br>    params.permit(:username, :password)<br>  end<br>end</pre><p>The private method login_params returns a hash containing both the username and password from the request body. This a very common way of making sure that the data coming from the request body is secured.</p><p>The Authentication class is then instantiated, passing the login_params. The authenticate method is called to ensure validity of the user after which an appropriate message is sent. If the user is valid, the generate_token method is called so as to include token in the response message.</p><p>To demonstrate an authorization example, let’s assume there’s a Group model in this application and there is a feature for posting messages to groups whereby only the creator of a group is permitted to post messages.</p><p>app/controllers/groups_controller.rb:</p><pre>class GroupsController &lt; ApplicationController</pre><pre>  def post_message<br>    authorization_object = Authorization.new(request)<br>    current_user = authorization_object.current_user</pre><pre>    if current_user == Group.find(params[:id]).created_by<br>      # post message<br>    else<br>      # respond: You are not allowed to post to this group<br>    end<br>  end<br>end</pre><p>I believe this covers the basics of how JWT can be integrated in Rails. In the second part of this tutorial, I will be explaining how JWT based requests can be tested with rspec.</p><p>If you have any suggestion/comment /question as regards this tutorial, kindly post as comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71102387c0b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up PostgreSQL with Rails Application]]></title>
            <link>https://medium.com/@noordean/setting-up-postgresql-with-rails-application-357fe5e9c28?source=rss-d114f84e2a57------2</link>
            <guid isPermaLink="false">https://medium.com/p/357fe5e9c28</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[andela]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Nurudeen Ibrahim]]></dc:creator>
            <pubDate>Thu, 15 Feb 2018 16:53:04 GMT</pubDate>
            <atom:updated>2019-02-17T08:02:39.815Z</atom:updated>
            <content:encoded><![CDATA[<p>PostgreSQL is an advanced, open-source relational database management system which gives it the importance of being extensible. Compared to other RDBMSs, PostgreSQL differs itself with its assist for complex data manipulation. Because of these benefits, and some other reasons, most developers now migrate to Postgres for storing data. In this short tutorial, we will be explaining how the sqlite3database that comes with every rails application can be changed to Postgres:</p><ol><li>First make Postgres available on your machine by following the instructions stated on their website <a href="https://www.postgresql.org/download/">https://www.postgresql.org/download/</a>. Also download either Postico or pgAdmin, these are intuitive applications that help you interact with your database table and records. The only important reason why some people choose pgAdmin over Postico is because it’s opened to contributions, and it’s being actively contributed to. I personally recommend Postico due to its simplicity, download Postico here <a href="https://eggerapps.at/postico/">https://eggerapps.at/postico/</a></li><li>Connect Postico to your database: Open Postico and Click on the `New Favorite` button, then fill in only the `Host` and `Database` fields as shown in the image below. Click on `Connect` to complete the process.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AM35TmfpoMAjrsQq7HQBfg.png" /><figcaption>Postico</figcaption></figure><p>3. Now that Postgres is setup, It’s time to tell your rails app that you want to use Postgres. Open the Gemfile in the root directory and add the these gems:</p><pre>gem &#39;pg&#39;<br>gem &#39;rails_12factor&#39;, group: :production</pre><p>The gem rails_12factor is needed for logging on Heroku and it’s <em>only</em> needed if your Rails version is lower than 5.0. This would be useful by the time you finally deploy the application, hence the reason for restricting it to only production environment.</p><p>Now you might want to remove the line that has:</p><pre>gem ‘sqlite3’</pre><p>Since sqlite is no more needed. Then run</p><pre>bundle install</pre><p>to install the new gem(s).</p><p>4. Open <em>config/database.yml</em> and replace the content with:</p><pre>default: &amp;default<br>  adapter: postgresql<br>  encoding: unicode<br>  username: &lt;%= ENV[&#39;POSTGRES_USER&#39;] %&gt;<br>  password: &lt;%= ENV[&#39;POSTGRES_PASSWORD&#39;] %&gt;<br>  pool: 5<br>  timeout: 5000<br>  host: &lt;%= ENV[&#39;POSTGRES_HOST&#39;] %&gt;</pre><pre>development:<br>  &lt;&lt;: *default<br>  database: &lt;%= ENV[&#39;POSTGRES_DB&#39;] %&gt;</pre><pre>test:<br>  &lt;&lt;: *default<br>  database: &lt;%= ENV[&#39;POSTGRES_TEST_DB&#39;] %&gt;</pre><pre>production:<br>  &lt;&lt;: *default<br>  database: &lt;%= ENV[&#39;POSTGRES_DB&#39;] %&gt;</pre><p>Here we are specifying postgresql as our database, and at the same time specifying different databases for different environments. It’s a common practice to always keep your secret keys safe, and dotenv-rails gem helps us with this. So go ahead and add:</p><pre>gem &#39;dotenv-rails&#39;</pre><p>to your Gemfile and run</p><pre>bundle install</pre><p>Create a .env file in your root directory and put the following:</p><pre>POSTGRES_USER=&#39;&#39;<br>POSTGRES_PASSWORD=&#39;&#39;<br>POSTGRES_HOST=&#39;localhost&#39;<br>POSTGRES_DB=&#39;your_database_name&#39;<br>POSTGRES_TEST_DB=&#39;your_database_name_test&#39;</pre><p>As you can see, we have specified a different database for the test environment. This is because it’s a good practice to always have a separate database for running tests.</p><p>4. Run</p><pre>rake db:setup</pre><p>to create your database. This command automatically creates your database, runs migrations if you have any, and seeds the necessary tables if you have any rake tasks. Now open your Postico to view your database, here you should see both your_database_name and your_database_name_test.</p><p>If this command gives an error that looks like this:</p><pre>rake aborted!<br>Gem::LoadError: Specified &#39;postgresql&#39; for database adapter, but the gem is not loaded. Add `gem &#39;pg&#39;` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).<br>/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec&#39;...</pre><p>Kindly specify a version number for the pg in your Gemfile, to have something like:</p><pre>gem &#39;pg&#39;, &#39;~&gt; 0.20&#39;</pre><p>This issue has been fixed in Rails 5.1.5 as discussed here: <a href="https://github.com/rails/rails/issues/31673">https://github.com/rails/rails/issues/31673</a></p><p><strong>Note:</strong> Using different databases for development and production is not recommended. Occasionally, Rails behaves differently on different databases. So you are advised to set up and develop on PostgreSQL , and more importantly if you intend to deploy your application to Heroku because Heroku has no support for sqlite.</p><p>If you have any suggestion/comment /question as regards this tutorial, kindly post as comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=357fe5e9c28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Andela-21 Experience]]></title>
            <link>https://medium.com/@noordean/my-andela-21-experience-89a71dd904d0?source=rss-d114f84e2a57------2</link>
            <guid isPermaLink="false">https://medium.com/p/89a71dd904d0</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[andelae]]></category>
            <category><![CDATA[andela]]></category>
            <dc:creator><![CDATA[Nurudeen Ibrahim]]></dc:creator>
            <pubDate>Fri, 12 May 2017 19:08:22 GMT</pubDate>
            <atom:updated>2017-05-12T19:08:22.393Z</atom:updated>
            <content:encoded><![CDATA[<p>Andela-21 ended today, after a 3-week rigorous learning experience. I will describe the whole process as ‘learning programming the hard way’. I have come to realise that at times if you are not forced to learn, you wouldn’t learn new things. Andela-21 was fun, and at the same time a very tedious one. I have learnt a lot of technologies through this program, which would have been quite impossible for me to learn outside Andela, even in months. The fact that i couldn’t make it into the fellowship after my 2-week bootcamp brought me to Andela-21, and i think it would serve as an opportunity for me to get better as a programmer before getting into the fellowship.</p><p>Immediately after my 3-week bootcamp, as i couldn’t make it in, i was invited for andela-21 where we were required to build an API(Application Programming Interface) in es6 with a lot of dependencies. The task was to develop an inverted-index-api which is an implementation of efficient search functionality for software applications. Some of technologies integrated with the project are stated below:</p><p><strong>i. Jasmine-node:</strong> This is a node test framework that enables developers to test every part of their codes before deployment. I used jasmine-node to test my InvertedIndex class in order to make sure the methods are working as expected.<br><strong>ii. Supertest:</strong> Supertest allows us to write tests for endpoints(routes) and check if correct responses are actually given for each route depending on the supplied payloads. Supertest can be used alone, and also with both jasmine and mocha. I integrated supertest with jasmine to test both my /api/create and /api/search/ endpoints.<br><strong>iii. Gulp:</strong> This is called a task runner. If probably there are many test files in an application, gulp enables us to run all the tasks at once. Apart from running tests, other tasks can also be created using gulp. I used gulp to run my tests using gulp-jasmine, also to start the server using gulp-nodemon and to get my coverage report using gulb-istanbul and gulp-coveralls.<br><strong>iv. Eslint:</strong> I integrated eslint in my visual studio editor to guide me in following the correct javascript coding style, and also to write in pure javascript es6. This called me to attention whenever i was going wrong.<br><strong>v. Codacy and Travis:</strong> These are called continous integration (CI) tools that help monitor codes once they are connected to a github repository. I integrated these tools in the project to show how reliable or good my project is, with different badges on my README file showing the results.</p><p>Due to my determination, and desires to become a great developer, i was forced to learn all these technologies within this short time, and that has made me a better developer. I was able to meet the project’s expectations, and i pray that i get a good result from my defence as i am patiently waiting for the outcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89a71dd904d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Andela Challenges And How I Have Been Able To Adapt]]></title>
            <link>https://medium.com/@noordean/andela-challenges-and-how-i-have-been-able-to-adapt-71ae33056f31?source=rss-d114f84e2a57------2</link>
            <guid isPermaLink="false">https://medium.com/p/71ae33056f31</guid>
            <category><![CDATA[andela-bootcamp-nigeria]]></category>
            <category><![CDATA[andela]]></category>
            <dc:creator><![CDATA[Nurudeen Ibrahim]]></dc:creator>
            <pubDate>Tue, 18 Apr 2017 12:07:32 GMT</pubDate>
            <atom:updated>2017-04-18T12:08:08.525Z</atom:updated>
            <content:encoded><![CDATA[<p>Making it to this stage of Andela Fellowship Recruitment process is one of the greatest achievements i have earned in my life. I feel so excited seeing myself in the second week of Andela’s Bootcamp after passing through a lot of hurdles.</p><p>The various challenges i have faced since the beginning of Bootcamp have come unexpectedly, because when i saw in my interview invite that “It’s one of the most rigorous training experiences in the world…”, i knew i was in for a serious game, and in serious games, challenges are unavoidable. However, i see challenges differently from most people’s perspective, i do take challenges as opportunities to always learn knew things. The various challenges i faced during the course of the training are stated below;</p><p>I had to push myself extra miles in getting some of my assignments done as i was very new to the technologies involved. The problems i faced while executing projects on Test Driven Development(TDD), Object oriented Programming Language(OOP), Application Programming Interface(API) have immensely enabled me to learn a lot of things, although under intense pressure.</p><p>My last two weeks was full of sleepless nights, as i needed to make sure i get myself updated as regards to the content of Andela Bootcamp’s curriculum, and also to get my assignments done before the given deadlines. This was due to the fact that electricity in my area is always restored in the middle of the night.</p><p>Upon all the challenges stated above, I am happy to say that i made to the Bootcamp’s second week. In every situation one finds himself, being able to adapt is what helps in making one successful, this is my belief and this is one of the things i have been gifted with, and it has really helped me to come this far.</p><p>Just as i said earlier, challenges give me opportunities to increase my knowledge, and right now, i am happy to say that i am now a better programmer and stronger person.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71ae33056f31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Bootcamp Experience Day-3]]></title>
            <link>https://medium.com/@noordean/my-bootcamp-experience-day-3-424048fb871d?source=rss-d114f84e2a57------2</link>
            <guid isPermaLink="false">https://medium.com/p/424048fb871d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nurudeen Ibrahim]]></dc:creator>
            <pubDate>Wed, 12 Apr 2017 07:55:00 GMT</pubDate>
            <atom:updated>2017-04-12T08:16:49.967Z</atom:updated>
            <content:encoded><![CDATA[<p>Few hours ago, i just received an invitation to the next self learning clinic which will hold on Thursday 13th of April, but a part of the message keep ringing in my head; “At the end of this full day, a selection decision is made to determine which people make it into the second week of Bootcamp”. Though i am very optimistic but this will surely move me to do more as i can’t imagine myself getting evicted from this training.</p><p>Every day of the Bootcamp has been so exciting because i keep learning new forms of technologies everyday. My last assignment has also tremendously pushed me to learn about HTTP client library and API(Application Programming Interface).</p><p>The task was to consume a public API using a HTTP client library. During the course of my research, i came to understand that the XMLHttpRequest object used mostly in calling APIs can not be used from the command line as it is browsers dependent. I came across two libraries that could solve my task; axios and superagent. I decided to go for axios , i read up its documentation, and used it with a weather API, as i thought building a weather app would be a great idea. I am glad to say that the whole thing was was easy for me to implement.</p><p>The qualified.io task for this assignment was slightly delayed before it was sent, and this time around was more difficult than the previous ones. I am still glad that i was able to solve the problems with the little Javascript knowledge i have gathered.</p><p>I am currently working on the last assignment of the home sessions, especially the HTML and CSS part of it, and i am already learning more things in addition to my previous HTML and CSS knowledge.</p><p>Tomorrow is the next self learning clinic, and i am looking forward to meet every Bootcamper again, and most importantly, looking forward to learn another set of technologies.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=424048fb871d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Bootcamp Experience Day-2]]></title>
            <link>https://medium.com/@noordean/my-bootcamp-experience-day-2-e822dc42dac5?source=rss-d114f84e2a57------2</link>
            <guid isPermaLink="false">https://medium.com/p/e822dc42dac5</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nurudeen Ibrahim]]></dc:creator>
            <pubDate>Tue, 11 Apr 2017 08:28:30 GMT</pubDate>
            <atom:updated>2017-04-11T08:28:30.721Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the second day of home session of the bootcamp training. I am happy to say that the pressure of getting the home session assignment done before the stated deadlines has made me a better programmer. I had two sets of assignments to be submitted on Sat. 8th April and Mon. 10th April respectively, and immediately after the end of the self learning clinic, i knew i’ve got a lot to read.</p><p>Having made up my mind to always make sure my assignments are submitted atleast 4hrs before the deadline, since i always get worried whenever i have a deadline fast approaching. The first task of the assignment was to write a blog post about my most recent learning challenge experience. Although i am not a good writer, but i had to put in my best in order keep myself in the race of becoming an Andela fellow.</p><p>The second task was to test our knowledge of programming logic, version control(Git) and test driven development(TDD). We were required to wite tests for three different functions; fizzBuzz, aritGeo and getPrimes using a different test framework, since we used mocha during the self learning clinic. We were categorically instructed to use jasmine, and after a lot of reasearch , i successfully did my assignment with the required framework(jasmine). I learnt these two very important things during the course of my research:</p><p><strong><em>1. </em></strong><em>Jasmine unlike mocha that uses chai assertion library, does not use any assertion library.<br></em><strong><em>2.</em></strong><em> Array can not be compared by the usual .to.equal() but rather with .to.deep.equal() since arrays are not primitive datatype.</em></p><p>The first task of the second assignment was done on the qualified.io through the link sent to our email. I took the test without wasting time as i did not encounter much problem on it.</p><p>The second task was about OOP(Object Oriented Programming), and i was glad that i eventually implemented a good real world OOP example. I created an Employee class and an Intern subclass that inherits some properties and methods from the superclass. This was implemented using the method of combination inheritance which combines prototype chaining and constructor stealing methods together.</p><p>The last task of this assignment, as usual was a blog post about my bootcamp experience so far. I tried my best as usual, and i hope and pray that what i have written would be enough to keep me in the race.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e822dc42dac5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>