Skip to content

Commit de4f995

Browse files
Add examples
1 parent f03c3ff commit de4f995

File tree

8 files changed

+297
-255
lines changed

8 files changed

+297
-255
lines changed

examples/accounts-list.py

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,48 @@
22

33
import sys
44
import os
5-
6-
# Add the parent directory to the Python path to import the SDK
7-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
8-
5+
import postmypost_rest_sdk
96
from postmypost_rest_sdk.api.accounts_api import AccountsApi
107
from postmypost_rest_sdk.configuration import Configuration
118
from postmypost_rest_sdk.exceptions import ApiException
129

10+
# Add the parent directory to the Python path to import the SDK
11+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
12+
1313
# Set your API access token and project ID
14-
access_token = 'YOUR_ACCESS_TOKEN'
14+
access_token = 'YOUR_API_ACCESS_TOKEN'
1515
project_id = 123456
1616

1717
# Configure the SDK
18-
config = Configuration()
19-
config.access_token = access_token
20-
21-
# Create an instance of the AccountsApi
22-
accounts_api = AccountsApi(config)
23-
24-
try:
25-
# Get accounts for the specified project
26-
accounts_response = accounts_api.get_accounts(project_id)
27-
28-
print("Accounts list:")
29-
30-
for account in accounts_response.data:
31-
print(f" - ID: {account.id} | Name: {account.name}")
32-
33-
# Output pagination info
34-
pagination = accounts_response.pages
35-
print("\nPagination:")
36-
print(f" Page: {pagination.page} | Per page: {pagination.per_page} | "
37-
f"Total pages: {pagination.total_pages} | Total count: {pagination.total_count}")
38-
39-
if pagination.prev is not None:
40-
print(f" Prev: {pagination.prev}")
41-
42-
if pagination.next is not None:
43-
print(f" Next: {pagination.next}")
44-
45-
except ApiException as e:
46-
print(f"Error while requesting accounts: {e}")
18+
configuration = Configuration(
19+
access_token=access_token
20+
)
21+
22+
# Create API client context
23+
with postmypost_rest_sdk.ApiClient(configuration) as api_client:
24+
# Create an instance of the AccountsApi with the api_client
25+
accounts_api = AccountsApi(api_client)
26+
27+
try:
28+
# Get accounts for the specified project
29+
accounts_response = accounts_api.get_accounts(project_id)
30+
31+
print("Accounts list:")
32+
33+
for account in accounts_response.data:
34+
print(f" - ID: {account.id} | Name: {account.name}")
35+
36+
# Output pagination info
37+
pagination = accounts_response.pages
38+
print("\nPagination:")
39+
print(f" Page: {pagination.page} | Per page: {pagination.per_page} | "
40+
f"Total pages: {pagination.total_pages} | Total count: {pagination.total_count}")
41+
42+
if pagination.prev is not None:
43+
print(f" Prev: {pagination.prev}")
44+
45+
if pagination.next is not None:
46+
print(f" Next: {pagination.next}")
47+
48+
except ApiException as e:
49+
print(f"Error while requesting accounts: {e}")

examples/projects-list.py

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,47 @@
22

33
import sys
44
import os
5-
6-
# Add the parent directory to the Python path to import the SDK
7-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
8-
5+
import postmypost_rest_sdk
96
from postmypost_rest_sdk.api.projects_api import ProjectsApi
107
from postmypost_rest_sdk.configuration import Configuration
118
from postmypost_rest_sdk.exceptions import ApiException
129

10+
# Add the parent directory to the Python path to import the SDK
11+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
12+
1313
# Set your API access token
14-
access_token = 'YOUR_ACCESS_TOKEN'
14+
access_token = 'YOUR_API_ACCESS_TOKEN'
1515

