From d21491ac946200cedcdf15e682aead0707a0f408 Mon Sep 17 00:00:00 2001 From: Arturo Corro Date: Wed, 5 Mar 2025 19:49:29 -0600 Subject: [PATCH] first commit --- .editorconfig | 18 +++++ .gitattributes | 38 +++++++++++ .gitignore | 10 +++ .prettierignore | 16 +++++ .prettierrc.json | 29 ++++++++ CHANGELOG.md | 39 +++++++++++ CONTRIBUTING.md | 9 +++ LICENSE | 9 +++ README.md | 104 +++++++++++++++++++++++++++++ Services/GeolocationApiService.php | 100 +++++++++++++++++++++++++++ composer.json | 28 ++++++++ 11 files changed, 400 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .prettierignore create mode 100644 .prettierrc.json create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 Services/GeolocationApiService.php create mode 100644 composer.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8f0de65 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 + +[docker-compose.yml] +indent_size = 4 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..7333620 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,38 @@ +* text=auto eol=lf + +*.blade.php diff=html +*.css diff=css +*.html diff=html +*.md diff=markdown +*.php diff=php + +/.github export-ignore +CHANGELOG.md export-ignore +.styleci.yml export-ignore + +# Ignorar archivos de configuración y herramientas de desarrollo +.editorconfig export-ignore +.prettierrc.json export-ignore +.prettierignore export-ignore +.eslintrc.json export-ignore + +# Ignorar node_modules y dependencias locales +node_modules/ export-ignore +vendor/ export-ignore + +# Ignorar archivos de build +npm-debug.log export-ignore + +# Ignorar carpetas de logs y caché +storage/logs/ export-ignore +storage/framework/ export-ignore + +# Ignorar carpetas de compilación de frontend +public/build/ export-ignore +dist/ export-ignore + +# Ignorar archivos de CI/CD +.github/ export-ignore +.gitlab-ci.yml export-ignore +.vscode/ export-ignore +.idea/ export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d07bec2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +/node_modules +/vendor +/.vscode +/.nova +/.fleet +/.phpactor.json +/.phpunit.cache +/.phpunit.result.cache +/.zed +/.idea diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..5d3dfee --- /dev/null +++ b/.prettierignore @@ -0,0 +1,16 @@ +# Dependencias de Composer y Node.js +/vendor/ +/node_modules/ + +# Caché y logs +/storage/ +*.log +*.cache + +# Archivos del sistema +.DS_Store +Thumbs.db + +# Configuración de editores +.idea/ +.vscode/ diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..5f11c9c --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,29 @@ +{ + "arrowParens": "avoid", + "bracketSpacing": true, + "bracketSameLine": true, + "htmlWhitespaceSensitivity": "css", + "insertPragma": false, + "jsxSingleQuote": true, + "printWidth": 120, + "proseWrap": "preserve", + "quoteProps": "as-needed", + "requirePragma": false, + "semi": true, + "singleQuote": true, + "tabWidth": 4, + "trailingComma": "none", + "useTabs": false, + "endOfLine": "lf", + "embeddedLanguageFormatting": "auto", + "overrides": [ + { + "files": [ + "resources/assets/**/*.js" + ], + "options": { + "semi": false + } + } + ] +} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3a912b5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,39 @@ +# 📜 CHANGELOG - Laravel Geolocation API + +Este documento sigue el formato [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). + +## [0.1.0] - ALPHA - 2024-03-05 + +### ✨ Added (Agregado) +- 🚀 Primera versión alpha de la librería. +- 🔹 Implementación inicial de [funcionalidad clave 1]. +- 🔹 Integración con [dependencia o servicio principal]. +- 🔹 Soporte para [Laravel/Vuexy Admin, si aplica]. + +### 🛠 Changed (Modificado) +- 🔄 Optimización de [código o estructura interna]. + +### 🐛 Fixed (Correcciones) +- 🐞 Correcciones iniciales en [migraciones, modelos, servicios, etc.]. + +--- + +## 📅 Próximos Cambios Planeados +- 📊 **Mejoras en [feature futuro]**. +- 🏪 **Compatibilidad con [Laravel 11, Vuexy, etc.]**. +- 📍 **Integración con [API o funcionalidad esperada]**. + +--- + +**📌 Nota:** Esta es una versión **ALPHA**, aún en desarrollo. + +--- + +## 🔄 Sincronización de Cambios +Este `CHANGELOG.md` se actualiza primero en nuestro repositorio principal en **[Tea - Koneko Git](https://git.koneko.mx/koneko/laravel-geolocation-api)** y luego se refleja en GitHub. +Los cambios recientes pueden verse antes en **Tea** que en **GitHub** debido a la sincronización automática. + +--- + +📅 Última actualización: **2024-03-05**. + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..936b326 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,9 @@ +## 🔐 Acceso al Repositorio Privado + +Nuestro servidor Git en **Tea** tiene un registro cerrado. Para contribuir: + +1. Abre un **Issue** en [GitHub](https://github.com/koneko-mx/laravel-geolocation-api/issues) indicando tu interés en contribuir. +2. Alternativamente, envía un correo a **admin@koneko.mx** solicitando acceso. +3. Una vez aprobado, recibirás una invitación para registrarte y clonar el repositorio. + +Si solo necesitas acceso de lectura, puedes clonar la versión pública en **GitHub**. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..486d340 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2025 koneko + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c64ca4f --- /dev/null +++ b/README.md @@ -0,0 +1,104 @@ +# 📦 Laravel Geolocation API + +

