Search This Blog

Tuesday, 31 January 2017

Retrieving ATM location's using the NAB API

NAB have released an API to determine ATM Locations amongst other things based on a GEO location. It's documented here.

https://developer.nab.com.au/docs#locations-api-get-locations-by-geo-coordinates

Here we use this API but I wanted to highlight a few things you would need to know to consume the API

1. You will need to provide the following and this has to be calculated based on a LAT/LONG. The screen shot below shows what a GEO location with a radius of 0.5 KM's would look like. You will see it's starting point is your current location in this case in Melbourne CBD.



2. The NAP API would required the following to be set which can be obtained using a calculation as per the screen shot above

swLat South-West latitude coordinates expressed as decimal
neLat North-East latitude coordinates expressed as decimal
neLng North-East longitude coordinates expressed as decimal
swLng South-West longitude coordinates expressed as decimal

3. The attribute LocationType allows you to filter what type of location your after I set this to "ATM" to only find ATM locations.

4. I also set the attribute Fields to extended as this gives me detailed information

5. Once you have the data here is an example of getting detailed information of ATM locations using the GEO location co-ordinates. In this example CURL is good enough to illustrate that

pasapicella@pas-macbook:~/pivotal$ curl -H "x-nab-key: NABAPI-KEY" "https://api.developer.nab.com.au/v2/locations?locationType=atm&searchCriteria=geo&swLat=-37.81851471355399&swLng=144.95235719310358&neLat=-37.812155549503025&neLng=144.96040686020137&fields=extended&v=1" | jq -r
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10371  100 10371    0     0   2016      0  0:00:05  0:00:05 --:--:--  2871
{
  "locationSearchResponse": {
    "totalRecords": 16,
    "viewport": {
      "swLat": -37.81586424048582,
      "swLng": 144.9589117502319,
      "neLat": -37.81109231077813,
      "neLng": 144.96758064976802
    },
    "locations": [
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Offsite",
          "isDeposit": false,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "NAB ATM",
          "address3": "Melbourne Central",
          "address4": "Lower Ground floor",
          "id": 5058548,
          "key": "atm_3B46",
          "description": "Melbourne Central",
          "address1": "300 Elizabeth Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.812031,
          "longitude": 144.9621768,
          "hours": "Mon-Thu 10.00am-06.00pm, Fri 10.00am-09.00pm, Sat 10.00am-06.00pm, Sun 10.00am-05.00pm"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Offsite",
          "isDeposit": false,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "NAB ATM",
          "address3": "Melbourne Central",
          "address4": "Ground Floor",
          "address5": "Near La Trobe St Entrance under escalator",
          "id": 5058552,
          "key": "atm_3B56",
          "description": "Melbourne Central",
          "address1": "300 Elizabeth Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.812031,
          "longitude": 144.9621768,
          "hours": "Mon-Thu 10.00am-06.00pm, Fri 10.00am-09.00pm, Sat 10.00am-06.00pm, Sun 10.00am-05.00pm"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Offsite",
          "isDeposit": false,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "NAB ATM",
          "address3": "Queen Victoria Market",
          "address5": "Outside the market facing the street",
          "id": 5058555,
          "key": "atm_3B61",
          "description": "Queen Victoria Market",
          "address1": "Queen Street",
          "address2": "Corner Therry Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.8130009,
          "longitude": 144.9597905,
          "hours": "24/7"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Offsite",
          "isDeposit": false,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "NAB ATM",
          "address3": "Target Centre",
          "id": 5058577,
          "key": "atm_3CC7",
          "description": "Target Centre",
          "address1": "236 Bourke Street Mall",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.8132227,
          "longitude": 144.9665518,
          "hours": "Mon-Fri 09.00am-05.00pm, Sat-Sun 10.00am-05.00pm"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Branch",
          "isDeposit": true,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "NAB ATM",
          "address3": "Queen Victoria Centre",
          "id": 5058614,
          "key": "atm_3F07",
          "description": "Queen Victoria",
          "address1": "228-234 Lonsdale Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.8122729,
          "longitude": 144.9622383,
          "hours": "24/7"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Offsite",
          "isDeposit": false,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "NAB ATM",
          "address3": "University of Melbourne",
          "address5": "Kenneth Myer Building",
          "id": 5058653,
          "key": "atm_3G28",
          "description": "KMB Foyer",
          "address1": "30 Royal Parade",
          "suburb": "Parkville",
          "state": "VIC",
          "postcode": "3052",
          "latitude": -37.8149256,
          "longitude": 144.9643156,
          "hours": "Mon-Fri 07.00am-07.00pm"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Branch",
          "isDeposit": true,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "SmartATM",
          "address3": "Midtown Plaza",
          "address4": "Shop 8",
          "id": 5058783,
          "key": "atm_3S02",
          "description": "Midtown Plaza",
          "address1": "186 Swanston Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.8131315,
          "longitude": 144.9654723,
          "hours": "Mon-Fri 09.30am-05.00pm, Sat 10.00am-02.00pm"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Branch",
          "isDeposit": true,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "SmartATM",
          "address3": "Midtown Plaza",
          "address4": "Shop 8",
          "id": 5058784,
          "key": "atm_3S03",
          "description": "Midtown Plaza",
          "address1": "186 Swanston Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.8131315,
          "longitude": 144.9654723,
          "hours": "Mon-Fri 09.30am-05.00pm, Sat 10.00am-02.00pm"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Branch",
          "isDeposit": true,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "SmartATM",
          "address3": "Melbourne NAB House",
          "id": 5058814,
          "key": "atm_3S38",
          "description": "National Bank House",
          "address1": "500 Bourke Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.8154128,
          "longitude": 144.9590017
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Branch",
          "isDeposit": true,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "SmartATM",
          "address3": "Melbourne NAB House",
          "id": 5058815,
          "key": "atm_3S39",
          "description": "National Bank House",
          "address1": "500 Bourke Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.8154128,
          "longitude": 144.9590017,
          "hours": "24/7"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Branch",
          "isDeposit": true,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "SmartATM",
          "address3": "Melbourne NAB House",
          "id": 5058837,
          "key": "atm_3S67",
          "description": "National Bank House",
          "address1": "500 Bourke Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.8154128,
          "longitude": 144.9590017,
          "hours": "24/7"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Branch",
          "isDeposit": true,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "SmartATM",
          "address3": "Midtown Plaza",
          "address4": "Shop 8",
          "id": 5058842,
          "key": "atm_3S72",
          "description": "Midtown Plaza",
          "address1": "186 Swanston Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.8131315,
          "longitude": 144.9654723,
          "hours": "24/7"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Offsite",
          "isDeposit": false,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "NAB ATM",
          "address3": "Midtown Plaza",
          "id": 5059024,
          "key": "atm_4G04",
          "description": "Midtown Plaza",
          "address1": "194 Swanston Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.8130332,
          "longitude": 144.9654279,
          "hours": "Mon-Tue 09.30am-05.30pm, Wed-Fri 09.30am-09.00pm, Sat 09.30am-05.30pm, Sun 11.00am-05.00pm"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Branch",
          "isDeposit": true,
          "isDisabilityApproved": true,
          "isAudio": false,
          "source": "BOQ ATM",
          "id": 5059452,
          "key": "atm_9036021I",
          "description": "455 Bourke Street",
          "address1": "455 Bourke Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.81518,
          "longitude": 144.960583
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Branch",
          "isDeposit": false,
          "isDisabilityApproved": false,
          "isAudio": false,
          "source": "rediATM",
          "id": 5060659,
          "key": "atm_C11243",
          "description": "Bourke Street",
          "address1": "460 Bourke Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.81494,
          "longitude": 144.96002,
          "hours": "24/7"
        }
      },
      {
        "apiStructType": "atm",
        "atm": {
          "location": "Offsite",
          "isDeposit": false,
          "isDisabilityApproved": false,
          "isAudio": false,
          "source": "rediATM",
          "address3": "Emporium Melbourne",
          "address5": "ATM 02",
          "id": 5060908,
          "key": "atm_C11662",
          "description": "Emporium Melbourne",
          "address1": "269-321 Lonsdale Street",
          "suburb": "Melbourne",
          "state": "VIC",
          "postcode": "3000",
          "latitude": -37.811932,
          "longitude": 144.963648,
          "hours": "Mon-Wed 10.00am-07.00pm, Thu-Fri 10.00am-09.00pm, Sat-Sun 10.00am-07.00pm"
        }
      }
    ]
  },
  "status": {
    "code": "API-200",
    "message": "Success"
  }
}

