digital_bible_platform 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTY4YmI3NGQyZmExNWZiZTlhZDdhNGJiNWVkZTY2NzVhMjNiOGM3Mg==
5
+ data.tar.gz: !binary |-
6
+ ZThlYTUyODlkY2U5YmZmNzkyY2JmMzEwNjg0NzM0YjljNjhhZDI0ZA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZWVhODRhMTdhZWFlNDZiNWY3MTliNWVjZTFjODc4NzllOTNmMDZiYzQzNTEy
10
+ ZDNiN2I1NTc4ZDI3ODcyN2VlM2ZjZGVkYzEyYTY5ZTNhZmY3MDlkY2UwNTAw
11
+ NWU1NjQzYjRjZjAxNzFmMjU0NTlmY2UxZTE0YmI4NzhiZDAwY2U=
12
+ data.tar.gz: !binary |-
13
+ MjExNDUxZWI4YTE4MDk1MDkxNTFiYjdkNjFkYTljZjVhMDZmNmU1Mzc2YTU2
14
+ NDBhZjk1MTQyMWE5MTVhMmJlZTYwN2VlMGZlYmQ3NTY5NTdiZGI3MjgwMThj
15
+ ZTc3YThkNWFiM2E3NjRhY2M4MjBhYTljMzM3NTYyZTdiZTI3OWI=
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .gitignore
19
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in digital_bible_platform.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Chip Miller
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # DigitalBiblePlatform
2
+
3
+ A ruby wrapper for the [Digital Bible Platform](http://www.digitalbibleplatform.com/docs/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'digital_bible_platform'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install digital_bible_platform
18
+
19
+ ## Usage
20
+
21
+ #### Get an [API Key](http://www.digitalbibleplatform.com/dev/signup/)
22
+ #### Initialize a Client
23
+ ```ruby
24
+ @client = DigitalBiblePlatform::Client.new(<your-api-key>)
25
+ ```
26
+
27
+ #### Get a list of the books of the Bible
28
+ You will need the short\_code (dam\_id)
29
+ ```ruby
30
+ books = @client.books
31
+ ```
32
+
33
+ #### Get the media link for a book of the bible
34
+ ```ruby
35
+ books = @client.url_for('2Tim', 4)
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( http://github.com/<my-github-username>/digital_bible_platform/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'digital_bible_platform/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "digital_bible_platform"
8
+ spec.version = DigitalBiblePlatform::VERSION
9
+ spec.authors = ["Chip Miller"]
10
+ spec.email = ["use github"]
11
+ spec.summary = %q{A Ruby client for http://www.digitalbibleplatform.com/}
12
+ spec.description = %q{A Ruby client for http://www.digitalbibleplatform.com/}
13
+ spec.homepage = "https://github.com/chip-miller/digital_bible_platform"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "iso-639", '~> 0.2.4'
22
+ spec.add_runtime_dependency 'typhoeus', '~> 0.6.8'
23
+ spec.add_runtime_dependency 'oj'
24
+ spec.add_runtime_dependency 'hashie'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.6"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "pry"
29
+ end
@@ -0,0 +1,89 @@
1
+ require 'iso-639'
2
+ module DigitalBiblePlatform
3
+
4
+ class DamId
5
+ class << self
6
+
7
+ # Example ENGESV
8
+ def partial(options={})
9
+ [ (Codes.language options[:language] ),
10
+ (Codes.version options[:version] ),
11
+ ].join('').upcase
12
+ end
13
+
14
+ # Example ENGESVN2DA
15
+ def full(options={})
16
+ collection = if options[:book]
17
+ Codes.collection_from_book options[:book]
18
+ else
19
+ Codes.collection options[:collection]
20
+ end
21
+
22
+ [ (Codes.language options[:language] ),
23
+ (Codes.version options[:version] ),
24
+ (collection ),
25
+ (Codes.drama options[:drama] ),
26
+ (Codes.media options[:media] ),
27
+ ].join('').upcase
28
+ end
29
+ end
30
+
31
+ # http://www.digitalbibleplatform.com/docs/core-concepts/
32
+ class Codes
33
+ class << self
34
+ def language(name)
35
+ lang = ISO_639.find_by_english_name(name.to_s.capitalize)
36
+ raise ArgumentError.new("#{name} Not recognized as a language") unless lang
37
+ lang.alpha3_bibliographic.upcase
38
+ end
39
+
40
+ def version(type)
41
+ type.upcase.to_s
42
+ end
43
+
44
+ def collection(type)
45
+ COLLECTIONS[type.to_sym]
46
+ end
47
+
48
+ def collection_from_book(book_short_name)
49
+ return COLLECTIONS[:old_testament] if OLD_TESTAMENT_SHORT_NAMES.include? book_short_name
50
+ return COLLECTIONS[:new_testament] if NEW_TESTAMENT_SHORT_NAMES.include? book_short_name
51
+ end
52
+
53
+ def drama(type)
54
+ DRAMA_TYPES[type.to_sym]
55
+ end
56
+
57
+ def media(type)
58
+ MEDIA_TYPES[type.to_sym]
59
+ end
60
+ end
61
+
62
+ COLLECTIONS = {
63
+ old_testament: "O", # Contains one or more books of the Old Testament.
64
+ new_testament: "N", # Contains one or more books of the New Testament.
65
+ complete: "C", # Contains books from both the Old and New Testament. (These volumes are used primarily for content downloads, and are not generally used by the actual reader applications).
66
+ story: "S", # Contains content that is not organized by books and chapters.
67
+ partial: "P", # Contains only partial content, such as a few chapters from one book of the Bible.
68
+ }
69
+
70
+ DRAMA_TYPES = {
71
+ drama: 2, # Audio includes spoken text, music, and sound effects.
72
+ non_drama: 1, # Audio includes only spoken text.
73
+ }
74
+
75
+ MEDIA_TYPES = {
76
+ text: "ET", # Electronic Text
77
+ audio: "DA", # Digital Audio
78
+ video: "DV", # Digital Video
79
+ }
80
+
81
+ OLD_TESTAMENT = ["Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job", "Psalms", "Proverbs", "Ecclesiastes", "Song of Solomon", "Isaiah", "Jeremiah", "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos", "Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai", "Zechariah", "Malachi"]
82
+ NEW_TESTAMENT = ["Matthew", "Mark", "Luke", "John", "Acts", "Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians", "Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians", "1 Timothy", "2 Timothy", "Titus", "Philemon", "Hebrews", "James", "1 Peter", "2 Peter", "1 John", "2 John", "3 John", "Jude", "Revelation"]
83
+
84
+ OLD_TESTAMENT_SHORT_NAMES = ["Gen", "Exod", "Lev", "Num", "Deut", "Josh", "Judg", "Ruth", "1Sam", "2Sam", "1Kgs", "2Kgs", "1Chr", "2Chr", "Ezra", "Neh", "Esth", "Job", "Ps", "Prov", "Eccl", "Song", "Isa", "Jer", "Lam", "Ezek", "Dan", "Hos", "Joel", "Amos", "Obad", "Jonah", "Mic", "Nah", "Hab", "Zeph", "Hag", "Zech", "Mal"]
85
+ NEW_TESTAMENT_SHORT_NAMES = ["Matt", "Mark", "Luke", "John", "Acts", "Rom", "1Cor", "2Cor", "Gal", "Eph", "Phil", "Col", "1Thess", "2Thess", "1Tim", "2Tim", "Titus", "Phlm", "Heb", "Jas", "1Pet", "2Pet", "1John", "2John", "3John", "Jude", "Rev"]
86
+
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,3 @@
1
+ module DigitalBiblePlatform
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,68 @@
1
+ require "digital_bible_platform/version"
2
+ require "digital_bible_platform/dam_id"
3
+ require "typhoeus"
4
+ require "hashie"
5
+ require "oj"
6
+
7
+ module DigitalBiblePlatform
8
+ class Client
9
+ attr_reader :api_key #'fd82d19821647fa4829c7ca160b82e6f'
10
+
11
+ def initialize(api_key, defaults={})
12
+ @api_key = api_key
13
+ @defaults = {
14
+ # API Defaults
15
+ protocol: 'http',
16
+ audio_encoding: 'mp3',
17
+ callback: false,
18
+
19
+ # Media Defaults
20
+ language: "English",
21
+ version: :esv,
22
+ collection: :complete,
23
+ drama: :drama,
24
+ media: :audio,
25
+ }.merge(defaults)
26
+ end
27
+
28
+
29
+ def url_for(book_short_name, chapter=1, overrides={})
30
+ response = connect!('/audio/path', {
31
+ dam_id: DamId.full( @defaults.merge(overrides.merge({book:book_short_name}) )),
32
+ book_id: book_short_name,
33
+ chapter_id: chapter,
34
+ })
35
+ file = response.find {|book| book.book_id==book_short_name}.path
36
+ "#{base_url}/#{file}"
37
+ end
38
+
39
+ def books(overrides={})
40
+ options = @defaults.merge(overrides)
41
+ connect!('/library/book', { dam_id: DamId.partial(options) })
42
+ end
43
+
44
+ private
45
+
46
+ def connect!(path, options={})
47
+ request_body = {key:@api_key, v:'2'}.merge(options)
48
+ request_body.merge!({reply:'jsonp',callback:@defaults[:callback]}) if @defaults[:callback]
49
+ response = Typhoeus.get("http://dbt.io#{path}", params:request_body, followlocation: true)
50
+ reply = Oj.load( response.body )
51
+
52
+ case reply
53
+ when Hash then Hashie::Mash.new(reply)
54
+ when Array then reply.map {|hash| Hashie::Mash.new(hash)}
55
+ end
56
+ end
57
+
58
+ def base_url
59
+ @cdns ||= connect!('/audio/location')
60
+ cdn = @cdns.sort_by(&:priority).first {|_cdn| _cdn.protocal==@defaults[:protocal]}
61
+ "#{cdn.protocol}://#{cdn.server}#{cdn.root_path}"
62
+ end
63
+ end
64
+ end
65
+
66
+
67
+ # DEV
68
+ @client = DigitalBiblePlatform::Client.new('fd82d19821647fa4829c7ca160b82e6f')
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digital_bible_platform
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chip Miller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: iso-639
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: typhoeus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.8
41
+ - !ruby/object:Gem::Dependency
42
+ name: oj
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hashie
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A Ruby client for http://www.digitalbibleplatform.com/
112
+ email:
113
+ - use github
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - digital_bible_platform.gemspec
124
+ - lib/digital_bible_platform.rb
125
+ - lib/digital_bible_platform/dam_id.rb
126
+ - lib/digital_bible_platform/version.rb
127
+ homepage: https://github.com/chip-miller/digital_bible_platform
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.2.2
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: A Ruby client for http://www.digitalbibleplatform.com/
151
+ test_files: []