alquran 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b0d4684603e83ea987b54a2bce6e433dc356f3f5b47e2808708f2fee109ea680
4
+ data.tar.gz: 642d68cb747f4eb031683ea227f9f4fee91e22428860fe83e243b8789cc37bc4
5
+ SHA512:
6
+ metadata.gz: 7183f3d14f11371d041907989598293b9ebf3cb2033cacdaa8bcb15d2d5d1eceb34806e97575e8beb8795ac2c73d4f3a27efd6a5a7ff49d15eb3a7eaa265219d
7
+ data.tar.gz: f57f0a15e00fbc48ecf64f4d565605531f9e6d44e09bc054435ee8f6be900076f9d0964148f22795c4e95f2aa6091835630f19345363359f4486fa081bf3c2d0
@@ -0,0 +1,16 @@
1
+ require 'httparty'
2
+ require 'active_support/inflector'
3
+
4
+ require_relative 'alquran/base'
5
+ require_relative 'alquran/parah'
6
+ require_relative 'alquran/surah'
7
+ require_relative 'alquran/ayah'
8
+ require_relative 'alquran/edition'
9
+
10
+ require_relative 'api/url_parser'
11
+ require_relative 'api/client'
12
+
13
+ require_relative 'extensions'
14
+
15
+ module Alquran
16
+ end
@@ -0,0 +1,25 @@
1
+ module Alquran
2
+ class Ayah < Base
3
+ class << self
4
+ def fetch(**options)
5
+ Api::Client.fetch(filter_options(options))
6
+ end
7
+
8
+ private
9
+ def show_options(options)
10
+ edition_option = { edition: options[:edition] }.compact
11
+ options.slice(:number).merge(self.entity_option).merge(action: :show).merge(extras: edition_option)
12
+ end
13
+
14
+ def filter_options(**options)
15
+ return show_options(options) unless options.has_key?(:sajdah)
16
+
17
+ action_option = { action: :sajdah }
18
+
19
+ edition_option = { edition: options[:edition] }.compact
20
+
21
+ options.slice(:number).merge(self.entity_option).merge(action_option).merge(extras: edition_option)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ module Alquran
2
+ class Base
3
+ class << self
4
+ protected
5
+ def entity_option
6
+ { entity: self.name.demodulize.downcase.to_sym }
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ module Alquran
2
+ class Edition < Base
3
+ class << self
4
+ def fetch(**options)
5
+ Api::Client.fetch(filter_options(options))
6
+ end
7
+
8
+ private
9
+ def filter_options(**options)
10
+ self.entity_option.merge(action: :index)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,40 @@
1
+ module Alquran
2
+ class Parah < Base
3
+ class << self
4
+ def fetch(**options)
5
+ Api::Client.fetch(filter_options(options))
6
+ end
7
+
8
+ private
9
+ def index_options
10
+ self.entity_option.merge(action: :index)
11
+ end
12
+
13
+ def show_options(number)
14
+ self.entity_option.merge(action: :show, number: number)
15
+ end
16
+
17
+ def filter_options(**options)
18
+ return index_options unless options.has_key?(:number)
19
+ return show_options(options[:number]) unless options.has_key?(:collection)
20
+
21
+ action_option = case options
22
+ when -> (opts) { opts[:collection] === :surahs }
23
+ { action: :surahs }
24
+ when -> (opts) { opts[:collection] === :ayahs }
25
+ { action: :ayahs }
26
+ else
27
+ raise RuntimeApiError.new
28
+ end
29
+
30
+ extra_options = {
31
+ offset: options[:offset],
32
+ limit: options[:limit],
33
+ sajdah: options[:sajdah]
34
+ }.compact
35
+
36
+ options.slice(:number).merge(self.entity_option).merge(action_option).merge(extras: extra_options)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,43 @@
1
+ module Alquran
2
+ class Surah < Base
3
+ class << self
4
+ def fetch(**options)
5
+ Api::Client.fetch(filter_options(options))
6
+ end
7
+
8
+ private
9
+ def index_options
10
+ self.entity_option.merge(action: :index)
11
+ end
12
+
13
+ def show_options(options)
14
+ edition_option = { edition: options[:edition] }.compact
15
+ options.slice(:number).merge(self.entity_option).merge(action: :show).merge(extras: edition_option)
16
+ end
17
+
18
+ def filter_options(**options)
19
+ return index_options unless options.has_key?(:number)
20
+ return show_options(options) unless has_extra_option?(options)
21
+
22
+ action_option = { action: :ayahs }
23
+
24
+ extra_options = {
25
+ offset: options[:offset],
26
+ limit: options[:limit],
27
+ edition: options[:edition],
28
+ sajdah: options[:sajdah]
29
+ }.compact
30
+
31
+ options.slice(:number).merge(self.entity_option).merge(action_option).merge(extras: extra_options)
32
+ end
33
+
34
+ def has_extra_option?(options)
35
+ not available_extra_options.map(&options).compact.empty?
36
+ end
37
+
38
+ def available_extra_options
39
+ %i(offset limit sajdah)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ module Api
2
+ class Client
3
+ extend UrlParser
4
+
5
+ class << self
6
+ def fetch(**options)
7
+ get(parse_url(options))
8
+ end
9
+
10
+ private
11
+ def get(url)
12
+ response = HTTParty.get(url, headers: headers)
13
+ handle_request_response(response)
14
+ end
15
+
16
+ def handle_request_response(response)
17
+ case response.code
18
+ when 200..201 then JSON.parse(response.body)
19
+ else raise RuntimeApiError.new
20
+ end
21
+ end
22
+
23
+ def headers
24
+ { 'Accept': 'application/alquran; v1' }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,55 @@
1
+ module Api
2
+ module UrlParser
3
+ # BASE_URL = 'http://api.alquranpak.com'
4
+ BASE_URL = 'http://localhost:3001'
5
+ RELATIVE_PARAH_PATH = 'parahs'
6
+ RELATIVE_SURAH_PATH = 'surahs'
7
+ RELATIVE_AYAH_PATH = 'ayahs'
8
+ RELATIVE_EDITION_PATH = 'editions'
9
+
10
+ def parse_url(**params)
11
+ method_name = "handle_#{params[:entity].to_s}_urls"
12
+ self.send(method_name, params)
13
+ end
14
+
15
+ def handle_parah_urls(**params)
16
+ case params[:action]
17
+ when :index then [BASE_URL, RELATIVE_PARAH_PATH].join('/')
18
+ when :show then [BASE_URL, RELATIVE_PARAH_PATH, params[:number]].join('/')
19
+ when :surahs then [BASE_URL, RELATIVE_PARAH_PATH, params[:number], params[:action]].join('/')
20
+ when :ayahs
21
+ relative_url = [BASE_URL, RELATIVE_PARAH_PATH, params[:number], params[:action]].join('/')
22
+ [relative_url, prepare_query_string(params[:extras])].join('?')
23
+ end
24
+ end
25
+
26
+ def handle_surah_urls(**params)
27
+ case params[:action]
28
+ when :index then [BASE_URL, RELATIVE_SURAH_PATH].join('/')
29
+ when :show
30
+ relative_url = [BASE_URL, RELATIVE_SURAH_PATH, params[:number]].join('/')
31
+ [relative_url, prepare_query_string(params[:extras])].join('?')
32
+ when :ayahs
33
+ relative_url = [BASE_URL, RELATIVE_SURAH_PATH, params[:number], params[:action]].join('/')
34
+ [relative_url, prepare_query_string(params[:extras])].join('?')
35
+ end
36
+ end
37
+
38
+ def handle_ayah_urls(**params)
39
+ case params[:action]
40
+ when :show
41
+ relative_url = [BASE_URL, RELATIVE_AYAH_PATH, params[:number]].join('/')
42
+ [relative_url, prepare_query_string(params[:extras])].join('?')
43
+ when :sajdah then [BASE_URL, RELATIVE_AYAH_PATH, :sujood].join('/')
44
+ end
45
+ end
46
+
47
+ def handle_edition_urls(**params)
48
+ [BASE_URL, RELATIVE_EDITION_PATH, params[:number]].join('/')
49
+ end
50
+
51
+ def prepare_query_string(extras)
52
+ extras.to_a.map(&:join.with('=')).join('&')
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,8 @@
1
+ class Symbol
2
+ def with(*args, &block)
3
+ -> (caller, *rest) { caller.send(self, *rest, *args, &block) }
4
+ end
5
+ end
6
+
7
+ class RuntimeApiError < RuntimeError
8
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alquran
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ahsan Ellahi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.17.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.17.1
41
+ description: All the details can be collected of Holy Quran inclduing Parahs, Surahs,
42
+ Ayahs and Transcriptions etc.
43
+ email: ahsan.ellahi896@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/alquran.rb
49
+ - lib/alquran/ayah.rb
50
+ - lib/alquran/base.rb
51
+ - lib/alquran/edition.rb
52
+ - lib/alquran/parah.rb
53
+ - lib/alquran/surah.rb
54
+ - lib/api/client.rb
55
+ - lib/api/url_parser.rb
56
+ - lib/extensions.rb
57
+ homepage:
58
+ licenses: []
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.0.3
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Provides all the information regarding the Holy Quran (Book)
79
+ test_files: []