Wednesday, 11 January 2017

Configuring Spring Boot Actuator information in Pivotal Cloud Foundry 1.9 Applications Manager

With the release of Pivotal Cloud Foundry 1.9 we added "Spring Boot Actuator In PCF" through Applications Manager Web UI. In this example below I will show what config you need on your application side to get Apps Manager Web UI to show you this information.

Spring Boot Actuator exposes information about a running Spring Boot application via an http endpoint. Get useful diagnostics about an app programmatically using these RESTful APIs:  health, git commit, build information, and so on. Now, developers can view some of this data in PCF Apps Manager. It’s easier to debug and monitor your apps in production, since Apps Manager shows this diagnostics info in context.

The steps are are described here BUT the steps below are more detailed and provide a sample application to verify this with.

http://docs.pivotal.io/pivotalcf/1-9/console/spring-boot-actuators.html

1. Add the maven dependency "spring-boot-starter-actuator" to your pom.xml
  
<dependencies>
    <dependency> 
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
</dependencies>

2. Ensure your using Spring Boot 1.5 snapshots/release candidates/final as earlier versions won't work.
  
<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.5.0.BUILD-SNAPSHOT</version>
  <relativePath/> <!-- lookup parent from repository -->
</parent>

https://spring.io/blog/2017/01/06/spring-boot-1-5-0-rc1-available-now

