Class: PrayerTime::Request
- Inherits:
-
Object
- Object
- PrayerTime::Request
- Defined in:
- lib/prayer_time/request.rb
Instance Method Summary collapse
- #get_cities(country) ⇒ Object
- #get_towns(country, city) ⇒ Object
-
#initialize ⇒ Request
constructor
A new instance of Request.
- #pray_times(country, city, town) ⇒ Object
Constructor Details
#initialize ⇒ Request
Returns a new instance of Request.
49 50 51 52 53 |
# 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 |
Instance Method Details
#get_cities(country) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# 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) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# 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) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# 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 |