From 1a7f6cba2de6073cdfe557f1e5d948dabce160dc Mon Sep 17 00:00:00 2001 From: David Wilkie Date: Fri, 11 Oct 2024 21:03:43 +0700 Subject: [PATCH] fix: Handle zero max stock --- skyetel/README.md | 20 +++++++++++-------- .../app/workflows/generate_shopping_list.rb | 2 +- skyetel/examples/README.md | 2 +- skyetel/examples/supported_cities.csv | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/skyetel/README.md b/skyetel/README.md index 44f5b0d..8babb91 100644 --- a/skyetel/README.md +++ b/skyetel/README.md @@ -2,20 +2,24 @@ [![Build](https://github.com/somleng/somleng-integrations/actions/workflows/skyetel.yml/badge.svg)](https://github.com/somleng/somleng-integrations/actions/workflows/skyetel.yml) -This integration connects [Skyetel](https://skyetel.com/) to [Somleng](https://www.somleng.org/docs.html). - -## Features - -* Automatically purchase DIDs from Skyetel and add them to your Somleng carrier account. +This integration runs on a schedule and automatically orders DIDs from [Skyetel](https://skyetel.com/) and adds them to [Somleng](https://www.somleng.org/docs.html). It keeps the stock levels between `MIN_STOCK` and `MAX_STOCK` for each city configured in the `supported_cities.csv` file. ## Configuration -Add configuration parameters here. +| Variable | Description | Example | Required | Default | +| -------------------------- | --------------------------------------------------------- | ---------------------- | -------- | ---------------------- | +| SOMLENG_API_KEY | Somleng Carrier API Key SID | change-me | true | none | +| SKYETEL_USERNAME | Skyetel API Username Token | change-me | true | none | +| SKYETEL_PASSWORD | Skyetel API Password | change-me | true | none | +| MIN_STOCK | Minimum number of phone numbers to maintain per city | 50 | true | 0 | +| MAX_STOCK | Maximum number of phone numbers to maintain per city | 100 | true | 0 | +| SUPPORTED_CITIES_DATA_FILE | Name of the CSV file containing supported cities | `supported_cities.csv` | false | `supported_cities.csv` | +| SOMLENG_NUMBER_VISIBILITY | Visibility of created phone number. `public` or `private` | `public` | false | public | ## Usage -Add usage instructions here. +See [examples](https://github.com/somleng/somleng-integrations/tree/develop/skyetel/examples). ## Deployment -The [docker image](https://github.com/somleng/somleng-integrations/pkgs/container/somleng-skyetel) is available on Github. +The [docker image](https://github.com/somleng/somleng-integrations/pkgs/container/somleng-skyetel) is automatically configured for deployment to AWS Lambda. diff --git a/skyetel/app/workflows/generate_shopping_list.rb b/skyetel/app/workflows/generate_shopping_list.rb index 77baf8f..3633c3d 100644 --- a/skyetel/app/workflows/generate_shopping_list.rb +++ b/skyetel/app/workflows/generate_shopping_list.rb @@ -21,7 +21,7 @@ def call ) current_stock = inventory_item ? inventory_item.quantity : 0 - next if current_stock >= min_stock + next if max_stock.zero? || current_stock >= min_stock result << ShoppingList::LineItem.new( country: city.country, diff --git a/skyetel/examples/README.md b/skyetel/examples/README.md index 4af4d21..0cde2fe 100644 --- a/skyetel/examples/README.md +++ b/skyetel/examples/README.md @@ -17,5 +17,5 @@ The image is ready to be deployed to AWS Lambda and can be triggered by a schedu If you're not using Lambda, you can run your image with the following command. ```bash -docker run --platform linux/amd64 --rm -it -e APP_ENV=production -e SOMLENG_API_KEY='somleng-carrier-api-key' SOMLENG_API_KEY='somleng-carrier-api-key' -e SKYETEL_USERNAME='skyetel-username' -e SKYETEL_PASSWORD='skyetel-password' -e MAX_STOCK=2 --entrypoint ruby somleng-skyetel:example -r ./app.rb -e App::Handler.process +docker run --platform linux/amd64 --rm -it -e APP_ENV=production -e SOMLENG_API_KEY='somleng-carrier-api-key' SOMLENG_API_KEY='somleng-carrier-api-key' -e SKYETEL_USERNAME='skyetel-username' -e SKYETEL_PASSWORD='skyetel-password' -e MIN_STOCK=2 -e MAX_STOCK=2 --entrypoint ruby somleng-skyetel:example -r ./app.rb -e App::Handler.process ``` diff --git a/skyetel/examples/supported_cities.csv b/skyetel/examples/supported_cities.csv index 9fb3f97..081d749 100644 --- a/skyetel/examples/supported_cities.csv +++ b/skyetel/examples/supported_cities.csv @@ -1,2 +1,2 @@ country,region,name -US,FL,Jacksonville +US,WA,Seattle