Skip to content

Commit

Permalink
Updated docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcohoon committed Apr 18, 2016
1 parent 7387e88 commit f96f799
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 20 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Google Analytics Reporting V4 Compatibility Library
# Google Analytics Reporting API V4 Compatibility Library [![Analytics](https://ga-beacon.appspot.com/UA-76561751-1/googleanalytics/gav4-python?pixel)](https://github.com/googleanalytics/gav4-python)

A library for converting Google Analytics Core Reporting API V3 request to Analytics Reporting API V4 requests.
A library for converting Google Analytics [Core Reporting API V3](https://developers.google.com/analytics/devguides/reporting/core/v3/) request to [Analytics Reporting API V4](https://developers.google.com/analytics/devguides/reporting/core/v4/) requests.

## Installation

Expand All @@ -9,23 +9,23 @@ A library for converting Google Analytics Core Reporting API V3 request to Analy

## Typical usage example

There are two methods of using the gav4 library. You can `apply` the library to an authorized Google Analytics Service object, which exposes a get method that operates much like the current Core Reporting API V3.
There are two methods of using the gav4 library. You can `apply` the library to an authorized `analyticsreporting` Service object, which exposes a get method that operates much like the current Core Reporting API V3.

import gav4

# Apply the gav4 get method to the authorized service object.
gav4.apply_gav4(analytics)
# Apply the gav4 get method to the analyticsreporting service object.
gav4.apply_gav4(analyticsreporting)

# Call the gav4_get method with a V3 request and get a V3 response.
v3_response = analytics.gav4_get(v3_request).execute()

Alternatively you can convert the requests and responses directly.
Alternatively, you can convert the requests and responses directly.

# Convert a V3 request into a V4 request.
v4_request = gav4.convert_request(v3_request)

# Call the V4 API.
v4_response = analytics.reports().batchGet(body=v4_request).execute()
v4_response = analyticsreporting.reports().batchGet(body=v4_request).execute()

# Convert the V4 API response into a V3 response.
v3_response = gav4.convert_report(v4_response.get('reports', [])[0])
Expand Down Expand Up @@ -61,3 +61,6 @@ You can sign these electronically (just scroll to the bottom). After that, we'll
All submissions, including submissions by project members, require review. We
use Github pull requests for this purpose.

### Naming

This library is strictly for the Analytics Reporting API and not to be confused with the [Google Analytics Android SDK V4](https://developers.google.com/analytics/devguides/collection/android/v4/).
15 changes: 15 additions & 0 deletions gav4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Google Analytics Reporting API V4 Compatibility Library [![Analytics](https://ga-beacon.appspot.com/UA-76561751-1/googleanalytics/gav4-python/gav4?pixel)](https://github.com/googleanalytics/gav4-python)

## Contents

### [`gav4.py`](gav4.py)

The `gav4.py` contains functions to convert each of the [Core Reporting API V3](https://developers.google.com/analytics/devguides/reporting/core/v3/) parameters to [Analytics Reporting API V4](https://developers.google.com/analytics/devguides/reporting/core/v4/) request fields.

The file also contains the `apply_gav4` function which can be called with an authorized `analyticsreporting` service object; once applied, you can call:

`analyticsreporting.gav4_get(...)`

which takes the same parameters and returns the same response as when you call the Core reporting API V3 method:

`analytics.data().ga().get(...)`
12 changes: 6 additions & 6 deletions gav4/gav4.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@

"""Library for converting V3 API request to V4 API requests.
This library contains helper functions to convert a Core Reporting API V3
This library contains helper functions which convert a Core Reporting API V3
request into a Analytics Reporting API V4 request.
It is designed to work in concert to the Google API Python client library.
import gav4
# Apply the gav4 get method to the authorized service object.
gav4.apply_gav4(analytics)
# Apply the gav4 get method to the analyticsreporting service object.
gav4.apply_gav4(analyticsreporting)
# Call the gav4_get method with a V3 request and get a V3 response.
v3_response = analytics.gav4_get(v3_request).execute()
Alternatively you can convert the requests and responses directly.
Alternatively, you can convert the requests and responses directly.
# Convert a V3 request into a V4 request.
v4_request = gav4.convert_request(v3_request)
# Call the V4 API.
v4_response = analytics.reports().batchGet(body=v4_request).execute()
v4_response = analyticsreporting.reports().batchGet(body=v4_request).execute()
# Convert the V4 API response into a V3 response.
v3_response = gav4.convert_report(v4_response.get('reports', [])[0])
Expand Down Expand Up @@ -171,7 +171,7 @@ def convert_request(**kwargs):


def gav4_get(self, **kwargs):
"""A service object method this method converts and calls the requests.
"""A service object method which converts and calls the requests.
This method gets attached to an authorized analytics V4 service object.
It operates like a V3 data().ga().get() method.
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[bdist_wheel]
universal = 1

[metadata]
description-file = README.md
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
description='Google Analytics V4 API Compatibility Library',
author='Google Analytics Platform',
author_email='[email protected]',
long_description=README,
scripts=[],
url='https://github.com/googleanalytics/gav4-python',
packages=find_packages(),
Expand Down
19 changes: 19 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# GAV4 Tests [![Analytics](https://ga-beacon.appspot.com/UA-76561751-1/googleanalytics/gav4-python/tests?pixel)](https://github.com/googleanalytics/gav4-python)

## Testing

Run the tests with the following command:

python setup.py tests

This may require you to install the nose library -- `pip install nose`.

## Contents

### [data.py](data.py)

The `data.py` file contain requests requests, converted requests, responses, converted responses, and mocks of the service objects and its member objects.

### [test_gav4.py](test_gav4.py)

The `test_gav4.py` file contains tests for the gav4 library. It includes unit tests for the individual conversion methods as well as an end-to-end integration test.
4 changes: 2 additions & 2 deletions tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ def batchGet(self, body): # pylint: disable=invalid-name
return BatchGet(body)


class Analytics(object):
"""Mock Google Analytics service object."""
class AnalyticsReporting(object):
"""Mock AnalyticsReporting service object."""

def reports(self):
"""Returns a mock Reports object."""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_gav4.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def testGav4Get(self):
"""

# Get the MOCK authenticated service object.
analytics = data.Analytics()
analyticsreporting = data.AnalyticsReporting()

# Apply the gav4 library.
gav4.apply_gav4(analytics)
gav4.apply_gav4(analyticsreporting)

# Call the veeneer_get() method.
request = analytics.gav4_get(**data.V3_REQUEST)
# Call the gav4_get() method.
request = analyticsreporting.gav4_get(**data.V3_REQUEST)

# Call the wrapped execute method.
response = request.execute()
Expand Down

0 comments on commit f96f799

Please sign in to comment.