google_suggest 1.0.0 → 1.0.1

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
- SHA1:
3
- metadata.gz: a3ead4838ea1a4c82772cb5c723e644b75b7a292
4
- data.tar.gz: a378ffc7c5d3d521cd76dc15ccdb90592ac8ba73
2
+ SHA256:
3
+ metadata.gz: 33a827514c56513e207d9e9716f5cae26873ea1289ac16657599c52cfb63e210
4
+ data.tar.gz: a4e7608c0a3bbbcbacbd43eda9528040c27944bf518538ea197e29b0576170d7
5
5
  SHA512:
6
- metadata.gz: 342ab56bc62c168fd9ad5696b55d592b0f7cbf704539d33f42f9c2333c5c0adca8da92fc65530c243056a43d7997f668a6a45ba835033481247a5e02276a2474
7
- data.tar.gz: 6579290639cc00c65eaaaf340df5997cf004c487726c14587f2573066c0de1b60780aa72a8a93bd0369a4f2c66e33c9e273bd3e5d1fc4c70f2c43562e9600e05
6
+ metadata.gz: 60f031165824f5c440852e0c963a925cfb3959e36c4707bd78a5145f3933021a4f600261034118ffd79a8fbd4a7823b8574b75ee654debef46eed5c93182aab1
7
+ data.tar.gz: 79d99ff6c0be42d5794daae83d1567dee1ac8649b74c99ad23066ff9d3bdb9166b88ddcec154cabd04135280e948ae15e4439348bd1a00a5ecb92e7b1eccc972
@@ -1,3 +1,10 @@
1
+ ## GoogleSuggest 1.0.1
2
+
3
+ * Drop ruby 2.1 and 2.2 from and add ruby 2.5 supported ruby versions. [#19](https://github.com/satoryu/google_suggest/pull/19)
4
+ [#22](https://github.com/satoryu/google_suggest/pull/22)
5
+ * Starting use Webmock and RSpec 3.[#15](https://github.com/satoryu/google_suggest/pull/15)[#21](https://github.com/satoryu/google_suggest/pull/21)
6
+
7
+
1
8
  ## GoogleSuggest 1.0.0
2
9
 
3
10
  * Removing the dependency on `nokogiri`, use REXML. [#10](https://github.com/satoryu/google_suggest/pull/10)
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ group :test do
6
+ gem 'codeclimate-test-reporter', '~> 1.0.0'
7
+ end
@@ -1,29 +1,56 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- google_suggest (1.0.0)
4
+ google_suggest (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ addressable (2.5.2)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ codeclimate-test-reporter (1.0.8)
12
+ simplecov (<= 0.13)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
9
15
  diff-lcs (1.2.5)
10
- rake (11.1.2)
11
- rspec (2.14.1)
12
- rspec-core (~> 2.14.0)
13
- rspec-expectations (~> 2.14.0)
14
- rspec-mocks (~> 2.14.0)
15
- rspec-core (2.14.8)
16
- rspec-expectations (2.14.5)
17
- diff-lcs (>= 1.1.3, < 2.0)
18
- rspec-mocks (2.14.6)
16
+ docile (1.1.5)
17
+ hashdiff (0.3.7)
18
+ json (2.1.0)
19
+ public_suffix (3.0.1)
20
+ rake (12.0.0)
21
+ rspec (3.5.0)
22
+ rspec-core (~> 3.5.0)
23
+ rspec-expectations (~> 3.5.0)
24
+ rspec-mocks (~> 3.5.0)
25
+ rspec-core (3.5.4)
26
+ rspec-support (~> 3.5.0)
27
+ rspec-expectations (3.5.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.5.0)
30
+ rspec-mocks (3.5.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.5.0)
33
+ rspec-support (3.5.0)
34
+ safe_yaml (1.0.4)
35
+ simplecov (0.13.0)
36
+ docile (~> 1.1.0)
37
+ json (>= 1.8, < 3)
38
+ simplecov-html (~> 0.10.0)
39
+ simplecov-html (0.10.2)
40
+ webmock (3.2.1)
41
+ addressable (>= 2.3.6)
42
+ crack (>= 0.3.2)
43
+ hashdiff
19
44
 
20
45
  PLATFORMS
21
46
  ruby
22
47
 
23
48
  DEPENDENCIES
49
+ codeclimate-test-reporter (~> 1.0.0)
24
50
  google_suggest!
25
51
  rake
26
- rspec (~> 2.14.0)
52
+ rspec (~> 3.5.0)
53
+ webmock (~> 3.2.1)
27
54
 
28
55
  BUNDLED WITH
29
- 1.10.6
56
+ 1.16.1
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # GoogleSuggest
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/google_suggest.svg)](https://badge.fury.io/rb/google_suggest)
3
4
  [![Build Status](https://travis-ci.org/satoryu/google_suggest.svg?branch=master)](https://travis-ci.org/satoryu/google_suggest)
5
+ [![Test Coverage](https://codeclimate.com/github/satoryu/google_suggest/badges/coverage.svg)](https://codeclimate.com/github/satoryu/google_suggest/coverage)
4
6
 
5
7
  This gem allows you to access google suggest API in your ruby codes.
6
8
 
@@ -19,24 +19,26 @@ class GoogleSuggest
19
19
  @configuration ||= Configuration.new
20
20
  end
21
21
 
22
- def self.suggest_for(keyword, options={})
23
- self.new(options).suggest_for(keyword)
22
+ def self.suggest_for(keyword, options = {})
23
+ new(options).suggest_for(keyword)
24
24
  end
25
25
 
26
- def initialize(options={})
26
+ def initialize(options = {})
27
27
  @home_language = self.class.configuration.home_language
28
28
  @proxy = self.class.configuration.proxy
29
29
  @region = options[:region] || self.class.configure.region
30
30
  end
31
31
 
32
32
  def suggest_for(keyword)
33
- query = {:output => 'toolbar',
34
- :hl => self.home_language,
35
- :q => URI.encode(keyword)}
33
+ query = {
34
+ output: 'toolbar',
35
+ hl: home_language,
36
+ q: keyword
37
+ }
36
38
 
37
39
  res = http_get('/complete/search', query)
38
40
 
39
- return parse(res.body.to_s)
41
+ parse(res.body.to_s)
40
42
  end
41
43
 
42
44
  private
@@ -52,7 +54,7 @@ class GoogleSuggest
52
54
  end
53
55
 
54
56
  def http_get(path, query)
55
- path = path + '?' + query.map{|k,v| "#{k}=#{v}"}.join('&')
57
+ path = path + '?' + URI.encode_www_form(query)
56
58
  req = Net::HTTP::Get.new(path)
57
59
  http.request(req)
58
60
  end
@@ -65,12 +67,12 @@ class GoogleSuggest
65
67
  xml = REXML::Document.new(doc)
66
68
  suggestions = REXML::XPath.match(xml, '/toplevel/CompleteSuggestion/suggestion').each_with_object([]) do |suggest, res|
67
69
  data = suggest.attribute('data').value
68
- if data and !data.valid_encoding?
70
+ if data && !data.valid_encoding?
69
71
  data.force_encoding('Shift_JIS').encode!('UTF-8')
70
72
  end
71
73
  res << data
72
74
  end
73
75
 
74
- return suggestions
76
+ suggestions
75
77
  end
76
78
  end
@@ -6,7 +6,6 @@ class GoogleSuggest
6
6
  ae: 'www.google.ae',
7
7
  af: 'www.google.com.af',
8
8
  ag: 'www.google.com.ag',
9
- ag: 'www.google.com.ag',
10
9
  ai: 'www.google.com.ai',
11
10
  al: 'www.google.al',
12
11
  am: 'www.google.am',
@@ -184,6 +183,7 @@ class GoogleSuggest
184
183
  ua: 'www.google.com.ua',
185
184
  ug: 'www.google.co.ug',
186
185
  uk: 'www.google.co.uk',
186
+ us: 'www.google.com',
187
187
  com: 'www.google.com',
188
188
  uy: 'www.google.com.uy',
189
189
  uz: 'www.google.co.uz',
@@ -199,7 +199,7 @@ class GoogleSuggest
199
199
  zw: 'www.google.co.zw'
200
200
  }.freeze
201
201
 
202
- def self.host_for(region_code=nil)
202
+ def self.host_for(region_code = nil)
203
203
  region_code = region_code.to_sym if region_code.is_a?(String)
204
204
  GOOGLE_HOSTS[region_code] || GOOGLE_HOSTS[:com]
205
205
  end
@@ -1,3 +1,3 @@
1
1
  class GoogleSuggest
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'.freeze
3
3
  end
@@ -8,21 +8,21 @@ describe GoogleSuggest::Region do
8
8
  let(:region_code) { nil }
9
9
 
10
10
  it 'should be default host "www.google.com"' do
11
- should be_eql('www.google.com')
11
+ is_expected.to be_eql('www.google.com')
12
12
  end
13
13
  end
14
14
  context 'when giving a valid region code like "ac"' do
15
15
  let(:region_code) { 'ac' }
16
16
 
17
17
  it 'shoud be the google host for the given region' do
18
- should be_eql('www.google.ac')
18
+ is_expected.to be_eql('www.google.ac')
19
19
  end
20
20
  end
21
21
  context 'when giving an undefined region code like "zz"' do
22
22
  let(:region_code) { 'zz' }
23
23
 
24
24
  it 'should be the default host' do
25
- should be_eql('www.google.com')
25
+ is_expected.to be_eql('www.google.com')
26
26
  end
27
27
  end
28
28
  end
@@ -30,7 +30,7 @@ describe GoogleSuggest::Region do
30
30
  describe '.codes' do
31
31
  subject { GoogleSuggest::Region.codes }
32
32
 
33
- it { should be_a(Array) }
34
- it { should be_all { |k| k.is_a?(Symbol) } }
33
+ it { is_expected.to be_a(Array) }
34
+ it { is_expected.to be_all { |k| k.is_a?(Symbol) } }
35
35
  end
36
36
  end
@@ -1,41 +1,43 @@
1
- # encoding: utf-8
2
1
  require 'spec_helper'
3
2
 
4
3
  describe GoogleSuggest do
5
- describe ".new" do
4
+ describe '.new' do
6
5
  let(:args) { {} }
7
6
  let(:google_suggest) { GoogleSuggest.new(args) }
8
7
 
9
8
  subject { google_suggest }
10
9
 
11
- its(:home_language) { should be_eql 'en' }
12
- its(:proxy) { should be_nil }
13
- its(:google_host) { should be_eql 'www.google.com' }
10
+ describe '#home_language' do
11
+ subject { super().home_language }
12
+ it { is_expected.to be_eql 'en' }
13
+ end
14
+
15
+ describe '#proxy' do
16
+ subject { super().proxy }
17
+ it { is_expected.to be_nil }
18
+ end
14
19
 
15
20
  context 'when giving region option' do
16
21
  let(:args) { { region: 'ac' } }
17
22
 
18
- its(:home_language) { should be_eql 'en' }
19
- its(:google_host) { should be_eql 'www.google.ac' }
23
+ describe '#home_language' do
24
+ subject { super().home_language }
25
+ it { is_expected.to be_eql 'en' }
26
+ end
20
27
  end
21
28
  end
22
29
 
23
- describe ".suggest_for" do
24
- before do
25
- google_suggest = GoogleSuggest.new
26
- res = Object.new
27
- allow(res).to receive(:body) do
28
- File.read(File.join(File.dirname(__FILE__), 'sample_us.xml'))
29
- end
30
- allow(google_suggest).to receive(:http_get) { res }
31
- suggestions = google_suggest.suggest_for('google')
32
- allow(GoogleSuggest).to receive(:new).and_return { double('google_suggest', :suggest_for => suggestions) }
30
+ describe '.suggest_for' do
31
+ let(:suggestions) { GoogleSuggest.suggest_for('google') }
33
32
 
34
- @suggestions = GoogleSuggest.suggest_for('google')
33
+ before do
34
+ stub_request(:get, 'http://www.google.com/complete/search')
35
+ .with(query: { hl: 'en', output: 'toolbar', q: 'google' })
36
+ .to_return(body: File.read(File.join(File.dirname(__FILE__), 'sample_us.xml')))
35
37
  end
36
38
 
37
39
  it do
38
- @suggestions.size.should be 10
40
+ expect(suggestions.size).to be 10
39
41
  end
40
42
 
41
43
  context 'When passing Hash as options' do
@@ -50,7 +52,7 @@ describe GoogleSuggest do
50
52
  end
51
53
 
52
54
  describe '.configure' do
53
- context "When called without block" do
55
+ context 'When called without block' do
54
56
  before do
55
57
  @configure = GoogleSuggest.configure
56
58
  @configure.home_language = 'ja'
@@ -60,11 +62,22 @@ describe GoogleSuggest do
60
62
 
61
63
  subject { GoogleSuggest.new }
62
64
 
63
- its(:home_language) { should be_eql 'ja' }
64
- its(:region) { should be_eql 'ac' }
65
- its(:proxy) { should be_eql 'http://proxy.example.com' }
65
+ describe '#home_language' do
66
+ subject { super().home_language }
67
+ it { is_expected.to be_eql 'ja' }
68
+ end
69
+
70
+ describe '#region' do
71
+ subject { super().region }
72
+ it { is_expected.to be_eql 'ac' }
73
+ end
74
+
75
+ describe '#proxy' do
76
+ subject { super().proxy }
77
+ it { is_expected.to be_eql 'http://proxy.example.com' }
78
+ end
66
79
  end
67
- context "When called with given block" do
80
+ context 'When called with given block' do
68
81
  before do
69
82
  GoogleSuggest.configure do |c|
70
83
  c.home_language = 'us'
@@ -74,66 +87,69 @@ describe GoogleSuggest do
74
87
 
75
88
  subject { GoogleSuggest.new }
76
89
 
77
- its(:home_language) { should be_eql 'us' }
78
- its(:proxy) { should be_eql 'http://proxy.example.com' }
90
+ describe '#home_language' do
91
+ subject { super().home_language }
92
+ it { is_expected.to be_eql 'us' }
93
+ end
94
+
95
+ describe '#proxy' do
96
+ subject { super().proxy }
97
+ it { is_expected.to be_eql 'http://proxy.example.com' }
98
+ end
79
99
  end
80
100
  end
81
101
 
82
- describe "#suggest_from" do
102
+ describe '#suggest_from' do
83
103
  before :all do
84
104
  GoogleSuggest.configure do |c|
85
105
  c.home_language = 'us'
106
+ c.region = :com
86
107
  end
87
108
  end
88
109
 
110
+ let(:google_suggest) { GoogleSuggest.new }
111
+ let(:suggestions) { google_suggest.suggest_for('google') }
112
+
89
113
  before do
90
- @google_suggest = GoogleSuggest.new
91
- res = double(:response)
92
- allow(res).to receive(:body) do
93
- doc = nil
94
- File.open(File.join(File.dirname(__FILE__), 'sample_us.xml')) do |f|
95
- doc = f.read
96
- end
97
- doc
98
- end
99
- allow(@google_suggest).to receive(:http_get) { res }
114
+ stub_request(:get, 'http://www.google.com/complete/search')
115
+ .with(query: { hl: 'us', output: 'toolbar', q: 'google'})
116
+ .and_return(body: File.read(File.join(__dir__, 'sample_us.xml')))
100
117
  end
101
118
 
102
119
  it do
103
- suggestions = @google_suggest.suggest_for 'google'
104
- suggestions.size.should == 10
120
+ expect(suggestions.size).to eq(10)
105
121
  end
106
122
 
107
123
  it 'all suggestions should have the value of the key \'suggest\' 'do
108
- suggestions = @google_suggest.suggest_for 'google'
109
- suggestions.should be_all do |suggest|
124
+ expect(suggestions).to be_all do |suggest|
110
125
  not suggest.nil?
111
126
  end
112
127
  end
113
128
  end
114
- describe "#suggest_for with home language 'ja'" do
129
+ describe '#suggest_for with home language \'ja\'' do
115
130
  before :all do
116
131
  GoogleSuggest.configure do |c|
117
132
  c.home_language = 'ja'
133
+ c.region = :com
118
134
  end
119
135
  end
120
136
 
137
+ let(:google_suggest) { GoogleSuggest.new }
138
+
121
139
  before do
122
- @google_suggest = GoogleSuggest.new
123
- res = Object.new
124
- allow(res).to receive(:body) do
125
- doc = nil
126
- File.open(File.join(File.dirname(__FILE__), 'sample_ja.xml')) do |f|
127
- doc = f.read
128
- end
129
- doc
130
- end
131
- allow(@google_suggest).to receive(:http_get) { res }
140
+ stub_request(:get, 'http://www.google.com/complete/search')
141
+ .with(query: { hl: 'ja', output: 'toolbar', q: 'グーグル' })
142
+ .to_return(body: File.read(File.join(File.dirname(__FILE__), 'sample_ja.xml')))
132
143
  end
133
144
 
134
- subject { @google_suggest.suggest_for('グーグル').shift }
145
+ subject { google_suggest.suggest_for('グーグル').shift }
146
+
147
+ describe '#encoding' do
148
+ subject { super().encoding }
149
+
150
+ it { is_expected.to be Encoding.find('UTF-8') }
151
+ end
135
152
 
136
- its(:encoding) { should be Encoding.find("UTF-8") }
137
- it { should be_valid_encoding }
153
+ it { is_expected.to be_valid_encoding }
138
154
  end
139
155
  end
@@ -1,8 +1,18 @@
1
- # encoding: utf-8
1
+ if ENV['CI']
2
+ require 'simplecov'
2
3
 
3
- require File.expand_path(File.join(File.dirname(__FILE__), '..',
4
- 'lib', 'google_suggest'))
4
+ SimpleCov.start do
5
+ add_filter '/spec/'
6
+ end
7
+ end
8
+
9
+ require File.expand_path(File.join(__dir__, '..', 'lib', 'google_suggest'))
10
+ require 'webmock/rspec'
5
11
 
6
12
  RSpec.configure do |c|
7
13
  c.mock_with :rspec
14
+
15
+ c.before :suite do
16
+ WebMock.disable_net_connect!
17
+ end
8
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_suggest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuya Sato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-30 00:00:00.000000000 Z
11
+ date: 2018-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -30,14 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.14.0
33
+ version: 3.5.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.14.0
40
+ version: 3.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.1
41
55
  description:
42
56
  email: satoryu.1981@gmail.com
43
57
  executables: []
@@ -51,7 +65,6 @@ files:
51
65
  - LICENSE.txt
52
66
  - README.md
53
67
  - Rakefile
54
- - google_suggest.gemspec
55
68
  - lib/google_suggest.rb
56
69
  - lib/google_suggest/configuration.rb
57
70
  - lib/google_suggest/region.rb
@@ -73,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
86
  requirements:
74
87
  - - ">="
75
88
  - !ruby/object:Gem::Version
76
- version: 2.1.0
89
+ version: 2.3.0
77
90
  required_rubygems_version: !ruby/object:Gem::Requirement
78
91
  requirements:
79
92
  - - ">="
@@ -81,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
94
  version: '0'
82
95
  requirements: []
83
96
  rubyforge_project:
84
- rubygems_version: 2.4.5.1
97
+ rubygems_version: 2.7.3
85
98
  signing_key:
86
99
  specification_version: 4
87
100
  summary: A gem which allows us to retrieve suggest words from Google in your Ruby
@@ -1,24 +0,0 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
-
4
- require 'google_suggest/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'google_suggest'
8
- spec.required_ruby_version = '>= 2.1.0'
9
- spec.summary = 'A gem which allows us to retrieve suggest words from Google in your Ruby Code.'
10
- spec.version = GoogleSuggest::VERSION
11
- spec.author = 'Tatsuya Sato'
12
- spec.email = 'satoryu.1981@gmail.com'
13
- spec.homepage = 'http://github.com/satoryu/google_suggest/'
14
- spec.license = "MIT"
15
- spec.files = Dir[
16
- 'lib/**/*.rb',
17
- '[A-Z]*',
18
- 'spec/**/*'
19
- ]
20
-
21
- spec.add_development_dependency 'rake'
22
- spec.add_development_dependency 'rspec', '~> 2.14.0'
23
- end
24
-