diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7fdbb43..bfe9477 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: @MODULE_NAME@ CI +name: ipify CI # Only on Development we build snapshots on: @@ -8,7 +8,7 @@ on: - master env: - MODULE_ID: @MODULE_SLUG@ + MODULE_ID: ipify jobs: ############################################# diff --git a/ModuleConfig.cfc b/ModuleConfig.cfc index 92257e3..b208150 100644 --- a/ModuleConfig.cfc +++ b/ModuleConfig.cfc @@ -6,20 +6,19 @@ component { // Module Properties - this.title = "@MODULE_NAME@"; + this.title = "ipify"; this.author = "Ortus Solutions"; this.webURL = "https://www.ortussolutions.com"; - this.description = "@MODULE_DESCRIPTION@"; + this.description = " A Simple Public IP Address API Module based on www.ipify.org"; this.version = "@build.version@+@build.number@"; - // Model Namespace - this.modelNamespace = "@MODULE_SLUG@"; - + this.modelNamespace = "ipify"; // CF Mapping - this.cfmapping = "@MODULE_SLUG@"; - + this.cfmapping = "ipify"; // Dependencies this.dependencies = []; + // Helpers + this.applicationHelper = [ "helpers/mixins.cfm" ]; /** * Configure Module diff --git a/box.json b/box.json index b117e92..290dbb6 100644 --- a/box.json +++ b/box.json @@ -1,14 +1,14 @@ { - "name" : "@MODULE_NAME@", + "name" : "ipify", "version" : "1.0.0", - "location" : "https://downloads.ortussolutions.com/ortussolutions/coldbox-modules/@MODULE_SLUG@/@build.version@/@MODULE_SLUG@-@build.version@.zip", + "location" : "https://downloads.ortussolutions.com/ortussolutions/coldbox-modules/ipify/@build.version@/ipify-@build.version@.zip", "author" : "Ortus Solutions ", - "homepage" : "https://github.com/coldbox-modules/@MODULE_SLUG@", - "documentation" : "https://github.com/coldbox-modules/@MODULE_SLUG@", - "repository" : { "type" : "git", "url" : "https://github.com/coldbox-modules/@MODULE_SLUG@" }, - "bugs" : "https://github.com/coldbox-modules/@MODULE_SLUG@", + "homepage" : "https://github.com/coldbox-modules/ipify", + "documentation" : "https://github.com/coldbox-modules/ipify", + "repository" : { "type" : "git", "url" : "https://github.com/coldbox-modules/ipify" }, + "bugs" : "https://github.com/coldbox-modules/ipify", "shortDescription" : "Description goes here", - "slug" : "@MODULE_SLUG@", + "slug" : "ipify", "type" : "modules", "keywords":"", "license" : [ diff --git a/build/.travis.yml b/build/.travis.yml index ecb48ff..d007b7c 100644 --- a/build/.travis.yml +++ b/build/.travis.yml @@ -7,7 +7,7 @@ notifications: env: # Fill out these global variables for build process global: - - MODULE_ID=@MODULE_NAME@ + - MODULE_ID=ipify matrix: - ENGINE=lucee@5 - ENGINE=adobe@2018 diff --git a/build/SetupTemplate.cfc b/build/SetupTemplate.cfc index ca18f24..640555a 100644 --- a/build/SetupTemplate.cfc +++ b/build/SetupTemplate.cfc @@ -39,7 +39,7 @@ component { command( "tokenReplace" ) .params( path = "/#variables.cwd#/**", - token = "@MODULE_NAME@", + token = "ipify", replacement = moduleName ) .run(); @@ -47,7 +47,7 @@ component { command( "tokenReplace" ) .params( path = "/#variables.cwd#/**", - token = "@MODULE_SLUG@", + token = "ipify", replacement = moduleSlug ) .run(); @@ -55,7 +55,7 @@ component { command( "tokenReplace" ) .params( path = "/#variables.cwd#/**", - token = "@MODULE_DESCRIPTION@", + token = " A Simple Public IP Address API Module based on www.ipify.org", replacement = moduleDescription ) .run(); diff --git a/helpers/mixins.cfm b/helpers/mixins.cfm new file mode 100644 index 0000000..37390ad --- /dev/null +++ b/helpers/mixins.cfm @@ -0,0 +1,7 @@ + + + function myIp(){ + return getInstance( "@ipify" ).get(); + } + + diff --git a/models/Ipify.cfc b/models/Ipify.cfc new file mode 100644 index 0000000..89294ee --- /dev/null +++ b/models/Ipify.cfc @@ -0,0 +1,25 @@ +/** + * Tap into the ipify API for public address retrieval + */ +component { + + variables.API_URL = "https://api.ipify.org/?format=json"; + + function init(){ + return this; + } + + /** + * Get the public IP Url of the caller + */ + string function get(){ + cfhttp( + method = "GET", + charset = "utf-8", + url = variables.API_URL, + result = "local.results" + ); + return deserializeJSON( results.fileContent ).ip; + } + +} diff --git a/readme.md b/readme.md index 590d847..ecb58ec 100644 --- a/readme.md +++ b/readme.md @@ -1,52 +1,68 @@ -# Ortus ColdBox Module Template +# IPIFY API Module -This template can be used to create Ortus based ColdBox Modules. To use, just click the `Use this Template` button in the github repository: https://github.com/coldbox-modules/module-template and run the setup task from where you cloned it. +This module allows you to tap into the ipify API: https://www.ipify.org/ : A Simple Public IP Address API, to get the IP address of where you made the call from; your public IP Address. -```bash -box task run taskFile=build/setupTemplate -``` +## LICENSE + +Apache License, Version 2.0. + +## IMPORTANT LINKS + +* Source: https://github.com/coldbox-modules/ipify +* ForgeBox: http://forgebox.io/view/ipify +* [Changelog](changelog.md) + +## SYSTEM REQUIREMENTS -The `setupTemplate` task will ask you for your module name, id and description and configure the template for you! Enjoy! +* Lucee 5+ +* ColdFusion 2018+ -## Directory Structure +## Why ipify? -The root of the module is the root of the repository. Add all the necessary files your module will need. +* Ever needed to get your public IP address programmatically? +* Maybe you're provisioning new cloud servers and need to know your IP -- maybe you're behind a corporate firewall and need to tunnel information -- whatever the reason: sometimes having a public IP address API is useful! +* ipify is completely open source (check out the GitHub repository): https://github.com/rdegges/ipify-api -* `.github/workflows` - These are the github actions to test and build the module via CI -* `build` - This is the CommandBox task that builds the project. Only modify if needed. Most modules will never modify it. (Modify if needed) -* `test-harness` - This is a ColdBox testing application, where you will add your testing files, specs etc. -* `.cfformat.json` - A CFFormat using the Ortus Standards -* `.cflintrc` - A CFLint configuration file according to Ortus Standards -* `.editorconfig` - Smooth consistency between editors -* `.gitattributes` - Git attributes -* `.gitignore` - Basic ignores. Modify as needed. -* `.markdownlint.json` - A linting file for markdown docs -* `box.json` - The box.json for YOUR module. Modify as needed. -* `changelog.md` - A nice changelog tracking file -* `ModuleConfig.cfc` - Your module's configuration. Modify as needed. -* `readme.md` - Your module's readme. Modify as needed. -* `server-xx@x.json` - A set of json files to configure the major engines your modules supports. +## Installation -## Test Harness +Just do `box install ipify` and you are ready to roll! -The test harness is created to bootstrap your working module into the application `afterAspectsLoad`. This is done in the `config/ColdBox.cfc`. It includes some key features: +## Usage -* `config` - Modify as needed -* `tests` - All your testing specs should go here. Please notice the commented out ORM fixtures. Enable them if your module requires ORM -* `.cfconfig.json` - A prepared cfconfig json file so your engine data is consistent. Modify as needed. -* `.env.sample` - An environment property file sample. Copy and create a `.env` if your app requires it. +You can get access to our model, or helper to get your public IP address +```js +// Via getInstance: handlers/layouts/views/interceptors +getInstance( "ipify" ).get() + +// Via injection: anywhere +property name="ipify" inject="@ipify"; +var ip = ipify.get(); + +// As a delegate: anywhere +component delegates="ip<@ipify" +// Then use with the ip suffix: getIp() + +// As a helper: handlers/layouts/views/interceptors +getMyIp() +``` -## API Docs +******************************************************************************** +Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp +www.ortussolutions.com +******************************************************************************** -The build task will take care of building API Docs using DocBox for you but **ONLY** for the `models` folder in your module. If you want to document more then make sure you modify the `build/Build.cfc` task. +## HONOR GOES TO GOD ABOVE ALL -## Github Actions Automation +Because of His grace, this project exists. If you don't like this, then don't read it, its not for you. -The github actions will clone, test, package, deploy your module to ForgeBox and the Ortus S3 accounts for API Docs and Artifacts. So please make sure the following environment variables are set in your repository. ** Please note that most of them are already defined at the org level ** +>"Therefore being justified by faith, we have peace with God through our Lord Jesus Christ: +By whom also we have access by faith into this grace wherein we stand, and rejoice in hope of the glory of God. +And not only so, but we glory in tribulations also: knowing that tribulation worketh patience; +And patience, experience; and experience, hope: +And hope maketh not ashamed; because the love of God is shed abroad in our hearts by the +Holy Ghost which is given unto us. ." Romans 5:5 -* `FORGEBOX_TOKEN` - The Ortus ForgeBox API Token -* `AWS_ACCESS_KEY` - The travis user S3 account -* `AWS_ACCESS_SECRET` - The travis secret S3 +### THE DAILY BREAD -> Please contact the admins in the `#infrastructure` channel for these credentials if needed + > "I am the way, and the truth, and the life; no one comes to the Father, but by me (JESUS)" Jn 14:1-12 diff --git a/server-adobe@2018.json b/server-adobe@2018.json index 8c13686..1453512 100644 --- a/server-adobe@2018.json +++ b/server-adobe@2018.json @@ -1,5 +1,5 @@ { - "name":"@MODULE_NAME@-adobe@2018", + "name":"ipify-adobe@2018", "app":{ "serverHomeDirectory":".engine/adobe2018", "cfengine":"adobe@2018" @@ -13,7 +13,7 @@ }, "webroot": "test-harness", "aliases":{ - "/moduleroot/@MODULE_NAME@":"../" + "/moduleroot/ipify":"../" } }, "openBrowser":"false", diff --git a/server-adobe@2021.json b/server-adobe@2021.json index d0630be..e188c67 100644 --- a/server-adobe@2021.json +++ b/server-adobe@2021.json @@ -1,5 +1,5 @@ { - "name":"@MODULE_NAME@-adobe@2021", + "name":"ipify-adobe@2021", "app":{ "serverHomeDirectory":".engine/adobe2021", "cfengine":"adobe@2021" @@ -13,7 +13,7 @@ }, "webroot": "test-harness", "aliases":{ - "/moduleroot/@MODULE_NAME@":"../" + "/moduleroot/ipify":"../" } }, "jvm":{ diff --git a/server-lucee@5.json b/server-lucee@5.json index 6423ca7..da0abdc 100644 --- a/server-lucee@5.json +++ b/server-lucee@5.json @@ -1,5 +1,5 @@ { - "name":"@MODULE_NAME@-lucee@5", + "name":"ipify-lucee@5", "app":{ "serverHomeDirectory":".engine/lucee5", "cfengine":"lucee@5" @@ -11,13 +11,13 @@ "rewrites":{ "enable":"true" }, - "webroot": "test-harness", - "aliases":{ - "/moduleroot/@MODULE_NAME@":"../" + "webroot":"test-harness", + "aliases":{ + "/moduleroot/ipify":"../" } }, "openBrowser":"false", - "cfconfig": { - "file" : ".cfconfig.json" - } + "cfconfig":{ + "file":".cfconfig.json" + } } diff --git a/test-harness/Application.cfc b/test-harness/Application.cfc index 0fcffde..2c4c7c7 100644 --- a/test-harness/Application.cfc +++ b/test-harness/Application.cfc @@ -7,7 +7,7 @@ www.ortussolutions.com component{ // UPDATE THE NAME OF THE MODULE IN TESTING BELOW - request.MODULE_NAME = "@MODULE_NAME@"; + request.MODULE_NAME = "ipify"; // Application properties this.name = hash( getCurrentTemplatePath() ); diff --git a/test-harness/box.json b/test-harness/box.json index e8f47b1..7db8ee8 100644 --- a/test-harness/box.json +++ b/test-harness/box.json @@ -11,8 +11,8 @@ "testbox":"*" }, "installPaths":{ - "coldbox":"coldbox", - "testbox":"testbox" + "coldbox":"coldbox/", + "testbox":"testbox/" }, "testbox":{ "runner":"http://localhost:60299/tests/runner.cfm" diff --git a/test-harness/tests/Application.cfc b/test-harness/tests/Application.cfc index 9da19bf..8dc77fd 100644 --- a/test-harness/tests/Application.cfc +++ b/test-harness/tests/Application.cfc @@ -6,9 +6,9 @@ component{ // The name of the module used in cfmappings ,etc - request.MODULE_NAME = "@MODULE_NAME@"; + request.MODULE_NAME = "ipify"; // The directory name of the module on disk. Usually, it's the same as the module name - request.MODULE_PATH = "@MODULE_NAME@"; + request.MODULE_PATH = "ipify"; // APPLICATION CFC PROPERTIES this.name = "#request.MODULE_NAME# Testing Suite"; diff --git a/test-harness/tests/specs/ModuleSpec.cfc b/test-harness/tests/specs/ModuleSpec.cfc index 4a2dd25..0fc00b1 100644 --- a/test-harness/tests/specs/ModuleSpec.cfc +++ b/test-harness/tests/specs/ModuleSpec.cfc @@ -14,10 +14,15 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="root" { /*********************************** BDD SUITES ***********************************/ function run(){ - describe( "MockData CFC", function(){ + describe( "Ipify", function(){ beforeEach( function( currentSpec ){ + setup(); } ); + it( "can get a public ip", function(){ + expect( getInstance( "ipify@ipify" ).get() ).notToBeEmpty(); + }); + } ); } diff --git a/test-harness/views/main/index.cfm b/test-harness/views/main/index.cfm index 992cabe..a541ec2 100644 --- a/test-harness/views/main/index.cfm +++ b/test-harness/views/main/index.cfm @@ -1,3 +1,8 @@ -Module Tester - \ No newline at end of file +

+ My IP is: #getInstance( "@ipify" ).get()# +

+

+ My helper IP is: #myIp()# +

+