项目作者: tashua314

项目描述 :
Wrapper of Google Custom Search API.
高级语言: Ruby
项目地址: git://github.com/tashua314/gcs_api_gem.git
创建时间: 2017-12-13T12:49:28Z
项目社区:https://github.com/tashua314/gcs_api_gem

开源协议:MIT License

下载


GcsApiGem

This project is a Ruby lib for Google’s Custom Search Engine API (http://www.google.com/cse).
This is very easy to use but available functions are restricted.

Welcome to your new gem! In this directory, you’ll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/gcs_api_gem. To experiment with that code, run bin/console for an interactive prompt.

Installation

Add this line to your application’s Gemfile:

  1. gem 'gcs_api_gem'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install gcs_api_gem

Configure

You need to configure KEY and CSE_ID to environment variables.

  1. $ export KEY=<GOOGLE_API_KEY>
  2. $ export SCE_ID=<GOOGLE_CUSTOM_SEARCH_ENGINE_ID>

Or write to .bashrc as below:

  1. export KEY=<GOOGLE_API_KEY>
  2. export SCE_ID=<GOOGLE_CUSTOM_SEARCH_ENGINE_ID>

And then execute:

  1. $ source ~/.bashrc

Remarks

If you want to know how to get GOOGLE_CUSTOME_SEARCH_ENGINE_ID and GOOGLE_API_KEY, look at here.
Or see here.

Usage

In a program

Write in your program as below:

  1. obj.GcsApiGem::SearchApi.new
  2. obj.random_image(<keyword>)

Then you get a random image searched by keyword.

Example

  1. > obj = GcsApiGem::SearchApi.new
  2. > obj.random_image('cat')
  3. => {
  4. :keyword=>"cat",
  5. :title=>"Cute Cat - Chrome Web Store",
  6. :image=>"https://lh3.googleusercontent.com/FnN1_Jabl5WITJrHYLGv80r-GNSNAPI_nwrrSgHh8fRUh5fsHFMmPFkPOjaX16H5Pi-Fwotg=w640-h400-e365",
  7. :search_result=>"320000000",
  8. :start_index=>2
  9. }

Response

Response of GcsApiGem::SearchApi#random_image is as below:

key detail
keyword It is using keyword to search image.
title The title of the web site that got the image.
image The URL of the got image.
search_result Number of images hit in search.
start_index Number of page on which the image is displayed.

In a command line

Write in a command line as below:

  1. $ gcs_api_gem -r cat

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tashua314/gcs_api_gem. 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 GcsApiGem project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct