From 2c1ad47a6246833e0d7ff3ae340e59fcbf926673 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Mon, 5 Feb 2018 09:25:09 -0500 Subject: [PATCH] Update 1900-01-10-10-api-driven-example.md --- .../chapters/1900-01-10-10-api-driven-example.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/_posts/chapters/1900-01-10-10-api-driven-example.md b/_posts/chapters/1900-01-10-10-api-driven-example.md index a9eb450..0134e6a 100644 --- a/_posts/chapters/1900-01-10-10-api-driven-example.md +++ b/_posts/chapters/1900-01-10-10-api-driven-example.md @@ -222,6 +222,20 @@ Time to hook it up to some events. Remember when I said `BubbleWrap` comes with The `when` function is available to every `UIControl` subclass (of which `UIButton` is one) and takes the usual bitmask of `UIControlEvent`s as its arguments. While the request runs, we temporarily disable our UI elements. + +In order to allow our app to access the web we need to add an application intitlement. So let's go into our rake file and add: + +```ruby +... + app.info_plist['ITSAppUsesNonExemptEncryption'] = false + app.info_plist["NSAppTransportSecurity"] = { "NSAllowsArbitraryLoads" => true +... + +``` +This a very simple way to get acess to the web. This allows everything, which is bad practice normally you would be very specific about the url's your are acessing in your release section, but for our purpose this is fine. + + + But wait...what's that `Color.find` method? Well, it's a good idea to keep all of your URL requests inside of models instead of controllers. That way if we want to get a `Color` from the server somewhere else in the app then there's no code duplication. Who knows, maybe we'll need that too...*foreshadowing* So in your `Color` class, add the `find` static method: @@ -240,6 +254,7 @@ class Color end ``` + Look bad? We use the basic `HTTP.get` to get some data from the server via the proper API URL. Note that we use the `&block` notation to make it plain that this function is intended to be used with a block. This block isn't explicitly passed as another argument, but rather is implicitly passed when we put a `do/end` after we call the method. The number and order of variables in `.call(some, variables)` corresponds to `do |some, variables|`. Anyway, `rake` and give it a go with a color like "3B5998". You should see something like this output in the console: