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

Class Method Details

.address_info(address:) ⇒ Hashie::Mash

Retrieve the latitude, longitude and timezone for given address

Parameters:

  • A (address)

    complete address string

Returns:

  • (Hashie::Mash)

    having latitude longitude and timezone



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

Parameters:

  • latitude. (Float)
  • longitude. (Float)
  • timezonestring (String)
  • method (Integer)
  • options, (Hash)

    year, month, and state are OPTIONAL



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: options[:month],
    year: options[: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

Parameters:

  • city (String)
  • country (String)
  • method (Integer)
  • options, (Hash)

    year, month, and state are OPTIONAL



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: options[:month],
    year: options[:year],
    state: options[: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

Parameters:

  • city (String)
  • country (String)
  • options (Hash) (defaults to: {})

    state is OPTIONAL

Returns:

  • (Hashie::Mash)

    having latitude longitude and timezone



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: options[:state]
  }

  response = connection.get(url, params)
  return Hashie::Mash.new(MultiJson.load(response.body)).data if response.success?
end

.connectionObject

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.

Parameters:

  • connection

    Connection object to be used.



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.

Parameters:

  • latitude. (Float)
  • longitude. (Float)
  • timezonestring (String)
  • method (Integer)
  • options (Hash) (defaults to: {})

    , Have optional values like timestamp, that is default to Current timestamp



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 = options[:timestamp] ? options[:timestamp] : Time.now.to_i
  namaz_url = [DEFAULT_API_URL, 'timings', timestamp].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.

Parameters:

  • city (String)
  • country (String)
  • method (Integer)
  • options, (Hash)

    Have optional values like timestamp, that is default to Current timestamp



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 = options[:timestamp] ? options[:timestamp] : Time.now.to_i
  namaz_url = [DEFAULT_API_URL, 'timingsByCity', timestamp].join('/')

  params = {
    city: city,
    country: country,
    state: options[: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.

Parameters:

  • latitude. (Float)
  • longitude. (Float)
  • timezonestring (String)
  • method (Integer)
  • options (Hash) (defaults to: {})

    , Have optional values like timestamp, that is default to Current timestamp

Returns:

  • (Hash)

    namaz_name, and time remain in seconds



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: 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

Parameters:

  • city (String)
  • country (String)
  • method (Integer)
  • options, (Hash)

    Have optional values like timestamp, that is default to Current timestamp

Returns:

  • (Hash)

    namaz_name, and time remain in seconds



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: options)

  prayer_and_time_remain(namaz_time_response, timezonestring)
end