Skip to main content

Swydo Python SDK (swydo)

Project description

swydo

PyPI version PyPI pyversions Build Status

A Python 3 module to interact with the Swydo API.

Developed in Mayple.

Install

pip install swydo

Example

import logging
import swydo
import itertools
from bravado.exception import HTTPError

logging.basicConfig()

from typing import Dict, Union, Any

YOUR_API_KEY="..."

# Manually injected, as Swydo sometimes doesn't return teams
yourTeamId = "..."

print("Starting...")
swydoClient = swydo.SwydoClient(apiKey=YOUR_API_KEY)

yourBrandTemplateId = "..."
yourReportTemplateId = "..."
yourFacebookAdsConnectionId = "..."
yourFacebookGraphConnectionId = "..."
yourGoogleAdWordsConnectionId = "..."
yourGoogleAnalyticsConnectionId = "..."

# If you have one
testClientId = ""

skipInitialEnumeration = False

if not skipInitialEnumeration:
    teams = list(swydoClient.getTeams())

    for teamId in itertools.chain(
            (team['id'] for team in teams),
            [yourTeamId]
    ):
        team = swydoClient.getTeam(teamId)
        assert team['id'] == teamId
        print("Team: %s" % team)

        teamUsers = swydoClient.getTeamUsers(teamId=teamId)
        for userId in (user['id'] for user in teamUsers):
            user = swydoClient.getTeamUser(teamId=teamId, userId=userId)
            assert userId == user['id']
            print("User: %s" % user)

        teamConnections = swydoClient.getTeamConnections(teamId=teamId)
        for connectionId in (connection['id'] for connection in teamConnections):
            connection = swydoClient.getTeamConnection(teamId=teamId, connectionId=connectionId)
            assert connectionId == connection['id']
            print("Connection: %s" % connection)

        teamBrandTemplates = swydoClient.getTeamBrandTemplates(teamId=teamId)
        for brandTemplateId in (brandTemplate['id'] for brandTemplate in teamBrandTemplates):
            brandTemplate = swydoClient.getTeamBrandTemplate(teamId=teamId, brandTemplateId=brandTemplateId)
            assert brandTemplateId == brandTemplate['id']
            print("BrandTemplate: %s" % brandTemplate)

        teamReportTemplates = swydoClient.getTeamReportTemplates(teamId=teamId)
        for reportTemplateId in (reportTemplate['id'] for reportTemplate in teamReportTemplates):
            reportTemplate = swydoClient.getTeamReportTemplate(teamId=teamId, reportTemplateId=reportTemplateId)
            assert reportTemplateId == reportTemplate['id']
            print("ReportTemplate: %s" % reportTemplate)

        teamClients = swydoClient.getTeamClients(teamId=teamId)
        for clientId in (client['id'] for client in teamClients):
            client = swydoClient.getTeamClient(teamId=teamId, clientId=clientId)
            assert clientId == client['id']
            print("Client: %s" % client)

            clientDataSources = swydoClient.getClientDataSources(teamId=teamId, clientId=clientId)
            assert clientId == clientDataSources['id']
            print("ClientDataSources: %s" % clientDataSources)

        teamReports = swydoClient.getTeamReports(teamId=teamId)
        for reportId in (report['id'] for report in teamReports):
            report = swydoClient.getTeamReport(teamId=teamId, reportId=reportId)
            assert reportId == report['id']
            print("Report: %s" % report)

# Find a specific client
try:
    testClient: Union[None, Dict[str, Any]] = \
        swydoClient.getTeamClient(teamId=yourTeamId, clientId=testClientId)
except HTTPError as he:
    if he.status_code == 404:
        testClient = None
    else:
        raise
if not testClient:
    testClient = swydoClient.createTeamClient(
        teamId=yourTeamId,
        name="Test Client via API",
        description="Test Client's Description",
        email="test@email.com"
    )
print("Test Client: %s" % testClient)

testClient = swydoClient.updateTeamClient(
    teamId=yourTeamId,
    clientId=testClient['id'],
    name="Updated Test Client via API",
    description="Updated Test Client's Description",
)
print("Test Client: %s" % testClient)

swydoClient.archiveTeamClient(
    teamId=yourTeamId,
    clientId=testClient['id'],
)
print("Test Client archived.")

swydoClient.unarchiveTeamClient(
    teamId=yourTeamId,
    clientId=testClient['id'],
)
print("Test Client unarchived.")

swydoClient.removeClientDataSourceFacebookAds(
    teamId=yourTeamId,
    clientId=testClientId,
)
print("facebookAdsDataSource removed")

swydoClient.removeClientDataSourceFacebookGraph(
    teamId=yourTeamId,
    clientId=testClientId,
)
print("FacebookGraph DataSource removed")

swydoClient.removeClientDataSourceGoogleAdWords(
    teamId=yourTeamId,
    clientId=testClientId,
)
print("GoogleAdWords DataSource removed")

swydoClient.removeClientDataSourceGoogleAnalytics(
    teamId=yourTeamId,
    clientId=testClientId,
)
print("GoogleAnalytics DataSource removed")

