esv_api 1.0.1 → 1.0.2
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 +7 -0
- data/README.md +4 -0
- data/esv_api.gemspec +3 -3
- data/lib/esv_api/client.rb +36 -36
- data/lib/esv_api/config.rb +3 -1
- data/lib/esv_api/version.rb +1 -1
- metadata +21 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e3792614c9313314f8a04daf433532160d302626
|
4
|
+
data.tar.gz: 24b72318f3af8bca01516cc5aa75e05e1545728b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a04bdf6a34ac115c4e6bd95a70f8ed6ba91f743b7b3807351ec350b87483823b1b46352a028a8ade03bd520eef08fed9d03248abee869551bae3453bdc6cfb30
|
7
|
+
data.tar.gz: 09d6aeae3288e8420f2ab0d456033e6513ce42a8090da9d1343325a3ce26a4702407e655bec82b66091d5e488edf6b79b3229639c41d7b40df19d68b29c2e1af
|
data/README.md
CHANGED
@@ -67,6 +67,10 @@ For example:
|
|
67
67
|
|
68
68
|
HTML is the default output and will appear unless output-format is specified. To make full use of the text, you will probably want to link a CSS stylesheet to your page, either one you've created or [GNP's CSS](http://www.gnpcb.org/esv/assets/style/text.css). This stylesheet contains close to the minimum markup needed to render the text accurately.
|
69
69
|
|
70
|
+
## Caching
|
71
|
+
|
72
|
+
If you have the `dalli` gem installed, `esv_api` will cache the data returned from passage_query calls, taking options into account when setting the key.
|
73
|
+
|
70
74
|
# Credits
|
71
75
|
|
72
76
|
With love to the Twitter Gem, from which I borrowed heavily.
|
data/esv_api.gemspec
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.add_dependency 'httparty'
|
3
3
|
s.add_development_dependency 'rspec'
|
4
|
-
|
4
|
+
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.name = 'esv_api'
|
7
|
-
s.version = '1.0.
|
7
|
+
s.version = '1.0.2'
|
8
8
|
s.authors = ["Jeff McFadden"]
|
9
9
|
s.email = ["jeff@forgeapps.com"]
|
10
10
|
s.homepage = "http://github.com/jeffmcfadden/esv_api"
|
11
11
|
s.summary = "ESV API Wrapper."
|
12
12
|
s.description = "ESV API Wrapper."
|
13
|
-
|
13
|
+
|
14
14
|
s.required_ruby_version = '>= 1.9.2'
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
data/lib/esv_api/client.rb
CHANGED
@@ -9,17 +9,17 @@ module ESV
|
|
9
9
|
rescue LoadError
|
10
10
|
HAS_DALLI = false
|
11
11
|
end
|
12
|
-
|
13
|
-
def self.
|
14
|
-
HAS_DALLI
|
12
|
+
|
13
|
+
def self.should_use_caching?
|
14
|
+
ESV.options[:should_cache] && HAS_DALLI
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
# Wrapper for the ESV API
|
18
18
|
#
|
19
19
|
class Client
|
20
20
|
include HTTParty
|
21
21
|
format :html
|
22
|
-
|
22
|
+
|
23
23
|
attr_accessor *Config::VALID_OPTIONS_KEYS
|
24
24
|
|
25
25
|
# Initializes a new API object
|
@@ -31,96 +31,96 @@ module ESV
|
|
31
31
|
Config::VALID_OPTIONS_KEYS.each do |key|
|
32
32
|
instance_variable_set("@#{key}".to_sym, attrs[key])
|
33
33
|
end
|
34
|
-
|
35
|
-
if ESV.
|
34
|
+
|
35
|
+
if ESV.should_use_caching?
|
36
36
|
@dc = Dalli::Client.new('localhost:11211')
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def passage_query(passage, options={})
|
41
41
|
query = {
|
42
42
|
'key' => self.api_key,
|
43
43
|
'passage' => passage
|
44
44
|
}
|
45
|
-
|
45
|
+
|
46
46
|
query = options.merge( query )
|
47
|
-
|
48
|
-
if ESV.
|
47
|
+
|
48
|
+
if ESV.should_use_caching?
|
49
49
|
cache_key = Digest::MD5.hexdigest( "esv_api_" + query.to_s )
|
50
|
-
|
50
|
+
|
51
51
|
cached_value = @dc.get( cache_key )
|
52
|
-
|
52
|
+
|
53
53
|
return cached_value unless cached_value.nil?
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
esv_text = ESV::Client.get( self.endpoint + '/passageQuery', { :query => query } )
|
57
|
-
|
58
|
-
@dc.set( cache_key, esv_text ) if ESV.
|
59
|
-
|
57
|
+
|
58
|
+
@dc.set( cache_key, esv_text ) if ESV.should_use_caching?
|
59
|
+
|
60
60
|
return esv_text
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def query( q, options={} )
|
64
64
|
query = {
|
65
65
|
'key' => self.api_key,
|
66
66
|
'q' => q
|
67
67
|
}
|
68
|
-
|
68
|
+
|
69
69
|
query = options.merge( query )
|
70
|
-
|
70
|
+
|
71
71
|
ESV::Client.get( self.endpoint + '/query', { :query => query } )
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def reading_plan_query( options={} )
|
75
75
|
query = {
|
76
76
|
'key' => self.api_key,
|
77
77
|
}
|
78
|
-
|
78
|
+
|
79
79
|
query = options.merge( query )
|
80
|
-
|
80
|
+
|
81
81
|
ESV::Client.get( self.endpoint + '/readingPlanQuery', { :query => query } )
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def query_info( q, options={} )
|
85
85
|
query = {
|
86
86
|
'key' => self.api_key,
|
87
87
|
'q' => q
|
88
88
|
}
|
89
|
-
|
89
|
+
|
90
90
|
query = options.merge( query )
|
91
|
-
|
91
|
+
|
92
92
|
ESV::Client.get( self.endpoint + '/queryInfo', { :query => query } )
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
def reading_plan_info( options={} )
|
96
96
|
query = {
|
97
97
|
'key' => self.api_key,
|
98
98
|
}
|
99
|
-
|
99
|
+
|
100
100
|
query = options.merge( query )
|
101
|
-
|
101
|
+
|
102
102
|
ESV::Client.get( self.endpoint + '/readingPlanQuery', { :query => query } )
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
def verse( options={} )
|
106
106
|
query = {
|
107
107
|
'key' => self.api_key,
|
108
108
|
}
|
109
|
-
|
109
|
+
|
110
110
|
query = options.merge( query )
|
111
|
-
|
111
|
+
|
112
112
|
ESV::Client.get( self.endpoint + '/verse', { :query => query } )
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
def daily_verse( options={} )
|
116
116
|
query = {
|
117
117
|
'key' => self.api_key,
|
118
118
|
}
|
119
|
-
|
119
|
+
|
120
120
|
query = options.merge( query )
|
121
|
-
|
121
|
+
|
122
122
|
ESV::Client.get( self.endpoint + '/verse', { :query => query } )
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
end
|
126
126
|
end
|
data/lib/esv_api/config.rb
CHANGED
@@ -17,7 +17,8 @@ module ESV
|
|
17
17
|
VALID_OPTIONS_KEYS = [
|
18
18
|
:api_key,
|
19
19
|
:endpoint,
|
20
|
-
:user_agent
|
20
|
+
:user_agent,
|
21
|
+
:should_cache
|
21
22
|
]
|
22
23
|
|
23
24
|
attr_accessor *VALID_OPTIONS_KEYS
|
@@ -45,6 +46,7 @@ module ESV
|
|
45
46
|
self.api_key = DEFAULT_API_KEY
|
46
47
|
self.endpoint = DEFAULT_ENDPOINT
|
47
48
|
self.user_agent = DEFAULT_USER_AGENT
|
49
|
+
self.should_cache = true
|
48
50
|
self
|
49
51
|
end
|
50
52
|
|
data/lib/esv_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,38 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esv_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jeff McFadden
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-09-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: httparty
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: rspec
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
description: ESV API Wrapper.
|
37
42
|
email:
|
38
43
|
- jeff@forgeapps.com
|
@@ -55,28 +60,27 @@ files:
|
|
55
60
|
- spec/helper.rb
|
56
61
|
homepage: http://github.com/jeffmcfadden/esv_api
|
57
62
|
licenses: []
|
63
|
+
metadata: {}
|
58
64
|
post_install_message:
|
59
65
|
rdoc_options: []
|
60
66
|
require_paths:
|
61
67
|
- lib
|
62
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
69
|
requirements:
|
65
|
-
- -
|
70
|
+
- - '>='
|
66
71
|
- !ruby/object:Gem::Version
|
67
72
|
version: 1.9.2
|
68
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
74
|
requirements:
|
71
|
-
- -
|
75
|
+
- - '>='
|
72
76
|
- !ruby/object:Gem::Version
|
73
77
|
version: '0'
|
74
78
|
requirements:
|
75
79
|
- none
|
76
80
|
rubyforge_project:
|
77
|
-
rubygems_version:
|
81
|
+
rubygems_version: 2.0.14
|
78
82
|
signing_key:
|
79
|
-
specification_version:
|
83
|
+
specification_version: 4
|
80
84
|
summary: ESV API Wrapper.
|
81
85
|
test_files:
|
82
86
|
- spec/esv_api/client_spec.rb
|