esv_api 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ESV_API
2
2
 
3
- An API Wrapper for the ESV API
3
+ An API Wrapper for the [ESV API](http://www.esvapi.org/api)
4
4
 
5
5
  # Limitations
6
6
 
@@ -11,12 +11,16 @@ Currently only supports `passage_query`
11
11
  ```ruby
12
12
 
13
13
  gem 'esv_api'
14
-
15
14
  ```
16
15
 
16
+
17
+ # Usage
18
+
19
+ For your rails app:
20
+
17
21
  ```ruby
18
22
 
19
- # Create an initializer:
23
+ #Create an initializer:
20
24
 
21
25
  ESV.configure do |config|
22
26
  config.api_key = YOUR_API_KEY
@@ -28,6 +32,44 @@ Currently only supports `passage_query`
28
32
  @esv_text = ESV.passage_query( params[:passage] || "John 1", { 'include-footnotes' => 'false', 'include-headings' => 'false', 'include-subheadings' => 'false', 'include-audio-link' => 'false' } )
29
33
  ```
30
34
 
35
+ ## Query Types
36
+
37
+ The following methods are available as query types:
38
+
39
+ ```ruby
40
+
41
+ passage_query(passage, options={})
42
+
43
+ query( q, options={} )
44
+
45
+ reading_plan_query( options={} )
46
+
47
+ query_info( q, options={} )
48
+
49
+ reading_plan_info( options={} )
50
+
51
+ verse( options={} )
52
+
53
+ daily_verse( options={} )
54
+ ```
55
+
56
+
57
+ ## Query Options
58
+
59
+ The gem mirrors the API. To pass in options, just use the options hash in any available method, using options of the same name as specified in the [ESV API documentation](http://www.esvapi.org/api).
60
+
61
+ For example:
62
+
63
+ ```ruby
64
+
65
+ @esv_text = ESV.passage_query( params[:passage] || "John 1", { 'include-footnotes' => 'false', 'include-headings' => 'false', 'include-subheadings' => 'false', 'include-audio-link' => 'false' } )
66
+ ```
67
+
68
+
69
+
70
+ ## Formatting HTML Output
71
+
72
+ 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.
31
73
 
32
74
  # Credits
33
75
 
data/Rakefile CHANGED
@@ -1,13 +1,10 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
1
+ #!/usr/bin/env rake
4
2
 
5
- desc 'Default: run unit tests.'
6
- task :default => :test
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
7
5
 
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
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :test => :spec
10
+ task :default => :spec
data/esv_api.gemspec CHANGED
@@ -1,9 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.add_dependency 'httparty'
3
+ s.add_development_dependency 'rspec'
3
4
 
4
5
  s.platform = Gem::Platform::RUBY
5
6
  s.name = 'esv_api'
6
- s.version = '0.0.1'
7
+ s.version = '1.0.0'
7
8
  s.authors = ["Jeff McFadden"]
8
9
  s.email = ["jeff@forgeapps.com"]
9
10
  s.homepage = "http://github.com/jeffmcfadden/esv_api"
@@ -32,5 +32,68 @@ module ESV
32
32
 
33
33
  ESV::Client.get( self.endpoint + '/passageQuery', { :query => query } )
34
34
  end
35
+
36
+ def query( q, options={} )
37
+ query = {
38
+ 'key' => self.api_key,
39
+ 'q' => q
40
+ }
41
+
42
+ query = options.merge( query )
43
+
44
+ ESV::Client.get( self.endpoint + '/query', { :query => query } )
45
+ end
46
+
47
+ def reading_plan_query( options={} )
48
+ query = {
49
+ 'key' => self.api_key,
50
+ }
51
+
52
+ query = options.merge( query )
53
+
54
+ ESV::Client.get( self.endpoint + '/readingPlanQuery', { :query => query } )
55
+ end
56
+
57
+ def query_info( q, options={} )
58
+ query = {
59
+ 'key' => self.api_key,
60
+ 'q' => q
61
+ }
62
+
63
+ query = options.merge( query )
64
+
65
+ ESV::Client.get( self.endpoint + '/queryInfo', { :query => query } )
66
+ end
67
+
68
+ def reading_plan_info( options={} )
69
+ query = {
70
+ 'key' => self.api_key,
71
+ }
72
+
73
+ query = options.merge( query )
74
+
75
+ ESV::Client.get( self.endpoint + '/readingPlanQuery', { :query => query } )
76
+ end
77
+
78
+ def verse( options={} )
79
+ query = {
80
+ 'key' => self.api_key,
81
+ }
82
+
83
+ query = options.merge( query )
84
+
85
+ ESV::Client.get( self.endpoint + '/verse', { :query => query } )
86
+ end
87
+
88
+ def daily_verse( options={} )
89
+ query = {
90
+ 'key' => self.api_key,
91
+ }
92
+
93
+ query = options.merge( query )
94
+
95
+ ESV::Client.get( self.endpoint + '/verse', { :query => query } )
96
+ end
97
+
35
98
  end
36
99
  end
@@ -3,7 +3,7 @@ module ESV
3
3
 
4
4
  # @return [Integer]
5
5
  def self.major
6
- 0
6
+ 1
7
7
  end
8
8
 
9
9
  # @return [Integer]
@@ -13,7 +13,7 @@ module ESV
13
13
 
14
14
  # @return [Integer]
15
15
  def self.patch
16
- 1
16
+ 0
17
17
  end
18
18
 
19
19
  # @return [String, NilClass]
@@ -0,0 +1,163 @@
1
+ require 'helper'
2
+
3
+ describe ESV::Client do
4
+ before do
5
+ @keys = ESV::Config::VALID_OPTIONS_KEYS
6
+
7
+ ESV.configure do |config|
8
+ config.api_key = 'aae0629deae45288'
9
+ end
10
+ end
11
+
12
+ context "with module configuration" do
13
+
14
+ before do
15
+ ESV.configure do |config|
16
+ @keys.each do |key|
17
+ config.send("#{key}=", key)
18
+ end
19
+ end
20
+ end
21
+
22
+ after do
23
+ ESV.reset
24
+ end
25
+
26
+ it "should inherit module configuration" do
27
+ api = ESV::Client.new
28
+ @keys.each do |key|
29
+ api.send(key).should == key
30
+ end
31
+ end
32
+
33
+ context "with class configuration" do
34
+
35
+ before do
36
+ @configuration = {
37
+ :api_key => 'hereisAnAPIKey',
38
+ :endpoint => 'http://api.esv.org/',
39
+ :user_agent => 'Custom User Agent'
40
+ }
41
+ end
42
+
43
+ context "during initialization" do
44
+ it "should override module configuration" do
45
+ api = ESV::Client.new(@configuration)
46
+ @keys.each do |key|
47
+ api.send(key).should == @configuration[key]
48
+ end
49
+ end
50
+ end
51
+
52
+ context "after initilization" do
53
+ it "should override module configuration after initialization" do
54
+ api = ESV::Client.new
55
+ @configuration.each do |key, value|
56
+ api.send("#{key}=", value)
57
+ end
58
+ @keys.each do |key|
59
+ api.send(key).should == @configuration[key]
60
+ end
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+
67
+ describe ".passage_query" do
68
+ it "should return a string" do
69
+ api = ESV::Client.new
70
+ api.passage_query( 'John 1:1' ).should be_a String
71
+ end
72
+
73
+ it "should not return an error with a valid passage" do
74
+ api = ESV::Client.new
75
+ api.passage_query( 'John 1:1' ).should_not include("ERROR")
76
+ end
77
+
78
+ it "should return an error with an invalid passage" do
79
+ api = ESV::Client.new
80
+ api.passage_query( 'Fail Whale' ).should include("ERROR")
81
+ end
82
+ end
83
+
84
+ describe ".query" do
85
+ it "should return a string" do
86
+ api = ESV::Client.new
87
+ api.query( 'John 1:1' ).should be_a String
88
+ end
89
+
90
+ it "should not return an error with a valid passage" do
91
+ api = ESV::Client.new
92
+ api.query( 'John 1:1' ).should_not include("ERROR")
93
+ end
94
+ end
95
+
96
+ describe ".reading_plan_query" do
97
+ it "should return a string" do
98
+ api = ESV::Client.new
99
+ api.reading_plan_query().should be_a String
100
+ end
101
+
102
+ it "should not return an error with a valid passage" do
103
+ api = ESV::Client.new
104
+ api.reading_plan_query().should_not include("ERROR")
105
+ end
106
+ end
107
+
108
+ describe ".query_info" do
109
+ it "should return a string" do
110
+ api = ESV::Client.new
111
+ api.query_info( 'John 1:1' ).should be_a String
112
+ end
113
+
114
+ it "should not return an error with a valid passage" do
115
+ api = ESV::Client.new
116
+ api.query_info( 'John 1:1' ).should_not include("ERROR")
117
+ end
118
+
119
+ end
120
+
121
+ describe ".reading_plan_info" do
122
+ it "should return a string" do
123
+ api = ESV::Client.new
124
+ api.reading_plan_info().should be_a String
125
+ end
126
+
127
+ it "should not return an error with a valid passage" do
128
+ api = ESV::Client.new
129
+ api.reading_plan_info().should_not include("ERROR")
130
+ end
131
+ end
132
+
133
+ describe ".verse" do
134
+ it "should return a string" do
135
+ api = ESV::Client.new
136
+ api.verse().should be_a String
137
+ end
138
+
139
+ it "should not return an error with a valid passage" do
140
+ api = ESV::Client.new
141
+ api.verse().should_not include("ERROR")
142
+ end
143
+ end
144
+
145
+ describe ".daily_verse" do
146
+ it "should return a string" do
147
+ api = ESV::Client.new
148
+ api.daily_verse().should be_a String
149
+ end
150
+
151
+ it "should not return an error with a valid passage" do
152
+ api = ESV::Client.new
153
+ api.daily_verse().should_not include("ERROR")
154
+ end
155
+ end
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+ end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ describe ESV do
4
+ after do
5
+ ESV.reset
6
+ end
7
+
8
+ describe ".new" do
9
+ it "should return an ESV::Client" do
10
+ ESV.new.should be_a ESV::Client
11
+ end
12
+ end
13
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'esv_api'
2
+ require 'rspec'
3
+
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: 0.0.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70296141623180 !ruby/object:Gem::Requirement
16
+ requirement: &70242206491240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,18 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70296141623180
24
+ version_requirements: *70242206491240
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70242206490820 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70242206490820
25
36
  description: ESV API Wrapper.
26
37
  email:
27
38
  - jeff@forgeapps.com
@@ -38,6 +49,9 @@ files:
38
49
  - lib/esv_api/client.rb
39
50
  - lib/esv_api/config.rb
40
51
  - lib/esv_api/version.rb
52
+ - spec/esv_api/client_spec.rb
53
+ - spec/esv_api_spec.rb
54
+ - spec/helper.rb
41
55
  homepage: http://github.com/jeffmcfadden/esv_api
42
56
  licenses: []
43
57
  post_install_message:
@@ -63,4 +77,7 @@ rubygems_version: 1.8.6
63
77
  signing_key:
64
78
  specification_version: 3
65
79
  summary: ESV API Wrapper.
66
- test_files: []
80
+ test_files:
81
+ - spec/esv_api/client_spec.rb
82
+ - spec/esv_api_spec.rb
83
+ - spec/helper.rb