Skip to content

APIv3: add analytics field to Project object #10239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/user/api/v3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ Projects list
"latest": "{VERSION}",
"19.0.2": "{VERSION}"
},
"analytics": {
"google": {
"code": "UA-XXXXX"
},
"readthedocs": {
"enabled": true
}
}
"_links": {
"_self": "/api/v3/projects/pip/",
"versions": "/api/v3/projects/pip/versions/",
Expand Down Expand Up @@ -279,6 +287,14 @@ Project details
},
"privacy_level": "public",
"external_builds_privacy_level": "public",
"analytics": {
"google": {
"code": "UA-XXXXX"
},
"readthedocs": {
"enabled": true
}
}
"_links": {
"_self": "/api/v3/projects/pip/",
"versions": "/api/v3/projects/pip/versions/",
Expand Down
44 changes: 29 additions & 15 deletions readthedocs/api/v3/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,18 @@ class ProjectUpdateSerializer(SettingsOverrideObject):
_default_class = ProjectUpdateSerializerBase


class AnalyticsSerializer(serializers.Serializer):

readthedocs = serializers.SerializerMethodField()
google = serializers.SerializerMethodField()

def get_readthedocs(self, obj):
return {"enabled": not obj.analytics_disabled}

def get_google(self, obj):
return {"code": obj.analytics_code}


class ProjectSerializer(FlexFieldsModelSerializer):

"""
Expand All @@ -616,6 +628,7 @@ class ProjectSerializer(FlexFieldsModelSerializer):
But we have organization.owners.
"""

analytics = AnalyticsSerializer(source="*")
homepage = serializers.SerializerMethodField()
language = LanguageSerializer()
programming_language = ProgrammingLanguageSerializer()
Expand All @@ -637,21 +650,22 @@ class ProjectSerializer(FlexFieldsModelSerializer):
class Meta:
model = Project
fields = [
'id',
'name',
'slug',
'created',
'modified',
'language',
'programming_language',
'homepage',
'repository',
'default_version',
'default_branch',
'subproject_of',
'translation_of',
'urls',
'tags',
"id",
"name",
"slug",
"created",
"modified",
"language",
"programming_language",
"analytics",
"homepage",
"repository",
"default_version",
"default_branch",
"subproject_of",
"translation_of",
"urls",
"tags",
"privacy_level",
"external_builds_privacy_level",

Expand Down
8 changes: 8 additions & 0 deletions readthedocs/api/v3/tests/responses/projects-detail.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
"translations": "https://readthedocs.org/api/v3/projects/project/translations/",
"versions": "https://readthedocs.org/api/v3/projects/project/versions/"
},
"analytics": {
"google": {
"code": null
},
"readthedocs": {
"enabled": true
}
},
"modified": "2019-04-29T12:00:00Z",
"name": "project",
"programming_language": {
Expand Down