namaz 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -15
  3. data/lib/namaz.rb +27 -2
  4. data/lib/namaz/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd82a6f994dc25e50a61a02c2ca8ff19122fc7a5
4
- data.tar.gz: d6ad635eb5da639a308f02f4ef3054bd8fde1081
3
+ metadata.gz: 871d931898844bbe7491afe62ab6c0bde3312f0b
4
+ data.tar.gz: cb6f79d1f7dd858e93b70da77c5e2a31ab766aef
5
5
  SHA512:
6
- metadata.gz: 7fad7a149e77080f674128aeef8418901cd5f5d2f67e5a743b15301d77d2ec77dcc27bcf656df5f34968778bb69e126cebbc8f2ad48bbcb12051ccd30ea595b7
7
- data.tar.gz: 2245dba4a8c9215590bd2453a2a5481860146a5d2dd0b710ea7164717cdc4f2aa4a91091c4c159cd46faf559ddacd4ad4a38648a626b04c6429350d2ec72dd2f
6
+ metadata.gz: 4269271a282a9783631b840125f21f09e1b54abf89bb73b357fa3c91f5de0e7ffba626ae0356874ac7c3b9f1a399c48e540ec92ff8b58249235391a3aeac2a82
7
+ data.tar.gz: 8e2949eaca4652acc770baa2b37dba51b0312f1de39e40d2020524080c0b48f525f6ba32d130ceee0f4ba0b774daa2ce7780d9c1767a47da8ea146ad0b23757b
data/README.md CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
 
25
25
  $ gem install namaz
26
26
 
27
- ## Usage
27
+ # Usage
28
28
  Make sure you require the library, where you want to use it, Or require in `application.rb` to use all over the application.
29
29
 
30
30
  ```ruby
@@ -33,19 +33,51 @@ require 'namaz'
33
33
 
34
34
  You can then make requests to the following method.
35
35
  ```ruby
36
+ ## Using Altitudes:
36
37
  Namaz.timings(latitude:, longitude:, timezonestring:, method:, options: {})
38
+ ## Using City and Country Information:
39
+ Namaz.timings(city:, country:, method:, options: {})
37
40
  ```
38
41
 
39
- Example
42
+ ### Examples:
40
43
  ```ruby
44
+ # Using Altitudes:
41
45
  Namaz.timings(latitude: 31.5546, longitude: 74.3572, timezonestring: "Asia/Karachi", method: 1, options: {timestamp: Time.now.to_i})
