Module: Namaz
- Defined in:
- lib/namaz.rb,
lib/namaz/version.rb
Constant Summary collapse
- DEFAULT_API_URL =
'http://api.aladhan.com/v1'
- VERSION =
'0.1.5'
Class Method Summary collapse
-
.address_info(address:) ⇒ Hashie::Mash
Retrieve the latitude, longitude and timezone for given address.
-
.calendar(latitude:, longitude:, timezonestring:, method:, options: {}) ⇒ Object
Retrieve the namaz timings for a given latitude, longitude, timezonestring and method.
-
.calendar_by_city(city:, country:, method:, options: {}) ⇒ Object
Retrieve the calender for a given city, country, method.
-
.city_info(city:, country:, options: {}) ⇒ Hashie::Mash
Retrieve the latitude, longitude and timezone for a given city.
-
.connection ⇒ Object
Build or get an HTTP connection object.
-
.connection=(connection) ⇒ Object
Set an HTTP connection object.
-
.timings(latitude:, longitude:, timezonestring:, method:, options: {}) ⇒ Object
Retrieve the namaz timings for a given latitude, longitude, timezonestring and method.
-
.timings_by_city(city:, country:, method:, options: {}) ⇒ Object
Retrieve the namaz timings for a given city, country, method.
-
.upcoming_namaz(latitude:, longitude:, timezonestring:, method:, options: {}) ⇒ Hash
Retrieve the remaining time to next namaz for a given latitude, longitude, timezonestring and method.
-
.upcoming_namaz_by_city(city:, country:, method:, timezonestring:, options: {}) ⇒ Hash
Retrieve the remaining time to next namaz for a given city, country, method and timezonestring.
Class Method Details
.address_info(address:) ⇒ Hashie::Mash
Retrieve the latitude, longitude and timezone for given address
71 72 73 74 75 76 77 |
# File 'lib/namaz.rb', line 71 def address_info(address:) url = [DEFAULT_API_URL, 'addressInfo'].join('/') params = { address: address } response = connection.get(url, params) return Hashie::Mash.new(MultiJson.load(response.body)).data if response.success? end |
.calendar(latitude:, longitude:, timezonestring:, method:, options: {}) ⇒ Object
Retrieve the namaz timings for a given latitude, longitude, timezonestring and method.
year is default to current year, and month is default to current month if not sent in OPTIONAL params
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/namaz.rb', line 128 def calendar(latitude:, longitude:, timezonestring:, method:, options: {}) namaz_url = [DEFAULT_API_URL, 'calendar'].join('/') params = { latitude: latitude, longitude: longitude, timezonestring: timezonestring, month: [:month], year: [:year], method: method } namaz_calender_response(namaz_url, params) end |
.calendar_by_city(city:, country:, method:, options: {}) ⇒ Object
Retrieve the calender for a given city, country, method. By default Retrieve current year, month
year is default to current year, and month is default to current month if not sent in OPTIONAL params
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/namaz.rb', line 152 def calendar_by_city(city:, country:, method:, options: {}) namaz_url = [DEFAULT_API_URL, 'calendarByCity'].join('/') params = { city: city, country: country, month: [:month], year: [:year], state: [:state], method: method } namaz_calender_response(namaz_url, params) end |
.city_info(city:, country:, options: {}) ⇒ Hashie::Mash
Retrieve the latitude, longitude and timezone for a given city
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/namaz.rb', line 55 def city_info(city:, country:, options: {}) url = [DEFAULT_API_URL, 'cityInfo'].join('/') params = { city: city, country: country, state: [:state] } response = connection.get(url, params) return Hashie::Mash.new(MultiJson.load(response.body)).data if response.success? end |
.connection ⇒ Object
Build or get an HTTP connection object.
168 169 170 |
# File 'lib/namaz.rb', line 168 def connection @connection ||= Faraday.new end |
.connection=(connection) ⇒ Object
Set an HTTP connection object.
175 176 177 |
# File 'lib/namaz.rb', line 175 def connection=(connection) @connection = connection end |
.timings(latitude:, longitude:, timezonestring:, method:, options: {}) ⇒ Object
Retrieve the namaz timings for a given latitude, longitude, timezonestring and method.
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/namaz.rb', line 86 def timings(latitude:, longitude:, timezonestring:, method:, options: {}) = [:timestamp] ? [:timestamp] : Time.now.to_i namaz_url = [DEFAULT_API_URL, 'timings', ].join('/') params = { latitude: latitude, longitude: longitude, timezonestring: timezonestring, method: method } namaz_time_response(namaz_url, params) end |
.timings_by_city(city:, country:, method:, options: {}) ⇒ Object
Retrieve the namaz timings for a given city, country, method.
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/namaz.rb', line 106 def timings_by_city(city:, country:, method:, options: {}) = [:timestamp] ? [:timestamp] : Time.now.to_i namaz_url = [DEFAULT_API_URL, 'timingsByCity', ].join('/') params = { city: city, country: country, state: [:state], method: method } namaz_time_response(namaz_url, params) end |
.upcoming_namaz(latitude:, longitude:, timezonestring:, method:, options: {}) ⇒ Hash
Retrieve the remaining time to next namaz for a given latitude, longitude, timezonestring and method.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/namaz.rb', line 21 def upcoming_namaz(latitude:, longitude:, timezonestring:, method:, options: {}) namaz_time_response = timings( latitude: latitude, longitude: longitude, timezonestring: timezonestring, method: method, options: ) prayer_and_time_remain(namaz_time_response, timezonestring) end |
.upcoming_namaz_by_city(city:, country:, method:, timezonestring:, options: {}) ⇒ Hash
Retrieve the remaining time to next namaz for a given city, country, method and timezonestring
40 41 42 43 44 45 46 47 48 |
# File 'lib/namaz.rb', line 40 def upcoming_namaz_by_city(city:, country:, method:, timezonestring:, options: {}) namaz_time_response = timings_by_city( city: city, country: country, method: method, options: ) prayer_and_time_remain(namaz_time_response, timezonestring) end |