#12 Fetch Fedora magazine images from API
Closed 5 years ago by amitosh. Opened 6 years ago by a2batic.

Look in the fedora magazine API and write code for fetching banner image for each post.


@a2batic I'm interested to give it a try

Umm, I was already giving it a go and i am almost done. Is it okay if i claim the issue if it is not assigned yet @a2batic?

@manaswinidas @shilpi1958, What approach are you planning to take ? How are you planning to do it?

Hey @a2batic,
I am planning to implement a function which will make a get request to: https://fedoramagazine.org/wp-json/wp/v2/posts/{id} . Then I would fetch the value of featured_media from the returned JSON response. After this making a request to https://fedoramagazine.org/wp-json/wp/v2/media/{featured_media_id} which will give us the banner image JSON object. The image media url is then fetched from guid.rendered key of that object. Please let me know if my approach is right.
Regards.

Hi @a2batic,
Sorry, it took me too long to reply.
As per WordPress REST API Documentation1, the post listing has a field called featured_media which contains the id to each of the media. We can then retrieve the media file and its associated thumbnails from https://fedoramagazine.org/wp-json/wp/v2/media/<id>2My plan is to introduce a new field called featuredImage in post object, fetch the media URLs asynchronously and update the post object with the appropriate size. While the media is not loaded, we can put a placeholder image in the featuredImage.For n posts we will need a total of n + 1 HTTP calls.

Looks good to me.

Hey @a2batic,
I am planning to implement a function which will make a get request to: https://fedoramagazine.org/wp-json/wp/v2/posts/{id} . Then I would fetch the value of featured_media from the returned JSON response. After this making a request to https://fedoramagazine.org/wp-json/wp/v2/media/{featured_media_id} which will give us the banner image JSON object. The image media url is then fetched from guid.rendered key of that object. Please let me know if my approach is right.
Regards.

You can go ahead with this issue.

@manaswinidas, the approach too looks good.

Hi @a2batic,
Sorry, it took me too long to reply.
As per WordPress REST API Documentation1, the post listing has a field called featured_media which contains the id to each of the media. We can then retrieve the media file and its associated thumbnails from https://fedoramagazine.org/wp-json/wp/v2/media/<id>2My plan is to introduce a new field called featuredImage in post object, fetch the media URLs asynchronously and update the post object with the appropriate size. While the media is not loaded, we can put a placeholder image in the featuredImage.For n posts we will need a total of n + 1 HTTP calls.

Since @shilpi1958 already started working, you can look intro other issues, one of them is easy and unassigned https://pagure.io/Fedora-app/issue/9.

Metadata Update from @a2batic:
- Issue assigned to shilpi1958

6 years ago

hi @a2batic
Yeah!, I have made getMedia_url working but I'm a little bit confused. It's not clear to me that how should I store the media_url. Do you want it to be stored in a separate key in every object of this.posts, or a separate list, where this.media_url[i] will be the URL corresponding to this.posts[i] for some 'i'. Till now, the function is able to fetch a list of media_urls.

@shilpi1958, I think it can be stored in a separate key in every object. It will be nice if you can you send the PR so that I can look and understand from code, we can modify can discuss it there. Add a WIP tag.

Metadata Update from @amitosh:
- Issue status updated to: Closed (was: Open)

5 years ago

Login to comment on this ticket.

Metadata