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

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



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

Parameters:

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

    year, month, and state are OPTIONAL



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



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



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



130
131
132
# File 'lib/namaz.rb', line 130

def connection
  @connection ||= Faraday.new
end

.connection=(connection) ⇒ Object

Set an HTTP connection object.

Parameters:

  • connection

    Connection object to be used.



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.

Parameters:

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

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



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 = 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)
  • timezonestring (String)
  • method (Integer)
  • options, (Hash)

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



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