Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Use the pre-made data model classes to display items.
View the 'Downloads' tab to access the Data Model Files
Want to know more about Parcelable
?
Check out Using Parcelable Data from the Lists and Adapters course.
Etsy API Endpoint
https://openapi.etsy.com/v2/listings/active?includes=Shop,Images&api_key=INSERT_YOUR_KEY
-
0:00
I've provided a few data model classes to help you get started.
-
0:04
These Java classes represent the data that Etsy API will return to us.
-
0:09
Download them in the link in the teacher's notes.
-
0:13
Once you have them downloaded, go ahead and unzip them, and
-
0:17
we can see what classes are included.
-
0:19
We're gonna wanna go ahead and take these classes, copy them,
-
0:22
and paste them into our project in Android Studio.
-
0:26
In Android Studio, I'm gonna create a new package to keep my code organized.
-
0:29
I'm gonna call it model.
-
0:32
And in model, I'm gonna go ahead and paste in those classes.
-
0:37
If we open one of these classes, for
-
0:39
instance image, we can see it's a simple class with properties.
-
0:43
The classes are all parcelable,
-
0:45
which allows us to easily use them with fragments and activities.
-
0:49
You're hopefully familiar with parcelable data, but if not, check out the links
-
0:53
in the teacher's notes to where we've already covered this at TreeHouse.
-
0:57
To understand why they're modeled this way, let's look at the documentation for
-
1:00
the API we're using.
-
1:02
Here on the Etsy Developers site, let's click on Documentation.
-
1:06
In Documentation, we can find all the information we need to connect and
-
1:09
access Etsy's data.
-
1:11
Let's look at the API Reference.
-
1:14
Here we can see all the different types of data we can get back from the Etsy API.
-
1:18
We're gonna be looking for listings, so let's go ahead and click on Listing.
-
1:22
If we scroll down a little bit, we'll be able to see an overview of what a listing
-
1:26
is, and it also lists a few different properties and fields that a listing has.
-
1:32
If we keep scrolling, we're gonna find information about how to search for
-
1:36
listings.
-
1:38
By default,
-
1:38
the method findAllListingActive returns all the active listings on Etsy.
-
1:43
This is exactly what we want, so let's go ahead and click on it.
-
1:47
And we can see here that this provides an overview of how to use this method.
-
1:52
It provides the method name, the HTTP protocol we need,
-
1:56
the URI and a whole list of parameters.
-
2:00
We can see that the method is found at /listing/active and it uses HTTP GET.
-
2:06
Let's break down the API call, so we can understand each part.
-
2:09
The Etsy endpoint is [SOUND]
-
2:13
https://openapi.etsy.com/v2.
-
2:20
[SOUND] Next, is the method name, which is /listings/active.
-
2:25
[SOUND] Next, we include the URL parameters that indicate we want the shop
-
2:29
and the image data returned along with the listing data.
-
2:32
This will make it so
-
2:33
we don't have to make additional API calls once we get the listing data.
-
2:37
Finally, [SOUND] at the very end, we're going to append our API key.
-
2:41
If we make this API call in our browser, we can see what data gets returned.
-
2:46
Let's go ahead and do that now.
-
2:47
So open a new tab and we'll just type in our call that we're gonna make,
-
2:56
[SOUND] openapi.etsy.com/v2/listings/active,
-
3:03
and we need to include, using the includes,
-
3:08
the images and shop and append our API key.
-
3:13
And we need to make sure we're using our current API key for this, so
-
3:18
let's go ahead and go to Android Studio and paste in the API key from our app.
-
3:26
Switching back to Chrome, I'm just gonna go ahead and
-
3:28
paste in our API key at the end.
-
3:31
And let's go ahead and make that call.
-
3:34
And we can see what gets returned to us.
-
3:36
It's a JSONObject and it has many fields included in it.
-
3:40
First, it gives us a count of how many objects there are that
-
3:43
can be possibly returned.
-
3:44
And then it starts listing them out in a JSON array.
-
3:47
If you look here, we can see that a JSON array has a number of listings included,
-
3:52
and within that,
-
3:54
are also the images that we asked to be included using the include statement.
-
3:59
And if we keep scrolling down, we can also see the shop data is included as well,
-
4:04
which we requested in the include statement.
-
4:07
If we switch back to Android Studio, let's take a look at the ActiveListings class,
-
4:12
we can see that this directly mirrors the result from the API.
-
4:16
So we have the count and an array of listing objects and if we go ahead and
-
4:20
go into the Listing objects class, we can see that this has
-
4:24
the exact same properties that were being passed back to us from the API.
-
4:29
Let's take a break and when we return,
-
4:31
we can start using these classes to make an API request.
You need to sign up for Treehouse in order to download course files.
Sign up