forked from mywebguydave/leafly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
186 lines (170 loc) · 5.9 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
(function() {
'use strict';
var leafly = require('leafly');
var APP_KEY = 'YOUR_APP_KEY', APP_ID = 'YOUR_APP_ID';
// Examples of the Strains API
// Search for strains with specific properties or text in the name
// Find recently added blueberry-flavored strains
// Returns a specified list of strains according to search values
// See Appendix A below for full list of filter values
leafly.search('strains',
{
page: 0, // required
take: 20, // required - how many results to return - max amount that can be taken is 50
search: 'blue', // optional - text to search for in strain name
sort: 'newest', // optional - sort by rating, alpha, newest, popular
filters: { // optional - filters
flavors: ['blueberry'],
category: ['hybrid'],
exclude: ['dry-mouth'],
conditions: ['anxiety'],
tags: ['anxious'],
symptoms: ['stress']
},
app_key: APP_KEY, // required
app_id: APP_ID // required
}).then(function(strains) {
console.log(strains);
}).catch(function(err) {
console.error(err);
});
// This operation returns high-level information about each strain.
// Details include a description, number of reviews, overall review score (out of 10), flavors, and effect information.
leafly.strain('girl scout cookie',
{
app_key: APP_KEY, // required
app_id: APP_ID // required
}).then(function(strain) {
console.log(strain);
}).catch(function(err) {
console.error(err);
});
// Retrieve user reviews for specified strain.
// Returns a list of reviews
leafly.reviews('strains', 'pineapple express',
{
page: 0, // required
take: 20, // required - how many results to return - max amount that can be taken is 20
sort: 'rating', // optional - can be 'date' or 'rating' - defaults to 'date' if not defined
app_key: APP_KEY, // required
app_id: APP_ID // required
}).then(function(reviews) {
console.log(reviews);
}).catch(function(err) {
console.error(err);
});
// Get more detailed information about a single review
// Returns a detailed review object
leafly.review('pineapple express',
{
reviewid: 13072, // required
app_key: APP_KEY, // required
app_id: APP_ID // required
}).then(function(review) {
console.log(review);
}).catch(function(err) {
console.error(err);
});
// Retrieve pictures of specified strain
// Returns a list of pictures
leafly.pictures('gods gift',
{
page: 0, // required
take: 20, // required - how many results to return - max amount that can be taken is 20
app_key: APP_KEY, // required
app_id: APP_ID // required
}).then(function(pictures) {
console.log(pictures);
}).catch(function(err) {
console.error(err);
});
// Find dispensaries and retail locations that have the strain on their menu.
// Returns a list of available dispensaries and locations or [] if not found
leafly.availability('ak-47',
{
lat: 32.7150, // required - latitude
lon: -117.1625, // required - longitude
radius: 50, // optional - in miles, default is 20
filter: 'flower', // optional - filter by type 'flower', 'clone', 'preroll', 'seeds',
// 'edible', 'concentrate', 'other'
app_key: APP_KEY, // required
app_id: APP_ID // required
}).then(function(locations) {
console.log(locations);
}).catch(function(err) {
console.error(err);
});
// Examples of the Locations API
// Search for dispensaries, deliveries, and retail stores within 20 miles of provided latitude & longitude.
// Returns a specific list of locations according to search values
leafly.search('locations',
{
page: 0, // required
take: 10, // required - how many results to return - max amount that can be taken is 50
latitude: 47.607, // required
longitude: -122.333, // required
storefront: false, // optional - Only return results with physical locations
delivery: false, // optional - Only return delivery services
retail: false, // optional - Only return retail locations (for CO & WA)
medical: false, // optional - Only return medical dispensaries
creditcards: false, // optional - Return locations that accept credit cards on site
hasclones: false, // optional - Only locations with clones available
hasconcentrates: false, // optional - Only locations with concentrates on the menu
hasedibles: false, // optional - Only locations with edibles on the menu
veterandiscount: false, // optional - Only locations that offer a discount for veterans
// strainIds: '14201,12322' // optional - Returns only locations that have specific strains on the menu. If multiple strains
// are specified, results are OR'd together.
app_key: APP_KEY, // required
app_id: APP_ID // required
}).then(function(locations) {
console.log(locations);
}).catch(function(err) {
console.error(err);
});
// Information about dispensary or retail locations
// Returns a location object with details about the dispensary or location
leafly.location('denver relief',
{
app_key: APP_KEY,
app_id: APP_ID
}).then(function(location) {
console.log(location);
}).catch(function(err) {
console.error(err);
});
// Get the menu of specified location
// Returns the entire menu of the specified location
leafly.menu('denver relief',
{
app_key: APP_KEY,
app_id: APP_ID
}).then(function(location) {
console.log(location);
}).catch(function(err) {
console.error(err);
});
// List of reviews for location
// Returns a list of reviews for the specified location
leafly.reviews('locations', 'denver relief',
{
skip: 0, // required
take: 10, // required - max amount that can be taken is 20
app_key: APP_KEY, // required
app_id: APP_ID // required
}).then(function(reviews) {
console.log(reviews);
}).catch(function(err) {
console.error(err);
});
// List of specials for location
// Returns a list of specials for the specified location
leafly.specials('denver relief',
{
app_key: APP_KEY, // required
app_id: APP_ID // required
}).then(function(specials) {
console.log(specials);
}).catch(function(err) {
console.error(err);
});
})();