1616
# Configure the SDK
17-
config = Configuration()
18-
config.access_token = access_token
19-
20-
# Create an instance of the ProjectsApi
21-
projects_api = ProjectsApi(config)
22-
23-
try:
24-
# Get projects
25-
projects_response = projects_api.get_projects()
26-
27-
print("Projects list:")
28-
29-
for project in projects_response.data:
30-
print(f" - ID: {project.id} | Name: {project.name}")
31-
32-
# Output pagination info
33-
pagination = projects_response.pages
34-
print("\nPagination:")
35-
print(f" Page: {pagination.page} | Per page: {pagination.per_page} | "
36-
f"Total pages: {pagination.total_pages} | Total count: {pagination.total_count}")
37-
38-
if pagination.prev is not None:
39-
print(f" Prev: {pagination.prev}")
40-
41-
if pagination.next is not None:
42-
print(f" Next: {pagination.next}")
43-
44-
except ApiException as e:
45-
print(f"Error while requesting projects: {e}")
17+
configuration = Configuration(
18+
access_token=access_token
19+
)
20+
21+
# Create API client context
22+
with postmypost_rest_sdk.ApiClient(configuration) as api_client:
23+
# Create an instance of the ProjectsApi with the api_client
24+
projects_api = ProjectsApi(api_client)
25+
26+
try:
27+
# Get projects
28+
projects_response = projects_api.get_projects()
29+
30+
print("Projects list:")
31+
32+
for project in projects_response.data:
33+
print(f" - ID: {project.id} | Name: {project.name}")
34+
35+
# Output pagination info
36+
pagination = projects_response.pages
37+
print("\nPagination:")
38+
print(f" Page: {pagination.page} | Per page: {pagination.per_page} | "
39+
f"Total pages: {pagination.total_pages} | Total count: {pagination.total_count}")
40+
41+
if pagination.prev is not None:
42+
print(f" Prev: {pagination.prev}")
43+
44+
if pagination.next is not None:
45+
print(f" Next: {pagination.next}")
46+
47+
except ApiException as e:
48+
print(f"Error while requesting projects: {e}")

examples/publication-create.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import sys
44
import os
55
import datetime
6-
7-
# Add the parent directory to the Python path to import the SDK
8-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
9-
6+
import postmypost_rest_sdk
107
from postmypost_rest_sdk.api.publications_api import PublicationsApi
118
from postmypost_rest_sdk.configuration import Configuration
129
from postmypost_rest_sdk.exceptions import ApiException
@@ -15,41 +12,47 @@
1512
from postmypost_rest_sdk.models.publication_detail_publication_type_enum import PublicationDetailPublicationTypeEnum
1613
from postmypost_rest_sdk.models.publication_status_enum_edit import PublicationStatusEnumEdit
1714

15+
# Add the parent directory to the Python path to import the SDK
16+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
17+
1818
# Set your API access token and project ID
19-
access_token = 'YOUR_ACCESS_TOKEN'
19+
access_token = 'YOUR_API_ACCESS_TOKEN'
2020
project_id = 123456
2121

2222
# Configure the SDK
23-
config = Configuration()
24-
config.access_token = access_token
25-
26-
# Create an instance of the PublicationsApi
27-
publications_api = PublicationsApi(config)
23+
configuration = Configuration(
24+
access_token=access_token
25+
)
2826

2927
# Build the publication request object
3028
publication_request = CreatePublicationRequest(
3129
project_id=project_id,
3230
post_at=datetime.datetime(2025, 6, 30, 12, 0, 0, tzinfo=datetime.timezone.utc), # Publication time (UTC)
3331
account_ids=[111111, 222222], # Example account IDs
34-
publication_status=PublicationStatusEnumEdit.NUMBER_PENDING_PUBLICATION,
32+
publication_status=PublicationStatusEnumEdit.PENDING_PUBLICATION,
3533
details=[
3634
PublicationDetailEditRequest(
3735
account_id=111111,
38-
publication_type=PublicationDetailPublicationTypeEnum.NUMBER_POST,
36+
publication_type=PublicationDetailPublicationTypeEnum.POST,
3937
content="Check out our new product launch! #newproduct #launch",
4038
file_ids=[42516053],
4139
),
4240
PublicationDetailEditRequest(
4341
account_id=222222,
44-
publication_type=PublicationDetailPublicationTypeEnum.NUMBER_POST,
42+
publication_type=PublicationDetailPublicationTypeEnum.POST,
4543
link="https://example.com/new-product",
4644
),
4745
]
4846
)
4947

50-
try:
51-
response = publications_api.create_publication(publication_request)
52-
print("Publication created successfully!")
53-
print(f" Publication ID: {response.id}")
54-
except ApiException as e:
55-
print(f"Error while creating publication: {e}")
48+
# Create API client context
49+
with postmypost_rest_sdk.ApiClient(configuration) as api_client:
50+
# Create an instance of the PublicationsApi with the api_client
51+
publications_api = PublicationsApi(api_client)
52+
53+
try:
54+
response = publications_api.create_publication(publication_request)
55+
print("Publication created successfully!")
56+
print(f" Publication ID: {response.id}")
57+
except ApiException as e:
58+
print(f"Error while creating publication: {e}")

examples/publications-list.py

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,48 @@
22

33
import sys
44
import os
5-
6-
# Add the parent directory to the Python path to import the SDK
7-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
8-
5+
import postmypost_rest_sdk
96
from postmypost_rest_sdk.api.publications_api import PublicationsApi
107
from postmypost_rest_sdk.configuration import Configuration
118
from postmypost_rest_sdk.exceptions import ApiException
129

