leafly_api_wrapper 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/leafly_api_wrapper.gemspec +1 -0
- data/lib/leafly_api_wrapper/feed_mapper/location_detail_mapper.json +36 -0
- data/lib/leafly_api_wrapper/feed_mapper/location_search_mapper.json +37 -0
- data/lib/leafly_api_wrapper/location.rb +41 -39
- data/lib/leafly_api_wrapper/mapper.rb +26 -0
- data/lib/leafly_api_wrapper/version.rb +1 -1
- data/lib/leafly_api_wrapper.rb +1 -0
- data/spec/json_responses/locations_search_result.json +53 -0
- data/spec/json_responses/single_location_result.json +117 -0
- data/spec/leafly_api_wrapper_spec.rb +4 -4
- data/spec/location_spec.rb +41 -0
- data/spec/mapper_spec.rb +59 -0
- data/spec/spec_helper.rb +0 -1
- metadata +27 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 683238eeb734154d684a95e6273b1e8bd9038f4b
|
4
|
+
data.tar.gz: 232e6ffdf02f042ea9f06de2e45333a8f9b1a226
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45c75518efd0d8b6212a747ab4767a8d58f3256d636b8bfac0c6c2fd9538f5f392f24e153f1adf58e2d2f3def4b5561e6feefe87e9b8bbe4d35a8cc0470d5d1c
|
7
|
+
data.tar.gz: c621b9be171eb8c4eb2db0d5b38859033b595296e7a5ed0393649545025c0b24602c0a3d04354ddb0ad64d70cbd4a6b6fdb004f00a781aadd81d7b510bdd0d4c
|
data/leafly_api_wrapper.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
22
22
|
spec.add_development_dependency 'rake', '~> 0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 0'
|
23
24
|
spec.add_development_dependency 'vcr', '~> 0'
|
24
25
|
spec.add_development_dependency 'webmock', '~> 0'
|
25
26
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
{
|
2
|
+
"id": "id",
|
3
|
+
"slug": "slug",
|
4
|
+
"name": "name",
|
5
|
+
"atm": "atm",
|
6
|
+
"creditCards": "creditCards",
|
7
|
+
"veteranDiscount": "veteranDiscount",
|
8
|
+
"ada": "ada",
|
9
|
+
"delivery": "delivery",
|
10
|
+
"retail": "retail",
|
11
|
+
"medical": "medical",
|
12
|
+
"storefront": "storefront",
|
13
|
+
"logo": "logo",
|
14
|
+
"address": [ "address1", "address2" ],
|
15
|
+
"city": "city",
|
16
|
+
"state": "state",
|
17
|
+
"zip": "zip",
|
18
|
+
"phone": "phone",
|
19
|
+
"hours": "hours",
|
20
|
+
"website": "website",
|
21
|
+
"desription": "blurb",
|
22
|
+
"latitude": "latitude",
|
23
|
+
"longitude": "longitude",
|
24
|
+
"photos": "photos",
|
25
|
+
"permalink": "permalink",
|
26
|
+
"canadaLP": "canadaLP",
|
27
|
+
"tagLine": "tagLine",
|
28
|
+
"tagLineBlurb": "tagLineBlurb",
|
29
|
+
"facebookUrl": "facebookUrl",
|
30
|
+
"twitterUrl": "twitterUrl",
|
31
|
+
"googlePlusUrl": "googlePlusUrl",
|
32
|
+
"pinterestUrl": "pinterestUrl",
|
33
|
+
"tumblrUrl": "tumblrUrl",
|
34
|
+
"instagramUrl": "instagramUrl",
|
35
|
+
"specials": "specialsList"
|
36
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"id": "id",
|
3
|
+
"slug": "slug",
|
4
|
+
"name": "name",
|
5
|
+
"atm": "atm",
|
6
|
+
"creditCards": "creditCards",
|
7
|
+
"veteranDiscount": "",
|
8
|
+
"ada": "ada",
|
9
|
+
"delivery": "delivery",
|
10
|
+
"retail": "retail",
|
11
|
+
"medical": "medical",
|
12
|
+
"storefront": "storefront",
|
13
|
+
"specials": "specials",
|
14
|
+
"logo": "logo",
|
15
|
+
"address": [ "address", "locationLabel" ],
|
16
|
+
"city": "",
|
17
|
+
"state": "",
|
18
|
+
"zip": "",
|
19
|
+
"phone": "phone",
|
20
|
+
"hours": "hours",
|
21
|
+
"website": "",
|
22
|
+
"description": "",
|
23
|
+
"latitude": "latitude",
|
24
|
+
"longitude": "longitude",
|
25
|
+
"photos": "coverPhoto",
|
26
|
+
"permalink": "permalink",
|
27
|
+
"canadaLP": "canadaLP",
|
28
|
+
"tagLine": "tagLine",
|
29
|
+
"tagLineBlurb": "",
|
30
|
+
"facebookUrl": "",
|
31
|
+
"twitterUrl": "",
|
32
|
+
"googlePlusUrl": "",
|
33
|
+
"pinterestUrl": "",
|
34
|
+
"tumblrUrl": "",
|
35
|
+
"instagramUrl": "",
|
36
|
+
"specials": "specials"
|
37
|
+
}
|
@@ -4,54 +4,53 @@ require "json"
|
|
4
4
|
|
5
5
|
module LeaflyApiWrapper
|
6
6
|
class Location
|
7
|
-
attr_reader :id, :
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
attr_reader :id, :slug, :name, :desription, :tagLine, :tagLineBlurb,
|
8
|
+
:address, :city, :state, :zip,
|
9
|
+
:phone, :hours, :website, :latitude, :longitude,
|
10
|
+
:logo, :photos, :permalink, :specials,
|
11
|
+
:atm, :creditCards, :veteranDiscount, :delivery,
|
12
|
+
:retail, :medical, :storefront, :ada, :canadaLP,
|
13
|
+
:facebookUrl, :twitterUrl, :googlePlusUrl,
|
14
|
+
:pinterestUrl, :tumblrUrl, :instagramUrl
|
15
|
+
|
13
16
|
|
14
17
|
def initialize(data)
|
15
|
-
@id
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
21
|
-
@
|
22
|
-
@locationLabel = data['locationLabel']
|
18
|
+
@id = data['id']
|
19
|
+
@slug = data['slug']
|
20
|
+
@name = data['name']
|
21
|
+
@atm = data['atm']
|
22
|
+
@creditCards = data['creditCards']
|
23
|
+
@veteranDiscount = data['veteranDiscount']
|
24
|
+
@ada = data['ada']
|
23
25
|
@delivery = data['delivery']
|
26
|
+
@retail = data['retail']
|
27
|
+
@medical = data['medical']
|
24
28
|
@storefront = data['storefront']
|
25
|
-
@
|
29
|
+
@logo = data['logo']
|
30
|
+
@address = data['address']
|
31
|
+
@city = data['city']
|
32
|
+
@state = data['state']
|
33
|
+
@zip = data['zip']
|
34
|
+
@phone = data['phone']
|
35
|
+
@hours = data['hours']
|
36
|
+
@website = data['website']
|
37
|
+
@desription = data['desription']
|
26
38
|
@latitude = data['latitude']
|
27
39
|
@longitude = data['longitude']
|
28
|
-
@
|
29
|
-
@
|
30
|
-
@sponsor = data['sponsor']
|
31
|
-
@ada = data['ada']
|
32
|
-
@creditCards = data['creditCards']
|
33
|
-
@atm = data['atm']
|
34
|
-
@marquee = data['marquee']
|
35
|
-
@coverPhoto = data['coverPhoto']
|
36
|
-
@logoId = data['logoId']
|
37
|
-
@logo = data['logo']
|
38
|
-
@medical = data['medical']
|
39
|
-
@retail = data['retail']
|
40
|
-
@price1 = data['price1']
|
41
|
-
@price2 = data['price2']
|
42
|
-
@price3 = data['price3']
|
43
|
-
@mapMarkerLevel = data['mapMarkerLevel']
|
40
|
+
@photos = data['photos']
|
41
|
+
@permalink = data['permalink']
|
44
42
|
@canadaLP = data['canadaLP']
|
45
43
|
@tagLine = data['tagLine']
|
46
|
-
@
|
47
|
-
@
|
48
|
-
@
|
49
|
-
@
|
50
|
-
@
|
44
|
+
@tagLineBlurb = data['tagLineBlurb']
|
45
|
+
@facebookUrl = data['facebookUrl']
|
46
|
+
@twitterUrl = data['twitterUrl']
|
47
|
+
@googlePlusUrl = data['googlePlusUrl']
|
48
|
+
@pinterestUrl = data['pinterestUrl']
|
49
|
+
@tumblrUrl = data['tumblrUrl']
|
50
|
+
@instagramUrl = data['instagramUrl']
|
51
51
|
@specials = data['specials']
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
54
|
def self.near(lat, lon, options = {})
|
56
55
|
response = connection.post '/locations', {
|
57
56
|
page: 0,
|
@@ -60,14 +59,17 @@ module LeaflyApiWrapper
|
|
60
59
|
longitude: lon
|
61
60
|
}.merge(options)
|
62
61
|
|
63
|
-
JSON.parse(response.body)['stores'].collect do |
|
62
|
+
JSON.parse(response.body)['stores'].collect do |raw_data|
|
63
|
+
data = LeaflyApiWrapper::Mapper.new(raw_data, 'location_search').mapped
|
64
64
|
new(data)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
def self.get(slug)
|
69
69
|
res = connection.get "/locations/#{slug}"
|
70
|
-
|
70
|
+
raw_data = JSON.parse(res.body)
|
71
|
+
data = LeaflyApiWrapper::Mapper.new(raw_data, 'location_detail').mapped
|
72
|
+
new(data)
|
71
73
|
end
|
72
74
|
|
73
75
|
private
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# This class helps to unify the key values of the feeds for location into
|
2
|
+
# a uniform hash that the Location initializer understands
|
3
|
+
|
4
|
+
module LeaflyApiWrapper
|
5
|
+
class Mapper
|
6
|
+
attr_accessor :mapper, :data
|
7
|
+
|
8
|
+
def initialize(data, feed_type)
|
9
|
+
@mapper = JSON.parse(File.read("./lib/leafly_api_wrapper/feed_mapper/#{feed_type}_mapper.json"))
|
10
|
+
@data = data
|
11
|
+
end
|
12
|
+
|
13
|
+
def mapped
|
14
|
+
res = {}
|
15
|
+
@mapper.each_pair do |k,v|
|
16
|
+
if v.is_a? Array
|
17
|
+
res[k] = v.map{ |cv| @data[cv] }.join(' ').strip
|
18
|
+
elsif
|
19
|
+
res[k] = @data[v]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
res
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/leafly_api_wrapper.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
{
|
2
|
+
"id": 92523,
|
3
|
+
"name": "Green Life - Bellevue",
|
4
|
+
"slug": "green-life---bellevue",
|
5
|
+
"hours": "7AM - 1AM 7 Days A Week!",
|
6
|
+
"phone": "425-298-7528",
|
7
|
+
"address": "Test",
|
8
|
+
"locationLabel": "Kirkland,WA",
|
9
|
+
"delivery": true,
|
10
|
+
"storefront": false,
|
11
|
+
"lastMenuUpdate": "/Date(1427337347541)/",
|
12
|
+
"latitude": 47.711573,
|
13
|
+
"longitude": -122.203949,
|
14
|
+
"rating": 4.5,
|
15
|
+
"numReviews": 65,
|
16
|
+
"sponsor": true,
|
17
|
+
"ada": true,
|
18
|
+
"creditCards": true,
|
19
|
+
"atm": false,
|
20
|
+
"marquee": true,
|
21
|
+
"coverPhoto": "http://d3odcnigi1nnzz.cloudfront.net/i/13223/w640/h320/crop",
|
22
|
+
"logoId": 20353,
|
23
|
+
"logo": "http://d3odcnigi1nnzz.cloudfront.net/i/20353/w64/h64",
|
24
|
+
"medical": true,
|
25
|
+
"retail": false,
|
26
|
+
"price1": false,
|
27
|
+
"price2": true,
|
28
|
+
"price3": false,
|
29
|
+
"mapMarkerLevel": 3,
|
30
|
+
"canadaLP": false,
|
31
|
+
"tagLine": "So fast you'll see smoke!",
|
32
|
+
"permalink": "http://www.leafly.com/dispensary-info/green-life---bellevue",
|
33
|
+
"starImage": "http://d3odcnigi1nnzz.cloudfront.net/stars/4.5/240?color=fcc91d",
|
34
|
+
"customMarker": "http://leaflystatic.blob.core.windows.net/files/glo2_ba90.png",
|
35
|
+
"customMarker2x": "http://leaflystatic.blob.core.windows.net/files/glo2_deb4.png",
|
36
|
+
"mapMarker": "http://leaflystatic.blob.core.windows.net/files/glo2_ba90.png",
|
37
|
+
"specials": [
|
38
|
+
{
|
39
|
+
"id": -27956883,
|
40
|
+
"title": "Ask us about our specials",
|
41
|
+
"details": "Call or text your order today! Please don't forget to ask about the daily special & bookmark our website at https://www.igreenlife.org/deals.html to see the latest products/ deals every day!",
|
42
|
+
"finePrint": "Limited to 1 offer per customer per day",
|
43
|
+
"permalink": "http://www.leafly.com/dispensary-info/green-life---bellevue/specialsprint?sid=-27956883"
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"id": -1865301558,
|
47
|
+
"title": "1 Free THC Ball",
|
48
|
+
"details": "Special - 1 Free THC Peanut Butter Chocolate Covered Ball (Contains 20mg THC & Very Strong CBD High) with $75 donation ",
|
49
|
+
"finePrint": "Limited to 1 offer per customer per day",
|
50
|
+
"permalink": "http://www.leafly.com/dispensary-info/green-life---bellevue/specialsprint?sid=-1865301558"
|
51
|
+
}
|
52
|
+
]
|
53
|
+
}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
{
|
2
|
+
"id": 1358,
|
3
|
+
"slug": "denver-relief",
|
4
|
+
"name": "Denver Relief",
|
5
|
+
"atm": false,
|
6
|
+
"creditCards": false,
|
7
|
+
"veteranDiscount": true,
|
8
|
+
"ada": true,
|
9
|
+
"isInfoOnlyListing": false,
|
10
|
+
"delivery": false,
|
11
|
+
"retail": true,
|
12
|
+
"medical": true,
|
13
|
+
"storefront": true,
|
14
|
+
"specials": true,
|
15
|
+
"specialsCount": 8,
|
16
|
+
"logo": "",
|
17
|
+
"address1": "1 Broadway",
|
18
|
+
"address2": "Suite A-150",
|
19
|
+
"city": "Denver",
|
20
|
+
"state": "CO",
|
21
|
+
"zip": "80203",
|
22
|
+
"phone": "303-420-6337",
|
23
|
+
"validPhone": true,
|
24
|
+
"approved": true,
|
25
|
+
"hours": "Daily: 8am-6:45pm",
|
26
|
+
"website": "http://www.denverrelief.com",
|
27
|
+
"blurb": "Debit cards and cash only accepted here\nWinner of the 2013 U.S. Cannabis Cup \"Best Hybrid\" for OG 18, we also stock the following award winners: Bio-Diesel, Outer Space, Ultimate '91 ChemDawg, and Reserva Privada. \nDenver Relief is a wellness and medical marijuana center dedicated to assisting people with making positive and natural changes in their lives.\nEstablished 2009. \n\n\n\nOn the web • Facebook • Twitter • YouTube\n",
|
28
|
+
"lastMenuUpdate": "/Date(1427488381107)/",
|
29
|
+
"rating": 4.5,
|
30
|
+
"meds": 4.5,
|
31
|
+
"service": 4.5,
|
32
|
+
"atmosphere": 4.5,
|
33
|
+
"followerCount": 569,
|
34
|
+
"reviewCount": 99,
|
35
|
+
"latitude": 39.7168451,
|
36
|
+
"longitude": -104.9877644,
|
37
|
+
"photos": [
|
38
|
+
"http://leaflystatic.blob.core.windows.net/dispensary-photos/denver-relief_320x240_b93a.jpg",
|
39
|
+
"http://leaflystatic.blob.core.windows.net/dispensary-photos/denver-relief_320x240_467c.jpg",
|
40
|
+
"http://leaflystatic.blob.core.windows.net/dispensary-photos/denver-relief_320x240_9b1d.jpg"
|
41
|
+
],
|
42
|
+
"photoCount": 65,
|
43
|
+
"permalink": "http://www.leafly.com/dispensary-info/denver-relief",
|
44
|
+
"menu": false,
|
45
|
+
"canadaLP": false,
|
46
|
+
"coverPhoto": "http://d3odcnigi1nnzz.cloudfront.net/i/1891/w680/h340/crop",
|
47
|
+
"tagLine": null,
|
48
|
+
"tagLineBlurb": null,
|
49
|
+
"facebookUrl": null,
|
50
|
+
"twitterUrl": null,
|
51
|
+
"googlePlusUrl": null,
|
52
|
+
"pinterestUrl": null,
|
53
|
+
"tumblrUrl": null,
|
54
|
+
"instagramUrl": null,
|
55
|
+
"starImage": "http://d3odcnigi1nnzz.cloudfront.net/stars/4.5/240?color=fcc91d",
|
56
|
+
"specialsList": [
|
57
|
+
{
|
58
|
+
"title": "Daily",
|
59
|
+
"details": "Buy 5 get 1 free on edibles and pre-rolls",
|
60
|
+
"finePrint": "The lowest priced item will be free with the purchase of 5."
|
61
|
+
},
|
62
|
+
{
|
63
|
+
"title": "Monday Edible Deal",
|
64
|
+
"details": "10% off all edibles on Monday",
|
65
|
+
"finePrint": "Munchies Monday"
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"title": "Fat Tuesday",
|
69
|
+
"details": "Your first eighth is weighed heavy today!",
|
70
|
+
"finePrint": "Only valid with purchase of a minimum of an eight."
|
71
|
+
},
|
72
|
+
{
|
73
|
+
"title": "Wax Wednesday ",
|
74
|
+
"details": "50% off your first gram of SCE!",
|
75
|
+
"finePrint": "Only valid on one gram. All additional grams are at full price."
|
76
|
+
},
|
77
|
+
{
|
78
|
+
"title": "Wax Weekends!",
|
79
|
+
"details": "50% off your first gram of SCE!!",
|
80
|
+
"finePrint": "Only valid on one gram. All additional grams are at full price."
|
81
|
+
},
|
82
|
+
{
|
83
|
+
"title": "Sunday Funday",
|
84
|
+
"details": "Your first eight will be weighed heavy.",
|
85
|
+
"finePrint": "Only valid with minimum purchase of an eighth."
|
86
|
+
},
|
87
|
+
{
|
88
|
+
"title": "First time patients",
|
89
|
+
"details": "Spend $30 or more and receive $15 off.",
|
90
|
+
"finePrint": "Offer not valid on O.pen pens or cartridges. "
|
91
|
+
},
|
92
|
+
{
|
93
|
+
"title": "Monday Vapeday",
|
94
|
+
"details": "10% off all vaporizers and vaporizer accessories. ",
|
95
|
+
"finePrint": "Including the o.pens and o.pen cartridges!"
|
96
|
+
}
|
97
|
+
],
|
98
|
+
"recentReviews": [
|
99
|
+
{
|
100
|
+
"username": "tCo27",
|
101
|
+
"starImage": "http://d3odcnigi1nnzz.cloudfront.net/stars/5/240?color=fcc91d",
|
102
|
+
"comments": ""
|
103
|
+
},
|
104
|
+
{
|
105
|
+
"username": "g.kirk",
|
106
|
+
"starImage": "http://d3odcnigi1nnzz.cloudfront.net/stars/5/240?color=fcc91d",
|
107
|
+
"comments": "I found DR online in a high times review and decided to pop in today. Their location is clean and in a relatively upscale spot. Everyone was really professional and you could tell that they actually cared about their customers. The prices are really low compared to my old spot, it may have something to do with the fact DR doesn't package their product in the medicine bottle, they use bags and at first it kind of bugged me but after trying their bud and seeing that it really is the best around I think I can deal with it. I bought HP-13, OG-18, Reserva Privada, Gumbo, Bio-Diesel and Outer Space. So far I've had Outer Space and its exactly what the name says. Sorry if this review is all over the place but my brain and OS are duking it out right now. Just go in and grab a few grams and see what the buzz is about."
|
108
|
+
},
|
109
|
+
{
|
110
|
+
"username": "lostsheep",
|
111
|
+
"starImage": "http://d3odcnigi1nnzz.cloudfront.net/stars/1.66666663/240?color=fcc91d",
|
112
|
+
"comments": "Strains were there, but as a medical customer it was a total rip off. Rec has made it difficult to find high quality affordable meds- and Denver Relief is the prime example of over inflating prices to take advantage of legalization AND their customers. Even though we were the ONLY people there we sat in the waiting room for 10+ minutes listening to the guy who helped us joke. Staff is pretentious and throw every gimmick sales pitch at you they have. \"One of Denvers oldest\", but not finest. "
|
113
|
+
}
|
114
|
+
],
|
115
|
+
"updates": [],
|
116
|
+
"updateCount": 0
|
117
|
+
}
|
@@ -3,14 +3,14 @@ require 'spec_helper'
|
|
3
3
|
describe LeaflyApiWrapper do
|
4
4
|
before do
|
5
5
|
LeaflyApiWrapper.configure do |config|
|
6
|
-
config.
|
7
|
-
config.
|
6
|
+
config.api_id = 'LEAFLY_API_ID'
|
7
|
+
config.api_key = 'LEAFLY_API_KEY'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should be configurable with a block' do
|
12
|
-
expect(LeaflyApiWrapper.configuration.api_key).to eq('
|
13
|
-
expect(LeaflyApiWrapper.configuration.api_id).to eq('
|
12
|
+
expect(LeaflyApiWrapper.configuration.api_key).to eq('LEAFLY_API_KEY')
|
13
|
+
expect(LeaflyApiWrapper.configuration.api_id).to eq('LEAFLY_API_ID')
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should set the default base url to the config' do
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LeaflyApiWrapper::Location do
|
4
|
+
let(:jsons_dir) { './spec/json_responses' }
|
5
|
+
|
6
|
+
context 'instantiated from a mapped search result' do
|
7
|
+
before do
|
8
|
+
raw_data = JSON.parse(File.read("#{jsons_dir}/locations_search_result.json"))
|
9
|
+
data = LeaflyApiWrapper::Mapper.new(raw_data, 'location_search').mapped
|
10
|
+
@location = LeaflyApiWrapper::Location.new(data)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should be able to instantiate' do
|
14
|
+
expect(@location).to be_a(LeaflyApiWrapper::Location)
|
15
|
+
end
|
16
|
+
|
17
|
+
%i{ id slug name address }.each do |attribute|
|
18
|
+
it "should set the #{attribute}" do
|
19
|
+
expect(@location.send(attribute)).not_to be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'instantiated from a mapped location result' do
|
25
|
+
before do
|
26
|
+
raw_data = JSON.parse(File.read("#{jsons_dir}/single_location_result.json"))
|
27
|
+
data = LeaflyApiWrapper::Mapper.new(raw_data, 'location_detail').mapped
|
28
|
+
@location = LeaflyApiWrapper::Location.new(data)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should be able to instantiate' do
|
32
|
+
expect(@location).to be_a(LeaflyApiWrapper::Location)
|
33
|
+
end
|
34
|
+
|
35
|
+
%i{ id slug name address }.each do |attribute|
|
36
|
+
it "should set the #{attribute}" do
|
37
|
+
expect(@location.send(attribute)).not_to be_nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/mapper_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LeaflyApiWrapper::Mapper do
|
4
|
+
describe '#new' do
|
5
|
+
context 'with unsupported feed type' do
|
6
|
+
it 'should rise error' do
|
7
|
+
expect{ LeaflyApiWrapper::Mapper.new([], 'unsupported_feed') }
|
8
|
+
.to raise_error
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with valid feed type' do
|
13
|
+
it 'should not rise error' do
|
14
|
+
expect{ LeaflyApiWrapper::Mapper.new([], 'location_detail') }
|
15
|
+
.not_to raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should set the mapper' do
|
19
|
+
expect(LeaflyApiWrapper::Mapper.new([], 'location_detail').mapper).not_to be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should set the data' do
|
23
|
+
expect(LeaflyApiWrapper::Mapper.new([], 'location_detail').data).not_to be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#mapping' do
|
29
|
+
context 'for the location detail' do
|
30
|
+
before do
|
31
|
+
data = JSON.parse(File.read("spec/json_responses/single_location_result.json"))
|
32
|
+
@mapper = LeaflyApiWrapper::Mapper.new(data, 'location_detail')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return simple values mapped like the id' do
|
36
|
+
expect(@mapper.mapped['id']).to eq(1358)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should return complex values mapped like the address' do
|
40
|
+
expect(@mapper.mapped['address']).to eq('1 Broadway Suite A-150')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'for the search result' do
|
45
|
+
before do
|
46
|
+
data = JSON.parse(File.read("spec/json_responses/locations_search_result.json"))
|
47
|
+
@mapper = LeaflyApiWrapper::Mapper.new(data, 'location_search')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should return simple values mapped like the id' do
|
51
|
+
expect(@mapper.mapped['id']).to eq(92523)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should return values that are not part of data empty like the website' do
|
55
|
+
expect(@mapper.mapped['website']).to be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leafly_api_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Siniscalchi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: vcr
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,9 +123,16 @@ files:
|
|
109
123
|
- leafly_api_wrapper.gemspec
|
110
124
|
- lib/leafly_api_wrapper.rb
|
111
125
|
- lib/leafly_api_wrapper/configuration.rb
|
126
|
+
- lib/leafly_api_wrapper/feed_mapper/location_detail_mapper.json
|
127
|
+
- lib/leafly_api_wrapper/feed_mapper/location_search_mapper.json
|
112
128
|
- lib/leafly_api_wrapper/location.rb
|
129
|
+
- lib/leafly_api_wrapper/mapper.rb
|
113
130
|
- lib/leafly_api_wrapper/version.rb
|
131
|
+
- spec/json_responses/locations_search_result.json
|
132
|
+
- spec/json_responses/single_location_result.json
|
114
133
|
- spec/leafly_api_wrapper_spec.rb
|
134
|
+
- spec/location_spec.rb
|
135
|
+
- spec/mapper_spec.rb
|
115
136
|
- spec/spec_helper.rb
|
116
137
|
- spec/vcr_cassettes/locations_detail.yml
|
117
138
|
- spec/vcr_cassettes/locations_near_point.yml
|
@@ -140,7 +161,11 @@ signing_key:
|
|
140
161
|
specification_version: 4
|
141
162
|
summary: An api wrapper for leapfly api
|
142
163
|
test_files:
|
164
|
+
- spec/json_responses/locations_search_result.json
|
165
|
+
- spec/json_responses/single_location_result.json
|
143
166
|
- spec/leafly_api_wrapper_spec.rb
|
167
|
+
- spec/location_spec.rb
|
168
|
+
- spec/mapper_spec.rb
|
144
169
|
- spec/spec_helper.rb
|
145
170
|
- spec/vcr_cassettes/locations_detail.yml
|
146
171
|
- spec/vcr_cassettes/locations_near_point.yml
|