whiz_client 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTFjZjMzMzRjMWVlNWMyYTM2Y2JiOTJkZTU4M2UxYWQ5Mzc0MWQ5Mw==
4
+ OThjMTMzZjc1NzI2MTliNzBmMzFhN2Y0YzU3MDVmZDZhYmEyMzNmZA==
5
5
  data.tar.gz: !binary |-
6
- MGZlOWJiM2NkMGZmMTRjNTYzMWNjNTliODc3NmU0MDM3MjY2ZGZjOQ==
6
+ OGRiYTA3ZWYzZWZiNTcyODc2MzNhODI1Y2IyYWE3NmQ5YWE5NDA4ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTQ1Mzc0YTU5MjE3MDY5NThhNWU1ZGRjYzhiZTRjMGJkMGZhMjAxODY2MzE0
10
- ZDhhY2M5ZjdhMWYwYmI4M2FjNzc3NDY1NjUwZGYzNDQyNjkyMDRkN2QzYWU4
11
- OTY0Y2Y1NDVlYTAwMzEyZDNhY2FmNjA0ZDY4MjQ0ODhmN2RlZDI=
9
+ YTQ0MGJjMzkyYjU5NDU1ODlmOGYwODNiNzc4MmY4NzFiYTUzMGNjNDk1MDVl
10
+ ZjM5NjU1NzMxOWU0ZjM0OWJmMTMyMWQ4MDFmNjFlNjNmZjZkZGIwZTAzMGQ3
11
+ MTE3ODBiYjEwMDRkMWJkYjkyMmY4OTNjZTFhMmJhMTE0NjhmZjI=
12
12
  data.tar.gz: !binary |-
13
- ODZhMmMyMzBmOGY5ZTdkYzY3NGU0YjUwZmEzNmYzMTFhY2ViNGQ1OWYxN2E1
14
- YzQyZDYzYTczZTIzOGJkM2Y1NGUxNWQxMDlhMDllMzM2M2I1OTdkMjgxZTc2
15
- MjVhMDZhZDZiNzVlYTkxODZlMmNmMGRlNDA5ZTY0Yjg0OTkyYjc=
13
+ NjExYTI0ZDUwNmEyZDNkOGZjNjNjYWI2ZGJmMWE0NjA3OWZiYjBiOWYyMTJl
14
+ NDg3ZDg2YmYxNjEwZTM1NWVlM2UxMDRlNmQzY2VkNzAzZmVhZWI4MjIyYWMy
15
+ ZTNhNGQ5MmNjZTRiOGY4Yjg4ZWU0NGM1NjRiZDUwMzU1MzY2MDg=
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: O4xhkBn9L65caCfwEedZb6S3IW6RSvfKT
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
- Gemfile.lock
2
+ *.rbc
20
3
  .bundle
21
- vendor/ruby
22
- ## PROJECT::SPECIFIC
23
- .rbenv-version
24
- .rbx
25
- .ruby-version
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
@@ -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
@@ -1,4 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ group :test do
4
+ gem 'coveralls', require: false
5
+ end
6
+
3
7
  # Specify your gem's dependencies in whiz_client.gemspec
4
8
  gemspec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # WhizClient
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/whiz_client.svg)](http://badge.fury.io/rb/whiz_client) [![Build Status](https://travis-ci.org/raychiranjib1/whiz_client.svg)](https://travis-ci.org/raychiranjib1/whiz_client) [![Code Climate](https://codeclimate.com/repos/5461c33f6956800ae807a7f0/badges/24da9482a4be8b92b3c3/gpa.svg)](https://codeclimate.com/repos/5461c33f6956800ae807a7f0/feed) [![Dependency Status](https://gemnasium.com/raychiranjib1/whiz_client.svg)](https://gemnasium.com/raychiranjib1/whiz_client) [![License](http://img.shields.io/license/MIT.png)](http://opensource.org/licenses/MIT) [![Coverage Status](https://coveralls.io/repos/raychiranjib1/whiz_client/badge.png?branch=master)](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.time_zones
72
+ WhizClient::Geo.list_all_time_zones
67
73
 
68
74
  Get current time of a particular time zone.
69
75
 
70
- WhizClient::Geo.current_time_of_timezone(<time zone>)
76
+ WhizClient::Geo.find_current_time_by_timezone(<time zone>)
71
77
 
72
78
 
73
- ## Error handaling
79
+ ## Error handling
74
80
 
75
81
  begin
76
82
  WhizClient::India.list_all_states
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ Bundler::GemHelper.install_tasks
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
8
+ task :test => :spec
@@ -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 India < WhizBase
30
+ class DynamicFinderMatch
20
31
 
21
- class << self
32
+ attr_accessor :first_attribute, :last_attribute, :arguments
22
33
 
23
- def list_all_states
24
- response = Client.request(request_params(method_name: 'indian-states-list'))
25
- parse(response)
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
- 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
45
+ def match?
46
+ @first_attribute != nil || @last_attribute != nil
47
+ end
32
48
 
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)
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
- 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
57
+ private
42
58
 
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)
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
- def find_postal_code_by_location(location)
49
- response = Client.request(request_params(location: location, method_name: 'indian-postal-codes'))
50
- parse(response)
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
- def self.method_missing(method_sym, *arguments, &block)
54
- puts method_sym
55
- puts arguments
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
@@ -1,3 +1,3 @@
1
1
  module WhizClient
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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.time_zones).to be_a_kind_of Array
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.current_time_of_timezone('Pacific Standard Time')).to be_a_kind_of String
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.time_zones }.to raise_error WhizClient::WhizResponseError
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
 
@@ -1,7 +1,9 @@
1
1
  require 'webmock/rspec'
2
2
  require 'support/request_helper'
3
3
  require 'whiz_client'
4
+ require 'coveralls'
4
5
 
6
+ Coveralls.wear!
5
7
 
6
8
  RSpec.configure do |config|
7
9
  config.color = true
@@ -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{It is wrapper to get access of WhizApi Service like Indian State, City, STD code and various api created by WhizApi.}
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.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 00:00:00.000000000 Z
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: It is wrapper to get access of WhizApi Service like Indian State, City,
98
- STD code and various api created by WhizApi.
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