namaz 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/LICENSE.txt +1 -1
- data/README.md +163 -22
- data/lib/namaz.rb +174 -7
- data/lib/namaz/version.rb +1 -1
- data/namaz.gemspec +9 -4
- metadata +70 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 66dad608d2a8a98f4f9b47d4c993d5c24b16d16052da321523837bce8e2372c3
|
4
|
+
data.tar.gz: 8e4a24b7ea26f07beff019aec0824c3d04131934d3aee17c1597f4ecf2814086
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44fd65370a4f9b7e4d83f4eb69842a2301c006fadc3a82b0316a52ec691b68a9841e6c09b813f1f952912e51c60c8a2d326a07908573e7a822008ada314c6f45
|
7
|
+
data.tar.gz: 39ac0bd0f2ce964d8f19c716fcfba11df05b50c92f669b7b4fb4b1e5fc906fa77d52e4e384845490f64efdf30d56d5b4146be0cf6291a4a9f3fb0146f844bc33
|
data/.gitignore
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Namaz
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a00997d44c73474b9372b8e88ae04fd5)](https://app.codacy.com/app/sohair.ahmad/namaz?utm_source=github.com&utm_medium=referral&utm_content=Sohair63/namaz&utm_campaign=Badge_Grade_Dashboard)
|
4
|
+
|
5
|
+
namaz ruby gem is an API wrapper. Namaz is aladhan.com wrapper in ruby to use REST API that is open for public use.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -13,7 +15,7 @@ gem 'namaz'
|
|
13
15
|
For latest code:
|
14
16
|
|
15
17
|
```ruby
|
16
|
-
gem 'namaz', git: '
|
18
|
+
gem 'namaz', git: 'https://github.com/Sohair63/namaz.git'
|
17
19
|
```
|
18
20
|
|
19
21
|
And then execute:
|
@@ -24,28 +26,165 @@ Or install it yourself as:
|
|
24
26
|
|
25
27
|
$ gem install namaz
|
26
28
|
|
27
|
-
|
29
|
+
# Usage
|
28
30
|
Make sure you require the library, where you want to use it, Or require in `application.rb` to use all over the application.
|
29
31
|
|
30
32
|
```ruby
|
31
33
|
require 'namaz'
|
32
34
|
```
|
33
35
|
|
34
|
-
|
36
|
+
## Upcoming Namaz and Namaz Time remain
|
37
|
+
Returns upcoming prayer time with the its name.
|
38
|
+
Note that: Returning time is in seconds, to help users to convert seconds to bigger units according to their needs or may be better use is placing in some jquery plugin e.g. jquery-countdown.
|
39
|
+
|
35
40
|
```ruby
|
41
|
+
## Using Altitudes:
|
42
|
+
upcoming_namaz = Namaz.upcoming_namaz(latitude: 31.5546, longitude: 74.3572, timezonestring: "Asia/Karachi", method: 1, options: {timestamp: Time.now.to_i})
|
43
|
+
|
44
|
+
=> #<Hashie::Mash namaz_name="Fajr" time_remaining_in_seconds=54821.0>
|
45
|
+
|
46
|
+
upcoming_namaz.namaz_name
|
47
|
+
=> "Fajr"
|
48
|
+
upcoming_namaz.time_remaining_in_seconds
|
49
|
+
=> 54821.0
|
50
|
+
|
51
|
+
## Using City and Country Information:
|
52
|
+
upcoming_namaz = Namaz.upcoming_namaz_by_city(city: 'Karachi', country: 'PK', method: 1, options: {state: 'Punjab', timestamp: Time.now.to_i})
|
53
|
+
=> #<Hashie::Mash namaz_name="Fajr" time_remaining_in_seconds=54821.0>
|
54
|
+
|
55
|
+
upcoming_namaz.namaz_name
|
56
|
+
=> "Fajr"
|
57
|
+
upcoming_namaz.time_remaining_in_seconds
|
58
|
+
=> 54821.0
|
59
|
+
```
|
60
|
+
|
61
|
+
## Timings
|
62
|
+
Returns all prayer times for a specific date and for a specific date in a city. You can then make requests to the following method.
|
63
|
+
```ruby
|
64
|
+
## Using Altitudes:
|
36
65
|
Namaz.timings(latitude:, longitude:, timezonestring:, method:, options: {})
|
66
|
+
## Using City and Country Information:
|
67
|
+
Namaz.timings_by_city(city:, country:, method:, options: {})
|
68
|
+
```
|
69
|
+
|
70
|
+
### Examples:
|
71
|
+
|
72
|
+
##### Example Request and response Using Altitudes
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
timings = Namaz.timings(latitude: 31.5546, longitude: 74.3572, timezonestring: "Asia/Karachi", method: 1, options: {timestamp: Time.now.to_i})
|
76
|
+
|
77
|
+
#=> #<Hashie::Mash Asr="15:27" Dhuhr="12:16" Fajr="05:19" Imsak="05:09" Isha="19:14" Maghrib="17:53" Midnight="00:17" Sunrise="06:41" Sunset="17:53">
|
78
|
+
|
79
|
+
timings.Fajr
|
80
|
+
#=> "05:19"
|
81
|
+
```
|
82
|
+
##### Example Request Using Country and City Information
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
timings = Namaz.timings_by_city(city: 'Karachi', country: 'PK', method: 1, options: {state: 'Punjab', timestamp: Time.now.to_i})
|
86
|
+
|
87
|
+
#<Hashie::Mash Asr="15:27" Dhuhr="12:16" Fajr="05:19" Imsak="05:09" Isha="19:14" Maghrib="17:53" Midnight="00:17" Sunrise="06:41" Sunset="17:53">
|
88
|
+
|
89
|
+
timings.Fajr
|
90
|
+
#=> "05:19"
|
91
|
+
```
|
92
|
+
|
93
|
+
## Calender
|
94
|
+
Returns prayer times for a specific month (in a given year) and for a specific month in a city
|
95
|
+
```ruby
|
96
|
+
## Using City and Country Information:
|
97
|
+
Namaz.calender_by_city(city:, country:, method:, options: {})
|
98
|
+
## Using City and Country Information:
|
99
|
+
Namaz.calendar(latitude:, longitude:, timezonestring:, method:, options: {})
|
100
|
+
```
|
101
|
+
|
102
|
+
#### Optional Params
|
103
|
+
`(options: {month: '8', year: '2017', state: 'Punjab' })`
|
104
|
+
- **month** - 1 or 2 digit month. Example: '08' or '8' for August, **DEFAULT is current month**, if not given
|
105
|
+
- **year** - 4 digit year. Example: 2017, **DEFAULT is current year**, if not given
|
106
|
+
|
107
|
+
|
108
|
+
### Examples:
|
109
|
+
|
110
|
+
##### Example Request and response Using Altitudes
|
111
|
+
```ruby
|
112
|
+
calendar = Namaz.calendar(latitude: 31.5546, longitude: 74.3572, timezonestring: "Asia/Karachi", method: 1, options: {month: '02', year: '2017'})
|
113
|
+
|
114
|
+
calendar.first
|
115
|
+
#<Hashie::Mash date=#<Hashie::Mash readable="01 Feb 2017" timestamp="1485921661"> timings=#<Hashie::Mash Asr="15:15 (PKT)" Dhuhr="12:16 (PKT)" Fajr="05:32 (PKT)" Imsak="05:22 (PKT)" Isha="19:00 (PKT)" Maghrib="17:37 (PKT)" Midnight="00:16 (PKT)" Sunrise="06:55 (PKT)" Sunset="17:37 (PKT)">>
|
116
|
+
|
117
|
+
calendar.first.timings
|
118
|
+
#=> #<Hashie::Mash Asr="15:15 (PKT)" Dhuhr="12:16 (PKT)" Fajr="05:32 (PKT)" Imsak="05:22 (PKT)" Isha="19:00 (PKT)" Maghrib="17:37 (PKT)" Midnight="00:16 (PKT)" Sunrise="06:55 (PKT)" Sunset="17:37 (PKT)">
|
119
|
+
|
120
|
+
calendar.first.timings.Asr
|
121
|
+
#=> "15:15 (PKT)"
|
122
|
+
|
123
|
+
calendar.first.date
|
124
|
+
#<Hashie::Mash readable="01 Feb 2017" timestamp="1485921661">
|
37
125
|
```
|
38
126
|
|
39
|
-
Example
|
127
|
+
##### Example Request Using Country and City Information
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
calendar = Namaz.calender_by_city(city: 'Lahore', country: 'PK', method: 2, options: {month: '02', year: '2017'})
|
131
|
+
|
132
|
+
calendar.first
|
133
|
+
#<Hashie::Mash date=#<Hashie::Mash readable="01 Feb 2017" timestamp="1485921661"> timings=#<Hashie::Mash Asr="15:54 (PKT)" Dhuhr="12:46 (PKT)" Fajr="05:56 (PKT)" Imsak="05:46 (PKT)" Isha="19:35 (PKT)" Maghrib="18:17 (PKT)" Midnight="00:46 (PKT)" Sunrise="07:14 (PKT)" Sunset="18:17 (PKT)">>
|
134
|
+
|
135
|
+
calendar.first.timings
|
136
|
+
#=> #<Hashie::Mash Asr="15:31 (PKT)" Dhuhr="12:15 (PKT)" Fajr="05:23 (PKT)" Imsak="05:13 (PKT)" Isha="19:07 (PKT)" Maghrib="18:01 (PKT)" Midnight="00:15 (PKT)" Sunrise="06:30 (PKT)" Sunset="18:01 (PKT)">
|
137
|
+
|
138
|
+
calendar.first.timings.Asr
|
139
|
+
#=> "15:31 (PKT)"
|
140
|
+
|
141
|
+
calendar.first.date
|
142
|
+
#<Hashie::Mash readable="01 Feb 2017" timestamp="1485921661">
|
143
|
+
```
|
144
|
+
|
145
|
+
## City Information
|
146
|
+
Returns City Geolocation Info of latitude, longitude and timezone for a given city
|
147
|
+
### Example:
|
148
|
+
```ruby
|
149
|
+
city_info = Namaz.city_info(city: 'Lahore', country: 'PK', options: {state: 'Punjab'})
|
150
|
+
#<Hashie::Mash latitude="31.5546061" longitude="74.3571581" timezone="Asia/Karachi">
|
151
|
+
city_info.longitude
|
152
|
+
# => "74.3571581"
|
153
|
+
city_info.timezone
|
154
|
+
# => "Asia/Karachi"
|
155
|
+
```
|
156
|
+
|
157
|
+
## Address Information
|
158
|
+
Returns Address Geolocation Info of latitude, longitude and timezone for a given city
|
159
|
+
|
160
|
+
### Additional Parameter
|
161
|
+
|
162
|
+
**address** - A complete address string. Example: 10 Upper Bank Street, London, Canary Wharf, London, UK
|
163
|
+
|
164
|
+
### Examples:
|
40
165
|
```ruby
|
41
|
-
|
166
|
+
address_info = address_info(address: '10 Upper Bank Street, London, Canary Wharf, London, UK')
|
167
|
+
#<Hashie::Mash latitude="51.5026562" longitude="-0.0171995" timezone="Europe/London">
|
168
|
+
-- OR --
|
169
|
+
address_info = address_info(address: 'Upper Bank Street, London, Canary Wharf, London, UK')
|
170
|
+
#<Hashie::Mash latitude=51.5045201 longitude=-0.0171009 timezone="Europe/London">
|
171
|
+
-- OR --
|
172
|
+
address_info = address_info(address: 'Bank Street, London, Canary Wharf, London, UK')
|
173
|
+
#<Hashie::Mash latitude=51.5035329 longitude=-0.0213304 timezone="Europe/London">
|
42
174
|
```
|
43
175
|
|
44
|
-
|
176
|
+
## General Parameters Description
|
45
177
|
* **timestamp OPTIONAL** - `DEFAULT = Time.now.to_i` a UNIX timestamp (from any time of the day) of the day for which you want the timings. If you don't specify a timestamp, the result will come back for today - today being the date in the Europe/London timezone.
|
178
|
+
|
46
179
|
* **latitude** - the decimal value for the latitude co-ordinate of the location you want the time computed for. Example: 51.75865125
|
47
180
|
* **longitude** - the decimal value for the longitude co-ordinate of the location you want the time computed for. Example: -1.25387785
|
48
181
|
* **timezonestring** - A valid timezone name as specified on http://php.net/manual/en/timezones.php. Example: Europe/London
|
182
|
+
|
183
|
+
|
184
|
+
* **city** - A city name. Example: London
|
185
|
+
* **country** - A country name or 2 character alpha ISO 3166 code. Example: GB or United Kindom
|
186
|
+
* **state** - State or province (optional). A state name or abbreviation. Example: Colorado / CO / Punjab / Bengal
|
187
|
+
|
49
188
|
* **method** - these are the different methods identifying various schools of thought about how to compute the timings. This parameter accepts values from 0-7, as signified below:
|
50
189
|
* 0 - Shia Ithna-Ashari
|
51
190
|
* 1 - University of Islamic Sciences, Karachi
|
@@ -55,18 +194,6 @@ Namaz.timings(latitude: 31.5546, longitude: 74.3572, timezonestring: "Asia/Karac
|
|
55
194
|
* 5 - Egyptian General Authority of Survey
|
56
195
|
* 7 - Institute of Geophysics, University of Tehran
|
57
196
|
|
58
|
-
### Example Request
|
59
|
-
|
60
|
-
```ruby
|
61
|
-
timings = Namaz.timings(latitude: 31.5546, longitude: 74.3572, timezonestring: "Asia/Karachi", method: 1, options: {timestamp: Time.now.to_i})
|
62
|
-
```
|
63
|
-
### Example Response
|
64
|
-
```ruby
|
65
|
-
=> #<Hashie::Mash Asr="15:27" Dhuhr="12:16" Fajr="05:19" Imsak="05:09" Isha="19:14" Maghrib="17:53" Midnight="00:17" Sunrise="06:41" Sunset="17:53">
|
66
|
-
|
67
|
-
timings.Fajr
|
68
|
-
=> "05:19"
|
69
|
-
```
|
70
197
|
## Optional HTTP Configuration
|
71
198
|
The HTTP requests are made with [Faraday](https://github.com/lostisland/faraday), which uses `Net::HTTP` by default. Changing the adapter is easy. We will use typhoeus as an example.
|
72
199
|
|
@@ -92,13 +219,27 @@ Namaz.connection = Faraday.new do |builder|
|
|
92
219
|
end
|
93
220
|
```
|
94
221
|
|
222
|
+
## CHANGE LOG:
|
223
|
+
|
224
|
+
* **0.1.4:** Added methods `city_info` and `address_info`
|
225
|
+
* **0.1.3:** Added methods `calendar` and `calendar_by_city`
|
226
|
+
* **0.1.2:** Updated method name for Timings information for city from `timings` to `timings_by_city`
|
227
|
+
* **0.1.1:** Added new request Using Country and City Information
|
228
|
+
* **0.1.0:** Request Using Altitudes
|
229
|
+
|
230
|
+
## TODO:
|
231
|
+
Follow the link https://aladhan.com/prayer-times-api and add patch by creating a Pull Rquest, I will merge and publish new version
|
232
|
+
|
233
|
+
* Timings by Address
|
234
|
+
* Calendar by Address
|
235
|
+
|
95
236
|
## License
|
96
237
|
|
97
238
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
98
239
|
|
99
240
|
## Copyright
|
100
241
|
|
101
|
-
Copyright (c)
|
242
|
+
Copyright (c) 2018 Sohair S. Ahmad. See LICENSE.txt for further details.
|
102
243
|
|
103
244
|
## Development
|
104
245
|
|
@@ -108,4 +249,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
108
249
|
|
109
250
|
## Contributing
|
110
251
|
|
111
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
252
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Sohair63/namaz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/lib/namaz.rb
CHANGED
@@ -3,17 +3,85 @@ require 'namaz/version'
|
|
3
3
|
require 'hashie'
|
4
4
|
require 'multi_json'
|
5
5
|
require 'faraday'
|
6
|
+
require 'time'
|
7
|
+
require 'active_support/core_ext/time/zones'
|
6
8
|
|
7
9
|
module Namaz
|
8
|
-
DEFAULT_API_URL = 'http://api.aladhan.com'
|
10
|
+
DEFAULT_API_URL = 'http://api.aladhan.com/v1'
|
9
11
|
|
10
12
|
class << self
|
13
|
+
# Retrieve the remaining time to next namaz for a given latitude, longitude, timezonestring and method.
|
14
|
+
#
|
15
|
+
# @param [Float] latitude.
|
16
|
+
# @param [Float] longitude.
|
17
|
+
# @param [String] timezonestring
|
18
|
+
# @param [Integer] method
|
19
|
+
# @param options [Hash], Have optional values like timestamp, that is default to Current timestamp
|
20
|
+
# @return [Hash] namaz_name, and time remain in seconds
|
21
|
+
def upcoming_namaz(latitude:, longitude:, timezonestring:, method:, options: {})
|
22
|
+
namaz_time_response = timings(
|
23
|
+
latitude: latitude,
|
24
|
+
longitude: longitude,
|
25
|
+
timezonestring: timezonestring,
|
26
|
+
method: method,
|
27
|
+
options: options
|
28
|
+
)
|
29
|
+
|
30
|
+
prayer_and_time_remain(namaz_time_response, timezonestring)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Retrieve the remaining time to next namaz for a given city, country, method and timezonestring
|
34
|
+
#
|
35
|
+
# @param [String] city
|
36
|
+
# @param [String] country
|
37
|
+
# @param [Integer] method
|
38
|
+
# @param [Hash] options, Have optional values like timestamp, that is default to Current timestamp
|
39
|
+
# @return [Hash] namaz_name, and time remain in seconds
|
40
|
+
def upcoming_namaz_by_city(city:, country:, method:, timezonestring:, options: {})
|
41
|
+
namaz_time_response = timings_by_city(
|
42
|
+
city: city,
|
43
|
+
country: country,
|
44
|
+
method: method,
|
45
|
+
options: options)
|
46
|
+
|
47
|
+
prayer_and_time_remain(namaz_time_response, timezonestring)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Retrieve the latitude, longitude and timezone for a given city
|
51
|
+
# @param [String] city
|
52
|
+
# @param [String] country
|
53
|
+
# @param [Hash] options state is OPTIONAL
|
54
|
+
# @return [Hashie::Mash] having latitude longitude and timezone
|
55
|
+
def city_info(city:, country:, options: {})
|
56
|
+
url = [DEFAULT_API_URL, 'cityInfo'].join('/')
|
57
|
+
|
58
|
+
params = {
|
59
|
+
city: city,
|
60
|
+
country: country,
|
61
|
+
state: options[:state]
|
62
|
+
}
|
63
|
+
|
64
|
+
response = connection.get(url, params)
|
65
|
+
return Hashie::Mash.new(MultiJson.load(response.body)).data if response.success?
|
66
|
+
end
|
67
|
+
|
68
|
+
# Retrieve the latitude, longitude and timezone for given address
|
69
|
+
# @param [address] A complete address string
|
70
|
+
# @return [Hashie::Mash] having latitude longitude and timezone
|
71
|
+
def address_info(address:)
|
72
|
+
url = [DEFAULT_API_URL, 'addressInfo'].join('/')
|
73
|
+
|
74
|
+
params = { address: address }
|
75
|
+
response = connection.get(url, params)
|
76
|
+
return Hashie::Mash.new(MultiJson.load(response.body)).data if response.success?
|
77
|
+
end
|
78
|
+
|
11
79
|
# Retrieve the namaz timings for a given latitude, longitude, timezonestring and method.
|
12
80
|
#
|
13
|
-
# @param
|
14
|
-
# @param
|
15
|
-
# @param
|
16
|
-
# @param
|
81
|
+
# @param [Float] latitude.
|
82
|
+
# @param [Float] longitude.
|
83
|
+
# @param [String] timezonestring
|
84
|
+
# @param [Integer] method
|
17
85
|
# @param options [Hash], Have optional values like timestamp, that is default to Current timestamp
|
18
86
|
def timings(latitude:, longitude:, timezonestring:, method:, options: {})
|
19
87
|
timestamp = options[:timestamp] ? options[:timestamp] : Time.now.to_i
|
@@ -26,8 +94,74 @@ module Namaz
|
|
26
94
|
method: method
|
27
95
|
}
|
28
96
|
|
29
|
-
|
30
|
-
|
97
|
+
namaz_time_response(namaz_url, params)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Retrieve the namaz timings for a given city, country, method.
|
101
|
+
#
|
102
|
+
# @param [String] city
|
103
|
+
# @param [String] country
|
104
|
+
# @param [Integer] method
|
105
|
+
# @param [Hash] options, Have optional values like timestamp, that is default to Current timestamp
|
106
|
+
def timings_by_city(city:, country:, method:, options: {})
|
107
|
+
timestamp = options[:timestamp] ? options[:timestamp] : Time.now.to_i
|
108
|
+
namaz_url = [DEFAULT_API_URL, 'timingsByCity', timestamp].join('/')
|
109
|
+
|
110
|
+
params = {
|
111
|
+
city: city,
|
112
|
+
country: country,
|
113
|
+
state: options[:state],
|
114
|
+
method: method
|
115
|
+
}
|
116
|
+
|
117
|
+
namaz_time_response(namaz_url, params)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Retrieve the namaz timings for a given latitude, longitude, timezonestring and method.
|
121
|
+
#
|
122
|
+
# @param [Float] latitude.
|
123
|
+
# @param [Float] longitude.
|
124
|
+
# @param [String] timezonestring
|
125
|
+
# @param [Integer] method
|
126
|
+
# @param [Hash] options, year, month, and state are OPTIONAL
|
127
|
+
# year is default to current year, and month is default to current month if not sent in OPTIONAL params
|
128
|
+
def calendar(latitude:, longitude:, timezonestring:, method:, options: {})
|
129
|
+
namaz_url = [DEFAULT_API_URL, 'calendar'].join('/')
|
130
|
+
|
131
|
+
params = {
|
132
|
+
latitude: latitude,
|
133
|
+
longitude: longitude,
|
134
|
+
timezonestring: timezonestring,
|
135
|
+
month: options[:month],
|
136
|
+
year: options[:year],
|
137
|
+
method: method
|
138
|
+
}
|
139
|
+
|
140
|
+
namaz_calender_response(namaz_url, params)
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
# Retrieve the calender for a given city, country, method.
|
145
|
+
# By default Retrieve current year, month
|
146
|
+
#
|
147
|
+
# @param [String] city
|
148
|
+
# @param [String] country
|
149
|
+
# @param [Integer] method
|
150
|
+
# @param [Hash] options, year, month, and state are OPTIONAL
|
151
|
+
# year is default to current year, and month is default to current month if not sent in OPTIONAL params
|
152
|
+
def calendar_by_city(city:, country:, method:, options: {})
|
153
|
+
namaz_url = [DEFAULT_API_URL, 'calendarByCity'].join('/')
|
154
|
+
|
155
|
+
params = {
|
156
|
+
city: city,
|
157
|
+
country: country,
|
158
|
+
month: options[:month],
|
159
|
+
year: options[:year],
|
160
|
+
state: options[:state],
|
161
|
+
method: method
|
162
|
+
}
|
163
|
+
|
164
|
+
namaz_calender_response(namaz_url, params)
|
31
165
|
end
|
32
166
|
|
33
167
|
# Build or get an HTTP connection object.
|
@@ -47,5 +181,38 @@ module Namaz
|
|
47
181
|
def get(path, params = {})
|
48
182
|
connection.get(path, params)
|
49
183
|
end
|
184
|
+
|
185
|
+
def namaz_time_response(namaz_url, params)
|
186
|
+
response = connection.get(namaz_url, params)
|
187
|
+
return Hashie::Mash.new(MultiJson.load(response.body)).data.timings if response.success?
|
188
|
+
end
|
189
|
+
|
190
|
+
def namaz_calender_response(namaz_url, params)
|
191
|
+
response = connection.get(namaz_url, params)
|
192
|
+
return Hashie::Mash.new(MultiJson.load(response.body)).data if response.success?
|
193
|
+
end
|
194
|
+
|
195
|
+
def prayer_and_time_remain(times, timezonestring)
|
196
|
+
times.delete('Sunset')
|
197
|
+
times.delete('Sunrise')
|
198
|
+
times.delete('Midnight')
|
199
|
+
times.delete('Imsak')
|
200
|
+
|
201
|
+
Time.zone = timezonestring
|
202
|
+
current_time = Time.now
|
203
|
+
current_time_hms = current_time.strftime('%H:%M:%S')
|
204
|
+
current_time_hm = current_time.strftime('%H:%M')
|
205
|
+
|
206
|
+
times.select { |key, value| times[key] = Time.strptime(value, '%H:%M').strftime('%H:%M') }
|
207
|
+
namaz_name, namaz_time = times.select { |_, value| current_time_hm <= value }.first
|
208
|
+
namaz_name, namaz_time = times.first if namaz_time.blank?
|
209
|
+
time_diff = Time.parse(namaz_time) - Time.parse(current_time_hms)
|
210
|
+
[namaz_name, time_diff.abs]
|
211
|
+
|
212
|
+
Time.zone = nil
|
213
|
+
|
214
|
+
Hashie::Mash.new(namaz_name: namaz_name, time_remaining_in_seconds: time_diff.abs)
|
215
|
+
end
|
216
|
+
|
50
217
|
end
|
51
218
|
end
|
data/lib/namaz/version.rb
CHANGED
data/namaz.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["sohair1991@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{Returns all prayer times for a specific date}
|
13
|
-
spec.description = %q{Namaz is AlAdhan.com wrapper in ruby to use REST API that is open for public use.
|
13
|
+
spec.description = %q{Namaz gem is AlAdhan.com wrapper in ruby to use REST API that is open for public use.}
|
14
14
|
spec.homepage = "https://github.com/Sohair63/namaz"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -30,7 +30,12 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.
|
34
|
-
spec.
|
35
|
-
spec.
|
33
|
+
spec.add_dependency 'faraday'
|
34
|
+
spec.add_dependency 'multi_json'
|
35
|
+
spec.add_dependency 'hashie'
|
36
|
+
|
37
|
+
spec.add_development_dependency 'typhoeus', '~> 1'
|
38
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
39
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.10"
|
36
41
|
end
|
metadata
CHANGED
@@ -1,60 +1,115 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: namaz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sohair Ahmad
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hashie
|
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: typhoeus
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1'
|
13
69
|
- !ruby/object:Gem::Dependency
|
14
70
|
name: bundler
|
15
71
|
requirement: !ruby/object:Gem::Requirement
|
16
72
|
requirements:
|
17
73
|
- - "~>"
|
18
74
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
75
|
+
version: '2.0'
|
20
76
|
type: :development
|
21
77
|
prerelease: false
|
22
78
|
version_requirements: !ruby/object:Gem::Requirement
|
23
79
|
requirements:
|
24
80
|
- - "~>"
|
25
81
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
82
|
+
version: '2.0'
|
27
83
|
- !ruby/object:Gem::Dependency
|
28
84
|
name: rake
|
29
85
|
requirement: !ruby/object:Gem::Requirement
|
30
86
|
requirements:
|
31
87
|
- - "~>"
|
32
88
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
89
|
+
version: '13.0'
|
34
90
|
type: :development
|
35
91
|
prerelease: false
|
36
92
|
version_requirements: !ruby/object:Gem::Requirement
|
37
93
|
requirements:
|
38
94
|
- - "~>"
|
39
95
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
96
|
+
version: '13.0'
|
41
97
|
- !ruby/object:Gem::Dependency
|
42
98
|
name: rspec
|
43
99
|
requirement: !ruby/object:Gem::Requirement
|
44
100
|
requirements:
|
45
101
|
- - "~>"
|
46
102
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
103
|
+
version: '3.10'
|
48
104
|
type: :development
|
49
105
|
prerelease: false
|
50
106
|
version_requirements: !ruby/object:Gem::Requirement
|
51
107
|
requirements:
|
52
108
|
- - "~>"
|
53
109
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
55
|
-
description: Namaz is AlAdhan.com wrapper in ruby to use REST API that is open
|
56
|
-
public use.
|
57
|
-
includes Timings only
|
110
|
+
version: '3.10'
|
111
|
+
description: Namaz gem is AlAdhan.com wrapper in ruby to use REST API that is open
|
112
|
+
for public use.
|
58
113
|
email:
|
59
114
|
- sohair1991@gmail.com
|
60
115
|
executables: []
|
@@ -80,7 +135,7 @@ licenses:
|
|
80
135
|
- MIT
|
81
136
|
metadata:
|
82
137
|
allowed_push_host: https://rubygems.org
|
83
|
-
post_install_message:
|
138
|
+
post_install_message:
|
84
139
|
rdoc_options: []
|
85
140
|
require_paths:
|
86
141
|
- lib
|
@@ -95,9 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
150
|
- !ruby/object:Gem::Version
|
96
151
|
version: '0'
|
97
152
|
requirements: []
|
98
|
-
|
99
|
-
|
100
|
-
signing_key:
|
153
|
+
rubygems_version: 3.0.3
|
154
|
+
signing_key:
|
101
155
|
specification_version: 4
|
102
156
|
summary: Returns all prayer times for a specific date
|
103
157
|
test_files: []
|