VsClient
Provides a seamless integration with vendor search service for ruby.
Installation
Add this line to your application's Gemfile:
gem 'vs_client', git: 'https://github.com/HungerStation/vs-client-rb.git'
And then execute:
$ bundle update --source vs_client
Or install it yourself as:
$ gem install vs_client
Setup
# if you are on Rails this block should be in:
# /config/initializers/vs_client.rb
VsClient.configure do |config|
config.url = 'service url goes here' # it should be the vendor search service host.
config.api_version = 'version path' # like '/api/v2'.
config.enable_http_debug_mode = true # helps you to see the request lifecycle, should be false over production.
config.use_ssl = true # enable connection over https.
config.keep_alive_timeout = 0 # for how long (in seconds) should the server keep tcp connection to be reused.
config.timeout = 60 # how long the client will wait till it gets a response.
end
Usage
# GET /filters
query = {
latitude: 24.828453624665187,
longitude: 46.640109869734395,
home_module_id: 10,
}
VsClient.get_filters(
query: payload,
headers: {
"Device-Uid" => "008FA000-0000-0000-0000-006E5B1A0000",
"App-Version" => "2570",
"Accept-Language" => "en"
},
fallback: -> () { fallback }
)
def fallback
# your logic to handle remote failures for consistency
# whenever the client failed to gets data this block will be executed as plan B.
end
For practical example check this Filters Example
Run Test
$ rspec spec
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/HungerStation/vs-client-rb.
License
The gem is available as open source under the terms of the MIT License.