climsoft / climsoft-api

API for Climsoft databases
MIT License
2 stars 4 forks source link

Opencdms api 42 #11

Closed faysal-ishtiaq closed 2 years ago

faysal-ishtiaq commented 2 years ago

translation added to responses

Here is an example

Request station lists with no translation

HOST=https://api-latest.opencdms.org

ACCESS_TOKEN=$(curl -X 'POST' $HOST'/auth' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "username": "admin",
  "password": "password123"
}' | jq '.access_token' | tr -d '"')

curl -sX 'GET' \
  $HOST'/climsoft/v1/stations/?limit=1&offset=0' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer '$ACCESS_TOKEN | jq .

Response

{
  "status": "success",
  "message": "Successfully fetched stations.",
  "limit": 1,
  "pages": 68,
  "page": 1,
  "result": [
    {
      "station_id": "2343403",
      "station_name": "Test Station",
      "wmoid": "",
      "icaoid": "",
      "latitude": -11.3454,
      "qualifier": "",
      "longitude": 827.255343,
      "elevation": "350",
      "geolocation_method": "",
      "geolocation_accuracy": 1.34,
      "opening_datetime": "",
      "closing_datetime": "",
      "country": "Zimbabwe",
      "authority": "",
      "admin_region": "",
      "drainage_basin": "",
      "waca_selection": true,
      "cpt_selection": true,
      "station_operational": true
    }
  ],
  "_schema": {
    "title": "StationQueryResponse",
    "type": "object",
    "properties": {
      "result": {
        "title": "Result",
        "type": "array",
        "items": {
          "$ref": "#/definitions/Station"
        }
      },
      "message": {
        "title": "Message",
        "type": "string"
      },
      "status": {
        "title": "Status",
        "type": "string"
      },
      "limit": {
        "title": "Limit",
        "type": "integer"
      },
      "page": {
        "title": "Page",
        "type": "integer"
      },
      "pages": {
        "title": "Pages",
        "type": "integer"
      }
    },
    "required": [
      "result",
      "message",
      "status",
      "limit",
      "page",
      "pages"
    ],
    "definitions": {
      "Station": {
        "title": "Station",
        "type": "object",
        "properties": {
          "station_id": {
            "title": "Station ID",
            "maxLength": 255,
            "type": "string"
          },
          "station_name": {
            "title": "Station Name",
            "maxLength": 255,
            "type": "string"
          },
          "wmoid": {
            "title": "Wmo ID",
            "maxLength": 20,
            "type": "string"
          },
          "icaoid": {
            "title": "Icao ID",
            "maxLength": 20,
            "type": "string"
          },
          "latitude": {
            "title": "Latitude",
            "type": "number"
          },
          "qualifier": {
            "title": "Qualifier",
            "maxLength": 20,
            "type": "string"
          },
          "longitude": {
            "title": "Longitude",
            "type": "number"
          },
          "elevation": {
            "title": "Elevation",
            "maxLength": 255,
            "type": "string"
          },
          "geolocation_method": {
            "title": "Geolocation Method",
            "maxLength": 255,
            "type": "string"
          },
          "geolocation_accuracy": {
            "title": "Geolocation Accuracy",
            "type": "number"
          },
          "opening_datetime": {
            "title": "Opening Datetime",
            "type": "string"
          },
          "closing_datetime": {
            "title": "Closing Datetime",
            "type": "string"
          },
          "country": {
            "title": "Country",
            "maxLength": 50,
            "type": "string"
          },
          "authority": {
            "title": "Authority",
            "maxLength": 255,
            "type": "string"
          },
          "admin_region": {
            "title": "Admin Region",
            "maxLength": 255,
            "type": "string"
          },
          "drainage_basin": {
            "title": "Drainage Basin",
            "maxLength": 255,
            "type": "string"
          },
          "waca_selection": {
            "title": "Waca Selection",
            "type": "boolean"
          },
          "cpt_selection": {
            "title": "Cpt Selection",
            "type": "boolean"
          },
          "station_operational": {
            "title": "Station Operational",
            "type": "boolean"
          }
        },
        "required": [
          "station_id",
          "station_name",
          "latitude",
          "longitude",
          "elevation",
          "closing_datetime",
          "country",
          "waca_selection",
          "cpt_selection",
          "station_operational"
        ]
      }
    }
  }
}

