whiz_client 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTFjZjMzMzRjMWVlNWMyYTM2Y2JiOTJkZTU4M2UxYWQ5Mzc0MWQ5Mw==
5
+ data.tar.gz: !binary |-
6
+ MGZlOWJiM2NkMGZmMTRjNTYzMWNjNTliODc3NmU0MDM3MjY2ZGZjOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTQ1Mzc0YTU5MjE3MDY5NThhNWU1ZGRjYzhiZTRjMGJkMGZhMjAxODY2MzE0
10
+ ZDhhY2M5ZjdhMWYwYmI4M2FjNzc3NDY1NjUwZGYzNDQyNjkyMDRkN2QzYWU4
11
+ OTY0Y2Y1NDVlYTAwMzEyZDNhY2FmNjA0ZDY4MjQ0ODhmN2RlZDI=
12
+ data.tar.gz: !binary |-
13
+ ODZhMmMyMzBmOGY5ZTdkYzY3NGU0YjUwZmEzNmYzMTFhY2ViNGQ1OWYxN2E1
14
+ YzQyZDYzYTczZTIzOGJkM2Y1NGUxNWQxMDlhMDllMzM2M2I1OTdkMjgxZTc2
15
+ MjVhMDZhZDZiNzVlYTkxODZlMmNmMGRlNDA5ZTY0Yjg0OTkyYjc=
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+ ## TEXTMATE
4
+ *.tmproj
5
+ ## netbeans
6
+ nbproject
7
+ tmtags
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+ ## VIM
13
+ *.swp
14
+ ## PROJECT::GENERAL
15
+ pkg
16
+ doc
17
+ .yardoc
18
+ *.gem
19
+ Gemfile.lock
20
+ .bundle
21
+ vendor/ruby
22
+ ## PROJECT::SPECIFIC
23
+ .rbenv-version
24
+ .rbx
25
+ .ruby-version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in whiz_client.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ whiz_client (1.0.0)
5
+ json (>= 1.8.1)
6
+ rest-client (>= 1.7.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.3.6)
12
+ crack (0.4.2)
13
+ safe_yaml (~> 1.0.0)
14
+ diff-lcs (1.2.5)
15
+ json (1.8.1)
16
+ mime-types (2.4.3)
17
+ netrc (0.8.0)
18
+ rake (10.3.2)
19
+ rest-client (1.7.2)
20
+ mime-types (>= 1.16, < 3.0)
21
+ netrc (~> 0.7)
22
+ rspec (2.13.0)
23
+ rspec-core (~> 2.13.0)
24
+ rspec-expectations (~> 2.13.0)
25
+ rspec-mocks (~> 2.13.0)
26
+ rspec-core (2.13.1)
27
+ rspec-expectations (2.13.0)
28
+ diff-lcs (>= 1.1.3, < 2.0)
29
+ rspec-mocks (2.13.1)
30
+ safe_yaml (1.0.4)
31
+ webmock (1.16.1)
32
+ addressable (>= 2.2.7)
33
+ crack (>= 0.3.2)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 1.5)
40
+ rake
41
+ rspec (~> 2.13.0)
42
+ webmock (= 1.16.1)
43
+ whiz_client!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Chiranjib Roy
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # WhizClient
2
+
3
+ A wrapper ruby library to access WhizApi. Get your api key from www.whizapi.com.
4
+
5
+ Using this library one can access following services...
6
+
7
+ Get the list of major cities of a state in India.
8
+ Get list of States and Union Territories of India.
9
+ Get city/area from the STD code in India.
10
+ Get STD dialing code for any location in India.
11
+ Get address, City, Locality by pin code in India.
12
+ Get pin code of any address, city, locality in India.
13
+ Get list of all time zones in the world.
14
+ Get current time of a particular time zone.
15
+
16
+ ## Supported versions
17
+
18
+ Ruby 1.9.2, 1.9.3, 2.0.0, 2.1.x
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ gem 'whiz_client'
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install whiz_client
33
+
34
+ ## Usage
35
+
36
+ Add following code to your environment file
37
+
38
+ WhizClient::Client::APP_KEY = '<your api key>' # Get your api key from www.whizapi.com
39
+
40
+ Get list of States and Union Territories of India.
41
+
42
+ WhizClient::India.list_all_states
43
+
44
+ Get the list of major cities of a state in India.
45
+
46
+ WhizClient::India.find_city_by_state(<state-id>)
47
+
48
+ Get city/area from the STD code in India.
49
+
50
+ WhizClient::India.find_city_by_std_codes(<STD-CODE>)
51
+
52
+ Get STD dialing code for any location in India.
53
+
54
+ WhizClient::India.find_std_codes_by_location(<city-name>)
55
+
56
+ Get address, City, Locality by pin code in India.
57
+
58
+ WhizClient::India.find_city_by_postal_code(<pin code>)
59
+
60
+ Get pin code of any address, city, locality in India.
61
+
62
+ WhizClient::India.find_postal_code_by_location(<location>)
63
+
64
+ Get list of all time zones in the world.
65
+
66
+ WhizClient::Geo.time_zones
67
+
68
+ Get current time of a particular time zone.
69
+
70
+ WhizClient::Geo.current_time_of_timezone(<time zone>)
71
+
72
+
73
+ ## Error handaling
74
+
75
+ begin
76
+ WhizClient::India.list_all_states
77
+ rescue WhizClient::WhizResponseError => e
78
+ puts e.error_message
79
+ end
80
+
81
+ WhizClient::Client::APP_KEY is not defined
82
+
83
+ ## Contributing
84
+
85
+ 1. Fork it ( http://github.com/<my-github-username>/whiz_client/fork )
86
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
87
+ 3. Run $ rspec.
88
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
89
+ 5. Push to the branch (`git push origin my-new-feature`)
90
+ 6. Create new Pull Request
91
+
92
+
93
+ ## License
94
+
95
+ WhizClient is Copyright (c) 2014 Chiranjib Roy. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,89 @@
1
+ require 'json'
2
+ require "whiz_client/version"
3
+ require "whiz_client/client"
4
+
5
+ module WhizClient
6
+ class WhizBase
7
+ class << self
8
+ def parse(response)
9
+ response_hash = JSON.parse(response)
10
+ response_hash['Data']
11
+ end
12
+
13
+ def request_params(params)
14
+ raise NotImplementedError
15
+ end
16
+ end
17
+ end
18
+
19
+ class India < WhizBase
20
+
21
+ class << self
22
+
23
+ def list_all_states
24
+ response = Client.request(request_params(method_name: 'indian-states-list'))
25
+ parse(response)
26
+ end
27
+
28
+ def find_city_by_state(stateid)
29
+ response = Client.request(request_params(stateid: stateid, method_name: 'indian-city-by-state'))
30
+ parse(response).map {|hash| hash['city'] }
31
+ end
32
+
33
+ def find_city_by_std_codes(std_code)
34
+ response = Client.request(request_params(std_code: std_code, method_name: 'city-from-std-codes'))
35
+ parse(response)
36
+ end
37
+
38
+ def find_std_codes_by_location(location)
39
+ response = Client.request(request_params(location: location, method_name: 'indian-std-codes'))
40
+ parse(response)
41
+ end
42
+
43
+ def find_city_by_postal_code(postal_code)
44
+ response = Client.request(request_params(postal_code: postal_code, method_name: 'indian-city-by-postal-code'))
45
+ parse(response)
46
+ end
47
+
48
+ def find_postal_code_by_location(location)
49
+ response = Client.request(request_params(location: location, method_name: 'indian-postal-codes'))
50
+ parse(response)
51
+ end
52
+
53
+ def self.method_missing(method_sym, *arguments, &block)
54
+ puts method_sym
55
+ puts arguments
56
+ end
57
+
58
+ private
59
+
60
+ def request_params(params)
61
+ { api_type: 'indian' }.merge(params)
62
+ end
63
+ end
64
+ end
65
+
66
+ class Geo < WhizBase
67
+ class << self
68
+
69
+ def time_zones
70
+ response = Client.request(request_params(method_name: 'time-zones'))
71
+ parse(response).map { |hash| hash.values }.flatten
72
+ end
73
+
74
+ def current_time_of_timezone(time_zone)
75
+ response = Client.request(request_params(method_name: 'current-time-of-timezone', time_zone: time_zone ))
76
+ parse(response)
77
+ end
78
+
79
+ private
80
+
81
+ def request_params(params)
82
+ { api_type: 'geo' }.merge(params)
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+
89
+ end
@@ -0,0 +1,60 @@
1
+ require 'rest_client'
2
+
3
+ module WhizClient
4
+
5
+ class WhizResponseError < StandardError
6
+ attr_reader :error_message, :error_code
7
+
8
+ def initialize(error_message, error_code)
9
+ @error_message = error_message
10
+ @error_code = error_code
11
+ end
12
+ end
13
+
14
+ class Client
15
+
16
+ INDIAN_API_URL = 'https://www.whizapi.com/api/v2/util/ui/in/'
17
+ GEO_API_URL = 'https://www.WhizAPI.com/api/v2/geo/time/ui/'
18
+
19
+ class << self
20
+
21
+ def request(params)
22
+ request_type = params[:api_type]
23
+ url = case request_type
24
+ when 'indian' then construct_indian_api_url(params)
25
+ when 'geo' then construct_geo_api_url(params)
26
+ end
27
+
28
+ begin
29
+ RestClient.get URI.encode(url)
30
+ rescue URI::InvalidURIError
31
+ raise WhizResponseError.new('Invalid Url', 500)
32
+ rescue => error
33
+ raise WhizResponseError.new("Error: #{error.message}", 500)
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def construct_indian_api_url(params)
40
+ raise WhizResponseError.new('WhizClient::Client::APP_KEY is not defined', 500) unless defined? APP_KEY
41
+
42
+ url = "#{INDIAN_API_URL}#{params[:method_name]}?AppKey=#{APP_KEY}"
43
+ url += "&stateid=#{params[:stateid]}" if params.has_key? :stateid
44
+ url += "&code=#{params[:std_code]}" if params.has_key? :std_code
45
+ url += "&search=#{params[:location]}" if params.has_key? :location
46
+ url += "&pin=#{params[:postal_code]}" if params.has_key? :postal_code
47
+ url
48
+ end
49
+
50
+ def construct_geo_api_url(params)
51
+ raise WhizResponseError.new('WhizClient::Client::APP_KEY is not defined', 500) unless defined? APP_KEY
52
+
53
+ url = "#{GEO_API_URL}#{params[:method_name]}?AppKey=#{APP_KEY}"
54
+ url += "&zid=#{params[:time_zone]}" if params.has_key? :time_zone
55
+ url
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module WhizClient
2
+ VERSION = "1.0.0"
3
+ end
data/spec/.DS_Store ADDED
Binary file
@@ -0,0 +1 @@
1
+ {"ResponseCode":0,"ResponseMessage":"OK","ResponseDateTime":"6/24/2014 12:29:11 PM GMT","Data":[{"city":"Adoor","State":"Kerala"},{"city":"Akathiyoor","State":"Kerala"},{"city":"Alappuzha","State":"Kerala"},{"city":"Ancharakandy","State":"Kerala"},{"city":"Aroor","State":"Kerala"},{"city":"Ashtamichira","State":"Kerala"},{"city":"Attingal","State":"Kerala"},{"city":"Avinissery","State":"Kerala"},{"city":"Chalakudy","State":"Kerala"},{"city":"Changanassery","State":"Kerala"},{"city":"Chendamangalam","State":"Kerala"},{"city":"Chengannur","State":"Kerala"},{"city":"Cherthala","State":"Kerala"},{"city":"Cheruthazham","State":"Kerala"},{"city":"Chittur-Thathamangalam","State":"Kerala"},{"city":"Chockli","State":"Kerala"},{"city":"Erattupetta","State":"Kerala"},{"city":"Guruvayoor","State":"Kerala"},{"city":"Irinjalakuda","State":"Kerala"},{"city":"Idukki","State":"Kerala"},{"city":"Kadirur","State":"Kerala"},{"city":"Kalliasseri","State":"Kerala"},{"city":"Kalpetta","State":"Kerala"},{"city":"Kanhangad","State":"Kerala"},{"city":"Kanjikkuzhi","State":"Kerala"},{"city":"Kannur","State":"Kerala"},{"city":"Kasaragod","State":"Kerala"},{"city":"Kayamkulam","State":"Kerala"},{"city":"Kochi","State":"Kerala"},{"city":"Kodungallur","State":"Kerala"},{"city":"Kollam","State":"Kerala"},{"city":"Koothuparamba","State":"Kerala"},{"city":"Kothamangalam","State":"Kerala"},{"city":"Kottayam","State":"Kerala"},{"city":"Kozhikode","State":"Kerala"},{"city":"Kunnamkulam","State":"Kerala"},{"city":"Malappuram","State":"Kerala"},{"city":"Mattannur","State":"Kerala"},{"city":"Mavelikkara","State":"Kerala"},{"city":"Mavoor","State":"Kerala"},{"city":"Muvattupuzha","State":"Kerala"},{"city":"Nedumangad","State":"Kerala"},{"city":"Neyyattinkara","State":"Kerala"},{"city":"Nilambur","State":"Kerala"},{"city":"Ottappalam","State":"Kerala"},{"city":"Palai","State":"Kerala"},{"city":"Palakkad","State":"Kerala"},{"city":"Panamattom","State":"Kerala"},{"city":"Panniyannur","State":"Kerala"},{"city":"Pappinisseri","State":"Kerala"},{"city":"Paravoor","State":"Kerala"},{"city":"Pathanamthitta","State":"Kerala"},{"city":"Peringathur","State":"Kerala"},{"city":"Perinthalmanna","State":"Kerala"},{"city":"Perumbavoor","State":"Kerala"},{"city":"Ponkunnam","State":"Kerala"},{"city":"Ponnani","State":"Kerala"},{"city":"Punalur","State":"Kerala"},{"city":"Puthuppally","State":"Kerala"}]}
@@ -0,0 +1 @@
1
+ {"ResponseCode":0,"ResponseMessage":"OK","ResponseDateTime":"6/24/2014 12:24:39 PM GMT","Data":[{"ID":"1","Name":"Assam ","Type":"state"},{"ID":"2","Name":"Jammu and Kashmir","Type":"state"},{"ID":"3","Name":"Maharashtra","Type":"state"},{"ID":"4","Name":"Uttar Pradesh","Type":"state"},{"ID":"5","Name":"Gujarat","Type":"state"},{"ID":"6","Name":"Andhra Pradesh","Type":"state"},{"ID":"7","Name":"Karnataka","Type":"state"},{"ID":"8","Name":"Kerala","Type":"state"},{"ID":"9","Name":"West Bengal","Type":"state"},{"ID":"10","Name":"Tripura","Type":"state"},{"ID":"11","Name":"Chhattisgarh","Type":"state"},{"ID":"12","Name":"Punjab","Type":"state"},{"ID":"13","Name":"Mizoram","Type":"state"},{"ID":"14","Name":"Rajasthan","Type":"state"},{"ID":"15","Name":"Goa","Type":"state"},{"ID":"16","Name":"Uttarakhand","Type":"state"},{"ID":"17","Name":"Arunachal Pradesh","Type":"state"},{"ID":"18","Name":"Bihar","Type":"state"},{"ID":"19","Name":"Lakshadweep","Type":"Union Territory"},{"ID":"20","Name":"Jharkhand","Type":"state"},{"ID":"21","Name":"Dadra and Nagar Haveli","Type":"National Capital Territory"},{"ID":"22","Name":"Orissa","Type":"state"},{"ID":"23","Name":"Tamil Nadu","Type":"state"},{"ID":"24","Name":"Himachal Pradesh","Type":"state"},{"ID":"25","Name":"Haryana","Type":"state"},{"ID":"26","Name":"Madhya Pradesh","Type":"state"},{"ID":"27","Name":"Delhi","Type":"Union Territory"},{"ID":"28","Name":"Chandigarh","Type":"Union Territory"},{"ID":"29","Name":"Daman and Diu","Type":"Union Territory"},{"ID":"30","Name":"Nagaland","Type":"state"},{"ID":"31","Name":"Sikkim","Type":"state"},{"ID":"32","Name":"Manipur","Type":"state"},{"ID":"33","Name":"Meghalaya","Type":"state"},{"ID":"34","Name":"Pondicherry","Type":"Union Territory"},{"ID":"35","Name":"Jammu & Kashmir","Type":"state"},{"ID":"36","Name":"Andaman and Nicobar Islands","Type":"Union Territory"}]}
@@ -0,0 +1 @@
1
+ {"ResponseCode":0,"ResponseMessage":"OK","ResponseDateTime":"6/24/2014 12:30:33 PM GMT","Data":[ { "_TimeZone": "Dateline Standard Time" }, { "_TimeZone": "UTC-11" }, { "_TimeZone": "Hawaiian Standard Time" }, { "_TimeZone": "Alaskan Standard Time" }, { "_TimeZone": "Pacific Standard Time (Mexico)" }, { "_TimeZone": "Pacific Standard Time" }, { "_TimeZone": "US Mountain Standard Time" }, { "_TimeZone": "Mountain Standard Time (Mexico)" }, { "_TimeZone": "Mountain Standard Time" }, { "_TimeZone": "Central America Standard Time" }, { "_TimeZone": "Central Standard Time" }, { "_TimeZone": "Central Standard Time (Mexico)" }, { "_TimeZone": "Canada Central Standard Time" }, { "_TimeZone": "SA Pacific Standard Time" }, { "_TimeZone": "Eastern Standard Time" }, { "_TimeZone": "US Eastern Standard Time" }, { "_TimeZone": "Venezuela Standard Time" }, { "_TimeZone": "Paraguay Standard Time" }, { "_TimeZone": "Atlantic Standard Time" }, { "_TimeZone": "Central Brazilian Standard Time" }, { "_TimeZone": "SA Western Standard Time" }, { "_TimeZone": "Pacific SA Standard Time" }, { "_TimeZone": "Newfoundland Standard Time" }, { "_TimeZone": "E. South America Standard Time" }, { "_TimeZone": "Argentina Standard Time" }, { "_TimeZone": "SA Eastern Standard Time" }, { "_TimeZone": "Greenland Standard Time" }, { "_TimeZone": "Montevideo Standard Time" }, { "_TimeZone": "Bahia Standard Time" }, { "_TimeZone": "UTC-02" }, { "_TimeZone": "Mid-Atlantic Standard Time" }, { "_TimeZone": "Azores Standard Time" }, { "_TimeZone": "Cape Verde Standard Time" }, { "_TimeZone": "Morocco Standard Time" }, { "_TimeZone": "Coordinated Universal Time" }, { "_TimeZone": "GMT Standard Time" }, { "_TimeZone": "Greenwich Standard Time" }, { "_TimeZone": "W. Europe Standard Time" }, { "_TimeZone": "Central Europe Standard Time" }, { "_TimeZone": "Romance Standard Time" }, { "_TimeZone": "Central European Standard Time" }, { "_TimeZone": "Libya Standard Time" }, { "_TimeZone": "W. Central Africa Standard Time" }, { "_TimeZone": "Namibia Standard Time" }, { "_TimeZone": "GTB Standard Time" }, { "_TimeZone": "Middle East Standard Time" }, { "_TimeZone": "Egypt Standard Time" }, { "_TimeZone": "Syria Standard Time" }, { "_TimeZone": "E. Europe Standard Time" }, { "_TimeZone": "South Africa Standard Time" }, { "_TimeZone": "FLE Standard Time" }, { "_TimeZone": "Turkey Standard Time" }, { "_TimeZone": "Jerusalem Standard Time" }, { "_TimeZone": "Jordan Standard Time" }, { "_TimeZone": "Arabic Standard Time" }, { "_TimeZone": "Kaliningrad Standard Time" }, { "_TimeZone": "Arab Standard Time" }, { "_TimeZone": "E. Africa Standard Time" }, { "_TimeZone": "Iran Standard Time" }, { "_TimeZone": "Arabian Standard Time" }, { "_TimeZone": "Azerbaijan Standard Time" }, { "_TimeZone": "Russian Standard Time" }, { "_TimeZone": "Mauritius Standard Time" }, { "_TimeZone": "Georgian Standard Time" }, { "_TimeZone": "Caucasus Standard Time" }, { "_TimeZone": "Afghanistan Standard Time" }, { "_TimeZone": "West Asia Standard Time" }, { "_TimeZone": "Pakistan Standard Time" }, { "_TimeZone": "India Standard Time" }, { "_TimeZone": "Sri Lanka Standard Time" }, { "_TimeZone": "Nepal Standard Time" }, { "_TimeZone": "Central Asia Standard Time" }, { "_TimeZone": "Bangladesh Standard Time" }, { "_TimeZone": "Ekaterinburg Standard Time" }, { "_TimeZone": "Myanmar Standard Time" }, { "_TimeZone": "SE Asia Standard Time" }, { "_TimeZone": "N. Central Asia Standard Time" }, { "_TimeZone": "China Standard Time" }, { "_TimeZone": "North Asia Standard Time" }, { "_TimeZone": "Malay Peninsula Standard Time" }, { "_TimeZone": "W. Australia Standard Time" }, { "_TimeZone": "Taipei Standard Time" }, { "_TimeZone": "Ulaanbaatar Standard Time" }, { "_TimeZone": "North Asia East Standard Time" }, { "_TimeZone": "Tokyo Standard Time" }, { "_TimeZone": "Korea Standard Time" }, { "_TimeZone": "Cen. Australia Standard Time" }, { "_TimeZone": "AUS Central Standard Time" }, { "_TimeZone": "E. Australia Standard Time" }, { "_TimeZone": "AUS Eastern Standard Time" }, { "_TimeZone": "West Pacific Standard Time" }, { "_TimeZone": "Tasmania Standard Time" }, { "_TimeZone": "Yakutsk Standard Time" }, { "_TimeZone": "Central Pacific Standard Time" }, { "_TimeZone": "Vladivostok Standard Time" }, { "_TimeZone": "New Zealand Standard Time" }, { "_TimeZone": "UTC+12" }, { "_TimeZone": "Fiji Standard Time" }, { "_TimeZone": "Magadan Standard Time" }, { "_TimeZone": "Kamchatka Standard Time" }, { "_TimeZone": "Tonga Standard Time" }, { "_TimeZone": "Samoa Standard Time" } ]}
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe WhizClient::Geo do
4
+
5
+ include RequestHelper
6
+ context 'When APP_KEY is defined' do
7
+
8
+ before(:each) do
9
+ stub_const('WhizClient::Client::GEO_API_URL', 'https://example.com/')
10
+ stub_const('WhizClient::Client::APP_KEY', 'xxxxxxxxxxx')
11
+ end
12
+
13
+ context '.time_zones' do
14
+ it 'returns an array' do
15
+ fake_response = '{"ResponseCode":0,"ResponseMessage":"OK","ResponseDateTime":"11/7/2014 9:04:32 AM GMT","Data":[ { "_TimeZone": "Dateline Standard Time" }, { "_TimeZone": "UTC-11" }, { "_TimeZone": "Hawaiian Standard Time" }, { "_TimeZone": "Alaskan Standard Time" } ]}'
16
+
17
+ stub_request(:get, 'https://example.com/time-zones?AppKey=xxxxxxxxxxx').
18
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
19
+ to_return(:status => 200, :body => valid_response(:time_zones), :headers => {})
20
+
21
+ expect(described_class.time_zones).to be_a_kind_of Array
22
+ end
23
+ end
24
+
25
+ context '.current_time_of_timezone' do
26
+ it 'returns a String' do
27
+ fake_response = '{"ResponseCode":0,"ResponseMessage":"OK","ResponseDateTime":"11/7/2014 9:12:16 AM GMT","Data":"11/7/2014 2:42:16 PM"}'
28
+
29
+ stub_request(:get, "https://example.com/current-time-of-timezone?AppKey=xxxxxxxxxxx&zid=Pacific%20Standard%20Time").
30
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
31
+ to_return(:status => 200, :body => fake_response, :headers => {})
32
+
33
+ expect(described_class.current_time_of_timezone('Pacific Standard Time')).to be_a_kind_of String
34
+ end
35
+ end
36
+ end
37
+
38
+ context 'When APP_KEY is uninitialized' do
39
+ it 'raise exception' do
40
+ expect{ described_class.time_zones }.to raise_error WhizClient::WhizResponseError
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe WhizClient::India do
4
+
5
+ include RequestHelper
6
+
7
+ context 'When APP_KEY is defined' do
8
+
9
+ before(:each) do
10
+ stub_const('WhizClient::Client::INDIAN_API_URL', 'https://example.com/')
11
+ stub_const('WhizClient::Client::APP_KEY', 'xxxxxxxxxxx')
12
+ end
13
+
14
+ context '.list_all_states' do
15
+ it 'returns an array' do
16
+ stub_request(:get, "https://example.com/indian-states-list?AppKey=xxxxxxxxxxx").
17
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
18
+ to_return(:status => 200, :body => valid_response(:states), :headers => {})
19
+
20
+ expect(described_class.list_all_states).to be_a_kind_of Array
21
+ end
22
+ end
23
+
24
+ context '.find_city_by_state' do
25
+ it 'returns an array' do
26
+ fake_response = '{"ResponseCode":0,"ResponseMessage":"OK","ResponseDateTime":"11/7/2014 9:40:15 AM GMT","Data":[{"city":"Adoor","State":"Kerala"},{"city":"Akathiyoor","State":"Kerala"}]}'
27
+
28
+ stub_request(:get, "https://example.com/indian-city-by-state?AppKey=xxxxxxxxxxx&stateid=9").
29
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
30
+ to_return(:status => 200, :body => fake_response, :headers => {})
31
+
32
+ expect(described_class.find_city_by_state(9)).to be_a_kind_of Array
33
+ end
34
+ end
35
+
36
+ context '.find_city_by_std_codes' do
37
+ it 'returns an array' do
38
+ fake_response = '{"ResponseCode":0,"ResponseMessage":"OK","ResponseDateTime":"11/7/2014 9:40:15 AM GMT","Data":[{"city":"Adoor","State":"Kerala"},{"city":"Akathiyoor","State":"Kerala"}]}'
39
+
40
+ stub_request(:get, "https://example.com/city-from-std-codes?AppKey=xxxxxxxxxxx&code=33").
41
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
42
+ to_return(:status => 200, :body => fake_response, :headers => {})
43
+
44
+ expect(described_class.find_city_by_std_codes('33')).to be_a_kind_of Array
45
+ end
46
+ end
47
+
48
+ context '.find_std_codes_by_location' do
49
+ it 'returns an array' do
50
+ fake_response = '{"ResponseCode":0,"ResponseMessage":"OK","ResponseDateTime":"11/7/2014 9:40:15 AM GMT","Data":[{"city":"Adoor","State":"Kerala"},{"city":"Akathiyoor","State":"Kerala"}]}'
51
+
52
+ stub_request(:get, "https://example.com/indian-std-codes?AppKey=xxxxxxxxxxx&search=Calcutta").
53
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
54
+ to_return(:status => 200, :body => fake_response, :headers => {})
55
+
56
+ expect(described_class.find_std_codes_by_location('Calcutta')).to be_a_kind_of Array
57
+ end
58
+ end
59
+
60
+ context '.find_city_by_postal_code' do
61
+ it 'returns an array' do
62
+ fake_response = '{"ResponseCode":0,"ResponseMessage":"OK","ResponseDateTime":"11/7/2014 9:40:15 AM GMT","Data":[{"city":"Adoor","State":"Kerala"},{"city":"Akathiyoor","State":"Kerala"}]}'
63
+
64
+ stub_request(:get, "https://example.com/indian-city-by-postal-code?AppKey=xxxxxxxxxxx&pin=700054").
65
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
66
+ to_return(:status => 200, :body => fake_response, :headers => {})
67
+
68
+ expect(described_class.find_city_by_postal_code('700054')).to be_a_kind_of Array
69
+ end
70
+ end
71
+
72
+ context '.find_postal_code_by_location' do
73
+ it 'returns an array' do
74
+ fake_response = '{"ResponseCode":0,"ResponseMessage":"OK","ResponseDateTime":"11/7/2014 9:40:15 AM GMT","Data":[{"city":"Adoor","State":"Kerala"},{"city":"Akathiyoor","State":"Kerala"}]}'
75
+
76
+ stub_request(:get, "https://example.com/indian-postal-codes?AppKey=xxxxxxxxxxx&search=kolkata").
77
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
78
+ to_return(:status => 200, :body => fake_response, :headers => {})
79
+
80
+ expect(described_class.find_postal_code_by_location('kolkata')).to be_a_kind_of Array
81
+ end
82
+ end
83
+ end
84
+
85
+ context 'When APP_KEY is uninitialized' do
86
+ it 'raise exception' do
87
+ expect{ described_class.list_all_states }.to raise_error WhizClient::WhizResponseError
88
+ end
89
+ end
90
+ end
91
+
@@ -0,0 +1,25 @@
1
+ require 'webmock/rspec'
2
+ require 'support/request_helper'
3
+ require 'whiz_client'
4
+
5
+
6
+ RSpec.configure do |config|
7
+ config.color = true
8
+ config.order = "rand"
9
+
10
+ # Filters
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+ config.filter_run_excluding :broken
15
+
16
+
17
+ # WebMock
18
+ config.before(:each, type: :feature, js: true) do
19
+ WebMock.disable_net_connect!(allow_localhost: true)
20
+ end
21
+
22
+ config.after(:each, type: :feature, js: true) do
23
+ WebMock.disable_net_connect!
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module RequestHelper
2
+ def valid_response(fixture)
3
+ File.read(fixture_filepath(:valid_responses, fixture))
4
+ end
5
+
6
+ def mock_valid_response(dir, fixture)
7
+ described_class.stub(:request_data) { valid_response(fixture) }
8
+ end
9
+
10
+ def fixture_filepath(sub_dir, name)
11
+ root_path.join('fixtures', sub_dir.to_s, name.to_s)
12
+ end
13
+
14
+ def root_path
15
+ Pathname.new(File.join(File.dirname(__FILE__), '../')).realpath
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'whiz_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "whiz_client"
8
+ spec.version = WhizClient::VERSION
9
+ spec.authors = ["Chiranjib Roy"]
10
+ spec.email = ["raychiranjib1@gmail.com"]
11
+ spec.summary = %q{A client program for WhizApi}
12
+ spec.description = %q{It is wrapper to get access of WhizApi Service like Indian State, City, STD code and various api created by WhizApi.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.rubyforge_project = 'whiz_client'
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'rest-client', ">=1.7.2"
24
+ spec.add_dependency 'json', ">=1.8.1"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.5"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec", '~> 2.13.0'
29
+ spec.add_development_dependency "webmock", '1.16.1'
30
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whiz_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Chiranjib Roy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 2.13.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 2.13.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.16.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.16.1
97
+ description: It is wrapper to get access of WhizApi Service like Indian State, City,
98
+ STD code and various api created by WhizApi.
99
+ email:
100
+ - raychiranjib1@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/whiz_client.rb
112
+ - lib/whiz_client/client.rb
113
+ - lib/whiz_client/version.rb
114
+ - spec/.DS_Store
115
+ - spec/fixtures/valid_responses/city
116
+ - spec/fixtures/valid_responses/states
117
+ - spec/fixtures/valid_responses/time_zones
118
+ - spec/lib/whiz_client_geo_spec.rb
119
+ - spec/lib/whiz_client_india_spec.rb
120
+ - spec/spec_helper.rb
121
+ - spec/support/request_helper.rb
122
+ - whiz_client.gemspec
123
+ homepage: ''
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project: whiz_client
143
+ rubygems_version: 2.1.11
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: A client program for WhizApi
147
+ test_files:
148
+ - spec/.DS_Store
149
+ - spec/fixtures/valid_responses/city
150
+ - spec/fixtures/valid_responses/states
151
+ - spec/fixtures/valid_responses/time_zones
152
+ - spec/lib/whiz_client_geo_spec.rb
153
+ - spec/lib/whiz_client_india_spec.rb
154
+ - spec/spec_helper.rb
155
+ - spec/support/request_helper.rb