forked from PipedreamHQ/pipedream
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PipedreamHQ#4856 - Yelp new actions (PipedreamHQ#4948)
* Yelp structure with first action * 'Search Businesses' with pagination complete * Adding more search props * Refining summary for search action * Moving doc links to constants * Search businesses by phone number * "Get Business Details" and improvements * List Business Reviews + improvements * ESLint * Incrementing package.json version
- Loading branch information
Showing
10 changed files
with
628 additions
and
8 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
components/yelp/actions/get-business-details/get-business-details.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { defineAction } from "@pipedream/types"; | ||
import yelp from "../../app/yelp.app"; | ||
import { | ||
DEVICE_OPTIONS, DOCS, | ||
} from "../../common/constants"; | ||
import { | ||
Business, GetBusinessDetailsParams, | ||
} from "../../common/types"; | ||
|
||
export default defineAction({ | ||
name: "Get Business Details", | ||
description: `Get details about a business [See docs here](${DOCS.getBusinessDetails})`, | ||
key: "yelp-get-business-details", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
yelp, | ||
businessIdOrAlias: { | ||
propDefinition: [ | ||
yelp, | ||
"businessIdOrAlias", | ||
], | ||
}, | ||
devicePlatform: { | ||
label: "Device Platform", | ||
description: "Determines the platform for mobile_link", | ||
type: "string", | ||
options: DEVICE_OPTIONS, | ||
optional: true, | ||
}, | ||
locale: { | ||
propDefinition: [ | ||
yelp, | ||
"locale", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
businessIdOrAlias, devicePlatform: device_platform, locale, | ||
} = this; | ||
|
||
const params: GetBusinessDetailsParams = { | ||
$, | ||
businessIdOrAlias, | ||
params: { | ||
device_platform, | ||
locale, | ||
}, | ||
}; | ||
|
||
const business: Business = await this.yelp.getBusinessDetails(params); | ||
|
||
$.export("$summary", `Obtained details for business "${business.name}"`); | ||
|
||
return business; | ||
}, | ||
}); |
64 changes: 64 additions & 0 deletions
64
components/yelp/actions/list-business-reviews/list-business-reviews.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { defineAction } from "@pipedream/types"; | ||
import yelp from "../../app/yelp.app"; | ||
import { DOCS } from "../../common/constants"; | ||
import { | ||
ListBusinessReviewsParams, | ||
ListBusinessReviewsResponse, | ||
} from "../../common/types"; | ||
|
||
export default defineAction({ | ||
name: "List Business Reviews", | ||
description: `List the reviews for a business [See docs here](${DOCS.listBusinessReviews})`, | ||
key: "yelp-list-business-reviews", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
yelp, | ||
businessIdOrAlias: { | ||
propDefinition: [ | ||
yelp, | ||
"businessIdOrAlias", | ||
], | ||
}, | ||
locale: { | ||
propDefinition: [ | ||
yelp, | ||
"locale", | ||
], | ||
}, | ||
sortBy: { | ||
label: "Sort By", | ||
description: "Sort reviews by Yelp's default sorting or newest first.", | ||
type: "string", | ||
options: [ | ||
"yelp_sort", | ||
"newest", | ||
], | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
businessIdOrAlias, locale, sortBy: sort_by, | ||
} = this; | ||
|
||
const params: ListBusinessReviewsParams = { | ||
$, | ||
businessIdOrAlias, | ||
params: { | ||
locale, | ||
sort_by, | ||
}, | ||
}; | ||
|
||
const response: ListBusinessReviewsResponse = | ||
await this.yelp.listBusinessReviews(params); | ||
|
||
$.export( | ||
"$summary", | ||
`Obtained ${response.reviews.length} business reviews`, | ||
); | ||
|
||
return response; | ||
}, | ||
}); |
60 changes: 60 additions & 0 deletions
60
...nents/yelp/actions/search-businesses-by-phone-number/search-businesses-by-phone-number.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { defineAction } from "@pipedream/types"; | ||
import yelp from "../../app/yelp.app"; | ||
import { DOCS } from "../../common/constants"; | ||
import { SearchBusinessesByPhoneResponse } from "../../common/types"; | ||
|
||
export default defineAction({ | ||
name: "Search Businesses By Phone Number", | ||
description: `Search businesses by phone number [See docs here](${DOCS.searchByPhone})`, | ||
key: "yelp-search-businesses-by-phone-number", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
yelp, | ||
phone: { | ||
label: "Phone Number", | ||
description: | ||
"Phone number of the business you want to search for. It must start with `+` and include the country code, like `+14159083801`.", | ||
type: "string", | ||
}, | ||
locale: { | ||
propDefinition: [ | ||
yelp, | ||
"locale", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
locale, phone, | ||
} = this; | ||
|
||
const params = { | ||
$, | ||
params: { | ||
locale, | ||
phone, | ||
}, | ||
}; | ||
|
||
const { businesses }: SearchBusinessesByPhoneResponse = | ||
await this.yelp.searchBusinessesByPhoneNumber(params); | ||
const { length } = businesses; | ||
|
||
let summary: string; | ||
switch (length) { | ||
case 0: | ||
summary = "No businesses found with the given phone number"; | ||
break; | ||
case 1: | ||
summary = `Found business "${businesses[0].name}"`; | ||
break; | ||
default: | ||
summary = `Found ${length} businesses`; | ||
} | ||
|
||
$.export("$summary", summary); | ||
|
||
return businesses; | ||
}, | ||
}); |
135 changes: 135 additions & 0 deletions
135
components/yelp/actions/search-businesses/search-businesses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { defineAction } from "@pipedream/types"; | ||
import yelp from "../../app/yelp.app"; | ||
import { | ||
SearchBusinessesParams, | ||
SearchBusinessesResponse, | ||
} from "../../common/types"; | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
import { | ||
ATTRIBUTE_OPTIONS, DOCS, PRICE_OPTIONS, | ||
} from "../../common/constants"; | ||
|
||
export default defineAction({ | ||
name: "Search Businesses", | ||
description: `Search businesses matching given criteria [See docs here](${DOCS.searchBusinesses})`, | ||
key: "yelp-search-businesses", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
yelp, | ||
location: { | ||
label: "Location", | ||
description: `The geographic area to be used when searching for businesses. Examples: "New York City", "NYC", "350 5th Ave, New York, NY 10118". | ||
\\ | ||
Required if \`latitude\` and \`longitude\` are not provided.`, | ||
type: "string", | ||
optional: true, | ||
}, | ||
latitude: { | ||
label: "Latitude", | ||
description: `Latitude of the location to search from. | ||
\\ | ||
Required if \`location\` is not provided. If \`longitude\` is provided, latitude is required too.`, | ||
type: "string", | ||
optional: true, | ||
}, | ||
longitude: { | ||
label: "Longitude", | ||
description: `Longitude of the location to search from. | ||
\\ | ||
Required if \`location\` is not provided. If \`latitude\` is provided, longitude is required too.`, | ||
type: "string", | ||
optional: true, | ||
}, | ||
term: { | ||
label: "Search Term", | ||
description: "Search term, e.g. \"food\" or \"restaurants\". The term may also be the business's name, such as \"Starbucks\". If term is not included, the action will default to searching across businesses from a small number of popular categories.", | ||
type: "string", | ||
optional: true, | ||
}, | ||
maxResults: { | ||
label: "Max Results", | ||
description: | ||
"The maximum amount of businesses to be listed. Yelp enforces a limit of 1000. Default is 200.", | ||
type: "integer", | ||
max: 1000, | ||
default: 200, | ||
optional: true, | ||
}, | ||
categories: { | ||
label: "Categories", | ||
description: `Categories to filter the search results with. [See the list of supported categories.](${DOCS.categories}) The category alias should be used (e.g. "discgolf", not "Disc Golf").`, | ||
type: "string[]", | ||
optional: true, | ||
}, | ||
price: { | ||
label: "Price", | ||
description: "Pricing levels to filter the search result with.", | ||
type: "integer[]", | ||
optional: true, | ||
options: PRICE_OPTIONS, | ||
}, | ||
attributes: { | ||
label: "Attributes", | ||
description: | ||
"Additional filters to return specific search results. If multiple attributes are used, only businesses that satisfy all the attributes will be returned.", | ||
type: "string[]", | ||
optional: true, | ||
options: ATTRIBUTE_OPTIONS, | ||
}, | ||
additionalOptions: { | ||
label: "Additional Options", | ||
description: `Additional parameters to pass in the request, such as \`open_now\`. [See the docs for all the parameters.](${DOCS.searchBusinesses})`, | ||
type: "object", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
additionalOptions, | ||
attributes, | ||
categories, | ||
location, | ||
latitude, | ||
longitude, | ||
maxResults, | ||
price, | ||
term, | ||
} = this; | ||
if (!(location || (latitude && longitude))) { | ||
throw new ConfigurationError( | ||
"Either `location`, or `latitude` and `longitude`, must be provided.", | ||
); | ||
} | ||
|
||
const params: SearchBusinessesParams = { | ||
$, | ||
params: { | ||
attributes: attributes?.join(), | ||
categories: categories?.join(), | ||
location, | ||
latitude, | ||
longitude, | ||
term, | ||
maxResults, | ||
price: price?.join(), | ||
...additionalOptions, | ||
}, | ||
}; | ||
|
||
const response: SearchBusinessesResponse = await this.yelp.searchBusinesses( | ||
params, | ||
); | ||
const { result: { length } } = response; | ||
|
||
const summary = length | ||
? `Listed ${length} business${length === 1 | ||
? "" | ||
: "es"}` | ||
: "No businesses found with the given criteria"; | ||
|
||
$.export("$summary", summary); | ||
|
||
return response; | ||
}, | ||
}); |
Oops, something went wrong.