class PrayerTime::Request

Public Class Methods

new() click to toggle source
# File lib/prayer_time/request.rb, line 49
def initialize
  @cities_url = 'http://www.diyanet.gov.tr/PrayerTime/FillState?countryCode='
  @towns_url = 'http://www.diyanet.gov.tr/PrayerTime/FillCity?itemId='
  @time_url = 'http://www.diyanet.gov.tr/PrayerTime/PrayerTimesSet'
end

Public Instance Methods

get_cities(country) click to toggle source
# File lib/prayer_time/request.rb, line 55
def get_cities(country)
  if COUNTRIES.key(country)
    response = RestClient.get(@cities_url + COUNTRIES.key(country))
    JSON.parse(response)
  else
    return nil
  end
rescue RestClient::ExceptionWithResponse => err
  err.response
end
get_towns(country, city) click to toggle source
# File lib/prayer_time/request.rb, line 66
def get_towns(country, city)
  if get_cities(country) || get_cities(country).select { |c| c if c['Text'] == city } != []
    city_id = get_cities(country).select { |c| c if c['Text'] == city }.first['Value']
    response = RestClient.get(@towns_url + city_id)
    JSON.parse(response)
  else
    return nil
  end
rescue RestClient::ExceptionWithResponse => err
  err.response
end
pray_times(country, city, town) click to toggle source
# File lib/prayer_time/request.rb, line 78
def pray_times(country, city, town)
  if !get_towns(country, city).nil?
    city_id = get_cities(country).select { |c| c if c['Text'] == city }.first['Value']
    if get_towns(country, city).select { |t| t if t['Text'] == town } != []
      town_id = get_towns(country, city).select { |t| t if t['Text'] == town }.first['Value']
      response = RestClient.post(@time_url, countryName: COUNTRIES.key(country), stateName: city_id, name: town_id)
      JSON.parse(response)
    elsif get_towns(country, city).select { |t| t if t['Text'] == town } == []
      response = RestClient.post(@time_url, countryName: COUNTRIES.key(country), name: city_id)
      JSON.parse(response)
    else
      return nil
    end
  else
    return nil
  end
rescue RestClient::ExceptionWithResponse => err
  err.response
end