3. Configure the Info Actuator as per link below

http://docs.pivotal.io/pivotalcf/1-9/console/spring-boot-actuators.html#info-endpoint

Note: It will differ depending on if your using Maven or Gradle

Ensure you add this property for GIT integration in your YML file or properties file, YML example

management:
  info:
    git:
      mode: full

4. The following demo below has the required setup for verification application , clone and push to CF as shown below.

Note: review pom.xml for everything that is needed for this to work

https://github.com/papicella/SpringBootPCFPas

$ git clone https://github.com/papicella/SpringBootPCFPas.git
$ mvn package
$ cf push -f manifest-inmemory-db.yml

....

0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running

App started


OK

App pas-springboot-pcf was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.2_RELEASE -memorySizes=metaspace:64m..,stack:228k.. -memoryWeights=heap:65,metaspace:10,native:15,stack:10 -memoryInitials=heap:100%,metaspace:100% -stackThreads=300 -totMemory=$MEMORY_LIMIT) && JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY -Djava.security.egd=file:///dev/urando" && SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/java $JAVA_OPTS -cp $PWD/. org.springframework.boot.loader.JarLauncher`

Showing health and status for app pas-springboot-pcf in org pivot-papicella / space development as papicella@pivotal.io...
OK

requested state: started
instances: 1/1
usage: 1G x 1 instances
urls: pas-springboot-pcf-squireless-clicha.cfapps.pez.pivotal.io
last uploaded: Wed Jan 11 03:59:24 UTC 2017
stack: cflinuxfs2
buildpack: java-buildpack=v3.10-offline-https://github.com/cloudfoundry/java-buildpack.git#193d6b7 java-main java-opts open-jdk-like-jre=1.8.0_111 open-jdk-like-memory-calculator=2.0.2_RELEASE spring-auto-reconfiguration=1.10.0_RELEASE

     state     since                    cpu      memory         disk           details
#0   running   2017-01-11 03:00:18 PM   207.1%   489.9M of 1G   161.7M of 1G

5. View the application in Application Manager UI as shown below and you will see that a Spring Icon appears next to the application name



More Screen Shots





More Information

http://docs.pivotal.io/pivotalcf/1-9/console/spring-boot-actuators.html

Monday, 9 January 2017

Spring Boot Application Consuming NAB FxRates API

National Australia Bank (NAB) recently released a set of BETA API's as per the link below.

https://developer.nab.com.au/

The following example is a Spring Boot Application that consumes the FxRates API. It's all documented on GitHub and you will need a NAB API key to run this demo. It can run stand alone as a FAT JAR through Spring Boot or deployed to Cloud Foundry, instructions appear for both.

https://github.com/papicella/NABApi-fx-demo