46
+ # Using City and Country Information:
47
+ Namaz.timings(city: 'Karachi', country: 'PK', method: 1, options: {timestamp: Time.now.to_i})
42
48
  ```
43
49
 
44
- ### Parameters
50
+ ##### Example Request Using Altitudes
51
+
52
+ ```ruby
53
+ timings = Namaz.timings(latitude: 31.5546, longitude: 74.3572, timezonestring: "Asia/Karachi", method: 1, options: {timestamp: Time.now.to_i})
54
+ ```
55
+ ##### Example Request Using Country and City Information
56
+
57
+ ```ruby
58
+ timings = Namaz.timings(city: 'Karachi', country: 'PK', method: 1, options: {state: 'Punjab', timestamp: Time.now.to_i})
59
+ ```
60
+ ##### Example Response
61
+
62
+ ```ruby
63
+ => #<Hashie::Mash Asr="15:27" Dhuhr="12:16" Fajr="05:19" Imsak="05:09" Isha="19:14" Maghrib="17:53" Midnight="00:17" Sunrise="06:41" Sunset="17:53">
64
+
65
+ timings.Fajr
66
+ => "05:19"
67
+ ```
68
+
69
+ ### Parameters Description
45
70
  * **timestamp OPTIONAL** - `DEFAULT = Time.now.to_i` a UNIX timestamp (from any time of the day) of the day for which you want the timings. If you don't specify a timestamp, the result will come back for today - today being the date in the Europe/London timezone.
71
+
46
72
  * **latitude** - the decimal value for the latitude co-ordinate of the location you want the time computed for. Example: 51.75865125
47
73
  * **longitude** - the decimal value for the longitude co-ordinate of the location you want the time computed for. Example: -1.25387785
48
74
  * **timezonestring** - A valid timezone name as specified on http://php.net/manual/en/timezones.php. Example: Europe/London
75
+
76
+
77
+ * **city** - A city name. Example: London
78
+ * **country** - A country name or 2 character alpha ISO 3166 code. Example: GB or United Kindom
79
+ * **state** - State or province (optional). A state name or abbreviation. Example: Colorado / CO / Punjab / Bengal
80
+
49
81
  * **method** - these are the different methods identifying various schools of thought about how to compute the timings. This parameter accepts values from 0-7, as signified below:
50
82
  * 0 - Shia Ithna-Ashari
51
83
  * 1 - University of Islamic Sciences, Karachi
@@ -55,18 +87,6 @@ Namaz.timings(latitude: 31.5546, longitude: 74.3572, timezonestring: "Asia/Karac
55
87
  * 5 - Egyptian General Authority of Survey
56
88
  * 7 - Institute of Geophysics, University of Tehran
57
89
 
58
- ### Example Request
59
-
60
- ```ruby
61
- timings = Namaz.timings(latitude: 31.5546, longitude: 74.3572, timezonestring: "Asia/Karachi", method: 1, options: {timestamp: Time.now.to_i})
62
- ```
63
- ### Example Response
64
- ```ruby
65
- => #<Hashie::Mash Asr="15:27" Dhuhr="12:16" Fajr="05:19" Imsak="05:09" Isha="19:14" Maghrib="17:53" Midnight="00:17" Sunrise="06:41" Sunset="17:53">
66
-
67
- timings.Fajr
68
- => "05:19"
69
- ```
70
90
  ## Optional HTTP Configuration
71
91
  The HTTP requests are made with [Faraday](https://github.com/lostisland/faraday), which uses `Net::HTTP` by default. Changing the adapter is easy. We will use typhoeus as an example.
72
92
 
@@ -26,8 +26,28 @@ module Namaz
26
26
  method: method
27
27
  }
28
28
 
29
- namaz_response = connection.get(namaz_url, params)
30
- return Hashie::Mash.new(MultiJson.load(namaz_response.body)).data.timings if namaz_response.success?
29
+ namaz_response(namaz_url, params)
30
+ end
31
+
32
+ # Retrieve the namaz timings for a given city, country, method.
33
+ #
34
+ # @param latitude [Float] Latitude.
35
+ # @param longitude [Float] Longitude.
36
+ # @param timezonestring [String]
37
+ # @param method [Integer]
38
+ # @param options [Hash], Have optional values like timestamp, that is default to Current timestamp
39
+ def timings(city:, country:, method:, options: {})
40
+ timestamp = options[:timestamp] ? options[:timestamp] : Time.now.to_i
41
+ namaz_url = [DEFAULT_API_URL, 'timingsByCity', timestamp].join('/')
42
+
43
+ params = {
44
+ city: city,
45
+ country: country,
46
+ state: options[:state],
47
+ method: method
48
+ }
49
+
50
+ namaz_response(namaz_url, params)
31
51
  end
32
52
 
33
53
  # Build or get an HTTP connection object.
@@ -47,5 +67,10 @@ module Namaz
47
67
  def get(path, params = {})
48
68
  connection.get(path, params)
49
69
  end
70
+
71
+ def namaz_response(namaz_url, params)
72
+ namaz_response = connection.get(namaz_url, params)
73
+ return Hashie::Mash.new(MultiJson.load(namaz_response.body)).data.timings if namaz_response.success?
74
+ end
50
75
  end
51
76
  end
@@ -1,3 +1,3 @@
1
1
  module Namaz
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namaz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sohair Ahmad