Request station lists with translated title and response messages.


HOST=https://api-latest.opencdms.org

ACCESS_TOKEN=$(curl -X 'POST' $HOST'/auth' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "username": "admin",
  "password": "password123"
}' | jq '.access_token' | tr -d '"')

curl -sX 'GET' \
  $HOST'/climsoft/v1/stations/?limit=1&offset=0' \
  -H 'accept: application/json' \
  -H 'accept-language: fr' \
  -H 'Authorization: Bearer '$ACCESS_TOKEN | jq .

Response

{
  "status": "success",
  "message": "Stations récupérées avec succès.",
  "limit": 1,
  "pages": 68,
  "page": 1,
  "result": [
    {
      "station_id": "2343403",
      "station_name": "Test Station",
      "wmoid": "",
      "icaoid": "",
      "latitude": -11.3454,
      "qualifier": "",
      "longitude": 827.255343,
      "elevation": "350",
      "geolocation_method": "",
      "geolocation_accuracy": 1.34,
      "opening_datetime": "",
      "closing_datetime": "",
      "country": "Zimbabwe",
      "authority": "",
      "admin_region": "",
      "drainage_basin": "",
      "waca_selection": true,
      "cpt_selection": true,
      "station_operational": true
    }
  ],
  "_schema": {
    "title": "StationQueryResponse",
    "type": "object",
    "properties": {
      "result": {
        "title": "Résultat",
        "type": "array",
        "items": {
          "$ref": "#/definitions/Station"
        }
      },
      "message": {
        "title": "Message",
        "type": "string"
      },
      "status": {
        "title": "Statut",
        "type": "string"
      },
      "limit": {
        "title": "Limite",
        "type": "integer"
      },
      "page": {
        "title": "Page",
        "type": "integer"
      },
      "pages": {
        "title": "Pages",
        "type": "integer"
      }
    },
    "required": [
      "result",
      "message",
      "status",
      "limit",
      "page",
      "pages"
    ],
    "definitions": {
      "Station": {
        "title": "Station",
        "type": "object",
        "properties": {
          "station_id": {
            "title": "Identifiant de la station",
            "maxLength": 255,
            "type": "string"
          },
          "station_name": {
            "title": "Nom de la station",
            "maxLength": 255,
            "type": "string"
          },
          "wmoid": {
            "title": "Identifiant de Wmo",
            "maxLength": 20,
            "type": "string"
          },
          "icaoid": {
            "title": "Identifiant de Icao",
            "maxLength": 20,
            "type": "string"
          },
          "latitude": {
            "title": "Latitude",
            "type": "number"
          },
          "qualifier": {
            "title": "Qualificatif",
            "maxLength": 20,
            "type": "string"
          },
          "longitude": {
            "title": "Longitude",
            "type": "number"
          },
          "elevation": {
            "title": "Élévation",
            "maxLength": 255,
            "type": "string"
          },
          "geolocation_method": {
            "title": "Méthode de géolocalisation",
            "maxLength": 255,
            "type": "string"
          },
          "geolocation_accuracy": {
            "title": "Précision de la géolocalisation",
            "type": "number"
          },
          "opening_datetime": {
            "title": "Date et heure d'ouverture",
            "type": "string"
          },
          "closing_datetime": {
            "title": "Date et heure de clôture",
            "type": "string"
          },
          "country": {
            "title": "De campagne",
            "maxLength": 50,
            "type": "string"
          },
          "authority": {
            "title": "Autorité",
            "maxLength": 255,
            "type": "string"
          },
          "admin_region": {
            "title": "Région administrative",
            "maxLength": 255,
            "type": "string"
          },
          "drainage_basin": {
            "title": "Bassin de drainage",
            "maxLength": 255,
            "type": "string"
          },
          "waca_selection": {
            "title": "Sélection Waca",
            "type": "boolean"
          },
          "cpt_selection": {
            "title": "Sélection de CP",
            "type": "boolean"
          },
          "station_operational": {
            "title": "Station opérationnelle",
            "type": "boolean"
          }
        },
        "required": [
          "station_id",
          "station_name",
          "latitude",
          "longitude",
          "elevation",
          "closing_datetime",
          "country",
          "waca_selection",
          "cpt_selection",
          "station_operational"
        ]
      }
    }
  }
}
isedwards commented 2 years ago

This looks great, thank you @faysal-ishtiaq