sogou-search-api 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5c716c3f0a2b1c807eb08265f4b9ee700ae33d7
4
- data.tar.gz: c66b6cd0d0e800170161a24b8ebde867ce54fce7
3
+ metadata.gz: f0b4319eb56256bda906b575a99471628c16cb52
4
+ data.tar.gz: d782793fda116ba744b925f2ee86e513034d958b
5
5
  SHA512:
6
- metadata.gz: 627e5d14ebd0314ecb7330761522375dff5a54fa20152d0177493120c44235ddcea00841f76b5285912a2e960afc5dfcffd49f3c2a112b12081f87fd5b1d6214
7
- data.tar.gz: a944be7071287c114fc205fb730d55c8e763fd7ef57e005e94e0c32c279da5a5b75fb6d09bba2620ff1a3fd9434cb6b3c5b1419d448348b97a1fa747df6dfc54
6
+ metadata.gz: '0815c7bc00e9751202be2ff7f15a56ed610ebcfc55d9da8dbaef9ba074562183067fcc2becdeda5c26c388e349fe33ebb4ecedb8e6dd3750f1624965158e74b9'
7
+ data.tar.gz: 97ec1f5bc46fbe71520378396410617c08a60990cc464798be6a554d1bab58ccdb77b9f594fb1067c6b1738832b5ca91db7664c177eb797fffc6b8c2ac9d654e
data/README.md CHANGED
@@ -6,3 +6,120 @@ A Client GEM for [Sogou Search API](http://apihome.sogou.com/document/ss/doc1-1.
6
6
 
7
7
  This library is in Alpha. We will make an effort to support the library, but we reserve the right to make incompatible
8
8
  changes when necessary.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'sogou-search-api'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install sogou-search-api
25
+
26
+ ## Usage
27
+
28
+ ### Basic usage
29
+
30
+ To use an API, instantiate the service. For example to use the Campaign API:
31
+
32
+ ```ruby
33
+ require 'sogou/search/api/auth'
34
+ require 'sogou/search/api/service/account'
35
+ require 'sogou/search/api/service/plan'
36
+
37
+ #
38
+ # Set your Sogou api credentials to ENVs
39
+ #
40
+ # ENV['SOGOU_API_TOKEN'] = 'xxxx'
41
+ # ENV['SOGOU_USERNAME'] = 'xxxx'
42
+ # ENV['SOGOU_PASSWORD'] = 'xxxx'
43
+
44
+ include Sogou::Search::Api
45
+
46
+ account = Service::Account.new
47
+ account.authorization = Auth.get_application_default
48
+ account.get_account_info(convert_regions_to_string: true) do |result, err|
49
+ if err != nil
50
+ p err
51
+ else
52
+ p result
53
+ end
54
+ end
55
+
56
+ ```
57
+
58
+ ### Callbacks
59
+
60
+ A block can be specified when making calls. If present, the block will be called with the result or error, rather than
61
+ returning the result from the call or raising the error. Example:
62
+
63
+ ```ruby
64
+ # Read account info
65
+ account.get_account_info(convert_regions_to_string: true) do |result, err|
66
+ if err
67
+ # Handle error
68
+ else
69
+ # Handle response
70
+ end
71
+ end
72
+ ```
73
+
74
+ ### Authorization using environment variables
75
+
76
+ The [Sogou Search API Auth](https://github.com/forward3d/sogou-search-api/blob/master/lib/sogou/search/api/auth.rb) also supports authorization via environment variables. Simply set the following variables
77
+ for your application:
78
+
79
+ ```sh
80
+ SOGOU_API_TOKEN="YOUR SOGOU DEVELOPER API TOKEN"
81
+ SOGOU_USERNAME="YOUR SOGOU USERNAME"
82
+ SOGOU_PASSWORD="YOUR SOGOU PASSWORD"
83
+ ```
84
+
85
+ ## Logging
86
+
87
+ The client includes a `Logger` instance that can be used to capture debugging information.
88
+
89
+ To set the logging level for the client:
90
+
91
+ ```ruby
92
+ Sogou::Search::Api.logger.level = Logger::DEBUG
93
+ ```
94
+
95
+ When running in a Rails environment, the client will default to using `::Rails.logger`. If you
96
+ prefer to use a separate logger instance for API calls, this can be changed via one of two ways.
97
+
98
+ The first is to provide a new logger instance:
99
+
100
+ ```ruby
101
+ Sogou::Search::Api.logger = Logger.new(STDERR)
102
+ ```
103
+
104
+ ## License
105
+
106
+ This library is licensed under Apache 2.0. Full license text is available in [LICENSE](LICENSE).
107
+
108
+ ## Contributing
109
+
110
+ 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](http://contributor-covenant.org) code of conduct.
111
+
112
+ We encourage contributors to follow [Bozhidar's ruby style guide](https://github.com/bbatsov/ruby-style-guide) in this project.
113
+
114
+ Pull requests (with tests) are appreciated. Please help with:
115
+
116
+ * Reporting bugs
117
+ * Suggesting features
118
+ * Writing or improving documentation
119
+ * Fixing typos
120
+ * Cleaning whitespace
121
+ * Refactoring code
122
+ * Adding tests
123
+
124
+ If you report a bug and don't include a fix, please include a failing test.
125
+
@@ -407,14 +407,16 @@ module Sogou
407
407
  # can be either Interger[] or Integer from
408
408
  # http://apihome.sogou.com/document/ss/doc9-1.jsp and
409
409
  # http://apihome.sogou.com/document/ss/doc9-2.jsp,
410
- # But "regions" value is returned always as integer value.
411
- # Unless we find the case for integer[], below method will work.
412
410
  #
413
411
  def convert_regions_to_string(results)
414
412
  if results.is_a?(Hash)
415
- region = results['regions']
416
- if region
417
- results['regions'] = REGIONS_CODE.fetch(region.to_i, region)
413
+ regions = results['regions']
414
+ if regions
415
+ if regions.is_a?(Array)
416
+ results['regions'] = regions.map { |r| REGIONS_CODE.fetch(r.to_i, r) }
417
+ else
418
+ results['regions'] = REGIONS_CODE.fetch(regions.to_i, regions)
419
+ end
418
420
  end
419
421
  elsif results.is_a?(Array)
420
422
  results = results.map { |r| convert_regions_to_string(r) }
@@ -1,7 +1,7 @@
1
1
  module Sogou
2
2
  module Search
3
3
  module Api
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
 
6
6
  OS_VERSION = begin
7
7
  if RUBY_PLATFORM =~ /mswin|win32|mingw|bccwin|cygwin/
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sogou-search-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Min Kim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-02 00:00:00.000000000 Z
11
+ date: 2018-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: savon