Barrio Client
A ruby gem that makes it easy to access the Barrio Platform API.
Installation
Add this line to your application's Gemfile:
gem 'barrio-client'
And then execute:
$ bundle
Or install it yourself as:
$ gem install barrio-client
Usage
Wherever you want to request data, include the library and create an instance of the client:
require 'barrio-client'
client = Barrio::Client.new('your-client_id-here')
You can get a client_id here.
Then you can query for information:
locations = client.locations(:city => 'tijuana', :category => 'restaurant', :q => "kokopelli")
puts locations.count # Result: 2
puts locations.first.name # Result: Tacos Kokopelli
puts locations.first.location.address # Result: Ave. Ocampo entre la 8va y 9na, Tijuana, Baja California
puts locations.first.location.latitude # 32.524164
puts locations.first.location.longitude # -117.030916
locations.each do |l|
puts l.name
end
# Tacos Kokopelli
# Foodgarden
Functionality
Four query methods are provided:
# Search for locations using any of the supported filters or criteria
locations = client.locations(:category => 'store', :city => 'ensenada')
# Query for one specific location by Barrio ID
location = client.location('barbacoa-el-corral-tijuana-mexico')
# Find all the pictures for a specific location
pictures = client.location_pictures('foodgarden-tijuana-mexico')
puts pictures.last.url.large # Result: https://www.filepicker.io/api/file/XRbqj4If...
# Look up one specific picture by id
picture = client.location_picture('foodgarden-tijuana-mexico', 1055)
Supported Filters
When using client.locations
to search, there are many supported filters you can use. They are all
documented here.
Here are some examples:
:sort
- Change the sort order of results
:q
- Search for locations by keyword or text
:lat
/:lng
- Search for locations near a certain latitude/longitude coordinate
:category
- Limit your search to one or more categories
:city
- Limit your search to one city
:neighborhood
- Limit your search to one neighborhood
There are many more filters available. This library supports everything supported by the Barrio.mx Platform API, so refer to the API documentation for a full list of available filters.
Help
If you need help or have questions, check out the documentation or contact us.