From a6de669ccaeead94d8bf98a32df55d85a27d8eea Mon Sep 17 00:00:00 2001 From: Sathish Date: Wed, 15 Mar 2017 20:43:04 +0530 Subject: [PATCH 1/3] purescript warpper for googleplaces --- .gitignore | 22 +++++++++++++++ bower.json | 28 +++++++++++++++++++ package.json | 12 ++++++++ src/RNGooglePlaces.js | 62 +++++++++++++++++++++++++++++++++++++++++ src/RNGooglePlaces.purs | 60 +++++++++++++++++++++++++++++++++++++++ yarn.lock | 6 ++++ 6 files changed, 190 insertions(+) create mode 100644 .gitignore create mode 100644 bower.json create mode 100644 package.json create mode 100644 src/RNGooglePlaces.js create mode 100644 src/RNGooglePlaces.purs create mode 100644 yarn.lock diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e8bdb0c --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +repl-temp-* +.pulp* +dist +cabal-dev +.cabal-sandbox +cabal.sandbox.config +*.o +*.hi +*.chi +*.chs.h +*.lksh* +.virthualenv +.psci_modules/ +.test_modules/ +bower_components/ +node_modules +tmp/ +.stack-work/ +output +examples/docs/docs/ +core-tests/full-core-docs.md +.psc-ide-port diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..7359e2e --- /dev/null +++ b/bower.json @@ -0,0 +1,28 @@ +{ + "name": "purescript-rnx-google-places", + "description": "Purescript wrapper for react-native-google-places", + "main": "index.js", + "authors": [ + "Sathish Kumar " + ], + "license": "MIT", + "keywords": [ + "purescript", + "rnx", + "react-native", + "google-places" + ], + "homepage": "", + "private": true, + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "dependencies": { + "purescript-rnx" : "^0.1.2-alpha", + "purescript-react": "^2.0.0" + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..adeba1f --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "purescript-rnx-google-places", + "version": "1.0.0", + "description": "Purescript wrapper for react-native-google-places", + "main": "index.js", + "repository": "atomicits/purescript-google-places", + "author": "Sathish Kumar ", + "license": "MIT", + "dependencies": { + "react-native-google-places": "^2.0.9" + } +} diff --git a/src/RNGooglePlaces.js b/src/RNGooglePlaces.js new file mode 100644 index 0000000..e3dd51c --- /dev/null +++ b/src/RNGooglePlaces.js @@ -0,0 +1,62 @@ +'use strict'; + +var rnxGooglePlaces = require("react-native-google-places"); + +exports._openAutocompleteModal = function(filterOptions){ + return function(success_callback){ + return function(error_callback){ + return function(){ + rnxGooglePlaces._openAutocompleteModal(filterOptions).then(function(resData){ + success_callback(resData)(); + }).catch(function(error){ + error_callback(error)(); + }); + }; + }; + }; +}; + +exports._openPlacePickerModal = function(boundsOptions){ + return function(success_callback){ + return function(error_callback){ + return function(){ + rnxGooglePlaces._openPlacePickerModal(boundsOptions).then(function (resData){ + success_callback (resData)(); + }).catch(function (error){ + error_callback(error)(); + }); + }; + }; + }; +}; + + +exports._getAutocompletePredictions = function(queryOptions){ + return function(success_callback){ + return function(error_callback){ + return function(){ + rnxGooglePlaces._getAutocompletePredictions(queryOptions).then(function (resData){ + success_callback (resData)(); + }).catch(function (error){ + error_callback(error)(); + }); + }; + }; + }; +}; + + + +exports._lookUpPlaceByID = function(placeID){ + return function(success_callback){ + return function(error_callback){ + return function(){ + rnxGooglePlaces._lookUpPlaceByID(placeID).then(function (resData){ + success_callback(resData)(); + }).catch(function(error){ + error_callback(error)(); + }); + }; + }; + }; +}; diff --git a/src/RNGooglePlaces.purs b/src/RNGooglePlaces.purs new file mode 100644 index 0000000..de3e176 --- /dev/null +++ b/src/RNGooglePlaces.purs @@ -0,0 +1,60 @@ +module RNGooglePlaces where + +import Prelude + +import Control.Monad.Aff (Aff, attempt, makeAff) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Exception (Error) +import Data.Either (Either) +import Unsafe.Coerce (unsafeCoerce) + +foreign import data FilterOptions :: * +foreign import data BoundOptions :: * +foreign import data Query :: * + +filterType :: forall a. a -> FilterOptions +filterType = unsafeCoerce + +boundType :: forall a. a -> BoundOptions +boundType = unsafeCoerce + +queryType :: forall a. a -> Query +queryType = unsafeCoerce + +newtype PlaceId = PlaceId String + +foreign import _openAutocompleteModal :: + forall e scallback ecallback. FilterOptions + -> scallback + -> ecallback + -> Eff e Unit + +foreign import _openPlacePickerModal :: + forall e scallback ecallback. BoundOptions + -> scallback + -> ecallback + -> Eff e Unit + +foreign import _getAutocompletePredictions :: + forall e scallback ecallback. Query + -> scallback + -> ecallback + -> Eff e Unit + +foreign import _lookUpPlaceByID :: + forall e scallback ecallback. PlaceId + -> scallback + -> ecallback + -> Eff e Unit + +openautoCompleteModal :: forall a b. FilterOptions -> Aff b (Either Error a) +openautoCompleteModal opt = attempt $ makeAff (\error success -> _openAutocompleteModal opt success error) + +openplacePickerModal :: forall a b. BoundOptions -> Aff b (Either Error a) +openplacePickerModal opt = attempt $ makeAff (\error success -> _openPlacePickerModal opt success error) + +getautocompletePredictions :: forall a b. Query -> Aff b (Either Error a) +getautocompletePredictions opt = attempt $ makeAff (\error success -> _getAutocompletePredictions opt success error) + +lookUpPlaceByID :: forall b. PlaceId -> Aff b (Either Error String) +lookUpPlaceByID opt = attempt $ makeAff (\error success -> _lookUpPlaceByID opt success error) diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..2d77ca2 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,6 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 +react-native-google-places@^2.0.9: + version "2.0.9" + resolved "https://registry.yarnpkg.com/react-native-google-places/-/react-native-google-places-2.0.9.tgz#4df2ad5ac930d1f99e3b7ada3a4cd04f1627c143" + From bc16eeed6127eb675027b5064f15f97091e98e7c Mon Sep 17 00:00:00 2001 From: Sathish Date: Thu, 16 Mar 2017 11:03:52 +0530 Subject: [PATCH 2/3] Types are changed --- src/RNGooglePlaces.js | 8 +++--- src/RNGooglePlaces.purs | 63 +++++++++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/RNGooglePlaces.js b/src/RNGooglePlaces.js index e3dd51c..5be03a4 100644 --- a/src/RNGooglePlaces.js +++ b/src/RNGooglePlaces.js @@ -6,7 +6,7 @@ exports._openAutocompleteModal = function(filterOptions){ return function(success_callback){ return function(error_callback){ return function(){ - rnxGooglePlaces._openAutocompleteModal(filterOptions).then(function(resData){ + rnxGooglePlaces.openAutocompleteModal(filterOptions).then(function(resData){ success_callback(resData)(); }).catch(function(error){ error_callback(error)(); @@ -20,7 +20,7 @@ exports._openPlacePickerModal = function(boundsOptions){ return function(success_callback){ return function(error_callback){ return function(){ - rnxGooglePlaces._openPlacePickerModal(boundsOptions).then(function (resData){ + rnxGooglePlaces.openPlacePickerModal(boundsOptions).then(function (resData){ success_callback (resData)(); }).catch(function (error){ error_callback(error)(); @@ -35,7 +35,7 @@ exports._getAutocompletePredictions = function(queryOptions){ return function(success_callback){ return function(error_callback){ return function(){ - rnxGooglePlaces._getAutocompletePredictions(queryOptions).then(function (resData){ + rnxGooglePlaces.getAutocompletePredictions(queryOptions).then(function (resData){ success_callback (resData)(); }).catch(function (error){ error_callback(error)(); @@ -51,7 +51,7 @@ exports._lookUpPlaceByID = function(placeID){ return function(success_callback){ return function(error_callback){ return function(){ - rnxGooglePlaces._lookUpPlaceByID(placeID).then(function (resData){ + rnxGooglePlaces.lookUpPlaceByID(placeID).then(function (resData){ success_callback(resData)(); }).catch(function(error){ error_callback(error)(); diff --git a/src/RNGooglePlaces.purs b/src/RNGooglePlaces.purs index de3e176..15ce5a5 100644 --- a/src/RNGooglePlaces.purs +++ b/src/RNGooglePlaces.purs @@ -6,23 +6,55 @@ import Control.Monad.Aff (Aff, attempt, makeAff) import Control.Monad.Eff (Eff) import Control.Monad.Eff.Exception (Error) import Data.Either (Either) -import Unsafe.Coerce (unsafeCoerce) -foreign import data FilterOptions :: * -foreign import data BoundOptions :: * -foreign import data Query :: * -filterType :: forall a. a -> FilterOptions -filterType = unsafeCoerce +type FilterOptions = + { type :: String + , country :: String + , latitude :: Number + , longitude :: Number + , radius :: Number + , useOverlay :: Number + } -boundType :: forall a. a -> BoundOptions -boundType = unsafeCoerce +type BoundOptions = + { latitude :: Number + , longitude :: Number + , radius :: Number + } -queryType :: forall a. a -> Query -queryType = unsafeCoerce +type Query = + { type :: String + , country :: String + , latitude :: Number + , longitude :: Number + , radius :: Number + } newtype PlaceId = PlaceId String +type ResponseModal = + { placeID :: String + , website :: String + , phoneNumber :: String + , address :: String + , name :: String + , types :: Array String + , latitude :: Number + , longitude :: Number + } + +type AutocompletePredictionsResponseModal = Array APResponseModal + +type APResponseModal = + { primaryText :: String + , placeID :: String + , secondaryText :: String + , fullText :: String + , types :: Array String + } + + foreign import _openAutocompleteModal :: forall e scallback ecallback. FilterOptions -> scallback @@ -47,14 +79,15 @@ foreign import _lookUpPlaceByID :: -> ecallback -> Eff e Unit -openautoCompleteModal :: forall a b. FilterOptions -> Aff b (Either Error a) + +openautoCompleteModal :: forall eff. FilterOptions -> Aff eff (Either Error ResponseModal) openautoCompleteModal opt = attempt $ makeAff (\error success -> _openAutocompleteModal opt success error) -openplacePickerModal :: forall a b. BoundOptions -> Aff b (Either Error a) +openplacePickerModal :: forall eff. BoundOptions -> Aff eff (Either Error ResponseModal) openplacePickerModal opt = attempt $ makeAff (\error success -> _openPlacePickerModal opt success error) -getautocompletePredictions :: forall a b. Query -> Aff b (Either Error a) +getautocompletePredictions :: forall eff. Query -> Aff eff (Either Error AutocompletePredictionsResponseModal) getautocompletePredictions opt = attempt $ makeAff (\error success -> _getAutocompletePredictions opt success error) -lookUpPlaceByID :: forall b. PlaceId -> Aff b (Either Error String) -lookUpPlaceByID opt = attempt $ makeAff (\error success -> _lookUpPlaceByID opt success error) +lookUpPlaceByID :: forall eff. PlaceId -> Aff eff (Either Error ResponseModal) +lookUpPlaceByID (PlaceId opt) = attempt $ makeAff (\error success -> _lookUpPlaceByID (PlaceId opt) success error) From 931c64b703ff14a43c00863ebb06972e9244bcfb Mon Sep 17 00:00:00 2001 From: Sathish Date: Thu, 16 Mar 2017 15:42:32 +0530 Subject: [PATCH 3/3] lookUpPlaceByID type is changed --- bower.json | 4 +--- src/RNGooglePlaces.purs | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/bower.json b/bower.json index 7359e2e..08501e6 100644 --- a/bower.json +++ b/bower.json @@ -2,9 +2,7 @@ "name": "purescript-rnx-google-places", "description": "Purescript wrapper for react-native-google-places", "main": "index.js", - "authors": [ - "Sathish Kumar " - ], + "authors": "Sathish Kumar ", "license": "MIT", "keywords": [ "purescript", diff --git a/src/RNGooglePlaces.purs b/src/RNGooglePlaces.purs index 15ce5a5..6936968 100644 --- a/src/RNGooglePlaces.purs +++ b/src/RNGooglePlaces.purs @@ -31,7 +31,7 @@ type Query = , radius :: Number } -newtype PlaceId = PlaceId String +newtype PlaceId = PlaceId String type ResponseModal = { placeID :: String @@ -90,4 +90,4 @@ getautocompletePredictions :: forall eff. Query -> Aff eff (Either Error Autocom getautocompletePredictions opt = attempt $ makeAff (\error success -> _getAutocompletePredictions opt success error) lookUpPlaceByID :: forall eff. PlaceId -> Aff eff (Either Error ResponseModal) -lookUpPlaceByID (PlaceId opt) = attempt $ makeAff (\error success -> _lookUpPlaceByID (PlaceId opt) success error) +lookUpPlaceByID opt = attempt $ makeAff (\error success -> _lookUpPlaceByID opt success error)