+ Koneko Soluciones Tecnológicas Logo +

+

+ Sitio Web + Latest Stable Version + License + Servidor Git + Build Status + Issues +

+ +--- + +## 📌 Descripción + +**Laravel Geolocation API** es un paquete de Laravel diseñado para [descripción breve de la funcionalidad]. + +### ✨ Características: +- 🔹 Funcionalidad clave 1 +- 🔹 Funcionalidad clave 2 +- 🔹 Funcionalidad clave 3 + +--- + +## 📦 Instalación + +Instalar vía **Composer**: + +```bash +composer require koneko/laravel-geolocation-api +``` + +Publicar archivos de configuración y migraciones (si aplica): + +```bash +php artisan vendor:publish --tag=laravel-geolocation-api-config +php artisan migrate +``` + +--- + +## 🚀 Uso básico + +```php +use Koneko\NombreLibreria\Models\Model; + +$model = Model::create([ + 'campo1' => 'Valor', + 'campo2' => 'Otro valor', +]); +``` + +--- + +## 📚 Configuración adicional + +Si necesitas personalizar la configuración del módulo, publica el archivo de configuración: + +```bash +php artisan vendor:publish --tag=laravel-geolocation-api-config +``` + +Esto generará `config/laravel-geolocation-api.php`, donde puedes modificar valores predeterminados. + +--- + +## 🛠 Dependencias + +Este paquete requiere las siguientes dependencias: +- Laravel 11 +- Dependencias específicas de la librería + +--- + +## 🌍 Repositorio Principal y Sincronización + +Este repositorio es una **copia sincronizada** del repositorio principal alojado en **[Tea - Koneko Git](https://git.koneko.mx/koneko/laravel-geolocation-api)**. + +### 🔄 Sincronización con GitHub +- **Repositorio Principal:** [git.koneko.mx](https://git.koneko.mx/koneko/laravel-geolocation-api) +- **Repositorio en GitHub:** [github.com/koneko-mx/laravel-geolocation-api](https://github.com/koneko-mx/laravel-geolocation-api) +- **Los cambios pueden reflejarse primero en Tea antes de GitHub.** + +### 🤝 Contribuciones +Si deseas contribuir: +1. Puedes abrir un **Issue** en [GitHub Issues](https://github.com/koneko-mx/laravel-geolocation-api/issues). +2. Para Pull Requests, **preferimos contribuciones en Tea**. Contacta a `admin@koneko.mx` para solicitar acceso. + +⚠️ **Nota:** Algunos cambios pueden tardar en reflejarse en GitHub, ya que este repositorio se actualiza automáticamente desde Tea. + +--- + +## 🏅 Licencia + +Este paquete es de código abierto bajo la licencia [MIT](LICENSE). + +--- + +