# FacebookAds
facebookAdsDataSource = swydoClient.setClientDataSourceFacebookAds(
    teamId=yourTeamId,
    clientId=testClientId,
    connectionId=yourFacebookAdsConnectionId,
    dataSourceId='adAccountId',
    dataSourceName='Added Facebook Ad Account',
    dataSourceCurrencyCode='USD',
)
print("FacebookAds DataSource: %s" % facebookAdsDataSource)

# FacebookGraph
facebookGraphDataSource = swydoClient.setClientDataSourceFacebookGraph(
    teamId=yourTeamId,
    clientId=testClientId,
    connectionId=yourFacebookGraphConnectionId,
    dataSourceId='dataSourceId',
    dataSourceName='Added Facebook Graph Account',
    dataSourcePageId='dataSourcePageId',
)
print("FacebookGraph DataSource: %s" % facebookGraphDataSource)

# GoogleAdWords
googleAdWordsDataSource = swydoClient.setClientDataSourceGoogleAdWords(
    teamId=yourTeamId,
    clientId=testClientId,
    connectionId=yourGoogleAdWordsConnectionId,
    dataSourceClientId='dataSourceClientId',
    dataSourceName='Added Google Ads Account',
    dataSourceCurrencyCode='USD',
)
print("GoogleAdWords DataSource: %s" % googleAdWordsDataSource)

# GoogleAnalytics
googleAnalyticsDataSource = swydoClient.setClientDataSourceGoogleAnalytics(
    teamId=yourTeamId,
    clientId=testClientId,
    connectionId=yourGoogleAnalyticsConnectionId,
    dataSourceAccountId='dataSourceAccountId',
    dataSourceName='Added Google Analytics Account',
    dataSourceAccountName='dataSourceAccountName',
    dataSourceWebPropertyId='dataSourceWebPropertyId',
    dataSourceProfileId='dataSourceProfileId',
    dataSourceCurrencyCode='USD',
)
print("GoogleAnalytics DataSource: %s" % googleAnalyticsDataSource)

# Create a report
testReport = swydoClient.createTeamReport(
    teamId=yourTeamId,
    name="Temporary Report",
    clientId=testClientId,
    brandTemplateId=yourBrandTemplateId,
    reportTemplateId=yourReportTemplateId,
    comparePeriod=swydo.Enumerations.ComparePeriod.previous,
)
print("TestReport: %s" % testReport)
testReportId = testReport['id']

# Share the report
swydoClient.shareTeamReport(
    teamId=yourTeamId,
    reportId=testReportId,
)

# Update the report
testReport = swydoClient.updateTeamReport(
    teamId=yourTeamId,
    reportId=testReportId,
    name="Temporary Report Updated",
)
print("TestReport: %s" % testReport)
testReportId = testReport['id']

# Unshare the report
swydoClient.unshareTeamReport(
    teamId=yourTeamId,
    reportId=testReportId,
)

# Delete the report
swydoClient.deleteTeamReport(
    teamId=yourTeamId,
    reportId=testReportId,
)

swydoClient.removeClientDataSourceFacebookAds(
    teamId=yourTeamId,
    clientId=testClientId,
)
print("facebookAdsDataSource removed")

swydoClient.removeClientDataSourceFacebookGraph(
    teamId=yourTeamId,
    clientId=testClientId,
)
print("FacebookGraph DataSource removed")

swydoClient.removeClientDataSourceGoogleAdWords(
    teamId=yourTeamId,
    clientId=testClientId,
)
print("GoogleAdWords DataSource removed")

swydoClient.removeClientDataSourceGoogleAnalytics(
    teamId=yourTeamId,
    clientId=testClientId,
)
print("GoogleAnalytics DataSource removed")

print("Success!...")

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Install with:

$ virtualenv .venv -p python3
$ . .venv/bin/activate
(.venv) $ pip install -r requirements.txt

and run the tests with:

(.venv) $ pip install -r tests/requirements.txt
(.venv) $ pytest tests/

documentation can be generated like this:

(.venv) $ pip install -r doc/requirements.txt
(.venv) $ sphinx-build -b html doc doc/_build/html

Related Projects

Used cookiecutter Python library template by mdklatt.

Author

Alon Diamant (advance512)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swydo-1.2019.5.19.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

swydo-1.2019.5.19-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file swydo-1.2019.5.19.tar.gz.

File metadata

  • Download URL: swydo-1.2019.5.19.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for swydo-1.2019.5.19.tar.gz
Algorithm Hash digest
SHA256 9705fbdea055fd2030ab34151c6083a923cf6bf57945ffe6978c85db1ef55500
MD5 73c7bac3f617e6cb3c6b21dc3b483320
BLAKE2b-256 523a986db30ca30b840c97d53edcf1c83cff5678689a5412bafe6d239f11f090

See more details on using hashes here.

File details

Details for the file swydo-1.2019.5.19-py3-none-any.whl.

File metadata

  • Download URL: swydo-1.2019.5.19-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for swydo-1.2019.5.19-py3-none-any.whl
Algorithm Hash digest
SHA256 627f2eb3a1c9ebcabc7594f9b749b893ddb21db4986ed76708c8fe451f195cea
MD5 def73994ee72e48d21b9511451c3516c
BLAKE2b-256 247047a1fa7ec88b89b58096bceebee1af4458e13077e8fe664661bf5603949a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page