diff options
author | CoprDistGit <infra@openeuler.org> | 2023-04-10 16:41:58 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-04-10 16:41:58 +0000 |
commit | 56652d98f701242a4a54a35c407c9d89163b1eba (patch) | |
tree | 0cc44c79ea4d3a009177e82a259b565257dbc584 | |
parent | 818363f09a0d578141a32c308c7346741818d768 (diff) |
automatic import of python-delighted
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-delighted.spec | 1002 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 1004 insertions, 0 deletions
@@ -0,0 +1 @@ +/delighted-4.1.0.tar.gz diff --git a/python-delighted.spec b/python-delighted.spec new file mode 100644 index 0000000..f853335 --- /dev/null +++ b/python-delighted.spec @@ -0,0 +1,1002 @@ +%global _empty_manifest_terminate_build 0 +Name: python-delighted +Version: 4.1.0 +Release: 1 +Summary: Delighted API Python Client. +License: MIT +URL: https://delighted.com/ +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/37/56/7cc8b408ded2375ddb1332bb613d3226b80793b6199094d6e24fb85a5a99/delighted-4.1.0.tar.gz +BuildArch: noarch + + +%description +[](https://travis-ci.org/delighted/delighted-python) + +# Delighted API Python Client + +Official Python client for the [Delighted API](https://delighted.com/docs/api). + +## Installation + +``` +pip install --upgrade delighted +``` + +or + +``` +easy_install --upgrade delighted +``` + +### Upgrading from delighted-python + +If you previously used the python package named `delighted-python`, please note that the package name is now just `delighted`. + +## Configuration + +To get started, you need to configure the client with your secret API key. + +```python +import delighted +delighted.api_key = 'YOUR_API_KEY' +``` + +For further options, read the [advanced configuration section](#advanced-configuration). + +**Note:** Your API key is secret, and you should treat it like a password. You can find your API key in your Delighted account, under *Settings* > *API*. + +## Usage + +Adding/updating people and scheduling surveys: + +```python +# Add a new person, and schedule a survey immediately +person1 = delighted.Person.create(email='foo+test1@delighted.com') + +# Add a new person, and schedule a survey after 1 minute (60 seconds) +person2 = delighted.Person.create(email='foo+test2@delighted.com', delay=60) + +# Add a new person, but do not schedule a survey +person3 = delighted.Person.create(email='foo+test3@delighted.com', send=False) + +# Add a new person with full set of attributes, including a custom question +# product name, and schedule a survey with a 30 second delay +person4 = delighted.Person.create( + email='foo+test4@delighted.com', + name='Joe Bloggs', + properties={'customer_id': 123, 'country': 'USA', + 'question_product_name': 'The London Trench'}, + delay=30) + +# Update an existing person (identified by email), adding a name, without +# scheduling a survey +updated_person1 = delighted.Person.create(email='foo+test1@delighted.com', + name='James Scott', send=False) +``` + +Unsubscribing people: + +```python +# Unsubscribe an existing person +delighted.Unsubscribe.create(person_email='foo+test1@delighted.com') +``` + +Listing people: + +```python +# List all people, auto pagination +# Note: Make sure to handle the possible rate limits error +people = delighted.Person.list() +while True: + try: + for person in people.auto_paging_iter(): + # Do something with person + except TooManyRequestsError as e: + # Indicates how long to wait (in seconds) before making this request again + e.retry_after + continue + +# For convenience, this method can use a sleep to automatically handle rate limits +people = delighted.Person.list(auto_handle_rate_limits=True) +for person in people.auto_paging_iter(): + # Do something with person +``` + +Listing people who have unsubscribed: + +```python +# List all people who have unsubscribed, 20 per page, first 2 pages +delighted.Unsubscribe.all() +delighted.Unsubscribe.all(page=2) +``` + +Listing people whose emails have bounced: + +```python +# List all people whose emails have bounced, 20 per page, first 2 pages +delighted.Bounce.all() +delighted.Bounce.all(page=2) +``` + +Deleting a person and all of the data associated with them: + +```python +# Delete by person id +delighted.Person.delete(id=42) +# Delete by email address +delighted.Person.delete(email='test@example.com') +# Delete by phone number (must be E.164 format) +delighted.Person.delete(phone_number='+14155551212') +``` + +Deleting pending survey requests + +```python +# Delete all pending (scheduled but unsent) survey requests for a person, by email. +delighted.SurveyRequest.delete_pending(person_email='foo+test1@delighted.com') +``` + +Adding survey responses: + +```python +# Add a survey response, score only +survey_response1 = delighted.SurveyResponse.create(person=person1.id, + score=10) + +# Add *another* survey response (for the same person), score and comment +survey_response2 = delighted.SurveyResponse.create(person=person1.id, + score=5, + comment='Really nice.') +``` + +Retrieving a survey response: + +```python +# Retrieve an existing survey response +survey_response3 = delighted.SurveyResponse.retrieve('123') +``` + +Updating survey responses: + +```python +# Update a survey response score +survey_response4 = delighted.SurveyResponse.retrieve('234') +survey_response4.score = 10 +survey_response4.save() +# <delighted.SurveyResponse object at 0xabc123> + +# Update (or add) survey response properties +survey_response4.person_properties = {'segment': 'Online'} +survey_response4.save() +# <delighted.SurveyResponse object at 0xabc123> + +# Update person who recorded the survey response +survey_response4.person = '321' +survey_response4.save() +# <delighted.SurveyResponse object at 0xabc123> +``` + +Listing survey responses: + +```python +# List all survey responses, 20 per page, first 2 pages +survey_responses_page1 = delighted.SurveyResponse.all() +survey_responses_page2 = delighted.SurveyResponse.all(page=2) + +# List all survey responses, 20 per page, expanding person object +survey_responses_page1_expanded = delighted.SurveyResponse.all(expand=['person']) +survey_responses_page1_expanded[0].person +# <delighted.Person object at 0xabc123> + +# List all survey responses, 20 per page, for a specific trend (ID: 123) +survey_responses_page1_trend = delighted.SurveyResponse.all(trend='123') + +# List all survey responses, 20 per page, in reverse chronological order (newest first) +survey_responses_page1_desc = delighted.SurveyResponse.all(order='desc') + +# List all survey responses, 100 per page, page 5, with a time range +import pytz +timezone = pytz.timezone('America/Chicago') +filtered_survey_responses = delighted.SurveyResponse.all( + page=5, + per_page=100, + since=timezone.localize(datetime.datetime(2014, 3, 1)), + until=timezone.localize(datetime.datetime(2014, 4, 30)) +) +``` + +Retrieving metrics: + +```python +# Get current metrics, 30-day simple moving average, from most recent response +metrics = delighted.Metrics.retrieve() + +# Get current metrics, 30-day simple moving average, from most recent response, +# for a specific trend (ID: 123) +metrics = delighted.Metrics.retrieve(trend='123') + +# Get metrics, for given time range +import pytz +timezone = pytz.timezone('America/Chicago') +metrics = delighted.Metrics.retrieve( + since=timezone.localize(datetime.datetime(2013, 10, 1)), + until=timezone.localize(datetime.datetime(2013, 11, 1)) +) +``` + +Managing Autopilot: + +```python +# Get Autopilot configuration for the `email` platform +autopilot = delighted.AutopilotConfiguration.retrieve('email') + +# List people in AutopilotMembership for the `email` platform +people_autopilot = delighted.AutopilotMembership.forEmail().list(auto_handle_rate_limits=True) +for person in people_autopilot.auto_paging_iter(): + # Do something with person + +# Add people to AutopilotMembership +autopilot = delighted.AutopilotMembership.forEmail().create(person_email='test@example.com') + +# Add people to AutopilotMembership, with a full set of attributes +properties = {'customer_id': 123, 'country': 'USA', 'question_product_name': 'The London Trench'} +autopilot = delighted.AutopilotMembership.forSms().create(person_phone_number='+14155551212', properties=properties) + +# Delete by person id +delighted.AutopilotMembership.forSms().delete(person_id=42) + +# Delete by email address +delighted.AutopilotMembership.forEmail().delete(person_email='test@example.com') + +# Delete by phone number (must be E.164 format) +delighted.AutopilotMembership.forSms().delete(person_phone_number='+14155551212') +``` + +## Rate limits + +If a request is rate limited, a `TooManyRequestsError` exception is raised. You can rescue that exception to implement exponential backoff or retry strategies. The exception provides a `retry_after` attribute to tell you how many seconds you should wait before retrying. For example: + +```python +try: + metrics = delighted.Metrics.retrieve() +except delighted.errors.TooManyRequestsError as err: + retry_after_seconds = err.retry_after + # wait for retry_after_seconds before retrying + # add your retry strategy here ... +``` + +## <a name="advanced-configuration"></a> Advanced configuration & testing + +The following options are configurable for the client: + +```python +delighted.api_key +delighted.api_base_url # default: 'https://api.delighted.com/v1/' +delighted.http_adapter # default: delighted.HTTPAdapter +``` + +By default, a shared instance of `delighted.Client` is created lazily in `delighted.get_shared_client()`. If you want to create your own client, perhaps for test or if you have multiple API keys, you can: + +```python +# Create an custom client instance, and pass as last argument to resource actions +import delighted +from delighted import Client +client = Client(api_key='API_KEY', + api_base_url='https://api.delighted.com/v1/', + http_adapter=HTTPAdapter()) +metrics_from_custom_client = delighted.Metrics.retrieve(client=client) + +# Or, you can set Delighted.shared_client yourself +delighted.shared_client = delighted.Client( + api_key='API_KEY', + api_base_url='https://api.delighted.com/v1/', + http_adapter=delighted.HTTPAdapter() +) +metrics_from_custom_shared_client = delighted.Metrics.retrieve() +``` + +## Supported versions + +- 2.6+, 3.3+ (PyPy supported) + +## Contributing + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Run the tests (`tox`) +4. Commit your changes (`git commit -am 'Add some feature'`) +5. Push to the branch (`git push origin my-new-feature`) +6. Create new Pull Request + +## Releasing + +1. Bump the version in `delighted/__init__.py`. +2. Update the README and CHANGELOG as needed. +3. Tag the commit for release. +4. Create the distribution `python setup.py sdist` +5. Update the package against PyPI's test server with [twine](https://pypi.org/project/twine/) +`twine upload --repository-url https://test.pypi.org/legacy/ dist/TEST_PACKAGE_NAME`. +6. If (4 and 5) work, repeat all steps, then push to PyPI's live servers with `twine upload dist/PACKAGE_NAME`. + +## Author + +Originally by [Jason Pearson](https://github.com/kaeawc). Graciously transfered and now officially maintained by Delighted. + +%package -n python3-delighted +Summary: Delighted API Python Client. +Provides: python-delighted +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-delighted +[](https://travis-ci.org/delighted/delighted-python) + +# Delighted API Python Client + +Official Python client for the [Delighted API](https://delighted.com/docs/api). + +## Installation + +``` +pip install --upgrade delighted +``` + +or + +``` +easy_install --upgrade delighted +``` + +### Upgrading from delighted-python + +If you previously used the python package named `delighted-python`, please note that the package name is now just `delighted`. + +## Configuration + +To get started, you need to configure the client with your secret API key. + +```python +import delighted +delighted.api_key = 'YOUR_API_KEY' +``` + +For further options, read the [advanced configuration section](#advanced-configuration). + +**Note:** Your API key is secret, and you should treat it like a password. You can find your API key in your Delighted account, under *Settings* > *API*. + +## Usage + +Adding/updating people and scheduling surveys: + +```python +# Add a new person, and schedule a survey immediately +person1 = delighted.Person.create(email='foo+test1@delighted.com') + +# Add a new person, and schedule a survey after 1 minute (60 seconds) +person2 = delighted.Person.create(email='foo+test2@delighted.com', delay=60) + +# Add a new person, but do not schedule a survey +person3 = delighted.Person.create(email='foo+test3@delighted.com', send=False) + +# Add a new person with full set of attributes, including a custom question +# product name, and schedule a survey with a 30 second delay +person4 = delighted.Person.create( + email='foo+test4@delighted.com', + name='Joe Bloggs', + properties={'customer_id': 123, 'country': 'USA', + 'question_product_name': 'The London Trench'}, + delay=30) + +# Update an existing person (identified by email), adding a name, without +# scheduling a survey +updated_person1 = delighted.Person.create(email='foo+test1@delighted.com', + name='James Scott', send=False) +``` + +Unsubscribing people: + +```python +# Unsubscribe an existing person +delighted.Unsubscribe.create(person_email='foo+test1@delighted.com') +``` + +Listing people: + +```python +# List all people, auto pagination +# Note: Make sure to handle the possible rate limits error +people = delighted.Person.list() +while True: + try: + for person in people.auto_paging_iter(): + # Do something with person + except TooManyRequestsError as e: + # Indicates how long to wait (in seconds) before making this request again + e.retry_after + continue + +# For convenience, this method can use a sleep to automatically handle rate limits +people = delighted.Person.list(auto_handle_rate_limits=True) +for person in people.auto_paging_iter(): + # Do something with person +``` + +Listing people who have unsubscribed: + +```python +# List all people who have unsubscribed, 20 per page, first 2 pages +delighted.Unsubscribe.all() +delighted.Unsubscribe.all(page=2) +``` + +Listing people whose emails have bounced: + +```python +# List all people whose emails have bounced, 20 per page, first 2 pages +delighted.Bounce.all() +delighted.Bounce.all(page=2) +``` + +Deleting a person and all of the data associated with them: + +```python +# Delete by person id +delighted.Person.delete(id=42) +# Delete by email address +delighted.Person.delete(email='test@example.com') +# Delete by phone number (must be E.164 format) +delighted.Person.delete(phone_number='+14155551212') +``` + +Deleting pending survey requests + +```python +# Delete all pending (scheduled but unsent) survey requests for a person, by email. +delighted.SurveyRequest.delete_pending(person_email='foo+test1@delighted.com') +``` + +Adding survey responses: + +```python +# Add a survey response, score only +survey_response1 = delighted.SurveyResponse.create(person=person1.id, + score=10) + +# Add *another* survey response (for the same person), score and comment +survey_response2 = delighted.SurveyResponse.create(person=person1.id, + score=5, + comment='Really nice.') +``` + +Retrieving a survey response: + +```python +# Retrieve an existing survey response +survey_response3 = delighted.SurveyResponse.retrieve('123') +``` + +Updating survey responses: + +```python +# Update a survey response score +survey_response4 = delighted.SurveyResponse.retrieve('234') +survey_response4.score = 10 +survey_response4.save() +# <delighted.SurveyResponse object at 0xabc123> + +# Update (or add) survey response properties +survey_response4.person_properties = {'segment': 'Online'} +survey_response4.save() +# <delighted.SurveyResponse object at 0xabc123> + +# Update person who recorded the survey response +survey_response4.person = '321' +survey_response4.save() +# <delighted.SurveyResponse object at 0xabc123> +``` + +Listing survey responses: + +```python +# List all survey responses, 20 per page, first 2 pages +survey_responses_page1 = delighted.SurveyResponse.all() +survey_responses_page2 = delighted.SurveyResponse.all(page=2) + +# List all survey responses, 20 per page, expanding person object +survey_responses_page1_expanded = delighted.SurveyResponse.all(expand=['person']) +survey_responses_page1_expanded[0].person +# <delighted.Person object at 0xabc123> + +# List all survey responses, 20 per page, for a specific trend (ID: 123) +survey_responses_page1_trend = delighted.SurveyResponse.all(trend='123') + +# List all survey responses, 20 per page, in reverse chronological order (newest first) +survey_responses_page1_desc = delighted.SurveyResponse.all(order='desc') + +# List all survey responses, 100 per page, page 5, with a time range +import pytz +timezone = pytz.timezone('America/Chicago') +filtered_survey_responses = delighted.SurveyResponse.all( + page=5, + per_page=100, + since=timezone.localize(datetime.datetime(2014, 3, 1)), + until=timezone.localize(datetime.datetime(2014, 4, 30)) +) +``` + +Retrieving metrics: + +```python +# Get current metrics, 30-day simple moving average, from most recent response +metrics = delighted.Metrics.retrieve() + +# Get current metrics, 30-day simple moving average, from most recent response, +# for a specific trend (ID: 123) +metrics = delighted.Metrics.retrieve(trend='123') + +# Get metrics, for given time range +import pytz +timezone = pytz.timezone('America/Chicago') +metrics = delighted.Metrics.retrieve( + since=timezone.localize(datetime.datetime(2013, 10, 1)), + until=timezone.localize(datetime.datetime(2013, 11, 1)) +) +``` + +Managing Autopilot: + +```python +# Get Autopilot configuration for the `email` platform +autopilot = delighted.AutopilotConfiguration.retrieve('email') + +# List people in AutopilotMembership for the `email` platform +people_autopilot = delighted.AutopilotMembership.forEmail().list(auto_handle_rate_limits=True) +for person in people_autopilot.auto_paging_iter(): + # Do something with person + +# Add people to AutopilotMembership +autopilot = delighted.AutopilotMembership.forEmail().create(person_email='test@example.com') + +# Add people to AutopilotMembership, with a full set of attributes +properties = {'customer_id': 123, 'country': 'USA', 'question_product_name': 'The London Trench'} +autopilot = delighted.AutopilotMembership.forSms().create(person_phone_number='+14155551212', properties=properties) + +# Delete by person id +delighted.AutopilotMembership.forSms().delete(person_id=42) + +# Delete by email address +delighted.AutopilotMembership.forEmail().delete(person_email='test@example.com') + +# Delete by phone number (must be E.164 format) +delighted.AutopilotMembership.forSms().delete(person_phone_number='+14155551212') +``` + +## Rate limits + +If a request is rate limited, a `TooManyRequestsError` exception is raised. You can rescue that exception to implement exponential backoff or retry strategies. The exception provides a `retry_after` attribute to tell you how many seconds you should wait before retrying. For example: + +```python +try: + metrics = delighted.Metrics.retrieve() +except delighted.errors.TooManyRequestsError as err: + retry_after_seconds = err.retry_after + # wait for retry_after_seconds before retrying + # add your retry strategy here ... +``` + +## <a name="advanced-configuration"></a> Advanced configuration & testing + +The following options are configurable for the client: + +```python +delighted.api_key +delighted.api_base_url # default: 'https://api.delighted.com/v1/' +delighted.http_adapter # default: delighted.HTTPAdapter +``` + +By default, a shared instance of `delighted.Client` is created lazily in `delighted.get_shared_client()`. If you want to create your own client, perhaps for test or if you have multiple API keys, you can: + +```python +# Create an custom client instance, and pass as last argument to resource actions +import delighted +from delighted import Client +client = Client(api_key='API_KEY', + api_base_url='https://api.delighted.com/v1/', + http_adapter=HTTPAdapter()) +metrics_from_custom_client = delighted.Metrics.retrieve(client=client) + +# Or, you can set Delighted.shared_client yourself +delighted.shared_client = delighted.Client( + api_key='API_KEY', + api_base_url='https://api.delighted.com/v1/', + http_adapter=delighted.HTTPAdapter() +) +metrics_from_custom_shared_client = delighted.Metrics.retrieve() +``` + +## Supported versions + +- 2.6+, 3.3+ (PyPy supported) + +## Contributing + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Run the tests (`tox`) +4. Commit your changes (`git commit -am 'Add some feature'`) +5. Push to the branch (`git push origin my-new-feature`) +6. Create new Pull Request + +## Releasing + +1. Bump the version in `delighted/__init__.py`. +2. Update the README and CHANGELOG as needed. +3. Tag the commit for release. +4. Create the distribution `python setup.py sdist` +5. Update the package against PyPI's test server with [twine](https://pypi.org/project/twine/) +`twine upload --repository-url https://test.pypi.org/legacy/ dist/TEST_PACKAGE_NAME`. +6. If (4 and 5) work, repeat all steps, then push to PyPI's live servers with `twine upload dist/PACKAGE_NAME`. + +## Author + +Originally by [Jason Pearson](https://github.com/kaeawc). Graciously transfered and now officially maintained by Delighted. + +%package help +Summary: Development documents and examples for delighted +Provides: python3-delighted-doc +%description help +[](https://travis-ci.org/delighted/delighted-python) + +# Delighted API Python Client + +Official Python client for the [Delighted API](https://delighted.com/docs/api). + +## Installation + +``` +pip install --upgrade delighted +``` + +or + +``` +easy_install --upgrade delighted +``` + +### Upgrading from delighted-python + +If you previously used the python package named `delighted-python`, please note that the package name is now just `delighted`. + +## Configuration + +To get started, you need to configure the client with your secret API key. + +```python +import delighted +delighted.api_key = 'YOUR_API_KEY' +``` + +For further options, read the [advanced configuration section](#advanced-configuration). + +**Note:** Your API key is secret, and you should treat it like a password. You can find your API key in your Delighted account, under *Settings* > *API*. + +## Usage + +Adding/updating people and scheduling surveys: + +```python +# Add a new person, and schedule a survey immediately +person1 = delighted.Person.create(email='foo+test1@delighted.com') + +# Add a new person, and schedule a survey after 1 minute (60 seconds) +person2 = delighted.Person.create(email='foo+test2@delighted.com', delay=60) + +# Add a new person, but do not schedule a survey +person3 = delighted.Person.create(email='foo+test3@delighted.com', send=False) + +# Add a new person with full set of attributes, including a custom question +# product name, and schedule a survey with a 30 second delay +person4 = delighted.Person.create( + email='foo+test4@delighted.com', + name='Joe Bloggs', + properties={'customer_id': 123, 'country': 'USA', + 'question_product_name': 'The London Trench'}, + delay=30) + +# Update an existing person (identified by email), adding a name, without +# scheduling a survey +updated_person1 = delighted.Person.create(email='foo+test1@delighted.com', + name='James Scott', send=False) +``` + +Unsubscribing people: + +```python +# Unsubscribe an existing person +delighted.Unsubscribe.create(person_email='foo+test1@delighted.com') +``` + +Listing people: + +```python +# List all people, auto pagination +# Note: Make sure to handle the possible rate limits error +people = delighted.Person.list() +while True: + try: + for person in people.auto_paging_iter(): + # Do something with person + except TooManyRequestsError as e: + # Indicates how long to wait (in seconds) before making this request again + e.retry_after + continue + +# For convenience, this method can use a sleep to automatically handle rate limits +people = delighted.Person.list(auto_handle_rate_limits=True) +for person in people.auto_paging_iter(): + # Do something with person +``` + +Listing people who have unsubscribed: + +```python +# List all people who have unsubscribed, 20 per page, first 2 pages +delighted.Unsubscribe.all() +delighted.Unsubscribe.all(page=2) +``` + +Listing people whose emails have bounced: + +```python +# List all people whose emails have bounced, 20 per page, first 2 pages +delighted.Bounce.all() +delighted.Bounce.all(page=2) +``` + +Deleting a person and all of the data associated with them: + +```python +# Delete by person id +delighted.Person.delete(id=42) +# Delete by email address +delighted.Person.delete(email='test@example.com') +# Delete by phone number (must be E.164 format) +delighted.Person.delete(phone_number='+14155551212') +``` + +Deleting pending survey requests + +```python +# Delete all pending (scheduled but unsent) survey requests for a person, by email. +delighted.SurveyRequest.delete_pending(person_email='foo+test1@delighted.com') +``` + +Adding survey responses: + +```python +# Add a survey response, score only +survey_response1 = delighted.SurveyResponse.create(person=person1.id, + score=10) + +# Add *another* survey response (for the same person), score and comment +survey_response2 = delighted.SurveyResponse.create(person=person1.id, + score=5, + comment='Really nice.') +``` + +Retrieving a survey response: + +```python +# Retrieve an existing survey response +survey_response3 = delighted.SurveyResponse.retrieve('123') +``` + +Updating survey responses: + +```python +# Update a survey response score +survey_response4 = delighted.SurveyResponse.retrieve('234') +survey_response4.score = 10 +survey_response4.save() +# <delighted.SurveyResponse object at 0xabc123> + +# Update (or add) survey response properties +survey_response4.person_properties = {'segment': 'Online'} +survey_response4.save() +# <delighted.SurveyResponse object at 0xabc123> + +# Update person who recorded the survey response +survey_response4.person = '321' +survey_response4.save() +# <delighted.SurveyResponse object at 0xabc123> +``` + +Listing survey responses: + +```python +# List all survey responses, 20 per page, first 2 pages +survey_responses_page1 = delighted.SurveyResponse.all() +survey_responses_page2 = delighted.SurveyResponse.all(page=2) + +# List all survey responses, 20 per page, expanding person object +survey_responses_page1_expanded = delighted.SurveyResponse.all(expand=['person']) +survey_responses_page1_expanded[0].person +# <delighted.Person object at 0xabc123> + +# List all survey responses, 20 per page, for a specific trend (ID: 123) +survey_responses_page1_trend = delighted.SurveyResponse.all(trend='123') + +# List all survey responses, 20 per page, in reverse chronological order (newest first) +survey_responses_page1_desc = delighted.SurveyResponse.all(order='desc') + +# List all survey responses, 100 per page, page 5, with a time range +import pytz +timezone = pytz.timezone('America/Chicago') +filtered_survey_responses = delighted.SurveyResponse.all( + page=5, + per_page=100, + since=timezone.localize(datetime.datetime(2014, 3, 1)), + until=timezone.localize(datetime.datetime(2014, 4, 30)) +) +``` + +Retrieving metrics: + +```python +# Get current metrics, 30-day simple moving average, from most recent response +metrics = delighted.Metrics.retrieve() + +# Get current metrics, 30-day simple moving average, from most recent response, +# for a specific trend (ID: 123) +metrics = delighted.Metrics.retrieve(trend='123') + +# Get metrics, for given time range +import pytz +timezone = pytz.timezone('America/Chicago') +metrics = delighted.Metrics.retrieve( + since=timezone.localize(datetime.datetime(2013, 10, 1)), + until=timezone.localize(datetime.datetime(2013, 11, 1)) +) +``` + +Managing Autopilot: + +```python +# Get Autopilot configuration for the `email` platform +autopilot = delighted.AutopilotConfiguration.retrieve('email') + +# List people in AutopilotMembership for the `email` platform +people_autopilot = delighted.AutopilotMembership.forEmail().list(auto_handle_rate_limits=True) +for person in people_autopilot.auto_paging_iter(): + # Do something with person + +# Add people to AutopilotMembership +autopilot = delighted.AutopilotMembership.forEmail().create(person_email='test@example.com') + +# Add people to AutopilotMembership, with a full set of attributes +properties = {'customer_id': 123, 'country': 'USA', 'question_product_name': 'The London Trench'} +autopilot = delighted.AutopilotMembership.forSms().create(person_phone_number='+14155551212', properties=properties) + +# Delete by person id +delighted.AutopilotMembership.forSms().delete(person_id=42) + +# Delete by email address +delighted.AutopilotMembership.forEmail().delete(person_email='test@example.com') + +# Delete by phone number (must be E.164 format) +delighted.AutopilotMembership.forSms().delete(person_phone_number='+14155551212') +``` + +## Rate limits + +If a request is rate limited, a `TooManyRequestsError` exception is raised. You can rescue that exception to implement exponential backoff or retry strategies. The exception provides a `retry_after` attribute to tell you how many seconds you should wait before retrying. For example: + +```python +try: + metrics = delighted.Metrics.retrieve() +except delighted.errors.TooManyRequestsError as err: + retry_after_seconds = err.retry_after + # wait for retry_after_seconds before retrying + # add your retry strategy here ... +``` + +## <a name="advanced-configuration"></a> Advanced configuration & testing + +The following options are configurable for the client: + +```python +delighted.api_key +delighted.api_base_url # default: 'https://api.delighted.com/v1/' +delighted.http_adapter # default: delighted.HTTPAdapter +``` + +By default, a shared instance of `delighted.Client` is created lazily in `delighted.get_shared_client()`. If you want to create your own client, perhaps for test or if you have multiple API keys, you can: + +```python +# Create an custom client instance, and pass as last argument to resource actions +import delighted +from delighted import Client +client = Client(api_key='API_KEY', + api_base_url='https://api.delighted.com/v1/', + http_adapter=HTTPAdapter()) +metrics_from_custom_client = delighted.Metrics.retrieve(client=client) + +# Or, you can set Delighted.shared_client yourself +delighted.shared_client = delighted.Client( + api_key='API_KEY', + api_base_url='https://api.delighted.com/v1/', + http_adapter=delighted.HTTPAdapter() +) +metrics_from_custom_shared_client = delighted.Metrics.retrieve() +``` + +## Supported versions + +- 2.6+, 3.3+ (PyPy supported) + +## Contributing + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Run the tests (`tox`) +4. Commit your changes (`git commit -am 'Add some feature'`) +5. Push to the branch (`git push origin my-new-feature`) +6. Create new Pull Request + +## Releasing + +1. Bump the version in `delighted/__init__.py`. +2. Update the README and CHANGELOG as needed. +3. Tag the commit for release. +4. Create the distribution `python setup.py sdist` +5. Update the package against PyPI's test server with [twine](https://pypi.org/project/twine/) +`twine upload --repository-url https://test.pypi.org/legacy/ dist/TEST_PACKAGE_NAME`. +6. If (4 and 5) work, repeat all steps, then push to PyPI's live servers with `twine upload dist/PACKAGE_NAME`. + +## Author + +Originally by [Jason Pearson](https://github.com/kaeawc). Graciously transfered and now officially maintained by Delighted. + +%prep +%autosetup -n delighted-4.1.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-delighted -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Mon Apr 10 2023 Python_Bot <Python_Bot@openeuler.org> - 4.1.0-1 +- Package Spec generated @@ -0,0 +1 @@ +3dbbcb301fa9e8db72b655972ca69834 delighted-4.1.0.tar.gz |