drop pagination from shelves api (#16370)
* drop pagination from shelves api * double check the pagination properties aren't in the full shelf response
This commit is contained in:
Родитель
147160d260
Коммит
64a8bad0b2
|
@ -406,6 +406,7 @@ These are `v5` specific changes - `v4` changes apply also.
|
|||
* 2021-01-07: changed API behavior with all fields that could be affected by ``wrap_outgoing_links``.
|
||||
Now the url is an object containing both the original url and the wrapped url. See :ref:`Outgoing Links <api-overview-outgoing>`.
|
||||
* 2021-01-21: in language-tools api, made ``application`` parameter only mandatory when ``appversion`` parameter is also present, and ignored otherwise. https://github.com/mozilla/addons-server/issues/12315
|
||||
* 2021-01-28: dropped the pagination fields from the shelves api (it's still an object with a ``results`` property though). https://github.com/mozilla/addons-server/issues/16342
|
||||
|
||||
.. _`#11380`: https://github.com/mozilla/addons-server/issues/11380/
|
||||
.. _`#11379`: https://github.com/mozilla/addons-server/issues/11379/
|
||||
|
|
|
@ -89,17 +89,13 @@ Homepage Shelves
|
|||
|
||||
This endpoint returns the shelves to display on the AMO Homepage.
|
||||
A single, randomly selected, primary hero shelf and a single, randomly selected secondary
|
||||
hero shelf is returned, along with the enabled shelves.
|
||||
hero shelf is returned, along with the enabled shelves. As there will only ever be a
|
||||
small number of shelves this endpoint is not paginated.
|
||||
|
||||
|
||||
.. http:get:: /api/v5/shelves/
|
||||
|
||||
:query int page_size: Maximum number of results to return for the requested page. Defaults to 25.
|
||||
:query string lang: Activate translations in the specific language for that query. (See :ref:`translated fields <api-overview-translations>`)
|
||||
:>query int page_count: The number of pages available in the pagination.
|
||||
:>json int count: The number of results for this query.
|
||||
:>json string next: The URL of the next page of results.
|
||||
:>json string previous: The URL of the previous page of results.
|
||||
:>json array results: The array of shelves displayed on the AMO Homepage.
|
||||
:>json string results[].title: The title of the shelf.
|
||||
:>json string results[].url: The configured URL using the shelf's endpoint and criteria; links to the shelf's returned add-ons.
|
||||
|
|
|
@ -334,6 +334,7 @@ v4 API changelog
|
|||
* 2020-10-22: added /shelves/sponsored/event endpoint for conversions, and to replace click endpoint https://github.com/mozilla/addons-server/issues/15718
|
||||
* 2020-11-05: dropped heading and description from discovery API https://github.com/mozilla/addons-server/issues/11272
|
||||
* 2020-11-05: added endpoint to receive Stripe events. https://github.com/mozilla/addons-server/issues/15879
|
||||
* 2021-01-28: removed the /shelves/ endpoints from /v4/. They are only useful internally within AMO and are still under rapid development making them unsuitable for a frozen API.
|
||||
|
||||
.. _`#11380`: https://github.com/mozilla/addons-server/issues/11380/
|
||||
.. _`#11379`: https://github.com/mozilla/addons-server/issues/11379/
|
||||
|
|
|
@ -82,82 +82,3 @@ small number of shelves - and likely only one - this endpoint is not paginated.
|
|||
:>json string results[].modules[].cta.url: The url the call to action would link to.
|
||||
:>json string results[].modules[].cta.outgoing: (v5+ only) url wrapped with outgoing (See :ref:`Outgoing Links <v4-api-overview-outgoing>`)
|
||||
:>json string results[].modules[].cta.text: The call to action text.
|
||||
|
||||
|
||||
----------------
|
||||
Homepage Shelves
|
||||
----------------
|
||||
|
||||
.. _v4-homepage-shelves:
|
||||
|
||||
This endpoint returns the enabled shelves displayed on the AMO Homepage below the hero area.
|
||||
|
||||
|
||||
.. http:get:: /api/v4/shelves/
|
||||
|
||||
:query int page_size: Maximum number of results to return for the requested page. Defaults to 25.
|
||||
:query int page_count: The number of pages available in the pagination.
|
||||
:query int count: The number of results for this query.
|
||||
:query string next: The URL of the next page of results.
|
||||
:query string previous: The URL of the previous page of results.
|
||||
:>json array results: The array of shelves displayed on the AMO Homepage.
|
||||
:>json string results[].title: The title of the shelf.
|
||||
:>json string results[].url: The configured URL using the shelf's endpoint and criteria; links to the shelf's returned add-ons.
|
||||
:>json string results[].endpoint: The endpoint selected for the shelf.
|
||||
:>json string results[].criteria: The criteria for the addons in the shelf.
|
||||
:>json string|null results[].footer_text: The optional text in the footer of the shelf.
|
||||
:>json string|null results[].footer_pathname: The optional pathname of the URL for the footer's text.
|
||||
:>json array results[].addons: An array of :ref:`add-ons <v4-addon-detail-object>` or :ref:`collections <v4-collection-detail-object>`.
|
||||
|
||||
---------------
|
||||
Sponsored Shelf
|
||||
---------------
|
||||
|
||||
.. _v4-sponsored-shelf:
|
||||
|
||||
This endpoint returns the addons that should be shown on the sponsored shelf.
|
||||
Current implementation relies on Adzerk to determine which addons are returned and in which order.
|
||||
|
||||
|
||||
.. http:get:: /api/v4/shelves/sponsored/
|
||||
|
||||
:query string lang: Activate translations in the specific language for that query. (See :ref:`translated fields <v4-api-overview-translations>`)
|
||||
:query int page_size: specify how many addons should be returned. Defaults to 6. Note: fewer addons could be returned if there are fewer than specifed sponsored addons currently, or the Adzerk service is unavailable.
|
||||
:query string wrap_outgoing_links: (v3/v4 only) If this parameter is present, wrap outgoing links through ``outgoing.prod.mozaws.net`` (See :ref:`Outgoing Links <v4-api-overview-outgoing>`)
|
||||
:>json array results: The array containing the addon results for this query. The object is a :ref:`add-on <v4-addon-detail-object>` as returned by :ref:`add-on search endpoint <v4-addon-search>` with an extra field of ``events``
|
||||
:>json object results[].event_data: contains data that for different events that can be recorded.
|
||||
:>json string results[].event_data.click: the signed data payload to send to the :ref:`event endpoint <v4-sponsored-shelf-event>` that identifies the sponsored placement clicked on.
|
||||
:>json string results[].event_data.conversion: the signed data payload to send to the :ref:`event endpoint <v4-sponsored-shelf-event>` that identifies the conversion (install) event for the sponsored addon placement.
|
||||
:>json string impression_url: the url to ping when the contents of this sponsored shelf is rendered on screen to the user.
|
||||
:>json string impression_data: the signed data payload to send to ``impression_url`` that identifies all of the sponsored placements displayed.
|
||||
|
||||
|
||||
---------------------------
|
||||
Sponsored Shelf Impressions
|
||||
---------------------------
|
||||
|
||||
.. _v4-sponsored-shelf-impression:
|
||||
|
||||
When the sponsored shelf is displayed for the user this endpoint can be used to record the impressions.
|
||||
The current implemenation forwards these impression pings to Adzerk.
|
||||
|
||||
|
||||
.. http:post:: /api/v4/shelves/sponsored/impression/
|
||||
|
||||
:form string impression_data: the signed data payload that was sent in the :ref:`sponsored shelf <v4-sponsored-shelf>` response.
|
||||
|
||||
|
||||
----------------------
|
||||
Sponsored Shelf Events
|
||||
----------------------
|
||||
|
||||
.. _v4-sponsored-shelf-event:
|
||||
|
||||
When an item on the sponsored shelf is clicked on by the user, to navigate to the detail page, or the addon is subsequently installed from the detail page, this endpoint should be used to record that event.
|
||||
The current implemenation forwards these events to Adzerk.
|
||||
|
||||
|
||||
.. http:post:: /api/v4/shelves/sponsored/event/
|
||||
|
||||
:form string data: the signed data payload that was sent in addon data in the :ref:`sponsored shelf <v4-sponsored-shelf>` response.
|
||||
:form string type: the type of event. Supported types are ``click`` and ``conversion``.
|
||||
|
|
|
@ -32,6 +32,9 @@ v4_api_urls = [
|
|||
re_path(r'^', include(amo_api_patterns)),
|
||||
re_path(r'^promoted/', include('olympia.promoted.api_urls')),
|
||||
re_path(r'^scanner/', include('olympia.scanners.api_urls')),
|
||||
]
|
||||
|
||||
v5_api_urls = v4_api_urls + [
|
||||
re_path(r'^shelves/', include('olympia.shelves.urls')),
|
||||
]
|
||||
|
||||
|
@ -39,5 +42,5 @@ urlpatterns = [
|
|||
re_path(r'^auth/', include((auth_callback_patterns, 'auth'))),
|
||||
re_path(r'^v3/', include((v3_api_urls, 'v3'))),
|
||||
re_path(r'^v4/', include((v4_api_urls, 'v4'))),
|
||||
re_path(r'^v5/', include((v4_api_urls, 'v5'))),
|
||||
re_path(r'^v5/', include((v5_api_urls, 'v5'))),
|
||||
]
|
||||
|
|
|
@ -125,11 +125,6 @@ class TestShelfViewSet(ESTestCase):
|
|||
response = self.client.get(self.url)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {
|
||||
'count': 0,
|
||||
'next': None,
|
||||
'page_count': 1,
|
||||
'page_size': 25,
|
||||
'previous': None,
|
||||
'results': [],
|
||||
'primary': None,
|
||||
'secondary': None,
|
||||
|
@ -140,7 +135,7 @@ class TestShelfViewSet(ESTestCase):
|
|||
self.hpshelf_b.update(enabled=True)
|
||||
# don't enable shelf_c
|
||||
|
||||
with self.assertNumQueries(26):
|
||||
with self.assertNumQueries(25):
|
||||
response = self.client.get(self.url)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
@ -199,11 +194,6 @@ class TestShelfViewSet(ESTestCase):
|
|||
response = self.client.get(self.url, {'lang': 'en-US'})
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {
|
||||
'count': 0,
|
||||
'next': None,
|
||||
'page_count': 1,
|
||||
'page_size': 25,
|
||||
'previous': None,
|
||||
'results': [],
|
||||
'primary': PrimaryHeroShelfSerializer(instance=phero).data,
|
||||
'secondary': SecondaryHeroShelfSerializer(instance=shero).data,
|
||||
|
@ -223,9 +213,9 @@ class TestShelfViewSet(ESTestCase):
|
|||
|
||||
self.hpshelf_a.update(enabled=True)
|
||||
|
||||
with self.assertNumQueries(17):
|
||||
# 17 queries:
|
||||
# - 4 to get the shelves
|
||||
with self.assertNumQueries(16):
|
||||
# 16 queries:
|
||||
# - 3 to get the shelves
|
||||
# - 11 as TestPrimaryHeroShelfViewSet.test_basic
|
||||
# - 2 as TestSecondaryHeroShelfViewSet.test_basic
|
||||
response = self.client.get(self.url)
|
||||
|
@ -233,6 +223,9 @@ class TestShelfViewSet(ESTestCase):
|
|||
|
||||
result = json.loads(response.content)
|
||||
|
||||
for prop in ('count', 'next', 'page_count', 'page_size', 'previous'):
|
||||
assert prop not in result
|
||||
|
||||
assert len(result['results']) == 1
|
||||
|
||||
assert result['results'][0]['title'] == 'Recommended extensions'
|
||||
|
|
|
@ -37,16 +37,21 @@ class ShelfViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
|
|||
)
|
||||
permission_classes = []
|
||||
serializer_class = ShelfSerializer
|
||||
pagination_class = None
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
response = super().list(request, *args, **kwargs)
|
||||
response.data['primary'] = PrimaryHeroShelfViewSet(
|
||||
request=request
|
||||
).get_one_random_data()
|
||||
response.data['secondary'] = SecondaryHeroShelfViewSet(
|
||||
request=request
|
||||
).get_one_random_data()
|
||||
return response
|
||||
results = super().list(request, *args, **kwargs).data
|
||||
return Response(
|
||||
{
|
||||
'results': results,
|
||||
'primary': PrimaryHeroShelfViewSet(
|
||||
request=request
|
||||
).get_one_random_data(),
|
||||
'secondary': SecondaryHeroShelfViewSet(
|
||||
request=request
|
||||
).get_one_random_data(),
|
||||
}
|
||||
)
|
||||
|
||||
@classonlymethod
|
||||
def as_view(cls, *args, **initkwargs):
|
||||
|
|
Загрузка…
Ссылка в новой задаче