esv_api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/Gemfile +3 -0
- data/README.md +34 -0
- data/Rakefile +13 -0
- data/esv_api.gemspec +19 -0
- data/lib/esv_api/client.rb +36 -0
- data/lib/esv_api/config.rb +52 -0
- data/lib/esv_api/version.rb +30 -0
- data/lib/esv_api.rb +24 -0
- metadata +66 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# ESV_API
|
2
|
+
|
3
|
+
An API Wrapper for the ESV API
|
4
|
+
|
5
|
+
# Limitations
|
6
|
+
|
7
|
+
Currently only supports `passage_query`
|
8
|
+
|
9
|
+
# Installation
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
|
13
|
+
gem 'esv_api'
|
14
|
+
|
15
|
+
```
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
|
19
|
+
# Create an initializer:
|
20
|
+
|
21
|
+
ESV.configure do |config|
|
22
|
+
config.api_key = YOUR_API_KEY
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
|
28
|
+
@esv_text = ESV.passage_query( params[:passage] || "John 1", { 'include-footnotes' => 'false', 'include-headings' => 'false', 'include-subheadings' => 'false', 'include-audio-link' => 'false' } )
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
# Credits
|
33
|
+
|
34
|
+
With love to the Twitter Gem, from which I borrowed heavily.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the esv_api gem.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
data/esv_api.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.add_dependency 'httparty'
|
3
|
+
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.name = 'esv_api'
|
6
|
+
s.version = '0.0.1'
|
7
|
+
s.authors = ["Jeff McFadden"]
|
8
|
+
s.email = ["jeff@forgeapps.com"]
|
9
|
+
s.homepage = "http://github.com/jeffmcfadden/esv_api"
|
10
|
+
s.summary = "ESV API Wrapper."
|
11
|
+
s.description = "ESV API Wrapper."
|
12
|
+
|
13
|
+
s.required_ruby_version = '>= 1.9.2'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.require_path = 'lib'
|
18
|
+
s.requirements << 'none'
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'esv_api/config'
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module ESV
|
6
|
+
# Wrapper for the ESV API
|
7
|
+
#
|
8
|
+
class Client
|
9
|
+
include HTTParty
|
10
|
+
format :html
|
11
|
+
|
12
|
+
attr_accessor *Config::VALID_OPTIONS_KEYS
|
13
|
+
|
14
|
+
# Initializes a new API object
|
15
|
+
#
|
16
|
+
# @param attrs [Hash]
|
17
|
+
# @return [ESV::Client]
|
18
|
+
def initialize(attrs={})
|
19
|
+
attrs = ESV.options.merge(attrs)
|
20
|
+
Config::VALID_OPTIONS_KEYS.each do |key|
|
21
|
+
instance_variable_set("@#{key}".to_sym, attrs[key])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def passage_query(passage, options={})
|
26
|
+
query = {
|
27
|
+
'key' => self.api_key,
|
28
|
+
'passage' => passage
|
29
|
+
}
|
30
|
+
|
31
|
+
query = options.merge( query )
|
32
|
+
|
33
|
+
ESV::Client.get( self.endpoint + '/passageQuery', { :query => query } )
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'esv_api/version'
|
2
|
+
|
3
|
+
module ESV
|
4
|
+
# Defines constants and methods related to configuration
|
5
|
+
module Config
|
6
|
+
|
7
|
+
# The API Key if none is set
|
8
|
+
DEFAULT_API_KEY = nil
|
9
|
+
|
10
|
+
# The endpoint that will be used to connect if none is set
|
11
|
+
DEFAULT_ENDPOINT = 'http://www.esvapi.org/v2/rest/'
|
12
|
+
|
13
|
+
# The value sent in the 'User-Agent' header if none is set
|
14
|
+
DEFAULT_USER_AGENT = "esv_api Ruby Gem #{ESV::Version}"
|
15
|
+
|
16
|
+
# An array of valid keys in the options hash when configuring a {Twitter::Client}
|
17
|
+
VALID_OPTIONS_KEYS = [
|
18
|
+
:api_key,
|
19
|
+
:endpoint,
|
20
|
+
:user_agent
|
21
|
+
]
|
22
|
+
|
23
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
24
|
+
|
25
|
+
# When this module is extended, set all configuration options to their default values
|
26
|
+
def self.extended(base)
|
27
|
+
base.reset
|
28
|
+
end
|
29
|
+
|
30
|
+
# Convenience method to allow configuration options to be set in a block
|
31
|
+
def configure
|
32
|
+
yield self
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
# Create a hash of options and their values
|
37
|
+
def options
|
38
|
+
options = {}
|
39
|
+
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
|
40
|
+
options
|
41
|
+
end
|
42
|
+
|
43
|
+
# Reset all configuration options to defaults
|
44
|
+
def reset
|
45
|
+
self.api_key = DEFAULT_API_KEY
|
46
|
+
self.endpoint = DEFAULT_ENDPOINT
|
47
|
+
self.user_agent = DEFAULT_USER_AGENT
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ESV
|
2
|
+
class Version
|
3
|
+
|
4
|
+
# @return [Integer]
|
5
|
+
def self.major
|
6
|
+
0
|
7
|
+
end
|
8
|
+
|
9
|
+
# @return [Integer]
|
10
|
+
def self.minor
|
11
|
+
0
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Integer]
|
15
|
+
def self.patch
|
16
|
+
1
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String, NilClass]
|
20
|
+
def self.pre
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String]
|
25
|
+
def self.to_s
|
26
|
+
[major, minor, patch, pre].compact.join('.')
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/esv_api.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'esv_api/client'
|
2
|
+
require 'esv_api/config'
|
3
|
+
|
4
|
+
module ESV
|
5
|
+
extend Config
|
6
|
+
class << self
|
7
|
+
# Alias for ESV::Client.new
|
8
|
+
#
|
9
|
+
# @return [ESV::Client]
|
10
|
+
def new(options={})
|
11
|
+
ESV::Client.new(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Delegate to ESV::Client
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
return super unless new.respond_to?(method)
|
17
|
+
new.send(method, *args, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def respond_to?(method, include_private=false)
|
21
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: esv_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeff McFadden
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-22 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: &70296141623180 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70296141623180
|
25
|
+
description: ESV API Wrapper.
|
26
|
+
email:
|
27
|
+
- jeff@forgeapps.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- esv_api.gemspec
|
37
|
+
- lib/esv_api.rb
|
38
|
+
- lib/esv_api/client.rb
|
39
|
+
- lib/esv_api/config.rb
|
40
|
+
- lib/esv_api/version.rb
|
41
|
+
homepage: http://github.com/jeffmcfadden/esv_api
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.9.2
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements:
|
60
|
+
- none
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.6
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: ESV API Wrapper.
|
66
|
+
test_files: []
|