guardian_searcher 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/Guardfile +8 -6
- data/README.md +30 -1
- data/guardian_searcher.gemspec +5 -4
- data/lib/guardian_searcher/base.rb +2 -6
- data/lib/guardian_searcher/options.rb +29 -2
- data/lib/guardian_searcher/version.rb +1 -1
- metadata +28 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbf80793abdcb30ddb0acb6ff62cc97bf5d2e230881d2057e391f61c3490fa4e
|
4
|
+
data.tar.gz: c6df4f2b8cd92f9ba2ae7fa29ae57eb3e4ad3d2a7637176e0c1a8ec53b7f654e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d5779ce66ac3507594a07a52db236e1c581729e8b2b05d27ff11287ef8e9dce7eb69b54a9f80298a0fc2d096d3b952f1eb8fc64d3b389713fbedfd0a8e70720
|
7
|
+
data.tar.gz: de83958f007a38e71bfe15d4637aa645feb2d88e370582cef5de3c4fc67a9daf720fae26bd4062e7a32ce7c6a5921aa42d8d5b57be8af8f51514ec2cd8e3fda9
|
data/.gitignore
CHANGED
data/Guardfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# A sample Guardfile
|
2
4
|
# More info at https://github.com/guard/guard#readme
|
3
5
|
|
@@ -14,7 +16,7 @@
|
|
14
16
|
#
|
15
17
|
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
16
18
|
|
17
|
-
#
|
19
|
+
# NOTE: The cmd option is now required due to the increasing number of ways
|
18
20
|
# rspec may be run, below are examples of the most common uses.
|
19
21
|
# * bundler: 'bundle exec rspec'
|
20
22
|
# * bundler binstubs: 'bin/rspec'
|
@@ -40,7 +42,7 @@ guard :rspec, cmd: "bundle exec rspec" do
|
|
40
42
|
dsl.watch_spec_files_for(ruby.lib_files)
|
41
43
|
|
42
44
|
# Rails files
|
43
|
-
rails = dsl.rails(view_extensions: %w
|
45
|
+
rails = dsl.rails(view_extensions: %w[erb haml slim])
|
44
46
|
dsl.watch_spec_files_for(rails.app_files)
|
45
47
|
dsl.watch_spec_files_for(rails.views)
|
46
48
|
|
@@ -69,12 +71,12 @@ guard :rspec, cmd: "bundle exec rspec" do
|
|
69
71
|
end
|
70
72
|
|
71
73
|
guard :bundler do
|
72
|
-
require
|
73
|
-
require
|
74
|
+
require "guard/bundler"
|
75
|
+
require "guard/bundler/verify"
|
74
76
|
helper = Guard::Bundler::Verify.new
|
75
77
|
|
76
|
-
files = [
|
77
|
-
files += Dir[
|
78
|
+
files = ["Gemfile"]
|
79
|
+
files += Dir["*.gemspec"] if files.any? { |f| helper.uses_gemspec?(f) }
|
78
80
|
|
79
81
|
# Assume files are symlinked from somewhere
|
80
82
|
files.each { |file| watch(helper.real_path(file)) }
|
data/README.md
CHANGED
@@ -26,7 +26,36 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
|
29
|
+
```ruby
|
30
|
+
# To include the gem in your code
|
31
|
+
require 'guardian_searcher'
|
32
|
+
|
33
|
+
# To initialise the gem
|
34
|
+
searcher = GuardianSearcher::Search.new(api_key: <your-api-key>)
|
35
|
+
|
36
|
+
# Simplest usage
|
37
|
+
results = searcher.search('your keyword')
|
38
|
+
```
|
39
|
+
|
40
|
+
There are some supported option that will be mapped to the api query and these are in the Options
|
41
|
+
class
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
{
|
45
|
+
from_date: "from-date",
|
46
|
+
to_date: "to-date",
|
47
|
+
page_size: "page-size",
|
48
|
+
page: "page"
|
49
|
+
}
|
50
|
+
```
|
51
|
+
|
52
|
+
In this way your search could become something like
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
results = searcher.search('your keyword', { from_date: '2022-10-01', page_size: 10 })
|
56
|
+
```
|
57
|
+
|
58
|
+
If you add something unsupported it will throw an `OptionsNotSupportedError`
|
30
59
|
|
31
60
|
## Development
|
32
61
|
|
data/guardian_searcher.gemspec
CHANGED
@@ -30,10 +30,11 @@ Gem::Specification.new do |spec|
|
|
30
30
|
# spec.add_dependency "example-gem", "~> 1.0"
|
31
31
|
spec.add_dependency "faraday", "~> 2.2"
|
32
32
|
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
33
|
+
spec.add_development_dependency "guard", "~> 2.18"
|
34
|
+
spec.add_development_dependency "guard-bundler", "~> 3.0"
|
35
|
+
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
36
|
+
spec.add_development_dependency "simplecov", "~> 0.21"
|
37
|
+
spec.add_development_dependency "vcr", "~> 6.1"
|
37
38
|
# For more information and examples about making a new gem, checkout our
|
38
39
|
# guide at: https://bundler.io/guides/creating_gem.html
|
39
40
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
module GuardianSearcher
|
4
4
|
class Base
|
5
5
|
include Faraday
|
6
|
+
|
6
7
|
attr_reader :api_key
|
7
8
|
attr_accessor :base_uri
|
8
9
|
|
@@ -31,12 +32,7 @@ module GuardianSearcher
|
|
31
32
|
private
|
32
33
|
|
33
34
|
def build_options(options)
|
34
|
-
|
35
|
-
|
36
|
-
opt = ""
|
37
|
-
options.each do |key, value|
|
38
|
-
opt += "&#{key}=#{value}"
|
39
|
-
end
|
35
|
+
Options.new(options).build_options
|
40
36
|
end
|
41
37
|
end
|
42
38
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GuardianSearcher
|
2
4
|
class OptionsNotHashError < StandardError; end
|
3
5
|
class OptionsNotSupportedError < StandardError; end
|
@@ -6,13 +8,38 @@ module GuardianSearcher
|
|
6
8
|
private attr_accessor :options
|
7
9
|
|
8
10
|
def method_missing(method_name, *args, &blk)
|
9
|
-
return
|
11
|
+
return options.[](method_name, &blk) if @options.key?(method_name)
|
12
|
+
|
10
13
|
super(method_name, *args, &blk)
|
11
14
|
end
|
12
|
-
|
15
|
+
|
13
16
|
def initialize(options)
|
14
17
|
raise OptionsNotHashError unless options.is_a?(Hash)
|
18
|
+
|
15
19
|
@options = options
|
16
20
|
end
|
21
|
+
|
22
|
+
def build_options
|
23
|
+
return {} if options.empty?
|
24
|
+
|
25
|
+
opt = ""
|
26
|
+
options.each do |key, value|
|
27
|
+
valid_option?(key)
|
28
|
+
opt += "&#{map_option(key)}=#{value}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid_option?(option)
|
33
|
+
raise OptionsNotSupportedError unless %i[from_date to_date page_size page].include?(option)
|
34
|
+
end
|
35
|
+
|
36
|
+
def map_option(key)
|
37
|
+
{
|
38
|
+
from_date: "from-date",
|
39
|
+
to_date: "to-date",
|
40
|
+
page_size: "page-size",
|
41
|
+
page: "page"
|
42
|
+
}[key]
|
43
|
+
end
|
17
44
|
end
|
18
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guardian_searcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alain Mauri
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -25,61 +25,75 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: guard
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.18'
|
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: '
|
40
|
+
version: '2.18'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: guard
|
42
|
+
name: guard-bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: guard-
|
56
|
+
name: guard-rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '4.7'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '4.7'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0.21'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0.21'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '6.1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '6.1'
|
83
97
|
description:
|
84
98
|
email: wildeng@hotmail.com
|
85
99
|
executables: []
|