0
1
00:00:00,900 --> 00:00:01,140
All right.
1

2
00:00:01,140 --> 00:00:02,270
So here's the solution.
2

3
00:00:02,280 --> 00:00:05,310
So in this file, we're going to copy this line
3

4
00:00:05,490 --> 00:00:11,460
that is the base you URL for our request. And we're going to put it up here so that we can make it available
4

5
00:00:11,460 --> 00:00:13,850
to all of our methods inside our class.
5

6
00:00:13,950 --> 00:00:18,990
And the next thing I'm going to do is I'm going to write a method. Now, you can call your method whatever
6

7
00:00:18,990 --> 00:00:26,910
you want, but I'm going to call it requestInfo and I'm going to pass in a single parameter that is the
7

8
00:00:26,910 --> 00:00:32,580
flowerName that we got back from our classification model. It's going to be of data type String.
8

9
00:00:32,950 --> 00:00:36,680
And inside here, I'm going to make my Alamofire request.
9

10
00:00:36,690 --> 00:00:42,090
So I've already imported Alamofire and SwiftyJSON, so I should be able to simply write 
10

11
00:00:44,700 --> 00:00:49,690
Alamofire.request. And this is almost the one that I want.
11

12
00:00:49,690 --> 00:00:55,100
So the URL I'm going to pass in, this is going to be that Wikipedia URL that we got up there.
12

13
00:00:55,230 --> 00:01:01,620
The method is, of course, a get method and the parameters are going to be the parameters that we got from
13

14
00:01:01,620 --> 00:01:03,450
that text file earlier on.
14

15
00:01:03,450 --> 00:01:10,680
So if I just copy all of these parameters over, then I can paste it in here and I can pass it into here.
15

16
00:01:10,770 --> 00:01:12,610
So it's called parameters.
16

17
00:01:12,630 --> 00:01:18,000
Now, I'm going to modify this template that I got from Alamofire a little bit.
17

18
00:01:18,000 --> 00:01:20,320
I want to get rid of the encoding and the headers.
18

19
00:01:20,340 --> 00:01:24,580
But instead, I'm going to call the completionHandler.
19

20
00:01:24,690 --> 00:01:26,960
So I'm going to write responseJSON
20

21
00:01:27,150 --> 00:01:31,510
and you can see that it suggested to me the one that I want which is the completionHandler.
21

22
00:01:31,800 --> 00:01:37,140
So I'm going to hit enter, then I'm going to select this placeholder and hit enter again. And the data
22

23
00:01:37,140 --> 00:01:37,730
I get back
23

24
00:01:37,740 --> 00:01:44,370
I'm just going to call response, and then inside the closure, I'm going to check to see if the response
24

25
00:01:44,370 --> 00:01:45,160
was successful.
25

26
00:01:45,180 --> 00:01:52,430
So if response.results.isSuccess, then I will
26

27
00:01:52,460 --> 00:02:00,960
print "Got the keep Wikipedia info." And finally, all we need to do is just to print the response into
27

28
00:02:01,230 --> 00:02:02,470
the debug console.
28

29
00:02:02,610 --> 00:02:02,850
All right.
29

30
00:02:02,850 --> 00:02:04,170
So we're always done.
30

31
00:02:04,170 --> 00:02:07,460
One thing to remember is that we haven't actually called this method anyway yet.
31

32
00:02:07,470 --> 00:02:12,540
So I've just realized that our classification isn't actually protected against the cases where our
32

33
00:02:12,540 --> 00:02:14,700
FlowerClassifier doesn't return any result.
33

34
00:02:14,730 --> 00:02:18,470
So let's be safe and use a guard statement to protect those situations.
34

35
00:02:23,320 --> 00:02:29,650
So after we've gotten back our classification identifier, then we're going to pass this in as the 
35

36
00:02:29,650 --> 00:02:30,170
flowerName.
36

37
00:02:30,190 --> 00:02:33,880
So that is going to be the title that we're going to pass into the URL.
37

38
00:02:34,120 --> 00:02:38,290
So let's do that once we've successfully gotten back our results.
38

39
00:02:38,560 --> 00:02:41,830
And I'm going to call this method request info.
39

40
00:02:41,860 --> 00:02:48,490
So because we're inside a closure, as denoted by the "in" keyword, then we're going to use "self" in front
40

41
00:02:48,490 --> 00:02:50,110
of all our method calls.
41

42
00:02:50,110 --> 00:02:57,990
So self.request info and the flowerName is going to be classification.identifier.
42

43
00:02:58,420 --> 00:02:59,000
All right. Cool.
43

44
00:02:59,020 --> 00:03:01,590
So that's done, and we're ready for a spin.
44

45
00:03:05,270 --> 00:03:12,770
And you can see down here, we've got "Got the wikipedia info," SUCCESS, and we've got all of this information
45

46
00:03:12,770 --> 00:03:17,510
back from Wikipedia including that extract that we're after.
46

47
00:03:17,540 --> 00:03:20,380
All right. So well done if you manage to get here by yourself.
47

48
00:03:20,390 --> 00:03:22,730
If not or if there's anything confusing,
48

49
00:03:22,730 --> 00:03:27,260
have a look back at the lessons where we covered Alamofire and HTTP requests.
49

50
00:03:27,260 --> 00:03:31,970
And if you're still stuck, then be sure to start a thread in the question-answer section, and we'll try
50

51
00:03:31,970 --> 00:03:33,680
and help you out. In the next lesson,
51

52
00:03:33,680 --> 00:03:39,770
we're going to go in and parse all of this JSON using SwiftyJSON so that we can grab out our extract
52

53
00:03:39,860 --> 00:03:41,540
and display it inside a label.
53

54
00:03:41,600 --> 00:03:42,330
So I'll see you there.
