MagicFeedback 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2024 MagicFeedback OÜ
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.  
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.1
2
+ Name: MagicFeedback
3
+ Version: 0.0.1
4
+ Summary: SDK for MagicFeedback API
5
+ Author-email: Francisco Arias <farias@magicfedback.io>
6
+ Project-URL: Homepage, https://github.com/MagicFeedback/magicfeedback_python_sdk
7
+ Project-URL: Issues, https://github.com/MagicFeedback/magicfeedback_python_sdk/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENCE
14
+
15
+ # MagicFeedback SDK
16
+
17
+ **A Python SDK for interacting with the MagicFeedback API**
18
+
19
+ **Installation**
20
+
21
+ Bash
22
+
23
+ ```
24
+ pip install MagicFeeedback
25
+
26
+ ```
27
+
28
+ Use code [with caution.](/faq#coding)
29
+
30
+ **Usage**
31
+
32
+ Python
33
+
34
+ ```
35
+ from magicfeedback import MagicFeedbackClient
36
+
37
+ # Create a MagicFeedbackClient instance
38
+ client = MagicFeedbackClient('email', 'password')
39
+
40
+ # Create a new feedback item
41
+ feedback_data = {
42
+ "name": "Test Feedback",
43
+ "type": "DOCUMENT",
44
+ # ... other required fields
45
+ }
46
+ response = client.create_feedback(feedback_data)
47
+
48
+ # Print the response
49
+ print(response)
50
+
51
+ ```
52
+
53
+ **API Reference**
54
+
55
+ - **`create_feedback(feedback)`:** Creates a new feedback item.
56
+ - **`get_feedback(feedback_id)`:** Retrieves a specific feedback item.
57
+ - **`update_feedback(feedback_id, feedback)`:** Updates a specific feedback item.
58
+ - **`delete_feedback(feedback_id)`:** Deletes a specific feedback item.
59
+
60
+ **Additional Information**
61
+
62
+ - **Authentication:** The SDK requires an user / password for authentication. You can obtain from the MagicFeedback platform.
63
+ - **Error Handling:** The SDK handles common API errors and raises appropriate exceptions.
64
+ - **Customizations:** You can customize the SDK to fit your specific needs by extending the `MagicFeedbackClient` class or creating additional helper functions.
65
+
66
+ **License**
67
+
68
+ This project is licensed under the MIT License.
69
+
70
+ **Contact**
71
+
72
+ For any questions or support, please contact farias@magicfeedback.io.
@@ -0,0 +1,7 @@
1
+ __init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ magicfeedback.py,sha256=Iu02MDT6WK9cFcpezl1OMoYjw3wVsxuH_qhNZdtdxvs,4701
3
+ MagicFeedback-0.0.1.dist-info/LICENCE,sha256=gIVSj35jJtSTUxMd2h9qra0bz8Brc-RjdBwC1_rEar0,1065
4
+ MagicFeedback-0.0.1.dist-info/METADATA,sha256=17MoxG4GH6KVWXL2uEEpmmuIw63UxetZDWe8TMEgJGc,1977
5
+ MagicFeedback-0.0.1.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
6
+ MagicFeedback-0.0.1.dist-info/top_level.txt,sha256=AHWmeorjEjdLtb7_51Qk5wGJoYqhcMj8-c_yvnyucgo,23
7
+ MagicFeedback-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (74.1.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ __init__
2
+ magicfeedback
__init__.py ADDED
File without changes
magicfeedback.py ADDED
@@ -0,0 +1,132 @@
1
+ import json
2
+ from typing import Any, Dict, Optional
3
+
4
+ import requests
5
+ from google.auth.transport.requests import Request
6
+
7
+
8
+ class MagicFeedbackClient:
9
+ """A Python SDK for interacting with the MagicFeedback API."""
10
+
11
+ def __init__(self, user: str, password: str, base_url: str = "https://api.magicfeedback.io", ip_key: str = 'AIzaSyAKcR895VURSQZSN2T_RD6jX_9y5HRmH80'):
12
+
13
+ self.base_url = base_url
14
+ self.ip_key = ip_key
15
+
16
+ self.api_key = self.get_api_key(user, password)
17
+ self.headers = {"Authorization": f"Bearer {self.api_key}"}
18
+
19
+ def get_api_key(self, user, password):
20
+ """Obtains the API key using user and password authentication."""
21
+ # TODO: Implement control to check if the token is still valid - Only for 1 hour
22
+ # Call your existing function
23
+ id_token = self.identity_login(user, password)
24
+ return id_token
25
+
26
+ def identity_login(self, user, password):
27
+ """
28
+ (Replace this function with your existing `identity_login` function)
29
+
30
+ Performs user and password-based login using the identity toolkit API.
31
+
32
+ Returns:
33
+ str: The obtained ID token.
34
+ """
35
+ # TODO: Control in case the call is not good
36
+ print("Logging in with user and password...")
37
+ print("User: ", user)
38
+ print("Password: ", password)
39
+
40
+ options = {
41
+ "method": "POST",
42
+ "url": "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=" + self.ip_key,
43
+ "headers": {
44
+ "Content-Type": "application/javascript",
45
+ },
46
+ "data": json.dumps({
47
+ "email": user,
48
+ "password": password,
49
+ "returnSecureToken": True
50
+ })
51
+ }
52
+
53
+ response = requests.post(
54
+ options["url"], headers=options["headers"], data=options["data"])
55
+ data = json.loads(response.text)
56
+ return data["idToken"]
57
+
58
+ def _make_request(
59
+ self, method: str, url: str, json: Dict[str, Any] = None
60
+ ) -> Dict[str, Any]:
61
+ """Makes a request to the MagicFeedback API."""
62
+ # TODO: Control token expiration
63
+ response = requests.request(
64
+ method, url, headers=self.headers, json=json)
65
+ response.raise_for_status() # Raise exception for non-2xx status codes
66
+ # TODO: Control the status of the call
67
+ print("Status code: ", response.status_code)
68
+ print("Response: ", response.json())
69
+
70
+ return response.json()
71
+
72
+ ####################################################################################
73
+ # Feedback API Methods #
74
+ ####################################################################################
75
+
76
+ def create_feedback(self, feedback: Dict[str, Any]) -> Dict[str, Any]:
77
+ """Creates a new feedback item.
78
+
79
+ Args:
80
+ feedback (Dict[str, Any]): The feedback data to create.
81
+
82
+ Returns:
83
+ Dict[str, Any]: The created feedback item.
84
+ """
85
+ url = f"{self.base_url}/feedbacks"
86
+
87
+ # Ensure required fields are present
88
+ required_fields = [
89
+ "name", "type", "identity",
90
+ "integrationId", "companyId",
91
+ "productId"
92
+ ]
93
+ for field in required_fields:
94
+ if field not in feedback:
95
+ raise ValueError(f"Missing required field: {field}")
96
+
97
+ return self._make_request("POST", url, json=feedback)
98
+
99
+ # Add other API methods as needed
100
+ def get_feedback(self, feedback_id: str) -> Dict[str, Any]:
101
+ """Retrieves a specific feedback item.
102
+
103
+ Args:
104
+ feedback_id (str): The ID of the feedback item.
105
+
106
+ Returns:
107
+ Dict[str, Any]: The retrieved feedback item.
108
+ """
109
+ url = f"{self.base_url}/feedbacks/{feedback_id}"
110
+ return self._make_request("GET", url)
111
+
112
+ def update_feedback(self, feedback_id: str, feedback: Dict[str, Any]) -> Dict[str, Any]:
113
+ """Updates a specific feedback item.
114
+
115
+ Args:
116
+ feedback_id (str): The ID of the feedback item.
117
+ feedback (Dict[str, Any]): The updated feedback data.
118
+
119
+ Returns:
120
+ Dict[str, Any]: The updated feedback item.
121
+ """
122
+ url = f"{self.base_url}/feedbacks/{feedback_id}"
123
+ return self._make_request("PUT", url, json=feedback)
124
+
125
+ def delete_feedback(self, feedback_id: str) -> None:
126
+ """Deletes a specific feedback item.
127
+
128
+ Args:
129
+ feedback_id (str): The ID of the feedback item.
130
+ """
131
+ url = f"{self.base_url}/feedbacks/{feedback_id}"
132
+ self._make_request("DELETE", url)