esv_api 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Jeff McFadden
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -2,10 +2,6 @@
2
2
 
3
3
  An API Wrapper for the [ESV API](http://www.esvapi.org/api)
4
4
 
5
- # Limitations
6
-
7
- Currently only supports `passage_query`
8
-
9
5
  # Installation
10
6
 
11
7
  ```ruby
data/esv_api.gemspec CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
 
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.name = 'esv_api'
7
- s.version = '1.0.0'
7
+ s.version = '1.0.1'
8
8
  s.authors = ["Jeff McFadden"]
9
9
  s.email = ["jeff@forgeapps.com"]
10
10
  s.homepage = "http://github.com/jeffmcfadden/esv_api"
@@ -3,6 +3,17 @@ require 'esv_api/config'
3
3
  require 'httparty'
4
4
 
5
5
  module ESV
6
+ begin
7
+ require "dalli"
8
+ HAS_DALLI = true
9
+ rescue LoadError
10
+ HAS_DALLI = false
11
+ end
12
+
13
+ def self.should_cache?
14
+ HAS_DALLI
15
+ end
16
+
6
17
  # Wrapper for the ESV API
7
18
  #
8
19
  class Client
@@ -20,6 +31,10 @@ module ESV
20
31
  Config::VALID_OPTIONS_KEYS.each do |key|
21
32
  instance_variable_set("@#{key}".to_sym, attrs[key])
22
33
  end
34
+
35
+ if ESV.should_cache?
36
+ @dc = Dalli::Client.new('localhost:11211')
37
+ end
23
38
  end
24
39
 
25
40
  def passage_query(passage, options={})
@@ -30,7 +45,19 @@ module ESV
30
45
 
31
46
  query = options.merge( query )
32
47
 
33
- ESV::Client.get( self.endpoint + '/passageQuery', { :query => query } )
48
+ if ESV.should_cache?
49
+ cache_key = Digest::MD5.hexdigest( "esv_api_" + query.to_s )
50
+
51
+ cached_value = @dc.get( cache_key )
52
+
53
+ return cached_value unless cached_value.nil?
54
+ end
55
+
56
+ esv_text = ESV::Client.get( self.endpoint + '/passageQuery', { :query => query } )
57
+
58
+ @dc.set( cache_key, esv_text ) if ESV.should_cache?
59
+
60
+ return esv_text
34
61
  end
35
62
 
36
63
  def query( q, options={} )
@@ -13,7 +13,7 @@ module ESV
13
13
 
14
14
  # @return [Integer]
15
15
  def self.patch
16
- 0
16
+ 1
17
17
  end
18
18
 
19
19
  # @return [String, NilClass]
@@ -5,7 +5,7 @@ describe ESV::Client do
5
5
  @keys = ESV::Config::VALID_OPTIONS_KEYS
6
6
 
7
7
  ESV.configure do |config|
8
- config.api_key = 'aae0629deae45288'
8
+ config.api_key = 'a_valid_api_key'
9
9
  end
10
10
  end
11
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esv_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-22 00:00:00.000000000Z
12
+ date: 2012-01-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70242206491240 !ruby/object:Gem::Requirement
16
+ requirement: &70177774736500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70242206491240
24
+ version_requirements: *70177774736500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70242206490820 !ruby/object:Gem::Requirement
27
+ requirement: &70177774736080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70242206490820
35
+ version_requirements: *70177774736080
36
36
  description: ESV API Wrapper.
37
37
  email:
38
38
  - jeff@forgeapps.com
@@ -42,6 +42,7 @@ extra_rdoc_files: []
42
42
  files:
43
43
  - .gitignore
44
44
  - Gemfile
45
+ - LICENSE.md
45
46
  - README.md
46
47
  - Rakefile
47
48
  - esv_api.gemspec