10+
# Add the parent directory to the Python path to import the SDK
11+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
12+
1313
# Set your API access token and project ID
14-
access_token = 'YOUR_ACCESS_TOKEN'
14+
access_token = 'YOUR_API_ACCESS_TOKEN'
1515
project_id = 123456
1616

1717
# Configure the SDK
18-
config = Configuration()
19-
config.access_token = access_token
20-
21-
# Create an instance of the PublicationsApi
22-
publications_api = PublicationsApi(config)
23-
24-
try:
25-
# Get publications for the specified project
26-
publications_response = publications_api.get_publications(project_id)
27-
28-
print("Publications list:")
29-
30-
for publication in publications_response.data:
31-
print(f" - ID: {publication.id} | Date: {publication.post_at.strftime('%Y-%m-%d %H:%M')}")
32-
33-
# Output pagination info
34-
pagination = publications_response.pages
35-
print("\nPagination:")
36-
print(f" Page: {pagination.page} | Per page: {pagination.per_page} | "
37-
f"Total pages: {pagination.total_pages} | Total count: {pagination.total_count}")
38-
39-
if pagination.prev is not None:
40-
print(f" Prev: {pagination.prev}")
41-
42-
if pagination.next is not None:
43-
print(f" Next: {pagination.next}")
44-
45-
except ApiException as e:
46-
print(f"Error while requesting publications: {e}")
18+
configuration = Configuration(
19+
access_token=access_token
20+
)
21+
22+
# Create API client context
23+
with postmypost_rest_sdk.ApiClient(configuration) as api_client:
24+
# Create an instance of the PublicationsApi with the api_client
25+
publications_api = PublicationsApi(api_client)
26+
27+
try:
28+
# Get publications for the specified project
29+
publications_response = publications_api.get_publications(project_id)
30+
31+
print("Publications list:")
32+
33+
for publication in publications_response.data:
34+
print(f" - ID: {publication.id} | Date: {publication.post_at.strftime('%Y-%m-%d %H:%M')}")
35+
36+
# Output pagination info
37+
pagination = publications_response.pages
38+
print("\nPagination:")
39+
print(f" Page: {pagination.page} | Per page: {pagination.per_page} | "
40+
f"Total pages: {pagination.total_pages} | Total count: {pagination.total_count}")
41+
42+
if pagination.prev is not None:
43+
print(f" Prev: {pagination.prev}")
44+
45+
if pagination.next is not None:
46+
print(f" Next: {pagination.next}")
47+
48+
except ApiException as e:
49+
print(f"Error while requesting publications: {e}")

examples/upload-get-status.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,35 @@
22

33
import sys
44
import os
5-
6-
# Add the parent directory to the Python path to import the SDK
7-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
8-
5+
import postmypost_rest_sdk
96
from postmypost_rest_sdk.api.upload_api import UploadApi
107
from postmypost_rest_sdk.configuration import Configuration
118
from postmypost_rest_sdk.exceptions import ApiException
129

10+
# Add the parent directory to the Python path to import the SDK
11+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
12+
1313
# Set your API access token and the upload ID you want to check
14-
access_token = 'YOUR_ACCESS_TOKEN'
14+
access_token = 'YOUR_API_ACCESS_TOKEN'
1515
upload_id = 123456
1616

1717
# Configure the SDK
18-
config = Configuration()
19-
config.access_token = access_token
20-
21-
# Create an instance of the UploadApi
22-
upload_api = UploadApi(config)
23-
24-
try:
25-
response = upload_api.status_upload(upload_id)
26-
27-
print("Upload status received successfully.")
28-
print(f" Upload ID: {response.id}")
29-
print(f" File ID: {response.file_id}")
30-
print(f" Status code: {response.status}")
31-
# You can map status codes to human-readable messages here if needed.
32-
except ApiException as e:
33-
print(f"Error while requesting upload status: {e}")
18+
configuration = Configuration(
19+
access_token=access_token
20+
)
21+
22+
# Create API client context
23+
with postmypost_rest_sdk.ApiClient(configuration) as api_client:
24+
# Create an instance of the UploadApi with the api_client
25+
upload_api = UploadApi(api_client)
26+
27+
try:
28+
response = upload_api.status_upload(upload_id)
29+
30+
print("Upload status received successfully.")
31+
print(f" Upload ID: {response.id}")
32+
print(f" File ID: {response.file_id}")
33+
print(f" Status code: {response.status}")
34+
# You can map status codes to human-readable messages here if needed.
35+
except ApiException as e:
36+
print(f"Error while requesting upload status: {e}")

0 commit comments

Comments
 (0)