Module: Namaz
- Defined in:
- lib/namaz.rb,
lib/namaz/version.rb
Constant Summary collapse
- DEFAULT_API_URL =
'http://api.aladhan.com'
- VERSION =
'0.1.4'
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.
Class Method Details
.address_info(address:) ⇒ Hashie::Mash
Retrieve the latitude, longitude and timezone for given address
32 33 34 35 36 37 38 |
# File 'lib/namaz.rb', line 32 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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/namaz.rb', line 90 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
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/namaz.rb', line 114 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
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/namaz.rb', line 16 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.
130 131 132 |
# File 'lib/namaz.rb', line 130 def connection @connection ||= Faraday.new end |
.connection=(connection) ⇒ Object
Set an HTTP connection object.
137 138 139 |
# File 'lib/namaz.rb', line 137 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.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/namaz.rb', line 47 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.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/namaz.rb', line 68 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 |