JsonClient
A simple crud json client so that I don't need to do this for all my web services
Installation
Add this line to your application's Gemfile:
gem 'json_client'
And then execute:
$ bundle
Or install it yourself as:
$ gem install json_client
Usage
I've avoided using a DSL in favor of good engineering principals. I am hoping the DSL will come after.
require 'json_client'
class Client < JsonClient::Base
def initialize(config)
super
end
def pather
@pather ||=
JsonClient::Pather.new(
'https://example.host.com',
'api/v1',
'objects'
)
end
end
config = {
api_key: 'api_key',
api_password: 'api_password'
}
client = Client.new(config)
# GET https://example.host.com/api/v1/objects?api_key=api_key&api_password=api_password
client.index.json
=> { 'server_json' : 'is_parsed_here' }
# GET https://my.host.com/api/v1/objects/2?api_key=api_key&api_password=api_password
client.show(2).json # fetches from
=> { 'object_json' : 'is_parsed_here' }
Best Guide
Is this test. Sorry non rspec people
Contributing
- Fork it ( https://github.com/johnmcconnell/json_client/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request