+ Hecho con ❤️ por Koneko Soluciones Tecnológicas +

diff --git a/Services/GeolocationApiService.php b/Services/GeolocationApiService.php new file mode 100644 index 0000000..806ab17 --- /dev/null +++ b/Services/GeolocationApiService.php @@ -0,0 +1,100 @@ + Setting::getValue('geolocation.enabled', false), + 'provider' => Setting::getValue('geolocation.provider', 'locationiq'), + 'api_keys' => json_decode(Setting::getValue('geolocation.api_keys', '{}'), true), + 'language' => Setting::getValue('geolocation.language', 'es'), + 'country_bias' => Setting::getValue('geolocation.country_bias', 'MX'), + ]; + } + + /** + * Obtiene coordenadas a partir de una dirección. + */ + public function getCoordinates(string $address, ?string $provider = null) + { + $config = $this->getConfig(); + + if (!$config['enabled']) { + return null; + } + + $provider = $provider ?: $config['provider']; + $apiKey = $config['api_keys'][$provider] ?? null; + + if (!$apiKey) { + return null; + } + + return match ($provider) { + 'locationiq' => $this->getLocationIQCoordinates($address, $apiKey, $config), + 'google' => $this->getGoogleCoordinates($address, $apiKey, $config), + default => null, + }; + } + + /** + * Llama a la API de LocationIQ para obtener coordenadas. + */ + protected function getLocationIQCoordinates(string $address, string $apiKey, array $config) + { + $url = "https://us1.locationiq.com/v1/search.php"; + + $response = Http::get($url, [ + 'key' => $apiKey, + 'q' => $address, + 'format' => 'json', + 'accept-language' => $config['language'], + 'countrycodes' => $config['country_bias'] + ]); + + if ($response->successful()) { + $data = $response->json(); + + return [ + 'lat' => $data[0]['lat'] ?? null, + 'lng' => $data[0]['lon'] ?? null, + ]; + } + + return null; + } + + /** + * Llama a la API de Google Maps para obtener coordenadas. + */ + protected function getGoogleCoordinates(string $address, string $apiKey, array $config) + { + $url = "https://maps.googleapis.com/maps/api/geocode/json"; + + $response = Http::get($url, [ + 'key' => $apiKey, + 'address' => $address, + 'language' => $config['language'], + 'region' => $config['country_bias'] + ]); + + if ($response->successful()) { + $data = $response->json(); + + return [ + 'lat' => $data['results'][0]['geometry']['location']['lat'] ?? null, + 'lng' => $data['results'][0]['geometry']['location']['lng'] ?? null, + ]; + } + + return null; + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..4fcf14d --- /dev/null +++ b/composer.json @@ -0,0 +1,28 @@ +{ + "name": "koneko/laravel-geolocation-api", + "description": "Laravel Geolocation API, un servicico para obtener coordenadas GPS a partir de una dirección.", + "keywords": ["laravel", "koneko", "framework", "geolocation", "api", "gps"], + "type": "library", + "license": "MIT", + "require": { + "php": "^8.2", + "laravel/framework": "^11.31" + }, + "autoload": { + "psr-4": { + "Koneko\\GeolocationApi\\": "" + } + }, + "authors": [ + { + "name": "Arturo Corro Pacheco", + "email": "arturo@koneko.mx" + } + ], + "support": { + "source": "https://github.com/koneko-mx/laravel-geolocation-api", + "issues": "https://github.com/koneko-mx/laravel-geolocation-api/issues" + }, + "minimum-stability": "dev", + "prefer-stable": true +}