pincode 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab7152b8b8f7c0e6212f492ae1b398d218fc02af
4
+ data.tar.gz: 294a680dc5417ba521b37396173e68be830ff52b
5
+ SHA512:
6
+ metadata.gz: 4dae5d1db289c71dabe4360dbf9b89fc157789358a90b4796af666f19926b896865ea58e0bb27883ea39d9e6d336a7c906a6a556504fc35f046d4e5f5412bd9a
7
+ data.tar.gz: 74dabe9e9f0c4cd62be0acaf0ada6e13e438ab5bfcc9951b909f5227b6d8a7614ccb36638a27ae0f3009ae8d1bd0e3fd216170e5d50cdff337ef25ec663ae2ee
@@ -0,0 +1,22 @@
1
+ # pincode - A ruby wrapper for the India Pincode API
2
+ Source : http://pin-codes.in/
3
+
4
+
5
+ ## Installation
6
+ gem install pincode
7
+
8
+ ## Usage
9
+
10
+ detail = Pincode.search <pincode>
11
+
12
+ detail.status
13
+
14
+ detail.post_office
15
+
16
+ detail.district
17
+
18
+ detail.state
19
+
20
+
21
+ ## Run tests
22
+ rake test
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,22 @@
1
+ require 'httparty'
2
+ require 'pincode/response'
3
+
4
+ module Pincode
5
+
6
+ include HTTParty
7
+ format :json
8
+
9
+ class << self
10
+
11
+ def search(query)
12
+ Response.new get(url + query.to_s)
13
+ end
14
+
15
+ def url
16
+ "http://pin-codes.in/api/pincode/"
17
+ end
18
+ end
19
+
20
+ class InvalidPincodeError < StandardError; end
21
+ end
22
+
@@ -0,0 +1,33 @@
1
+ module Pincode
2
+ class Response
3
+
4
+ def initialize(response)
5
+ @response = response
6
+ handle_response(@response)
7
+ end
8
+
9
+ def handle_response(response)
10
+ if response["status"] == "ERROR"
11
+ raise Pincode::InvalidPincodeError, response["message"]
12
+ else
13
+ response
14
+ end
15
+ end
16
+
17
+ def status
18
+ @response["status"]
19
+ end
20
+
21
+ def post_office
22
+ @response["PostOffice"]
23
+ end
24
+
25
+ def district
26
+ @response["District"]
27
+ end
28
+
29
+ def state
30
+ @response["State"]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Version
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/pincode/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'pincode'
6
+ s.version = Version::VERSION
7
+ s.date = '2014-09-14'
8
+ s.summary = "Pincode API"
9
+ s.description = "Gem to get details from pincode"
10
+ s.authors = ["A D Vishnu Prasad"]
11
+ s.email = 'advishnuprasad@gmail.com'
12
+ s.files = `git ls-files`.split("\n")
13
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
14
+ s.require_path = 'lib'
15
+ s.homepage = 'https://github.com/advishnuprasad/pincode'
16
+ s.license = 'MIT'
17
+
18
+ s.add_runtime_dependency 'httparty', '~> 0'
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+ require 'pincode'
3
+
4
+ class PincodeTest < Test::Unit::TestCase
5
+ def test_response
6
+ response = Pincode.search("560068")
7
+ assert_equal "SUCCESS", response.status
8
+ assert_equal "Singasandra", response.post_office
9
+ assert_equal "Bangalore Rural", response.district
10
+ assert_equal "Karnataka", response.state
11
+ end
12
+
13
+ def test_exception
14
+ assert_raise_with_message(Pincode::InvalidPincodeError, "Wrong PIN Code") do
15
+ Pincode.search("56006")
16
+ end
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pincode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - A D Vishnu Prasad
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Gem to get details from pincode
28
+ email: advishnuprasad@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - Rakefile
35
+ - lib/pincode.rb
36
+ - lib/pincode/response.rb
37
+ - lib/pincode/version.rb
38
+ - pincode.gemspec
39
+ - test/test_pincode.rb
40
+ homepage: https://github.com/advishnuprasad/pincode
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.2.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Pincode API
64
+ test_files: []