nebrija 1.0.8 → 1.0.9

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: e88cf6582f87d79939a6875adb7fa7c577f00316
4
- data.tar.gz: c9f8856abd41c69a0990821261f1fcc99134c52c
3
+ metadata.gz: b05db641a064b02de12be55a7213ebd7a8c33032
4
+ data.tar.gz: bd51dda0fee5787e964959ae8fc5b43204553407
5
5
  SHA512:
6
- metadata.gz: 867a51af868ec5cd7fc8e1df3967162948b803931ea76d1c8f38fec815b4ab3abc0e9b8c02c39fa64d1dd0f86024491f643e297af740731118a06b87cbfa8305
7
- data.tar.gz: b8d59ebecf6ccf5c7d12d0054d597408f62ecebad183d474bf71f15a6eb1b2d361aff054d13e818b4885e620398a2be541bb8230a20c1c925deea4105f332a30
6
+ metadata.gz: d0ecbd51c7867bec5cdd08e8af68db16a63b8c2c41c63d1cfd2cf91d37db38883208aea672e59833179e04dbbb312add2606e41320f1eb8a6e0af95ad0327c9c
7
+ data.tar.gz: 126b5dd142c1958043178b7d1c8b68010f67c6b56a6e183cd16e541946f3cc614119fc525836065a766580dae4f820b9e95646959c5add7d0af355f5197421a0
data/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ test/mocks/* linguist-vendored
@@ -1,9 +1,7 @@
1
1
  require 'nokogiri'
2
2
 
3
3
  class Parser
4
- META_REGEX = /^([a-zA-Z]{1,4}+\.[ ]{1,2})+/
5
-
6
- def initialize(rae_data, _word)
4
+ def initialize(rae_data)
7
5
  @doc = Nokogiri::HTML(rae_data)
8
6
  end
9
7
 
data/lib/nebrija/rae.rb CHANGED
@@ -4,26 +4,44 @@ require 'net/http'
4
4
  class Rae
5
5
  SEARCH_URL = 'http://dle.rae.es/srv/fetch'.freeze
6
6
  # rubocop:disable LineLength
7
- USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'.freeze
7
+ USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'.freeze
8
8
  OPEN_TIMEOUT = 2
9
9
  READ_TIMEOUT = 3
10
10
 
11
11
  def search(word)
12
- Parser.new(query(word), word).parse
12
+ Parser.new(query(word)).parse
13
13
  end
14
14
 
15
15
  private
16
16
 
17
17
  def query(word)
18
- uri = URI "#{SEARCH_URL}?w=#{CGI.escape(word)}".encode('iso-8859-1')
18
+ uri = URI.parse "#{SEARCH_URL}?w=#{CGI.escape(word)}".encode('iso-8859-1')
19
19
 
20
20
  Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
21
21
  http.open_timeout = OPEN_TIMEOUT
22
22
  http.read_timeout = READ_TIMEOUT
23
23
 
24
- request = Net::HTTP::Get.new uri
24
+ request = Net::HTTP::Post.new(uri)
25
+ request['User-Agent'] = USER_AGENT
26
+ request.form_data = form_data
27
+
25
28
  response = http.request request
29
+
26
30
  response.body
27
31
  end
28
32
  end
33
+
34
+ private
35
+ def form_data
36
+ {
37
+ 'TS017111a7_id' => '3',
38
+ 'TS017111a7_cr' => '1895c885a17201dca76eb401d01fd59f:jlmn:U9YRi5sw:1485055093',
39
+ 'TS017111a7_76' => '0',
40
+ 'TS017111a7_86' => '0',
41
+ 'TS017111a7_md' => '1',
42
+ 'TS017111a7_rf' => '0',
43
+ 'TS017111a7_ct' => '0',
44
+ 'TS017111a7_pd' => '0',
45
+ }
46
+ end
29
47
  end
@@ -1,7 +1,7 @@
1
1
  module Nebrija
2
2
  MAJOR = 1
3
3
  MINOR = 0
4
- PATCH = 8
4
+ PATCH = 9
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
data/test/test_rae.rb CHANGED
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class TestRae < Minitest::Test
4
4
  def test_cli_basic
5
5
  word = 'amor'
6
- stub_request(:get, "#{Rae::SEARCH_URL}?w=#{word}")
6
+ stub_request(:post, "#{Rae::SEARCH_URL}?w=#{word}")
7
7
  .to_return(status: 200, body: mock('single'))
8
8
 
9
9
  out, = capture_io do
@@ -14,7 +14,7 @@ class TestRae < Minitest::Test
14
14
  end
15
15
 
16
16
  def test_error_basic
17
- stub_request(:get, "#{Rae::SEARCH_URL}?w=wadus")
17
+ stub_request(:post, "#{Rae::SEARCH_URL}?w=wadus")
18
18
  .to_return(status: 200, body: mock('error'))
19
19
 
20
20
  search = Rae.new.search('wadus')
@@ -22,7 +22,7 @@ class TestRae < Minitest::Test
22
22
  end
23
23
 
24
24
  def test_single_basic
25
- stub_request(:get, "#{Rae::SEARCH_URL}?w=amor")
25
+ stub_request(:post, "#{Rae::SEARCH_URL}?w=amor")
26
26
  .to_return(status: 200, body: mock('single'))
27
27
 
28
28
  search = Rae.new.search('amor')
@@ -34,7 +34,7 @@ class TestRae < Minitest::Test
34
34
  end
35
35
 
36
36
  def test_multiple_basic
37
- stub_request(:get, "#{Rae::SEARCH_URL}?w=banco")
37
+ stub_request(:post, "#{Rae::SEARCH_URL}?w=banco")
38
38
  .to_return(status: 200, body: mock('multiple'))
39
39
 
40
40
  search = Rae.new.search('banco')
@@ -53,7 +53,6 @@ class TestRae < Minitest::Test
53
53
 
54
54
  def mock_cli
55
55
  # rubocop:disable LineLength
56
- 'Sentimiento hacia otra persona que naturalmente nos atrae y que, procurando reciprocidad en el deseo de unión, nos completa, alegra y da energía para convivir, comunicarnos y crear
57
- '
56
+ 'Sentimiento hacia otra persona que naturalmente nos atrae y que, procurando reciprocidad en el deseo de unión, nos completa, alegra y da energía para convivir, comunicarnos y crear'
58
57
  end
59
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nebrija
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - javierhonduco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-13 00:00:00.000000000 Z
11
+ date: 2017-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -87,6 +87,7 @@ executables:
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".gitattributes"
90
91
  - ".gitignore"
91
92
  - ".rubocop.yml"
92
93
  - ".travis.yml"