whiz_client 1.0.0 → 1.0.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.
- checksums.yaml +8 -8
- data/.coveralls.yml +2 -0
- data/.gitignore +25 -23
- data/.travis.yml +18 -0
- data/Gemfile +4 -0
- data/README.md +9 -3
- data/Rakefile +7 -0
- data/lib/whiz_client.rb +66 -37
- data/lib/whiz_client/version.rb +1 -1
- data/spec/lib/whiz_client_geo_spec.rb +9 -3
- data/spec/lib/whiz_client_india_spec.rb +6 -0
- data/spec/spec_helper.rb +2 -0
- data/whiz_client.gemspec +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OThjMTMzZjc1NzI2MTliNzBmMzFhN2Y0YzU3MDVmZDZhYmEyMzNmZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGRiYTA3ZWYzZWZiNTcyODc2MzNhODI1Y2IyYWE3NmQ5YWE5NDA4ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTQ0MGJjMzkyYjU5NDU1ODlmOGYwODNiNzc4MmY4NzFiYTUzMGNjNDk1MDVl
|
10
|
+
ZjM5NjU1NzMxOWU0ZjM0OWJmMTMyMWQ4MDFmNjFlNjNmZjZkZGIwZTAzMGQ3
|
11
|
+
MTE3ODBiYjEwMDRkMWJkYjkyMmY4OTNjZTFhMmJhMTE0NjhmZjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjExYTI0ZDUwNmEyZDNkOGZjNjNjYWI2ZGJmMWE0NjA3OWZiYjBiOWYyMTJl
|
14
|
+
NDg3ZDg2YmYxNjEwZTM1NWVlM2UxMDRlNmQzY2VkNzAzZmVhZWI4MjIyYWMy
|
15
|
+
ZTNhNGQ5MmNjZTRiOGY4Yjg4ZWU0NGM1NjRiZDUwMzU1MzY2MDg=
|
data/.coveralls.yml
ADDED
data/.gitignore
CHANGED
@@ -1,25 +1,27 @@
|
|
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
1
|
*.gem
|
19
|
-
|
2
|
+
*.rbc
|
20
3
|
.bundle
|
21
|
-
|
22
|
-
|
23
|
-
.
|
24
|
-
|
25
|
-
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.rvmrc
|
24
|
+
.DS_Store
|
25
|
+
lib/.DS_Store
|
26
|
+
lib/whiz_client/.DS_Store
|
27
|
+
nbproject
|
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.0
|
6
|
+
- 2.1.1
|
7
|
+
- 2.1.2
|
8
|
+
- 2.1.3
|
9
|
+
- 2.1.4
|
10
|
+
|
11
|
+
install:
|
12
|
+
- "travis_retry bundle install"
|
13
|
+
|
14
|
+
gemfile:
|
15
|
+
- gemfiles/3.1.gemfile
|
16
|
+
- gemfiles/3.2.gemfile
|
17
|
+
- gemfiles/4.0.gemfile
|
18
|
+
- gemfiles/4.1.gemfile
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# WhizClient
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/whiz_client) [](https://travis-ci.org/raychiranjib1/whiz_client) [](https://codeclimate.com/repos/5461c33f6956800ae807a7f0/feed) [](https://gemnasium.com/raychiranjib1/whiz_client) [](http://opensource.org/licenses/MIT) [](https://coveralls.io/r/raychiranjib1/whiz_client?branch=master)
|
4
|
+
|
3
5
|
A wrapper ruby library to access WhizApi. Get your api key from www.whizapi.com.
|
4
6
|
|
5
7
|
Using this library one can access following services...
|
@@ -45,6 +47,10 @@ Get the list of major cities of a state in India.
|
|
45
47
|
|
46
48
|
WhizClient::India.find_city_by_state(<state-id>)
|
47
49
|
|
50
|
+
example:
|
51
|
+
|
52
|
+
WhizClient::India.find_city_by_state(9).map {|hash| hash['city'] }
|
53
|
+
|
48
54
|
Get city/area from the STD code in India.
|
49
55
|
|
50
56
|
WhizClient::India.find_city_by_std_codes(<STD-CODE>)
|
@@ -63,14 +69,14 @@ Get pin code of any address, city, locality in India.
|
|
63
69
|
|
64
70
|
Get list of all time zones in the world.
|
65
71
|
|
66
|
-
WhizClient::Geo.
|
72
|
+
WhizClient::Geo.list_all_time_zones
|
67
73
|
|
68
74
|
Get current time of a particular time zone.
|
69
75
|
|
70
|
-
WhizClient::Geo.
|
76
|
+
WhizClient::Geo.find_current_time_by_timezone(<time zone>)
|
71
77
|
|
72
78
|
|
73
|
-
## Error
|
79
|
+
## Error handling
|
74
80
|
|
75
81
|
begin
|
76
82
|
WhizClient::India.list_all_states
|
data/Rakefile
CHANGED
data/lib/whiz_client.rb
CHANGED
@@ -10,50 +10,91 @@ module WhizClient
|
|
10
10
|
response_hash['Data']
|
11
11
|
end
|
12
12
|
|
13
|
+
def method_missing(method_sym, *arguments, &block)
|
14
|
+
finder = DynamicFinderMatch.new(method_sym, arguments)
|
15
|
+
|
16
|
+
raise WhizResponseError.new('Undefined Method', 500) unless finder.match?
|
17
|
+
|
18
|
+
params = request_params(finder.params)
|
19
|
+
|
20
|
+
response = Client.request(params)
|
21
|
+
parse(response)
|
22
|
+
end
|
23
|
+
|
13
24
|
def request_params(params)
|
14
25
|
raise NotImplementedError
|
15
26
|
end
|
16
27
|
end
|
17
28
|
end
|
18
29
|
|
19
|
-
class
|
30
|
+
class DynamicFinderMatch
|
20
31
|
|
21
|
-
|
32
|
+
attr_accessor :first_attribute, :last_attribute, :arguments
|
22
33
|
|
23
|
-
|
24
|
-
|
25
|
-
|
34
|
+
def initialize(method_sym, arguments)
|
35
|
+
if method_sym.to_s =~ /^find_(.*)_by_(.*)$/
|
36
|
+
@first_attribute = $1
|
37
|
+
@last_attribute = $2
|
38
|
+
@arguments = arguments
|
39
|
+
elsif method_sym.to_s =~ /^list_all_(.*)$/
|
40
|
+
@first_attribute = $1
|
41
|
+
@arguments = arguments
|
26
42
|
end
|
43
|
+
end
|
27
44
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
45
|
+
def match?
|
46
|
+
@first_attribute != nil || @last_attribute != nil
|
47
|
+
end
|
32
48
|
|
33
|
-
|
34
|
-
|
35
|
-
|
49
|
+
def params
|
50
|
+
if last_attribute.nil?
|
51
|
+
params_with_single_attribute
|
52
|
+
else
|
53
|
+
params_with_multiple_attibutes
|
36
54
|
end
|
55
|
+
end
|
37
56
|
|
38
|
-
|
39
|
-
response = Client.request(request_params(location: location, method_name: 'indian-std-codes'))
|
40
|
-
parse(response)
|
41
|
-
end
|
57
|
+
private
|
42
58
|
|
43
|
-
|
44
|
-
|
45
|
-
|
59
|
+
def argument
|
60
|
+
arguments.first
|
61
|
+
end
|
62
|
+
|
63
|
+
def params_with_single_attribute
|
64
|
+
if first_attribute == 'states'
|
65
|
+
{ method_name: 'indian-states-list' }
|
66
|
+
elsif first_attribute == 'time_zones'
|
67
|
+
{ method_name: 'time-zones' }
|
46
68
|
end
|
69
|
+
end
|
47
70
|
|
48
|
-
|
49
|
-
|
50
|
-
|
71
|
+
def params_with_multiple_attibutes
|
72
|
+
if first_attribute == 'city'
|
73
|
+
params_for_cities
|
74
|
+
elsif first_attribute == 'std_codes' && last_attribute == 'location'
|
75
|
+
{ location: argument, method_name: 'indian-std-codes' }
|
76
|
+
elsif first_attribute == 'postal_code' && last_attribute == 'location'
|
77
|
+
{ location: argument, method_name: 'indian-postal-codes' }
|
78
|
+
elsif first_attribute == 'current_time' && last_attribute == 'timezone'
|
79
|
+
{ time_zone: argument, method_name: 'current-time-of-timezone' }
|
51
80
|
end
|
81
|
+
end
|
52
82
|
|
53
|
-
|
54
|
-
|
55
|
-
|
83
|
+
def params_for_cities
|
84
|
+
if last_attribute == 'state'
|
85
|
+
{ stateid: argument, method_name: 'indian-city-by-state' }
|
86
|
+
elsif last_attribute == 'std_codes'
|
87
|
+
{ std_code: argument, method_name: 'city-from-std-codes' }
|
88
|
+
elsif last_attribute == 'postal_code'
|
89
|
+
{ postal_code: argument, method_name: 'indian-city-by-postal-code' }
|
56
90
|
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
class India < WhizBase
|
96
|
+
|
97
|
+
class << self
|
57
98
|
|
58
99
|
private
|
59
100
|
|
@@ -66,16 +107,6 @@ module WhizClient
|
|
66
107
|
class Geo < WhizBase
|
67
108
|
class << self
|
68
109
|
|
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
110
|
private
|
80
111
|
|
81
112
|
def request_params(params)
|
@@ -83,7 +114,5 @@ module WhizClient
|
|
83
114
|
end
|
84
115
|
|
85
116
|
end
|
86
|
-
|
87
117
|
end
|
88
|
-
|
89
118
|
end
|
data/lib/whiz_client/version.rb
CHANGED
@@ -18,7 +18,7 @@ describe WhizClient::Geo do
|
|
18
18
|
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
|
19
19
|
to_return(:status => 200, :body => valid_response(:time_zones), :headers => {})
|
20
20
|
|
21
|
-
expect(described_class.
|
21
|
+
expect(described_class.list_all_time_zones).to be_a_kind_of Array
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -30,14 +30,20 @@ describe WhizClient::Geo do
|
|
30
30
|
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
|
31
31
|
to_return(:status => 200, :body => fake_response, :headers => {})
|
32
32
|
|
33
|
-
expect(described_class.
|
33
|
+
expect(described_class.find_current_time_by_timezone('Pacific Standard Time')).to be_a_kind_of String
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
context 'When APP_KEY is uninitialized' do
|
39
39
|
it 'raise exception' do
|
40
|
-
expect{ described_class.
|
40
|
+
expect{ described_class.list_all_time_zones }.to raise_error WhizClient::WhizResponseError
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'When method missing' do
|
45
|
+
it 'raise exception' do
|
46
|
+
expect{ described_class.a_undefined_method }.to raise_error WhizClient::WhizResponseError
|
41
47
|
end
|
42
48
|
end
|
43
49
|
end
|
@@ -87,5 +87,11 @@ describe WhizClient::India do
|
|
87
87
|
expect{ described_class.list_all_states }.to raise_error WhizClient::WhizResponseError
|
88
88
|
end
|
89
89
|
end
|
90
|
+
|
91
|
+
context 'When method missing' do
|
92
|
+
it 'raise exception' do
|
93
|
+
expect{ described_class.a_undefined_method }.to raise_error WhizClient::WhizResponseError
|
94
|
+
end
|
95
|
+
end
|
90
96
|
end
|
91
97
|
|
data/spec/spec_helper.rb
CHANGED
data/whiz_client.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Chiranjib Roy"]
|
10
10
|
spec.email = ["raychiranjib1@gmail.com"]
|
11
11
|
spec.summary = %q{A client program for WhizApi}
|
12
|
-
spec.description = %q{
|
12
|
+
spec.description = %q{A wrapper to get access of WhizApi Service like Indian State, City, STD code and various api created by WhizApi.}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whiz_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chiranjib Roy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -94,17 +94,18 @@ dependencies:
|
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 1.16.1
|
97
|
-
description:
|
98
|
-
|
97
|
+
description: A wrapper to get access of WhizApi Service like Indian State, City, STD
|
98
|
+
code and various api created by WhizApi.
|
99
99
|
email:
|
100
100
|
- raychiranjib1@gmail.com
|
101
101
|
executables: []
|
102
102
|
extensions: []
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
|
+
- .coveralls.yml
|
105
106
|
- .gitignore
|
107
|
+
- .travis.yml
|
106
108
|
- Gemfile
|
107
|
-
- Gemfile.lock
|
108
109
|
- LICENSE.txt
|
109
110
|
- README.md
|
110
111
|
- Rakefile
|