Code Monkey home page Code Monkey logo

sogou-search-api's Introduction

Sogou Search API

A Client GEM for Sogou Search API

Alpha

This library is in Alpha. We will make an effort to support the library, but we reserve the right to make incompatible changes when necessary.

Installation

Add this line to your application's Gemfile:

gem 'sogou-search-api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sogou-search-api

Usage

Basic usage

To use an API, instantiate the service. For example to use the Campaign API:

require 'sogou/search/api/auth'
require 'sogou/search/api/service/account'
require 'sogou/search/api/service/plan'

#
# Set your Sogou api credentials to ENVs
#
# ENV['SOGOU_API_TOKEN'] = 'xxxx'
# ENV['SOGOU_USERNAME'] = 'xxxx'
# ENV['SOGOU_PASSWORD'] = 'xxxx'

include Sogou::Search::Api

account = Service::Account.new
account.authorization = Auth.get_application_default
account.get_account_info(options: { convert_regions_to_string: true }) do |result, err|
  if err != nil
    p err
  else
    p result
  end
end

Callbacks

A block can be specified when making calls. If present, the block will be called with the result or error, rather than returning the result from the call or raising the error. Example:

# Read account info
account.get_account_info(options: { convert_regions_to_string: true }) do |result, err|
  if err
    # Handle error
  else
    # Handle response
  end
end

Authorization using environment variables

The Sogou Search API Auth also supports authorization via environment variables. Simply set the following variables for your application:

SOGOU_API_TOKEN="YOUR SOGOU DEVELOPER API TOKEN"
SOGOU_USERNAME="YOUR SOGOU USERNAME"
SOGOU_PASSWORD="YOUR SOGOU PASSWORD"

Env

There are two ways to set the environment. One is ENV['ENV'] environment variable. Another is service attribute. If service attribute is set, environment variable will be ignored.

account = Service::Account.new
account.env = 'production'

Logging

The client includes a Logger instance that can be used to capture debugging information.

To set the logging level for the client:

Sogou::Search::Api.logger.level = Logger::DEBUG

When running in a Rails environment, the client will default to using ::Rails.logger. If you prefer to use a separate logger instance for API calls, this can be changed via one of two ways.

The first is to provide a new logger instance:

Sogou::Search::Api.logger = Logger.new(STDERR)

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/forward3d/sogou-search-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.

We encourage contributors to follow Bozhidar's ruby style guide in this project.

Pull requests (with tests) are appreciated. Please help with:

  • Reporting bugs
  • Suggesting features
  • Writing or improving documentation
  • Fixing typos
  • Cleaning whitespace
  • Refactoring code
  • Adding tests

If you report a bug and don't include a fix, please include a failing test.

sogou-search-api's People

Contributors

hoblin avatar minsikzzang avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sogou-search-api's Issues

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler could not find compatible versions for gem "bundler":
  In Gemfile:
    bundler (~> 1.14)

  Current Bundler version:
    bundler (2.2.15)

Your bundle requires a different version of Bundler than the one you're running.
Install the necessary version with `gem install bundler:1.17.3` and rerun bundler using `run.rb _1.17.3_`

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.