mcm-cli 1.0.1__tar.gz → 1.1.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. {mcm_cli-1.0.1/mcm_cli.egg-info → mcm_cli-1.1.0}/PKG-INFO +1 -1
  2. {mcm_cli-1.0.1 → mcm_cli-1.1.0/mcm_cli.egg-info}/PKG-INFO +1 -1
  3. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcm_cli.egg-info/SOURCES.txt +1 -0
  4. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/__main__.py +5 -1
  5. mcm_cli-1.1.0/mcmcli/command/admin.py +88 -0
  6. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/command/wallet.py +15 -5
  7. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/setup.py +1 -1
  8. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/LICENSE +0 -0
  9. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/NOTICE +0 -0
  10. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/README.md +0 -0
  11. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcm_cli.egg-info/dependency_links.txt +0 -0
  12. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcm_cli.egg-info/entry_points.txt +0 -0
  13. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcm_cli.egg-info/requires.txt +0 -0
  14. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcm_cli.egg-info/top_level.txt +0 -0
  15. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/__init__.py +0 -0
  16. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/command/account.py +0 -0
  17. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/command/auth.py +0 -0
  18. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/command/config.py +0 -0
  19. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/command/decision.py +0 -0
  20. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/data/account.py +0 -0
  21. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/data/account_user.py +0 -0
  22. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/data/decision.py +0 -0
  23. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/data/error.py +0 -0
  24. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/data/seller.py +0 -0
  25. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/data/token.py +0 -0
  26. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/data/wallet.py +0 -0
  27. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/logging.py +0 -0
  28. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/mcmcli/requests.py +0 -0
  29. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/setup.cfg +0 -0
  30. {mcm_cli-1.0.1 → mcm_cli-1.1.0}/tests/test_config.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mcm-cli
3
- Version: 1.0.1
3
+ Version: 1.1.0
4
4
  Summary: A command-line interface for Moloco Commerde Media
5
5
  Home-page: https://github.com/moloco-mcm/mcm-cli
6
6
  Author: Moloco MCM Team
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mcm-cli
3
- Version: 1.0.1
3
+ Version: 1.1.0
4
4
  Summary: A command-line interface for Moloco Commerde Media
5
5
  Home-page: https://github.com/moloco-mcm/mcm-cli
6
6
  Author: Moloco MCM Team
@@ -13,6 +13,7 @@ mcmcli/__main__.py
13
13
  mcmcli/logging.py
14
14
  mcmcli/requests.py
15
15
  mcmcli/command/account.py
16
+ mcmcli/command/admin.py
16
17
  mcmcli/command/auth.py
17
18
  mcmcli/command/config.py
18
19
  mcmcli/command/decision.py
@@ -17,7 +17,10 @@
17
17
  """mcm cli entry point script."""
18
18
  # mcmcli/__main__.py
19
19
 
20
+ from typing import Optional
21
+
20
22
  import mcmcli.command.account
23
+ import mcmcli.command.admin
21
24
  import mcmcli.command.auth
22
25
  import mcmcli.command.config
23
26
  import mcmcli.command.decision
@@ -32,9 +35,10 @@ def version():
32
35
  """
33
36
  Show the tool version
34
37
  """
35
- typer.echo(f"Version: mcm-cli v1.0.1")
38
+ typer.echo(f"Version: mcm-cli v1.1.0")
36
39
 
37
40
  app.add_typer(mcmcli.command.account.app, name="account", help="Ad account management")
41
+ app.add_typer(mcmcli.command.admin.app, name="admin", help="Platform administration")
38
42
  app.add_typer(mcmcli.command.auth.app, name="auth", help="Authentication management")
39
43
  app.add_typer(mcmcli.command.config.app, name="config", help="Configurations")
40
44
  app.add_typer(mcmcli.command.decision.app, name="decision", help="Decision command")
@@ -0,0 +1,88 @@
1
+ # Copyright 2023 Moloco, Inc
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import mcmcli.command.account
16
+ import mcmcli.command.auth
17
+ import mcmcli.command.config
18
+ import mcmcli.command.wallet
19
+ import mcmcli.requests
20
+ import sys
21
+ import typer
22
+
23
+ app = typer.Typer(add_completion=False)
24
+
25
+ def _create_admin_command(profile):
26
+ auth = mcmcli.command.auth.AuthCommand(profile)
27
+ _, error, token = auth.get_token()
28
+ if error:
29
+ print(f"ERROR: {error.message}")
30
+ return None
31
+ return AdminCommand(profile, auth, token.token)
32
+
33
+ @app.command()
34
+ def list_wallet_balances(
35
+ profile: str = typer.Option("default", help="profile name of the MCM CLI."),
36
+ ):
37
+ """
38
+ List the wallet balances of all of the ad accounts
39
+ """
40
+ admin = _create_admin_command(profile)
41
+ if admin is None:
42
+ return
43
+ admin.list_wallet_balances()
44
+
45
+
46
+ class AdminCommand:
47
+ def __init__(
48
+ self,
49
+ profile,
50
+ auth_command: mcmcli.command.auth.AuthCommand,
51
+ token
52
+ ):
53
+ self.profile = profile
54
+ self.auth_command = auth_command
55
+ self.config = mcmcli.command.config.get_config(profile)
56
+ mcmcli.command.config.assert_config_exists(self.config)
57
+
58
+ self.token = token
59
+ self.api_base_url = f"{self.config['management_api_hostname']}/rmp/mgmt/v1/platforms/{self.config['platform_id']}"
60
+ self.headers = {
61
+ "accept": "application/json",
62
+ "content-type": "application/json",
63
+ "Authorization": f"Bearer {token}"
64
+ }
65
+
66
+ def list_wallet_balances(
67
+ self
68
+ ):
69
+ ac = mcmcli.command.account.AccountCommand(self.profile, self.auth_command, self.token)
70
+ wc = mcmcli.command.wallet.WalletCommand(self.profile, self.auth_command, self.token)
71
+ _, error, accounts = ac.list_accounts()
72
+ if error:
73
+ print(error, file=sys.stderr, flush=True)
74
+ return
75
+
76
+ print("ad_account_title, ad_account_id, credit_balance, prepaid_balance")
77
+ for id in accounts:
78
+ _, error, wallet = wc.get_balance(id, to_curl=False)
79
+ if error:
80
+ continue
81
+ w0 = wallet.accounts[0]
82
+ w1 = wallet.accounts[1]
83
+ credits = w0 if w0.type == 'CREDITS' else w1
84
+ prepaid = w1 if w1.type == 'PRE_PAID' else w0
85
+ credits = int(credits.balance.amount_micro) / 1000000
86
+ prepaid = int(prepaid.balance.amount_micro) / 1000000
87
+ print(f'"{accounts[id].title}", {id}, {credits}, {prepaid}')
88
+
@@ -52,7 +52,7 @@ def balance(
52
52
  print(f"ERROR: {error.message}")
53
53
  return
54
54
 
55
- wc = WalletCommand(profile, token.token)
55
+ wc = WalletCommand(profile, auth, token.token)
56
56
  curl, error, wallet = wc.get_balance(account_id, to_curl)
57
57
  if to_curl:
58
58
  print(curl)
@@ -97,7 +97,7 @@ def deposit(
97
97
  print(f"ERROR: {error.message}")
98
98
  return
99
99
 
100
- wc = WalletCommand(profile, token.token)
100
+ wc = WalletCommand(profile, auth, token.token)
101
101
 
102
102
  # Check the wallet first
103
103
  curl, error, wallet = wc.get_balance(account_id, to_curl=False)
@@ -148,7 +148,7 @@ def withdraw(
148
148
  print(f"ERROR: {error.message}")
149
149
  return
150
150
 
151
- wc = WalletCommand(profile, token.token)
151
+ wc = WalletCommand(profile, auth, token.token)
152
152
 
153
153
  # Check the wallet first
154
154
  curl, error, wallet = wc.get_balance(account_id, to_curl=False)
@@ -182,10 +182,19 @@ def withdraw(
182
182
  return
183
183
 
184
184
  class WalletCommand:
185
- def __init__(self, profile, token):
185
+ def __init__(
186
+ self,
187
+ profile,
188
+ auth_command: mcmcli.command.auth.AuthCommand,
189
+ token
190
+ ):
186
191
  self.config = mcmcli.command.config.get_config(profile)
187
- mcmcli.command.config.assert_config_exists(self.config)
192
+ if (self.config is None):
193
+ print(f"ERROR: Failed to load the CLI profile", file=sys.stderr, flush=True)
194
+ sys.exit()
188
195
 
196
+ self.profile = profile
197
+ self.auth_command = auth_command
189
198
  self.api_base_url = f"{self.config['management_api_hostname']}/rmp/mgmt/v1/platforms/{self.config['platform_id']}"
190
199
  self.headers = {
191
200
  "accept": "application/json",
@@ -193,6 +202,7 @@ class WalletCommand:
193
202
  "Authorization": f"Bearer {token}"
194
203
  }
195
204
 
205
+
196
206
  def get_balance(
197
207
  self,
198
208
  account_id: str,
@@ -18,7 +18,7 @@ from setuptools import setup, find_packages
18
18
 
19
19
  setup(
20
20
  name='mcm-cli',
21
- version='1.0.1',
21
+ version='1.1.0',
22
22
  description='A command-line interface for Moloco Commerde Media',
23
23
  long_description=open('README.md').read(),
24
24
  long_description_content_type='text/markdown',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes