项目作者: tomholford

项目描述 :
Ruby client gem for the unofficial Jisho API
高级语言: Ruby
项目地址: git://github.com/tomholford/jisho-api.git
创建时间: 2020-03-10T10:23:01Z
项目社区:https://github.com/tomholford/jisho-api

开源协议:MIT License

下载


JishoAPI

An unofficial Ruby gem client for Jisho, a Japanese dictionary.

For details about the API, check out this thread by the developer.

Installation

Add this line to your application’s Gemfile:

  1. gem 'jisho_api'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install jisho_api

Usage

Querying

A search query is required, and can be set in a few ways:

  1. require 'jisho_api'
  2. # Class method
  3. JishoAPI::JishoAPI.search('hamburger')
  4. >> [{ ... }]
  5. # Initializer
  6. api = JishoAPI::JishoAPI.new(query: 'ピザ')
  7. # Accessor
  8. api.query = '#jlpt-n5'
  9. # Instance method
  10. api.search # will use the internally stored query
  11. >> [{ ... }]
  12. api.search(query: 'something else') # will override (but not set) the internally stored query
  13. >> [{ ... }]

Pagination

By default, the gem will fetch the first page of results. There are also a few ways to override this behavior:

  1. # Initializer
  2. api = JishoAPI::JishoAPI.new(query: 'ピザ', page: 2)
  3. # Accessor
  4. api.page = 3
  5. # Instance methods
  6. # Fetching a page for a given query
  7. api.search(query: 'something else', page: 2)
  8. >> [{ ... }]
  9. # This increments the internal page counter and executes a request
  10. api.next_page!
  11. >> [{ ... }]
  12. puts api.page
  13. >> 4

Development

After checking out the repo, run bin/setup to install dependencies. 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/tomholford/jisho-api.

License

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