google_suggest 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile.lock +8 -5
- data/{LICENCE.txt → LICENSE.txt} +2 -2
- data/README.md +54 -0
- data/google_suggest.gemspec +6 -7
- data/lib/google_suggest/configuration.rb +12 -0
- data/lib/google_suggest/region.rb +208 -0
- data/lib/google_suggest/version.rb +1 -1
- data/lib/google_suggest.rb +23 -25
- data/spec/google_suggest/region_spec.rb +22 -0
- data/spec/google_suggest_spec.rb +36 -17
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97a251c55415e7ecf907421034dd5a120c6cd9c7
|
4
|
+
data.tar.gz: fb6b46af27920ff5da1770dba21925a23e5d37cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d802d3d3f7d3508c895f66b327c1f0817bbdcc94630e92ea1cd0a51e3314185aa9db748c26f3fe0650db130dbfa967ba16baedf597ddb5ddc8c41558b5a010d5
|
7
|
+
data.tar.gz: 4517dc27d8908a516ae2214701432fc922cef2661c7afd5d23e082afafec3ff148db838dbcc247db4729b943db4f4c569a657a1a90dd3852f81539a97a4de080
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
## GoogleSuggest 0.1.0
|
2
|
+
|
3
|
+
* `GoogleSuggest.suggest_for` supports `region` [#2](https://github.com/satoryu/google_suggest/issues/2)
|
4
|
+
The class method allows users to choose their regions by passing `region` option to it like
|
5
|
+
`GoogleSuggest.suggest_for 'foo', region: 'jp'`. You would get different results and different order.
|
6
|
+
@imargonis, Thank you for proposing your idea.
|
7
|
+
|
8
|
+
* Renamed `GoogleSuggest::Configure` with `GoogleSuggest::Configuration`
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
google_suggest (0.0
|
4
|
+
google_suggest (0.1.0)
|
5
5
|
nokogiri (~> 1.6.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.2.5)
|
11
|
-
|
12
|
-
nokogiri (1.6.
|
13
|
-
|
14
|
-
rake (
|
11
|
+
mini_portile2 (2.0.0)
|
12
|
+
nokogiri (1.6.7.2)
|
13
|
+
mini_portile2 (~> 2.0.0.rc2)
|
14
|
+
rake (11.1.2)
|
15
15
|
rspec (2.14.1)
|
16
16
|
rspec-core (~> 2.14.0)
|
17
17
|
rspec-expectations (~> 2.14.0)
|
@@ -28,3 +28,6 @@ DEPENDENCIES
|
|
28
28
|
google_suggest!
|
29
29
|
rake
|
30
30
|
rspec (~> 2.14.0)
|
31
|
+
|
32
|
+
BUNDLED WITH
|
33
|
+
1.10.6
|
data/{LICENCE.txt → LICENSE.txt}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
The MIT License
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2016 Tatsuya Sato
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# GoogleSuggest
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/satoryu/google_suggest.svg?branch=master)](https://travis-ci.org/satoryu/google_suggest)
|
4
|
+
|
5
|
+
This gem allows you to access google suggest API in your ruby codes.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'google_suggest'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install google_suggest
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
`GoogleSuggest.suggest_for` gives suggestions for a given keyword.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
GoogleSuggest.suggest_for 'google'
|
29
|
+
=> [{"suggestion"=>"google"}, {"suggestion"=>"google maps"}, {"suggestion"=>"google translate"}, {"suggestion"=>"google classroom"}, {"suggestion"=>"google docs"}, {"suggestion"=>"google drive"}, {"suggestion"=>"google earth"}, {"suggestion"=>"google play"}, {"suggestion"=>"google scholar"}, {"suggestion"=>"google slides"}]
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
and allows developers to switch the endpoint by specifying `region` option:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
GoogleSuggest.suggest_for 'google'
|
37
|
+
=> [{"suggestion"=>"google maps"}, {"suggestion"=>"google"}, {"suggestion"=>"google translate"}, {"suggestion"=>"google drive"}, {"suggestion"=>"google scholar"}, {"suggestion"=>"google docs"}, {"suggestion"=>"google news"}, {"suggestion"=>"google flights"}, {"suggestion"=>"google play"}, {"suggestion"=>"google earth"}]
|
38
|
+
```
|
39
|
+
|
40
|
+
## Development
|
41
|
+
|
42
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
43
|
+
|
44
|
+
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](https://rubygems.org).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/satoryu/google_suggest. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
49
|
+
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
54
|
+
|
data/google_suggest.gemspec
CHANGED
@@ -2,22 +2,21 @@ lib = File.expand_path('../lib', __FILE__)
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
|
4
4
|
require 'google_suggest/version'
|
5
|
-
require 'rake'
|
6
5
|
|
7
6
|
Gem::Specification.new do |spec|
|
8
7
|
spec.name = 'google_suggest'
|
9
|
-
spec.required_ruby_version = '>= 1.
|
8
|
+
spec.required_ruby_version = '>= 2.1.0'
|
10
9
|
spec.summary = 'A gem which allows us to retrieve suggest words from Google in your Ruby Code.'
|
11
10
|
spec.version = GoogleSuggest::VERSION
|
12
11
|
spec.author = 'Tatsuya Sato'
|
13
12
|
spec.email = 'satoryu.1981@gmail.com'
|
14
13
|
spec.homepage = 'http://github.com/satoryu/google_suggest/'
|
15
14
|
spec.license = "MIT"
|
16
|
-
spec.files =
|
17
|
-
|
18
|
-
|
19
|
-
spec/**/*
|
20
|
-
]
|
15
|
+
spec.files = Dir[
|
16
|
+
'lib/**/*.rb',
|
17
|
+
'[A-Z]*',
|
18
|
+
'spec/**/*'
|
19
|
+
]
|
21
20
|
|
22
21
|
spec.add_runtime_dependency "nokogiri", '~> 1.6.0'
|
23
22
|
|
@@ -0,0 +1,208 @@
|
|
1
|
+
class GoogleSuggest
|
2
|
+
GOOGLE_HOSTS = {
|
3
|
+
ac: 'www.google.ac',
|
4
|
+
ad: 'www.google.ad',
|
5
|
+
ae: 'www.google.ae',
|
6
|
+
af: 'www.google.com.af',
|
7
|
+
ag: 'www.google.com.ag',
|
8
|
+
ag: 'www.google.com.ag',
|
9
|
+
ai: 'www.google.com.ai',
|
10
|
+
al: 'www.google.al',
|
11
|
+
am: 'www.google.am',
|
12
|
+
ao: 'www.google.am',
|
13
|
+
ar: 'www.google.com.ar',
|
14
|
+
as: 'www.google.as',
|
15
|
+
at: 'www.google.at',
|
16
|
+
au: 'www.google.com.au',
|
17
|
+
az: 'www.google.az',
|
18
|
+
ba: 'www.google.ga',
|
19
|
+
bd: 'www.google.com.bd',
|
20
|
+
be: 'www.google.be',
|
21
|
+
bf: 'www.google.bf',
|
22
|
+
bg: 'www.google.bg',
|
23
|
+
bh: 'www.google.com.bh',
|
24
|
+
bi: 'www.google.bi',
|
25
|
+
bj: 'www.google.bj',
|
26
|
+
bn: 'www.google.com.bn',
|
27
|
+
bo: 'www.google.com.bo',
|
28
|
+
br: 'www.google.com.br',
|
29
|
+
bs: 'www.google.bs',
|
30
|
+
bt: 'www.google.bt',
|
31
|
+
bw: 'www.google.co.bw',
|
32
|
+
by: 'www.google.by',
|
33
|
+
bz: 'www.google.com.bz',
|
34
|
+
ca: 'www.google.ca',
|
35
|
+
kh: 'www.google.com.kh',
|
36
|
+
cc: 'www.google.cc',
|
37
|
+
cd: 'www.google.cd',
|
38
|
+
cf: 'www.google.cf',
|
39
|
+
cat: 'www.google.cat',
|
40
|
+
cg: 'www.google.cg',
|
41
|
+
ch: 'www.google.ch',
|
42
|
+
ci: 'www.google.ci',
|
43
|
+
ck: 'www.google.co.ck',
|
44
|
+
cl: 'www.google.cl',
|
45
|
+
cm: 'www.google.cm',
|
46
|
+
cn: 'www.google.cn',
|
47
|
+
co: 'www.google.com.co',
|
48
|
+
cr: 'www.google.co.cr',
|
49
|
+
cu: 'www.google.com.cu',
|
50
|
+
cv: 'www.google.cv',
|
51
|
+
cy: 'www.google.com.cy',
|
52
|
+
cz: 'www.google.cz',
|
53
|
+
de: 'www.google.de',
|
54
|
+
dj: 'www.google.dj',
|
55
|
+
dk: 'www.google.dk',
|
56
|
+
dm: 'www.google.dm',
|
57
|
+
do: 'www.google.com.do',
|
58
|
+
dz: 'www.google.dz',
|
59
|
+
ec: 'www.google.com.ec',
|
60
|
+
ee: 'www.google.ee',
|
61
|
+
eg: 'www.google.com.eg',
|
62
|
+
es: 'www.google.es',
|
63
|
+
et: 'www.google.com.et',
|
64
|
+
fi: 'www.google.fi',
|
65
|
+
fj: 'www.google.com.fj',
|
66
|
+
fm: 'www.google.fm',
|
67
|
+
fr: 'www.google.fr',
|
68
|
+
ga: 'www.google.ga',
|
69
|
+
ge: 'www.google.ge',
|
70
|
+
gf: 'www.google.gf',
|
71
|
+
gg: 'www.google.gg',
|
72
|
+
gh: 'www.google.com.gh',
|
73
|
+
gi: 'www.google.com.gi',
|
74
|
+
gl: 'www.google.gl',
|
75
|
+
gm: 'www.google.gm',
|
76
|
+
gp: 'www.google.gp',
|
77
|
+
gr: 'www.google.gr',
|
78
|
+
gt: 'www.google.com.gt',
|
79
|
+
gy: 'www.google.gy',
|
80
|
+
hk: 'www.google.com.hk',
|
81
|
+
hn: 'www.google.hn',
|
82
|
+
hr: 'www.google.hr',
|
83
|
+
ht: 'www.google.ht',
|
84
|
+
hu: 'www.google.hu',
|
85
|
+
id: 'www.google.co.id',
|
86
|
+
iq: 'www.google.iq',
|
87
|
+
ie: 'www.google.ie',
|
88
|
+
il: 'www.google.co.il',
|
89
|
+
im: 'www.google.im',
|
90
|
+
in: 'www.google.co.in',
|
91
|
+
io: 'www.google.io',
|
92
|
+
is: 'www.google.is',
|
93
|
+
it: 'www.google.it',
|
94
|
+
je: 'www.google.je',
|
95
|
+
jm: 'www.google.com.jm',
|
96
|
+
jo: 'www.google.jo',
|
97
|
+
jp: 'www.google.co.jp',
|
98
|
+
ke: 'www.google.co.ke',
|
99
|
+
ki: 'www.google.ki',
|
100
|
+
kg: 'www.google.kg',
|
101
|
+
kr: 'www.google.co.kr',
|
102
|
+
kw: 'www.google.com.kw',
|
103
|
+
kz: 'www.google.kz',
|
104
|
+
la: 'www.google.la',
|
105
|
+
lb: 'www.google.com.lb',
|
106
|
+
lc: 'www.google.com.lc',
|
107
|
+
li: 'www.google.li',
|
108
|
+
lk: 'www.google.lk',
|
109
|
+
ls: 'www.google.co.ls',
|
110
|
+
lt: 'www.google.lt',
|
111
|
+
lu: 'www.google.lu',
|
112
|
+
lv: 'www.google.lv',
|
113
|
+
ly: 'www.google.com.ly',
|
114
|
+
ma: 'www.google.co.ma',
|
115
|
+
md: 'www.google.md',
|
116
|
+
me: 'www.google.me',
|
117
|
+
mg: 'www.google.mg',
|
118
|
+
mk: 'www.google.mk',
|
119
|
+
ml: 'www.google.ml',
|
120
|
+
mm: 'www.google.com.mm',
|
121
|
+
mn: 'www.google.mn',
|
122
|
+
ms: 'www.google.ms',
|
123
|
+
mt: 'www.google.com.mt',
|
124
|
+
mu: 'www.google.mu',
|
125
|
+
mv: 'www.google.mv',
|
126
|
+
mz: 'www.google.co.mz',
|
127
|
+
na: 'www.google.com.na',
|
128
|
+
ne: 'www.google.ne',
|
129
|
+
nf: 'www.google.com.nf',
|
130
|
+
ng: 'www.google.com.ng',
|
131
|
+
ni: 'www.google.com.ni',
|
132
|
+
nl: 'www.google.nl',
|
133
|
+
no: 'www.google.no',
|
134
|
+
np: 'www.google.com.np',
|
135
|
+
nr: 'www.google.nr',
|
136
|
+
nu: 'www.google.nu',
|
137
|
+
nz: 'www.google.co.nz',
|
138
|
+
om: 'www.google.com.om',
|
139
|
+
pk: 'www.google.com.pk',
|
140
|
+
pa: 'www.google.com.pa',
|
141
|
+
pe: 'www.google.com.pe',
|
142
|
+
ph: 'www.google.com.ph',
|
143
|
+
pl: 'www.google.pl',
|
144
|
+
pg: 'www.google.com.pg',
|
145
|
+
pn: 'www.google.pn',
|
146
|
+
pr: 'www.google.com.pr',
|
147
|
+
ps: 'www.google.ps',
|
148
|
+
pt: 'www.google.pt',
|
149
|
+
py: 'www.google.com.py',
|
150
|
+
qa: 'www.google.com.qa',
|
151
|
+
ro: 'www.google.ro',
|
152
|
+
rs: 'www.google.rs',
|
153
|
+
ru: 'www.google.ru',
|
154
|
+
rw: 'www.google.rw',
|
155
|
+
sa: 'www.google.com.sa',
|
156
|
+
sb: 'www.google.com.sb',
|
157
|
+
sc: 'www.google.sc',
|
158
|
+
se: 'www.google.se',
|
159
|
+
sg: 'www.google.com.sg',
|
160
|
+
sh: 'www.google.sh',
|
161
|
+
si: 'www.google.si',
|
162
|
+
sk: 'www.google.sk',
|
163
|
+
sl: 'www.google.sl',
|
164
|
+
sn: 'www.google.sn',
|
165
|
+
sm: 'www.google.sm',
|
166
|
+
so: 'www.google.so',
|
167
|
+
st: 'www.google.st',
|
168
|
+
sr: 'www.google.sr',
|
169
|
+
sv: 'www.google.com.sv',
|
170
|
+
td: 'www.google.td',
|
171
|
+
tg: 'www.google.tg',
|
172
|
+
th: 'www.google.co.th',
|
173
|
+
tj: 'www.google.com.tj',
|
174
|
+
tk: 'www.google.tk',
|
175
|
+
tl: 'www.google.tl',
|
176
|
+
tm: 'www.google.tm',
|
177
|
+
to: 'www.google.to',
|
178
|
+
tn: 'www.google.tn',
|
179
|
+
tr: 'www.google.com.tr',
|
180
|
+
tt: 'www.google.tt',
|
181
|
+
tw: 'www.google.com.tw',
|
182
|
+
tz: 'www.google.co.tz',
|
183
|
+
ua: 'www.google.com.ua',
|
184
|
+
ug: 'www.google.co.ug',
|
185
|
+
uk: 'www.google.co.uk',
|
186
|
+
com: 'www.google.com',
|
187
|
+
uy: 'www.google.com.uy',
|
188
|
+
uz: 'www.google.co.uz',
|
189
|
+
vc: 'www.google.com.vc',
|
190
|
+
ve: 'www.google.co.ve',
|
191
|
+
vg: 'www.google.vg',
|
192
|
+
vi: 'www.google.co.vi',
|
193
|
+
vn: 'www.google.com.vn',
|
194
|
+
vu: 'www.google.vu',
|
195
|
+
ws: 'www.google.ws',
|
196
|
+
za: 'www.google.co.za',
|
197
|
+
zm: 'www.google.co.zm',
|
198
|
+
zw: 'www.google.co.zw'
|
199
|
+
}
|
200
|
+
|
201
|
+
class Region
|
202
|
+
def self.host_for(region_code=nil)
|
203
|
+
region_code = :com if region_code.nil?
|
204
|
+
region_code = region_code.to_sym if region_code.is_a?(String)
|
205
|
+
GOOGLE_HOSTS[region_code] || DEFAULT_GOOGLE_HOST
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
data/lib/google_suggest.rb
CHANGED
@@ -3,36 +3,32 @@
|
|
3
3
|
require 'uri'
|
4
4
|
require 'nokogiri'
|
5
5
|
require 'net/http'
|
6
|
+
require 'google_suggest/configuration'
|
7
|
+
require 'google_suggest/region'
|
6
8
|
|
7
9
|
class GoogleSuggest
|
8
|
-
class Configure
|
9
|
-
attr_accessor :home_language
|
10
|
-
attr_accessor :proxy
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@home_language = 'en'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
10
|
attr_accessor :home_language
|
11
|
+
attr_accessor :region
|
18
12
|
attr_accessor :proxy
|
19
13
|
|
20
|
-
|
14
|
+
def self.configure
|
15
|
+
yield configuration if block_given?
|
21
16
|
|
22
|
-
|
23
|
-
|
24
|
-
yield @@configure if block_given?
|
25
|
-
@@configure
|
26
|
-
end
|
17
|
+
configuration
|
18
|
+
end
|
27
19
|
|
28
|
-
|
29
|
-
|
30
|
-
end
|
20
|
+
def self.configuration
|
21
|
+
@configuration ||= Configuration.new
|
31
22
|
end
|
32
23
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
24
|
+
def self.suggest_for(keyword, options={})
|
25
|
+
self.new(options).suggest_for(keyword)
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(options={})
|
29
|
+
@home_language = self.class.configuration.home_language
|
30
|
+
@proxy = self.class.configuration.proxy
|
31
|
+
@region = options[:region] || self.class.configure.region
|
36
32
|
end
|
37
33
|
|
38
34
|
def suggest_for(keyword)
|
@@ -56,22 +52,24 @@ class GoogleSuggest
|
|
56
52
|
end
|
57
53
|
|
58
54
|
private
|
59
|
-
GOOGLE_HOST = 'www.google.com'
|
60
55
|
|
61
56
|
def http
|
62
57
|
if @proxy
|
63
|
-
proxy_url = URI.parse(@proxy)
|
58
|
+
proxy_url = URI.parse(@proxy)
|
64
59
|
http_class = Net::HTTP.Proxy(proxy_url.host, proxy_url.port)
|
65
60
|
else
|
66
61
|
http_class = Net::HTTP
|
67
62
|
end
|
68
|
-
http_class.new(
|
63
|
+
http_class.new(google_host)
|
69
64
|
end
|
70
65
|
|
71
|
-
def http_get(path, query)
|
66
|
+
def http_get(path, query)
|
72
67
|
path = path + '?' + query.map{|k,v| "#{k}=#{v}"}.join('&')
|
73
68
|
req = Net::HTTP::Get.new(path)
|
74
69
|
http.request(req)
|
75
70
|
end
|
76
71
|
|
72
|
+
def google_host
|
73
|
+
Region.host_for(region)
|
74
|
+
end
|
77
75
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GoogleSuggest::Region do
|
4
|
+
describe '.host_for' do
|
5
|
+
subject { GoogleSuggest::Region.host_for(region_code) }
|
6
|
+
|
7
|
+
context 'when giving nil as region code' do
|
8
|
+
let(:region_code) { nil }
|
9
|
+
|
10
|
+
it 'should be default host "www.google.com"' do
|
11
|
+
should be_eql('www.google.com')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
context 'when giving a valid region code like "ac"' do
|
15
|
+
let(:region_code) { 'ac' }
|
16
|
+
|
17
|
+
it 'shoud be the google host for the given region' do
|
18
|
+
should be_eql('www.google.ac')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/google_suggest_spec.rb
CHANGED
@@ -1,23 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe GoogleSuggest do
|
4
|
-
|
5
|
-
|
5
|
+
describe ".new" do
|
6
|
+
let(:args) { {} }
|
7
|
+
let(:google_suggest) { GoogleSuggest.new(args) }
|
8
|
+
|
9
|
+
subject { google_suggest }
|
6
10
|
|
7
11
|
its(:home_language) { should be_eql 'en' }
|
8
12
|
its(:proxy) { should be_nil }
|
13
|
+
its(:google_host) { should be_eql 'www.google.com' }
|
14
|
+
|
15
|
+
context 'when giving region option' do
|
16
|
+
let(:args) { { region: 'ac' } }
|
17
|
+
|
18
|
+
its(:home_language) { should be_eql 'en' }
|
19
|
+
its(:google_host) { should be_eql 'www.google.ac' }
|
20
|
+
end
|
9
21
|
end
|
10
22
|
|
11
|
-
|
23
|
+
describe ".suggest_for" do
|
12
24
|
before do
|
13
25
|
google_suggest = GoogleSuggest.new
|
14
26
|
res = Object.new
|
15
27
|
allow(res).to receive(:body) do
|
16
|
-
|
17
|
-
File.open(File.join(File.dirname(__FILE__), 'sample_us.xml')) do |f|
|
18
|
-
doc = f.read
|
19
|
-
end
|
20
|
-
doc
|
28
|
+
File.read(File.join(File.dirname(__FILE__), 'sample_us.xml'))
|
21
29
|
end
|
22
30
|
allow(google_suggest).to receive(:http_get) { res }
|
23
31
|
suggestions = google_suggest.suggest_for('google')
|
@@ -25,41 +33,53 @@ describe GoogleSuggest do
|
|
25
33
|
|
26
34
|
@suggestions = GoogleSuggest.suggest_for('google')
|
27
35
|
end
|
28
|
-
|
29
|
-
it do
|
36
|
+
|
37
|
+
it do
|
30
38
|
@suggestions.size.should be 10
|
31
39
|
end
|
32
|
-
|
33
|
-
|
40
|
+
|
41
|
+
context 'When passing Hash as options' do
|
42
|
+
specify 'should initialize new object with the options.' do
|
43
|
+
obj = double(:google_suggest)
|
44
|
+
expect(obj).to receive(:suggest_for).with('google')
|
45
|
+
expect(GoogleSuggest).to receive(:new).with(region: 'jp').and_return(obj)
|
46
|
+
|
47
|
+
GoogleSuggest.suggest_for('google', region: 'jp')
|
34
48
|
end
|
35
49
|
end
|
36
50
|
end
|
37
51
|
|
38
|
-
describe
|
39
|
-
context "
|
52
|
+
describe '.configure' do
|
53
|
+
context "When called without block" do
|
40
54
|
before do
|
41
55
|
@configure = GoogleSuggest.configure
|
42
56
|
@configure.home_language = 'ja'
|
57
|
+
@configure.region = 'ac'
|
43
58
|
@configure.proxy = 'http://proxy.example.com'
|
44
59
|
end
|
60
|
+
|
45
61
|
subject { GoogleSuggest.new }
|
62
|
+
|
46
63
|
its(:home_language) { should be_eql 'ja' }
|
64
|
+
its(:region) { should be_eql 'ac' }
|
47
65
|
its(:proxy) { should be_eql 'http://proxy.example.com' }
|
48
66
|
end
|
49
|
-
context "
|
67
|
+
context "When called with given block" do
|
50
68
|
before do
|
51
69
|
GoogleSuggest.configure do |c|
|
52
70
|
c.home_language = 'us'
|
53
71
|
c.proxy = 'http://proxy.example.com'
|
54
72
|
end
|
55
73
|
end
|
74
|
+
|
56
75
|
subject { GoogleSuggest.new }
|
76
|
+
|
57
77
|
its(:home_language) { should be_eql 'us' }
|
58
78
|
its(:proxy) { should be_eql 'http://proxy.example.com' }
|
59
79
|
end
|
60
80
|
end
|
61
81
|
|
62
|
-
|
82
|
+
describe "#suggest_from" do
|
63
83
|
before :all do
|
64
84
|
GoogleSuggest.configure do |c|
|
65
85
|
c.home_language = 'us'
|
@@ -91,7 +111,6 @@ describe GoogleSuggest do
|
|
91
111
|
end
|
92
112
|
end
|
93
113
|
|
94
|
-
|
95
114
|
it 'all suggestions should have the value of the key \'num_queries\' 'do
|
96
115
|
suggestions = @google_suggest.suggest_for 'google'
|
97
116
|
suggestions.should be_all do |suggest|
|
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: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tatsuya Sato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -58,13 +58,19 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
+
- CHANGELOG.md
|
62
|
+
- CODE_OF_CONDUCT.md
|
61
63
|
- Gemfile
|
62
64
|
- Gemfile.lock
|
63
|
-
-
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
64
67
|
- Rakefile
|
65
68
|
- google_suggest.gemspec
|
66
69
|
- lib/google_suggest.rb
|
70
|
+
- lib/google_suggest/configuration.rb
|
71
|
+
- lib/google_suggest/region.rb
|
67
72
|
- lib/google_suggest/version.rb
|
73
|
+
- spec/google_suggest/region_spec.rb
|
68
74
|
- spec/google_suggest_spec.rb
|
69
75
|
- spec/sample_ja.xml
|
70
76
|
- spec/sample_us.xml
|
@@ -81,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
87
|
requirements:
|
82
88
|
- - ">="
|
83
89
|
- !ruby/object:Gem::Version
|
84
|
-
version: 1.
|
90
|
+
version: 2.1.0
|
85
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
93
|
- - ">="
|
@@ -89,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
95
|
version: '0'
|
90
96
|
requirements: []
|
91
97
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.4.5
|
98
|
+
rubygems_version: 2.4.5.1
|
93
99
|
signing_key:
|
94
100
|
specification_version: 4
|
95
101
|
summary: A gem which allows us to retrieve suggest words from Google in your Ruby
|