rlocu2 0.1.0
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 +7 -0
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +41 -0
- data/README.md +50 -0
- data/lib/rlocu2/client/venues.rb +55 -0
- data/lib/rlocu2/client.rb +83 -0
- data/lib/rlocu2/objects.rb +231 -0
- data/lib/rlocu2.rb +24 -0
- data/rlocu2.gemspec +22 -0
- data/spec/configuration.rb +1 -0
- data/spec/rlocu2_spec.rb +14 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/venues_spec.rb +114 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 26de612b01f871cc85fdc050a23abd9153182944
|
4
|
+
data.tar.gz: 36afb4e8bf6a279880ab9247e5d67137a4c2284c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5b99139807aa68f7814164fea04bf287428be649e40e14e84c38e0a127c97b9903949fc7af720030de088dfe62dc7fdd0670ffdfea5ea3feabb303898b3830e2
|
7
|
+
data.tar.gz: 4ae868af86ea6631e940295883c413065b423eee0d38533edd57f953dcc0f0a859265e9068df391670e175a55a5488957835f343241278046cf87360259c284f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rlocu2 (0.1.0)
|
5
|
+
faraday (~> 0.9.2)
|
6
|
+
faraday_middleware (~> 0.10.0)
|
7
|
+
json (~> 1.8, >= 1.8.3)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
diff-lcs (1.2.5)
|
13
|
+
faraday (0.9.2)
|
14
|
+
multipart-post (>= 1.2, < 3)
|
15
|
+
faraday_middleware (0.10.0)
|
16
|
+
faraday (>= 0.7.4, < 0.10)
|
17
|
+
json (1.8.3)
|
18
|
+
multipart-post (2.0.0)
|
19
|
+
rspec (3.4.0)
|
20
|
+
rspec-core (~> 3.4.0)
|
21
|
+
rspec-expectations (~> 3.4.0)
|
22
|
+
rspec-mocks (~> 3.4.0)
|
23
|
+
rspec-core (3.4.2)
|
24
|
+
rspec-support (~> 3.4.0)
|
25
|
+
rspec-expectations (3.4.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.4.0)
|
28
|
+
rspec-mocks (3.4.1)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.4.0)
|
31
|
+
rspec-support (3.4.1)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
rlocu2!
|
38
|
+
rspec (~> 3.4, >= 3.4.0)
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
1.11.2
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Rlocu2
|
2
|
+
|
3
|
+
Unoffical, and currently incomplete wrapper for the Locu API 2.0 (locu.com)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rlocu2'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
Or install it yourself:
|
16
|
+
|
17
|
+
$ gem install rlocu2
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
First initialize the client with YOUR API KEY:
|
22
|
+
|
23
|
+
$ require 'rlocu2'
|
24
|
+
$
|
25
|
+
$ client = Rlocu2::Client.new(:api_key => YOUR_API_KEY)
|
26
|
+
|
27
|
+
Prepare Hash with params to send to Locu:
|
28
|
+
|
29
|
+
$ params = Hash.new
|
30
|
+
$ params['fields'] = ['name','location','contact']
|
31
|
+
$ params['venue_queries'] = []
|
32
|
+
$ params['venue_queries'] << { 'name' => 'bistro central parc' }
|
33
|
+
|
34
|
+
Make call:
|
35
|
+
|
36
|
+
$ client.venues_search(params)
|
37
|
+
|
38
|
+
Response is a Rlocu2::Venue object
|
39
|
+
|
40
|
+
## Test - RSpec
|
41
|
+
|
42
|
+
If you want to donwload the repository and test-it remember to change the API KEY inside 'spec/configuration.rb'
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it
|
47
|
+
2. Create your feature branch (`git checkout -b my-checkout`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add features'`)
|
49
|
+
4. Push to the branch (`git push origin my-checkout`)
|
50
|
+
5. Create new Pull Request
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Rlocu2
|
2
|
+
|
3
|
+
module Venues
|
4
|
+
|
5
|
+
FIELDS = ['locu_id',
|
6
|
+
'name',
|
7
|
+
'short_name',
|
8
|
+
'description',
|
9
|
+
'website_url',
|
10
|
+
'menu_url',
|
11
|
+
'menu_items',
|
12
|
+
'menus',
|
13
|
+
'open_hours',
|
14
|
+
'external',
|
15
|
+
'redirected_from',
|
16
|
+
'categories',
|
17
|
+
'location',
|
18
|
+
'contact',
|
19
|
+
'locu', # pro account
|
20
|
+
'delivery',
|
21
|
+
'extended',
|
22
|
+
'media' # pro account
|
23
|
+
].freeze
|
24
|
+
|
25
|
+
def venues_search(params={})
|
26
|
+
options={}
|
27
|
+
options['api_key'] = @api_key if @api_key
|
28
|
+
options['fields'] = Array.new
|
29
|
+
if (params.has_key? 'fields') && params['fields'].is_a?(Array)
|
30
|
+
params['fields'].each do |p|
|
31
|
+
options['fields'] << p if FIELDS.include? p
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if (params.has_key? 'venue_queries') && params['venue_queries'].is_a?(Array)
|
36
|
+
# TODO check possible venue_queries
|
37
|
+
options['venue_queries'] = params['venue_queries']
|
38
|
+
end
|
39
|
+
|
40
|
+
if (params.has_key? 'menu_item_queries') && params['menu_item_queries'].is_a?(Array)
|
41
|
+
# TODO check possible menu_item_queries
|
42
|
+
options['menu_item_queries'] = params['menu_item_queries']
|
43
|
+
end
|
44
|
+
|
45
|
+
response = connection.post do |req|
|
46
|
+
req.url "venue/search"
|
47
|
+
req.body = options.to_json
|
48
|
+
end
|
49
|
+
|
50
|
+
return_error_or_body(response, response.body,'venues')
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Rlocu2
|
2
|
+
# Wrapper for the Locu API v 2.0
|
3
|
+
#
|
4
|
+
class Client
|
5
|
+
attr_reader :api_key
|
6
|
+
|
7
|
+
DEFAULT_CONNECTION_MIDDLEWARE = [
|
8
|
+
Faraday::Request::UrlEncoded,
|
9
|
+
FaradayMiddleware::ParseJson
|
10
|
+
]
|
11
|
+
|
12
|
+
|
13
|
+
def initialize(options={})
|
14
|
+
@api_key = options[:api_key] || Rlocu2.api_key
|
15
|
+
@connection_middleware = options[:connection_middleware] || Rlocu2.connection_middleware || []
|
16
|
+
@connection_middleware += DEFAULT_CONNECTION_MIDDLEWARE
|
17
|
+
end
|
18
|
+
|
19
|
+
def connection
|
20
|
+
@connection ||= Faraday::Connection.new(:url => api_url, :headers => default_headers) do |builder|
|
21
|
+
@connection_middleware.each do |middleware|
|
22
|
+
builder.use *middleware
|
23
|
+
end
|
24
|
+
builder.adapter Faraday.default_adapter
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def api_url
|
29
|
+
'https://api.locu.com/v2/'
|
30
|
+
end
|
31
|
+
|
32
|
+
def return_error_or_body(response, response_body, type)
|
33
|
+
if response.status == 200
|
34
|
+
# REMAP & PARSE Objects
|
35
|
+
output = Hash.new
|
36
|
+
output['status'] = response_body['status']
|
37
|
+
output['http_status'] = response_body['http_status']
|
38
|
+
if type == 'venues'
|
39
|
+
output['venues'] = response_body['venues'].each.reduce([]) { |accum, venue| accum << Rlocu2::Venue.new(venue) }
|
40
|
+
end
|
41
|
+
output
|
42
|
+
else
|
43
|
+
raise Rlocu2::APIError.new(response.body)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
include Venues
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def default_headers
|
53
|
+
headers = {
|
54
|
+
:accept => 'application/json',
|
55
|
+
:user_agent => 'Rlocu2 Ruby Gem'
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
class APIError < StandardError
|
65
|
+
|
66
|
+
attr_reader :code
|
67
|
+
attr_reader :status
|
68
|
+
attr_reader :detail
|
69
|
+
|
70
|
+
def initialize(response)
|
71
|
+
@code = response['http_status']
|
72
|
+
@status = response['errorType']
|
73
|
+
@detail = response['error']
|
74
|
+
end
|
75
|
+
|
76
|
+
def message
|
77
|
+
"#{@status}: #{@detail} (#{@code})"
|
78
|
+
end
|
79
|
+
alias :to_s :message
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,231 @@
|
|
1
|
+
module Rlocu2
|
2
|
+
|
3
|
+
class Venue
|
4
|
+
attr_accessor :locu_id, :name, :short_name, :description, :website_url, :menu_url, :menus, :menu_items, :open_hours, :external,
|
5
|
+
:redirected_from, :categories, :location, :contact, :locu, :delivery, :extended, :media
|
6
|
+
|
7
|
+
def initialize(venue)
|
8
|
+
build_from_hash(venue)
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_from_hash(venue)
|
12
|
+
venue.each { |k,v| self.send("#{k.to_s}=", v) }
|
13
|
+
end
|
14
|
+
|
15
|
+
# BUILD sub structures
|
16
|
+
|
17
|
+
def external=(externals_list)
|
18
|
+
@external = []
|
19
|
+
externals_list.each { |external_id| @external << Rlocu2::ExternalID.new(id: external_id['id'], url: external_id['url'], mobile_url: external_id['mobile_url'])}
|
20
|
+
end
|
21
|
+
|
22
|
+
def categories=(categories_list)
|
23
|
+
@categories = []
|
24
|
+
categories_list.each do |category|
|
25
|
+
c = Rlocu2::Category.new
|
26
|
+
category.each { |k,v| c.send("#{k.to_s}=", v) }
|
27
|
+
@categories << c
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def location=(location)
|
32
|
+
l = Rlocu2::Location.new
|
33
|
+
location.each { |k,v| l.send("#{k.to_s}=", v) }
|
34
|
+
@location = l
|
35
|
+
end
|
36
|
+
|
37
|
+
def contact=(contact)
|
38
|
+
c = Rlocu2::Contact.new
|
39
|
+
contact.each { |k,v| c.send("#{k.to_s}=", v) }
|
40
|
+
@location = c
|
41
|
+
end
|
42
|
+
|
43
|
+
def locu=(locu)
|
44
|
+
lc = Rlocu2::Locu.new
|
45
|
+
locu.each { |k,v| lc.send("#{k.to_s}=", v) }
|
46
|
+
@locu = lc
|
47
|
+
end
|
48
|
+
|
49
|
+
def delivery=(delivery)
|
50
|
+
d = Rlocu2::Delivery.new
|
51
|
+
delivery.each { |k,v| d.send("#{k.to_s}=", v) }
|
52
|
+
@location = l
|
53
|
+
end
|
54
|
+
|
55
|
+
def extended=(extended)
|
56
|
+
e = Rlocu2::Extended.new
|
57
|
+
extended.each { |k,v| e.send("#{k.to_s}=", v) }
|
58
|
+
@extended = e
|
59
|
+
end
|
60
|
+
|
61
|
+
def media=(media)
|
62
|
+
m = Rlocu2::Media.new
|
63
|
+
media.each { |k,v| m.send("#{k.to_s}=", v) }
|
64
|
+
@media = m
|
65
|
+
end
|
66
|
+
|
67
|
+
def menus=(menu_list)
|
68
|
+
@menus = []
|
69
|
+
menu_list.each do |menu|
|
70
|
+
@menus << Menu.new(menu)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
class ExternalID
|
77
|
+
attr_accessor :id, :url, :mobile_url
|
78
|
+
end
|
79
|
+
|
80
|
+
class Category
|
81
|
+
attr_accessor :name, :str_id
|
82
|
+
end
|
83
|
+
|
84
|
+
class Location
|
85
|
+
attr_accessor :address1, :address2, :address3, :locality, :region, :postal_code, :country, :geo
|
86
|
+
end
|
87
|
+
|
88
|
+
class Contact
|
89
|
+
attr_accessor :phone, :fax, :email, :phones, :faxes, :emails, :business_owner
|
90
|
+
end
|
91
|
+
|
92
|
+
class Locu
|
93
|
+
attr_accessor :owner_controlled, :verification_level, :last_updated_by_owner, :last_updated_by_locu, :last_updated_listings, :last_updated_menu, :last_modified, :added_to_locu
|
94
|
+
end
|
95
|
+
|
96
|
+
class Delivery
|
97
|
+
attr_accessor :will_deliver, :hours, :minimum_order, :areas
|
98
|
+
end
|
99
|
+
|
100
|
+
class Extended
|
101
|
+
attr_accessor :established_date, :closed_date, :closed_permanently, :payment_methods, :cash_only, :history, :alcohol, :parking, :wifi , :corkage, :dietary_restrictions,
|
102
|
+
:music, :sports , :wheelchair_accessible, :reservations, :outdoor_seating, :good_for_kids, :good_for_groups, :meals, :takeout, :smoking, :noise_level,
|
103
|
+
:minimum_age, :specialties, :attire, :waiter_service, :television, :caters, :ambience, :price_range, :currency
|
104
|
+
end
|
105
|
+
|
106
|
+
class Media
|
107
|
+
attr_accessor :cover_photo, :venue_photos, :menu_photos, :logos, :videos
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# class copied from old locu gem ( https://github.com/swelltrain/rlocu/blob/master/lib/rlocu/menu.rb )
|
112
|
+
|
113
|
+
class Menu
|
114
|
+
attr_accessor :menu_name, :sections
|
115
|
+
|
116
|
+
def initialize(menu_hash)
|
117
|
+
@menu_name = menu_hash['menu_name']
|
118
|
+
self.sections = menu_hash['sections']
|
119
|
+
end
|
120
|
+
|
121
|
+
def sections=(sections_list)
|
122
|
+
@sections = []
|
123
|
+
sections_list.each { |section| @sections << Rlocu2::Menu::Section.new(section) } unless sections_list.nil?
|
124
|
+
end
|
125
|
+
|
126
|
+
class Section
|
127
|
+
attr_accessor :section_name, :subsections
|
128
|
+
def initialize(section_hash)
|
129
|
+
@section_name = section_hash['section_name']
|
130
|
+
self.subsections = section_hash['subsections']
|
131
|
+
end
|
132
|
+
|
133
|
+
def subsections=(subsections_list)
|
134
|
+
@subsections = []
|
135
|
+
subsections_list.each { |subsection| @subsections << Rlocu2::Menu::Subsection.new(subsection) } unless subsections_list.nil?
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class Subsection
|
140
|
+
attr_accessor :subsection_name, :contents
|
141
|
+
def initialize(subsection_hash)
|
142
|
+
@subsection_name = subsection_hash['subsection_name']
|
143
|
+
self.contents = subsection_hash['contents']
|
144
|
+
end
|
145
|
+
|
146
|
+
def contents=(contents_list)
|
147
|
+
@contents = []
|
148
|
+
return if contents_list.nil?
|
149
|
+
contents_list.each do |content|
|
150
|
+
@contents << case content['type']
|
151
|
+
when 'SECTION_TEXT'
|
152
|
+
Rlocu2::Menu::SectionText.new(content)
|
153
|
+
when 'ITEM'
|
154
|
+
Rlocu2::Menu::MenuItem.new(content)
|
155
|
+
else
|
156
|
+
raise "Menu Content type not found #{content['type']}"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
class SectionText
|
163
|
+
attr_accessor :type, :text
|
164
|
+
def initialize(section_text_hash)
|
165
|
+
@type = section_text_hash['type']
|
166
|
+
@text = section_text_hash['text']
|
167
|
+
end
|
168
|
+
|
169
|
+
def to_s
|
170
|
+
@text
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class Item
|
175
|
+
attr_accessor :type, :name, :description, :price, :option_groups
|
176
|
+
def initialize(item_hash)
|
177
|
+
@type = item_hash['type']
|
178
|
+
@name = item_hash['name']
|
179
|
+
@description = item_hash['description']
|
180
|
+
@price = item_hash['price']
|
181
|
+
self.option_groups = item_hash['option_groups']
|
182
|
+
end
|
183
|
+
|
184
|
+
def option_groups=(option_groups_list)
|
185
|
+
@option_groups = []
|
186
|
+
return if option_groups_list.nil?
|
187
|
+
option_groups_list.each { |option_group| @option_groups << Rlocu2::Menu::OptionGroup.new(option_group) }
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
class MenuItem < Rlocu2::Menu::Item
|
192
|
+
attr_accessor :menu_name, :section_name, :subsection_name, :section_text, :type, :currency_symbol, :photos
|
193
|
+
def initialize(menu_item_hash)
|
194
|
+
@menu_name = menu_item_hash['menu_name']
|
195
|
+
@section_name = menu_item_hash['section_name']
|
196
|
+
@subsection_name = menu_item_hash['subsection_name']
|
197
|
+
@section_text = menu_item_hash['section_text']
|
198
|
+
@currency_symbol = menu_item_hash['currency_symbol']
|
199
|
+
@photos = menu_item_hash['photos']
|
200
|
+
super
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
class OptionGroup
|
205
|
+
attr_accessor :options, :type, :text
|
206
|
+
def initialize(option_group_hash)
|
207
|
+
@type = option_group_hash['type']
|
208
|
+
@text = option_group_hash['text']
|
209
|
+
self.options = option_group_hash['options']
|
210
|
+
end
|
211
|
+
|
212
|
+
def options=(options_list)
|
213
|
+
@options = []
|
214
|
+
options_list.each { |option| @options << Rlocu2::Menu::Option.new(option) } unless options_list.nil?
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
class Option
|
219
|
+
attr_accessor :name, :price
|
220
|
+
def initialize(option_hash)
|
221
|
+
@name = option_hash['name']
|
222
|
+
@price = option_hash['price']
|
223
|
+
end
|
224
|
+
|
225
|
+
def to_s
|
226
|
+
"#{name} #{price}"
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
end
|
data/lib/rlocu2.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
6
|
+
|
7
|
+
module Rlocu2
|
8
|
+
class << self
|
9
|
+
|
10
|
+
FIELDS = [:api_key,
|
11
|
+
:connection_middleware]
|
12
|
+
attr_accessor(*FIELDS)
|
13
|
+
|
14
|
+
def configure
|
15
|
+
yield self
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rlocu2/client/venues'
|
22
|
+
require 'rlocu2/client'
|
23
|
+
require 'rlocu2/objects'
|
24
|
+
end
|
data/rlocu2.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'rlocu2'
|
4
|
+
s.version = '0.1.0'
|
5
|
+
s.date = '2016-02-12'
|
6
|
+
s.summary = "A ruby wrapper for Locu API 2.0"
|
7
|
+
s.description = "The Locu API gives you access to real-time local business data, from opening hours to price lists, such as restaurant menus"
|
8
|
+
s.authors = ["Andrea Cadamuro"]
|
9
|
+
s.homepage = 'https://github.com/caimano/rlocu2'
|
10
|
+
s.license = 'MIT'
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
|
16
|
+
s.add_runtime_dependency('faraday', '~> 0.9.2') # 08.02.2016
|
17
|
+
s.add_runtime_dependency('faraday_middleware', '~> 0.10.0') # 09.02.2016
|
18
|
+
s.add_runtime_dependency('json', '~> 1.8', '>= 1.8.3') # 09.02.2016
|
19
|
+
|
20
|
+
s.add_development_dependency('rspec', '~> 3.4', '>= 3.4.0') # 05.02.2016
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
API_KEY = '3760eae936ff2505c23984e3743f0a868a15128e'
|
data/spec/rlocu2_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rlocu2 do
|
4
|
+
let(:client) do
|
5
|
+
client = Rlocu2::Client.new(:api_key => API_KEY)
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'Rlocu2' do
|
9
|
+
it 'client should be a Rlocu2::Client' do
|
10
|
+
expect(client).to be_an_instance_of(Rlocu2::Client)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/venues_spec.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Rlocu2 do
|
3
|
+
let(:client) do
|
4
|
+
client = Rlocu2::Client.new(:api_key => API_KEY)
|
5
|
+
end
|
6
|
+
|
7
|
+
context 'Venues' do
|
8
|
+
|
9
|
+
it 'Querying for venues by name' do
|
10
|
+
|
11
|
+
params = Hash.new
|
12
|
+
params['fields'] = ['name','location','contact']
|
13
|
+
params['venue_queries'] = []
|
14
|
+
params['venue_queries'] << { 'name' => 'bistro central parc' }
|
15
|
+
response = client.venues_search(params)
|
16
|
+
|
17
|
+
expect(response['status']).to eq('success')
|
18
|
+
expect(response['http_status']).to eq(200)
|
19
|
+
expect(response['venues']).to be_an_instance_of(Array)
|
20
|
+
response['venues'].each do |v|
|
21
|
+
expect(v).to be_an_instance_of(Rlocu2::Venue)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'Querying for venues in a circular area' do
|
27
|
+
|
28
|
+
params = Hash.new
|
29
|
+
params['fields'] = ['name','location','contact']
|
30
|
+
params['venue_queries'] = []
|
31
|
+
params['venue_queries'] << { 'location' => { 'geo' => {'$in_lat_lng_radius' => [37.7750, -122.4183, 5000] } } }
|
32
|
+
response = client.venues_search(params)
|
33
|
+
|
34
|
+
expect(response['status']).to eq('success')
|
35
|
+
expect(response['http_status']).to eq(200)
|
36
|
+
expect(response['venues']).to be_an_instance_of(Array)
|
37
|
+
|
38
|
+
response['venues'].each do |v|
|
39
|
+
expect(v).to be_an_instance_of(Rlocu2::Venue)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'Querying for presence or absence of fields' do
|
44
|
+
|
45
|
+
params = Hash.new
|
46
|
+
params['fields'] = ['name','location','contact']
|
47
|
+
params['venue_queries'] = []
|
48
|
+
params['venue_queries'] << {'menus' => {'$present' => true}}
|
49
|
+
response = client.venues_search(params)
|
50
|
+
|
51
|
+
expect(response['status']).to eq('success')
|
52
|
+
expect(response['http_status']).to eq(200)
|
53
|
+
expect(response['venues']).to be_an_instance_of(Array)
|
54
|
+
|
55
|
+
response['venues'].each do |v|
|
56
|
+
expect(v).to be_an_instance_of(Rlocu2::Venue)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'Querying for venues open during certain hours' do
|
61
|
+
|
62
|
+
params = Hash.new
|
63
|
+
params['fields'] = ['name','location','contact']
|
64
|
+
params['venue_queries'] = []
|
65
|
+
params['venue_queries'] << { 'open_hours' => { 'monday' => ['18:00', '20:00']} }
|
66
|
+
response = client.venues_search(params)
|
67
|
+
|
68
|
+
expect(response['status']).to eq('success')
|
69
|
+
expect(response['http_status']).to eq(200)
|
70
|
+
expect(response['venues']).to be_an_instance_of(Array)
|
71
|
+
|
72
|
+
response['venues'].each do |v|
|
73
|
+
expect(v).to be_an_instance_of(Rlocu2::Venue)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
=begin
|
77
|
+
# ?!? The "menu_items" key is not supported. (400)
|
78
|
+
it 'Querying for all restaurants in Boston that serve pizza' do
|
79
|
+
|
80
|
+
params = Hash.new
|
81
|
+
params['fields'] = ['name']
|
82
|
+
params['venue_queries'] = []
|
83
|
+
params['venue_queries'] << { 'location' => { 'locality' => 'Boston'} }
|
84
|
+
params['menu_item_queries'] = []
|
85
|
+
params['menu_item_queries'] << { 'name' => 'pizza' }
|
86
|
+
response = client.venues_search(params)
|
87
|
+
|
88
|
+
expect(response['status']).to eq('success')
|
89
|
+
expect(response['http_status']).to eq(200)
|
90
|
+
expect(response['venues']).to be_an_instance_of(Array)
|
91
|
+
|
92
|
+
end
|
93
|
+
=end
|
94
|
+
it 'Querying for many attributes' do
|
95
|
+
|
96
|
+
params = Hash.new
|
97
|
+
params['fields'] = ['locu_id','name','description','website_url','location','categories','menus','open_hours','extended','description','short_name']
|
98
|
+
params['venue_queries'] = []
|
99
|
+
params['venue_queries'] << { 'name' => 'bistro central parc', 'menus' => {'$present' => true} }
|
100
|
+
response = client.venues_search(params)
|
101
|
+
|
102
|
+
expect(response['status']).to eq('success')
|
103
|
+
expect(response['http_status']).to eq(200)
|
104
|
+
expect(response['venues']).to be_an_instance_of(Array)
|
105
|
+
|
106
|
+
response['venues'].each do |v|
|
107
|
+
expect(v).to be_an_instance_of(Rlocu2::Venue)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rlocu2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrea Cadamuro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.10.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.10.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.8.3
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1.8'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.8.3
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.4'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 3.4.0
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.4'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 3.4.0
|
81
|
+
description: The Locu API gives you access to real-time local business data, from
|
82
|
+
opening hours to price lists, such as restaurant menus
|
83
|
+
email:
|
84
|
+
executables: []
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- ".gitignore"
|
89
|
+
- ".rspec"
|
90
|
+
- Gemfile
|
91
|
+
- Gemfile.lock
|
92
|
+
- README.md
|
93
|
+
- lib/rlocu2.rb
|
94
|
+
- lib/rlocu2/client.rb
|
95
|
+
- lib/rlocu2/client/venues.rb
|
96
|
+
- lib/rlocu2/objects.rb
|
97
|
+
- rlocu2.gemspec
|
98
|
+
- spec/configuration.rb
|
99
|
+
- spec/rlocu2_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
- spec/venues_spec.rb
|
102
|
+
homepage: https://github.com/caimano/rlocu2
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.4.8
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: A ruby wrapper for Locu API 2.0
|
126
|
+
test_files: []
|