GitXplorerGitXplorer
a

nice_json_api

public
2 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
1da88bd48f7a60913fd2068e56e237b76fabcbaf

v1.0.1

aandycroll committed 7 years ago
Unverified
c1d36465c7974b540788438b1116f09eaa6937d6

Catch connection reset error

aandycroll committed 7 years ago
Unverified
17a1e8f1d47d6e7f078040c197a923eda6760938

Use my name in readme links

aandycroll committed 7 years ago
Unverified
21752dba35ebad5962561ffd7dc5fc4ff7df3686

Need to require standard library stuff

aandycroll committed 7 years ago
Unverified
6053351ca739f7673943d36e8779a1fc6ce52ab2

Expand readme

aandycroll committed 7 years ago
Unverified
e32c41e5842505068721f1daa198c1b4e359f29a

Naming is more ruby focussed

aandycroll committed 7 years ago

README

The README file for this repository.

NiceJsonApi

A useful hundred-line-ish wrapper around Net::HTTP for well behaved JSON-based APIs.

This gem can be used as a basis for http://jsonapi.org compatible APIs but it is not exclusively for that use. Any 'nice' JSON-based API should work.

If you're looking for a good gem to use with JSON API I like json-api-vanilla.

Supports Authorization:

  • HTTP Basic Auth
  • Bearer Token Auth (like Twitter)
  • Other header-based authorisation (custom header & value)

Installation

Add this line to your application's Gemfile:

gem 'nice_json_api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install nice_json_api

Usage

The main interface is:

# A simple GET request
> response = NiceJsonApi::Response.new('http://ip.jsontest.com')
=> #<NiceJsonApi::Response:...>
> response.code
#=> '200'
> response.body
#=> { ip: '8.8.8.8' }
> response.raw_body
#=> "{\"ip\": \"146.199.147.93\"}\n"
> response.message
#=> "OK"
> response.raw
#=> #<Net::HTTPOK 200 OK readbody=true>

# A Bearer token POST request
> response = NiceJsonApi::Response.new('https://api.twitter.com/1.1/statuses/update.json',
                                       auth: { bearer: "YOURTOKEN" },
                                       body: { status: 'This gem is awesome' },
                                       method: :post)

# A custom header GET request
> response = NiceJsonApi::Response.new('https://yourapiserver.com/',
                                       auth: { header: { name: 'X-Weird-Auth', value: 'TOKEN' } })

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test 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/andycroll/nice_json_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the NiceJsonApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.