ahiru 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 503c60d3f4cfd72ed13cccc9319e627bd03ba9e7b4832d22a13d4c8e52d97493
4
- data.tar.gz: ba05588b758293f9a3939e44e26822db8ad621de1b6069e83d79e470caa3cd58
3
+ metadata.gz: 29c306e23dbb64c85d29bf8535922e8b5ca364a36998044ea5ae10926f04c6ad
4
+ data.tar.gz: 32826aca8e5952bd84d653816c8f9c3c46eff157bad31478ba3cb007a2ee71cf
5
5
  SHA512:
6
- metadata.gz: ac0107171b051857cb6b82813ef4c30a11ee1147be70f10ef337989dd8c114ca6d3a818ec85ea66760d5ff1c200da402481dfd4b9e4dd56125c749f97889f81d
7
- data.tar.gz: 829108f6ddeeb1d262ff17756dc118e24c15b969073e693c3fd1b01b774522614f5defba43f2137803695eb209e990c88f4b76d30f770f6d7aa19afb70fca071
6
+ metadata.gz: 3b078f4fcff09afbbb8c5393b401e9ba7f6189463f4d9dadf46c7663a752e898273c56f31316afd3a7169ede71312c355ca5b164f7b8156cd6a13b5b561c772e
7
+ data.tar.gz: '018523406c89c930659ea45361b627d7324470ce8bb28dcfd66bfa732e93ec49c38c26a3c0eabda22309cbc804fc953864da69082fb646d6a547207ee5ff952d'
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # ahiru
2
2
 
3
+ [![Gem version](https://img.shields.io/gem/v/ahiru.svg)](https://rubygems.org/gems/ahiru)
3
4
  [![Build Status](https://travis-ci.org/ninoseki/ahiru.svg?branch=master)](https://travis-ci.org/ninoseki/ahiru)
4
5
  [![Coverage Status](https://coveralls.io/repos/github/ninoseki/ahiru/badge.svg?branch=master)](https://coveralls.io/github/ninoseki/ahiru?branch=master)
5
6
 
@@ -32,6 +32,6 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "vcr", "~> 4.0"
33
33
  spec.add_development_dependency "webmock", "~> 3.5"
34
34
 
35
- spec.add_dependency "http", "~> 4.0"
35
+ spec.add_dependency "http", "~> 4.1"
36
36
  spec.add_dependency "oga", "~> 2.15"
37
37
  end
@@ -2,12 +2,14 @@
2
2
 
3
3
  require "http"
4
4
  require "oga"
5
+ require "uri"
5
6
 
6
7
  module Ahiru
7
8
  class API
8
9
  DUCKDUCKGO_ENDPOINT = "https://duckduckgo.com/html/"
9
10
 
10
- def search(params)
11
+ def search(q:, s: nil, dc: nil)
12
+ params = { q: q, s: s, dc: dc }.compact
11
13
  body = get_body(DUCKDUCKGO_ENDPOINT, params)
12
14
  return nil if body.nil?
13
15
 
@@ -20,8 +22,23 @@ module Ahiru
20
22
 
21
23
  private
22
24
 
25
+ def proxy?
26
+ proxy != nil
27
+ end
28
+
29
+ def proxy
30
+ @proxy ||= [].tap do |out|
31
+ https_proxy = ENV["https_proxy"] || ENV["HTTPS_PROXY"]
32
+ out << URI(https_proxy) if https_proxy
33
+ end.first
34
+ end
35
+
36
+ def http
37
+ proxy? ? HTTP.via(proxy.host, proxy.port) : HTTP
38
+ end
39
+
23
40
  def get_body(url, params)
24
- res = HTTP.get(url, params: params)
41
+ res = http.get(url, params: params)
25
42
  return nil unless res.code == 200
26
43
 
27
44
  res.body.to_s
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ahiru
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahiru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manabu Niseki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-10 00:00:00.000000000 Z
11
+ date: 2019-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '4.0'
117
+ version: '4.1'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '4.0'
124
+ version: '4.1'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: oga
127
127
  requirement: !ruby/object:Gem::Requirement