bible_gateway 0.0.12 → 0.1.0
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 +4 -4
- data/.github/workflows/ruby.yml +33 -0
- data/.travis.yml +1 -0
- data/README.md +19 -6
- data/VERSION +1 -1
- data/bible_gateway.gemspec +4 -3
- data/lib/bible_gateway.rb +46 -12
- data/lib/bible_gateway/version.rb +1 -1
- data/spec/bible_gateway_spec.rb +66 -1
- metadata +23 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6c2cf9ceec0c095ec1a5ec095b0b77f21cadb4715e754a8640248b60c004201
|
4
|
+
data.tar.gz: 9609fe5c68301042cae31812f0c4f8e62f363fe7d83e326d57aa89310c401bd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9d1980166dd51fc83cc34b9e380479e74c7e6756daf9c587565a8657dfab5b6f24a1fe8d6f841813dae0829ac6f30b760dd9203f40ae66643d01b4c428b644a
|
7
|
+
data.tar.gz: 5167444cb5ae0af6df52f6988e3d4ed5e0d59944dac009ea1734abb3b887be5fee66d20956df6a15810a46b1bcf0a6d890d4592c1368d391db53420bcf659681
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v2
|
23
|
+
- name: Set up Ruby
|
24
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
25
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
26
|
+
# uses: ruby/setup-ruby@v1
|
27
|
+
uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
|
28
|
+
with:
|
29
|
+
ruby-version: 2.6
|
30
|
+
- name: Install dependencies
|
31
|
+
run: bundle install
|
32
|
+
- name: Run tests
|
33
|
+
run: bundle exec rake
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -22,15 +22,28 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
```
|
26
|
+
require 'bible_gateway'
|
26
27
|
|
27
|
-
|
28
|
-
b.version = :english_standard_version
|
29
|
-
b.lookup('John 1:1') # => "<h4>John 1</h4>\n<h5>The Word Became Flesh</h5> <sup>1</sup> In the beginning was the Word, and the Word was with God, and the Word was God."
|
28
|
+
BibleGateway.versions # available versions
|
30
29
|
|
31
|
-
|
30
|
+
BibleGateway.versions # available versions
|
32
31
|
|
33
|
-
|
32
|
+
b = BibleGateway.new # defaults to :king_james_version, but can be initialized to different version
|
33
|
+
|
34
|
+
b.version = :english_standard_version
|
35
|
+
b.lookup('John 1:1') # => "<h4>John 1</h4>\n<h5>The Word Became Flesh</h5> <sup>1</sup> In the beginning was the Word, and the Word was with God, and the Word was God."
|
36
|
+
```
|
37
|
+
|
38
|
+
## Scraping the old site through old_lookup
|
39
|
+
|
40
|
+
```
|
41
|
+
require 'bible_gateway'
|
42
|
+
|
43
|
+
b = BibleGateway.new # defaults to :king_james_version, but can be initialized to different version
|
44
|
+
|
45
|
+
b.old_lookup('John 1:1') # scraping the old site
|
46
|
+
```
|
34
47
|
|
35
48
|
## Contributing
|
36
49
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/bible_gateway.gemspec
CHANGED
@@ -7,9 +7,9 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "bible_gateway"
|
8
8
|
spec.version = BibleGateway::VERSION
|
9
9
|
spec.authors = ["Geoffrey Dagley"]
|
10
|
-
spec.email = ["gdagley@gmail.com", "bibleableproject@gmail.com"]
|
10
|
+
spec.email = ["gdagley@gmail.com", "bibleableproject@gmail.com", "ytbryan@gmail.com"]
|
11
11
|
spec.description = %q{An unofficial 'API' for BibleGateway.com.}
|
12
|
-
spec.summary = %q{An unofficial 'API' for BibleGateway.com
|
12
|
+
spec.summary = %q{An unofficial 'API' for BibleGateway.com and the classic BibleGateway}
|
13
13
|
spec.homepage = "https://github.com/gdagley/bible_gateway"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -21,7 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "nokogiri"
|
22
22
|
spec.add_dependency "typhoeus"
|
23
23
|
|
24
|
-
spec.add_development_dependency "
|
24
|
+
spec.add_development_dependency "net-ping"
|
25
|
+
spec.add_development_dependency "bundler"
|
25
26
|
spec.add_development_dependency "rake"
|
26
27
|
spec.add_development_dependency "rspec"
|
27
28
|
end
|
data/lib/bible_gateway.rb
CHANGED
@@ -6,7 +6,8 @@ require 'uri'
|
|
6
6
|
class BibleGatewayError < StandardError; end
|
7
7
|
|
8
8
|
class BibleGateway
|
9
|
-
GATEWAY_URL = "http://
|
9
|
+
GATEWAY_URL = "http://biblegateway.com"
|
10
|
+
CLASSIC_GATEWAY_URL = "http://classic.biblegateway.com"
|
10
11
|
|
11
12
|
VERSIONS = {
|
12
13
|
:american_standard_version => "ASV",
|
@@ -62,15 +63,54 @@ class BibleGateway
|
|
62
63
|
def lookup(passage)
|
63
64
|
response = Typhoeus.get(passage_url(passage), followlocation: true)
|
64
65
|
doc = Nokogiri::HTML(response.body)
|
65
|
-
scrape_passage(doc)
|
66
|
+
scrape_passage(doc, @version)
|
67
|
+
end
|
68
|
+
|
69
|
+
def old_lookup(passage)
|
70
|
+
response = Typhoeus.get(old_passage_url(passage), followlocation: true)
|
71
|
+
doc = Nokogiri::HTML(response.body)
|
72
|
+
old_way_scrape_passage(doc)
|
66
73
|
end
|
67
74
|
|
68
75
|
private
|
69
76
|
def passage_url(passage)
|
70
|
-
|
77
|
+
"#{GATEWAY_URL}/passage/?search=#{URI.encode_www_form_component(passage)}&version=#{URI.encode_www_form_component(VERSIONS[version])}"
|
78
|
+
end
|
79
|
+
|
80
|
+
def old_passage_url(passage)
|
81
|
+
"#{CLASSIC_GATEWAY_URL}/passage/?search=#{URI.encode_www_form_component(passage)}&version=#{URI.encode_www_form_component(VERSIONS[version])}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def scrape_passage(doc, version)
|
85
|
+
container = doc.css('div.passage-text')
|
86
|
+
title = container.css("div.version-#{VERSIONS[version]}.result-text-style-normal.text-html h1 span")[0].content.strip if container.css("div.version-#{VERSIONS[version]}.result-text-style-normal.text-html h1")[0] != nil
|
87
|
+
segment = doc.at('div.passage-text')
|
88
|
+
|
89
|
+
segment.search('sup.crossreference').remove # remove cross reference links
|
90
|
+
segment.search('sup.footnote').remove # remove footnote links
|
91
|
+
segment.search("div.crossrefs").remove # remove cross references
|
92
|
+
segment.search("div.footnotes").remove # remove footnotes
|
93
|
+
|
94
|
+
text = ""
|
95
|
+
segment.search("span.text").each do |span|
|
96
|
+
text += span.inner_text
|
97
|
+
end
|
98
|
+
|
99
|
+
segment.search("span.text").each do |span|
|
100
|
+
html_content = span.inner_html
|
101
|
+
span.swap html_content
|
102
|
+
end
|
103
|
+
|
104
|
+
segment.search('sup.versenum').each do |sup|
|
105
|
+
html_content = sup.content
|
106
|
+
sup.swap "<sup>#{html_content}</sup>"
|
107
|
+
end
|
108
|
+
|
109
|
+
content = segment.inner_html.gsub('<p></p>', '').gsub(/<!--.*?-->/, '').strip
|
110
|
+
{:title => title, :content => content, :text => text }
|
71
111
|
end
|
72
112
|
|
73
|
-
def
|
113
|
+
def old_way_scrape_passage(doc)
|
74
114
|
container = doc.css('div.container')
|
75
115
|
title = container.css('div.passage-details h1')[0].content.strip
|
76
116
|
segment = doc.at('div.passage-wrap')
|
@@ -79,29 +119,23 @@ class BibleGateway
|
|
79
119
|
segment.search("div.crossrefs").remove # remove cross references
|
80
120
|
segment.search("div.footnotes").remove # remove footnotes
|
81
121
|
|
82
|
-
#
|
122
|
+
# extract text only from scripture
|
83
123
|
text = ""
|
84
124
|
segment.search("span.text").each do |span|
|
85
125
|
text += span.inner_text
|
86
126
|
end
|
87
127
|
|
88
|
-
# text should be html so that text can be used above.
|
89
128
|
segment.search("span.text").each do |span|
|
90
129
|
html_content = span.inner_html
|
91
130
|
span.swap html_content
|
92
131
|
end
|
93
132
|
|
94
|
-
# text should be html so that text can be used above.
|
95
133
|
segment.search('sup.versenum').each do |sup|
|
96
134
|
html_content = sup.content
|
97
135
|
sup.swap "<sup>#{html_content}</sup>"
|
98
136
|
end
|
99
137
|
|
100
138
|
content = segment.inner_html.gsub('<p></p>', '').gsub(/<!--.*?-->/, '').strip
|
101
|
-
|
102
|
-
#scripture_text should be text
|
103
|
-
{:title => title,
|
104
|
-
:content => content,
|
105
|
-
:text => text }
|
139
|
+
{:title => title, :content => content, :text => text }
|
106
140
|
end
|
107
141
|
end
|
data/spec/bible_gateway_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require "spec_helper"
|
3
|
+
require 'net/ping'
|
3
4
|
|
4
5
|
describe BibleGateway do
|
5
6
|
it "should have a list of versions" do
|
@@ -39,7 +40,35 @@ describe BibleGateway do
|
|
39
40
|
|
40
41
|
end
|
41
42
|
|
43
|
+
describe "reachability" do
|
44
|
+
context "biblegateway.com" do
|
45
|
+
it "should reach biblegateway.com" do
|
46
|
+
check = Net::Ping::External.new(BibleGateway::GATEWAY_URL)
|
47
|
+
check.ping?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "classic biblegateway.com" do
|
52
|
+
it "should reach classic biblegateway.com" do
|
53
|
+
check = Net::Ping::External.new(BibleGateway::CLASSIC_GATEWAY_URL)
|
54
|
+
check.ping?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
42
59
|
describe "lookup" do
|
60
|
+
context "text only" do
|
61
|
+
it "should find the scripture text" do
|
62
|
+
text = BibleGateway.new(:english_standard_version).lookup("John 1:1")[:text]
|
63
|
+
expect(text).to eq("The Word Became Flesh1 In the beginning was the Word, and the Word was with God, and the Word was God.")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should find the scripture text via old_lookup" do
|
67
|
+
text = BibleGateway.new(:english_standard_version).old_lookup("John 1:1")[:text]
|
68
|
+
expect(text).to eq("The Word Became Flesh1 In the beginning was the Word, and the Word was with God, and the Word was God.")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
43
72
|
context "verse" do
|
44
73
|
it "should find the passage title" do
|
45
74
|
title = BibleGateway.new(:english_standard_version).lookup("John 1:1")[:title]
|
@@ -56,6 +85,17 @@ describe BibleGateway do
|
|
56
85
|
expect(content).to include("<h3>The Word Became Flesh</h3>")
|
57
86
|
expect(content).to include("In the beginning was the Word, and the Word was with God, and the Word was God.")
|
58
87
|
end
|
88
|
+
|
89
|
+
it "should find the passage title via old_lookup" do
|
90
|
+
title = BibleGateway.new(:english_standard_version).old_lookup("John 1:1")[:title]
|
91
|
+
expect(title).to eq("John 1:1")
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should find and clean the passage content via old_lookup" do
|
95
|
+
content = BibleGateway.new(:english_standard_version).old_lookup("John 1:1")[:content]
|
96
|
+
expect(content).to include("<h3>The Word Became Flesh</h3>")
|
97
|
+
expect(content).to include("In the beginning was the Word, and the Word was with God, and the Word was God.")
|
98
|
+
end
|
59
99
|
end
|
60
100
|
|
61
101
|
context "chapter" do
|
@@ -75,6 +115,18 @@ describe BibleGateway do
|
|
75
115
|
expect(content).to include("<h3>For God So Loved the World</h3>")
|
76
116
|
expect(content).to include("For God so loved the world, that he gave his only Son, that whoever believes in him should not perish but have eternal life.")
|
77
117
|
end
|
118
|
+
|
119
|
+
it "should find the passage title via old_lookup" do
|
120
|
+
title = BibleGateway.new(:english_standard_version).old_lookup("John 3")[:title]
|
121
|
+
expect(title).to eq("John 3")
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should find and clean the passage content via old_lookup" do
|
125
|
+
content = BibleGateway.new(:english_standard_version).old_lookup("John 3")[:content]
|
126
|
+
expect(content).to include("<h3>You Must Be Born Again</h3>")
|
127
|
+
expect(content).to include("<h3>For God So Loved the World</h3>")
|
128
|
+
expect(content).to include("For God so loved the world, that he gave his only Son, that whoever believes in him should not perish but have eternal life.")
|
129
|
+
end
|
78
130
|
end
|
79
131
|
|
80
132
|
context "multiple chapters" do
|
@@ -91,7 +143,20 @@ describe BibleGateway do
|
|
91
143
|
expect(content).to include("<span class=\"chapternum\">1 </span>")
|
92
144
|
expect(content).to include("For you are not a God who delights in wickedness;")
|
93
145
|
end
|
146
|
+
|
147
|
+
it "should find the passage title via old_lookup" do
|
148
|
+
title = BibleGateway.new(:english_standard_version).old_lookup("Psalm 1-5")[:title]
|
149
|
+
expect(title).to eq("Psalm 1-5")
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should find and clean the passage content via old_lookup" do
|
153
|
+
content = BibleGateway.new(:english_standard_version).old_lookup("Psalm 1-5")[:content]
|
154
|
+
expect(content).to include("<h3>The Way of the Righteous and the Wicked</h3>")
|
155
|
+
expect(content).to include("<span class=\"chapternum\">1 </span>")
|
156
|
+
expect(content).to include("<h3>Save Me, O My God</h3>")
|
157
|
+
expect(content).to include("<span class=\"chapternum\">1 </span>")
|
158
|
+
expect(content).to include("For you are not a God who delights in wickedness;")
|
159
|
+
end
|
94
160
|
end
|
95
161
|
end
|
96
|
-
|
97
162
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bible_gateway
|
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
|
- Geoffrey Dagley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -38,20 +38,34 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: net-ping
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,11 +98,13 @@ description: An unofficial 'API' for BibleGateway.com.
|
|
84
98
|
email:
|
85
99
|
- gdagley@gmail.com
|
86
100
|
- bibleableproject@gmail.com
|
101
|
+
- ytbryan@gmail.com
|
87
102
|
executables: []
|
88
103
|
extensions: []
|
89
104
|
extra_rdoc_files: []
|
90
105
|
files:
|
91
106
|
- ".document"
|
107
|
+
- ".github/workflows/ruby.yml"
|
92
108
|
- ".gitignore"
|
93
109
|
- ".rspec"
|
94
110
|
- ".travis.yml"
|
@@ -124,7 +140,7 @@ requirements: []
|
|
124
140
|
rubygems_version: 3.0.3
|
125
141
|
signing_key:
|
126
142
|
specification_version: 4
|
127
|
-
summary: An unofficial 'API' for BibleGateway.com
|
143
|
+
summary: An unofficial 'API' for BibleGateway.com and the classic BibleGateway
|
128
144
|
test_files:
|
129
145
|
- spec/bible_gateway_spec.rb
|
130
146
|
- spec/spec_helper.rb
|