feat(positionstack): Add reverse geocoding action
This commit is contained in:
		
							
								
								
									
										3
									
								
								packages/backend/src/apps/positionstack/actions/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								packages/backend/src/apps/positionstack/actions/index.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| import reverseGeocoding from './reverse-geocoding'; | ||||
|  | ||||
| export default [reverseGeocoding]; | ||||
| @@ -0,0 +1,35 @@ | ||||
| import defineAction from '../../../../helpers/define-action'; | ||||
|  | ||||
| export default defineAction({ | ||||
|   name: 'Reverse Geocoding', | ||||
|   key: 'reverseGeocoding', | ||||
|   description: 'Get the address of a location from its longitude and latitude.', | ||||
|   arguments: [ | ||||
|     { | ||||
|       label: 'Longitude', | ||||
|       key: 'longitude', | ||||
|       type: 'string' as const, | ||||
|       required: true, | ||||
|       description: 'Longitude of the location.', | ||||
|       variables: true, | ||||
|     }, | ||||
|     { | ||||
|       label: 'Latitude', | ||||
|       key: 'latitude', | ||||
|       type: 'string' as const, | ||||
|       required: true, | ||||
|       description: 'Latitude of the location.', | ||||
|       variables: true, | ||||
|     }, | ||||
|   ], | ||||
|  | ||||
|   async run($) { | ||||
|     const response = await $.http.get( | ||||
|       `/reverse?access_key=${$.auth.data.apiKey}&query=${$.step.parameters.longitude},${$.step.parameters.latitude}` | ||||
|     ); | ||||
|  | ||||
|     $.setActionItem({ | ||||
|       raw: response.data.data[0], | ||||
|     }); | ||||
|   }, | ||||
| }); | ||||
| @@ -0,0 +1,4 @@ | ||||
| <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||||
| <path d="M12 21C15.5 17.4 19 14.1764 19 10.2C19 6.22355 15.866 3 12 3C8.13401 3 5 6.22355 5 10.2C5 14.1764 8.5 17.4 12 21Z" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/> | ||||
| <path d="M12 12C13.1046 12 14 11.1046 14 10C14 8.89543 13.1046 8 12 8C10.8954 8 10 8.89543 10 10C10 11.1046 10.8954 12 12 12Z" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/> | ||||
| </svg> | ||||
| After Width: | Height: | Size: 526 B | 
							
								
								
									
										33
									
								
								packages/backend/src/apps/positionstack/auth/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								packages/backend/src/apps/positionstack/auth/index.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| import verifyCredentials from './verify-credentials'; | ||||
| import isStillVerified from './is-still-verified'; | ||||
|  | ||||
| export default { | ||||
|   fields: [ | ||||
|     { | ||||
|       key: 'screenName', | ||||
|       label: 'Screen Name', | ||||
|       type: 'string' as const, | ||||
|       required: true, | ||||
|       readOnly: false, | ||||
|       value: null, | ||||
|       placeholder: null, | ||||
|       description: | ||||
|         'Screen name of your connection to be used on Automatisch UI.', | ||||
|       clickToCopy: false, | ||||
|     }, | ||||
|     { | ||||
|       key: 'apiKey', | ||||
|       label: 'API Key', | ||||
|       type: 'string' as const, | ||||
|       required: true, | ||||
|       readOnly: false, | ||||
|       value: null, | ||||
|       placeholder: null, | ||||
|       description: 'Positionstack API Key of your account.', | ||||
|       clickToCopy: false, | ||||
|     }, | ||||
|   ], | ||||
|  | ||||
|   verifyCredentials, | ||||
|   isStillVerified, | ||||
| }; | ||||
| @@ -0,0 +1,9 @@ | ||||
| import { IGlobalVariable } from '@automatisch/types'; | ||||
| import verifyCredentials from './verify-credentials'; | ||||
|  | ||||
| const isStillVerified = async ($: IGlobalVariable) => { | ||||
|   await verifyCredentials($); | ||||
|   return true; | ||||
| }; | ||||
|  | ||||
| export default isStillVerified; | ||||
| @@ -0,0 +1,13 @@ | ||||
| import { IGlobalVariable } from '@automatisch/types'; | ||||
|  | ||||
| const verifyCredentials = async ($: IGlobalVariable) => { | ||||
|   await $.http.get( | ||||
|     `/reverse?access_key=${$.auth.data.apiKey}&query=50.94852,6.944772` | ||||
|   ); | ||||
|  | ||||
|   await $.auth.set({ | ||||
|     screenName: $.auth.data.screenName, | ||||
|   }); | ||||
| }; | ||||
|  | ||||
| export default verifyCredentials; | ||||
							
								
								
									
										0
									
								
								packages/backend/src/apps/positionstack/index.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								packages/backend/src/apps/positionstack/index.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										16
									
								
								packages/backend/src/apps/positionstack/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								packages/backend/src/apps/positionstack/index.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| import defineApp from '../../helpers/define-app'; | ||||
| import auth from './auth'; | ||||
| import actions from './actions'; | ||||
|  | ||||
| export default defineApp({ | ||||
|   name: 'Positionstack', | ||||
|   key: 'positionstack', | ||||
|   iconUrl: '{BASE_URL}/apps/positionstack/assets/favicon.svg', | ||||
|   authDocUrl: 'https://automatisch.io/docs/apps/positionstack/connection', | ||||
|   supportsConnections: true, | ||||
|   baseUrl: 'https://positionstack.com', | ||||
|   apiBaseUrl: 'http://api.positionstack.com/v1', | ||||
|   primaryColor: '0d2d45', | ||||
|   auth, | ||||
|   actions, | ||||
| }); | ||||
		Reference in New Issue
	
	Block a user
	 Faruk AYDIN
					Faruk AYDIN