binocular 0.0.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 499b708c3a3e0ea14c539342939f76108e9a4bc0
4
- data.tar.gz: 1510ff50130d828a029f32b09de785649cf5f7f0
3
+ metadata.gz: 51b2d605d0d5398dfc93c3f8a59a4aaabe960e9f
4
+ data.tar.gz: 5b83ac19d6a8a450881126c63409d92c4d497141
5
5
  SHA512:
6
- metadata.gz: caafc9445d7313ac9abe41b59a31c2000db9d5bfb876bab1581e84297daae53e20b2d85e420fa2fa7301ba3998514ed72b29702b0e6df2dd947b215d4da2d151
7
- data.tar.gz: cf24bfd6503d887b6c47f6124aabd9746f7fa1a62975459a32e8faa242ec3d7ec63e091e88b7ffdbf9ae3983989dd5d9d8c509e096078c319650c704d5782322
6
+ metadata.gz: a5d9e8d1c442462756ab270b0132e8ee81a125e725f79343ec014f82666abed945e173581b13613f5b94059b3066bd17504d50e7bf21035ff1745b9d2440c9e7
7
+ data.tar.gz: f313629e9020c42fbae51e51e512f8672d35f89960818abd095a8d50c77964fefc28ea1ca9b209defadadbbf1a03e53b31000faa89570357cdf2d51528dfcf00
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Binocular
2
2
 
3
- TODO: Write a gem description
3
+ Get detail info of Bank Identification Number (BIN) / Issuer Identification Number (IIN) from http://www.binlist.net/
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,7 +20,50 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ #### Sample code
24
+
25
+ ```ruby
26
+ bin_number = Binocular::Bin.new(431940)
27
+ bin_number.fetch_info # fetch bin info from http://www.binlist.net/
28
+ bin_number.info # return Hash of fetched bin info.
29
+
30
+ ```
31
+
32
+ or for more simple use:
33
+
34
+ ```ruby
35
+ Binocular::Bin.info(431940) # fetch bin info from http://www.binlist.net/ & return Hash of fetched bin info
36
+
37
+ ```
38
+
39
+ #### From command line:
40
+
41
+ Binocular can be used from command line: `binocular <(6-length numeric) bin number>`
42
+
43
+ Sample:
44
+
45
+ ```
46
+ binocular 431940
47
+ ```
48
+
49
+ #### Sample result
50
+
51
+ ```ruby
52
+ {
53
+ "bin"=>"431940",
54
+ "brand"=>"VISA",
55
+ "sub_brand"=>"",
56
+ "country_code"=>"IE",
57
+ "country_name"=>"Ireland",
58
+ "bank"=>"BANK OF IRELAND",
59
+ "card_type"=>"DEBIT",
60
+ "card_category"=>"",
61
+ "latitude"=>"53",
62
+ "longitude"=>"-8",
63
+ "query_time"=>"385.784\u00B5s"
64
+ }
65
+ ```
66
+
24
67
 
25
68
  ## Contributing
26
69
 
data/bin/binocular CHANGED
@@ -27,7 +27,7 @@ def instruction
27
27
  end
28
28
 
29
29
  if (ARGV.length == 1) && (valid? ARGV[0])
30
- Binocular::Bin.info ARGV[0]
30
+ puts Binocular::Bin.info ARGV[0]
31
31
  else
32
32
  puts instruction
33
33
  exit
@@ -1,3 +1,3 @@
1
1
  module Binocular
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/binocular.rb CHANGED
@@ -1,18 +1,21 @@
1
1
  require "net/https"
2
2
  require "uri"
3
+ require "json"
3
4
  require "binocular/version"
4
5
 
5
6
  module Binocular
6
7
  class Bin
7
8
  attr_accessor :settings, :bin_number
9
+ attr_reader :info
10
+ DEFAULT_SETTINGS = { proxy_host: nil, proxy_port: nil }
8
11
 
9
12
  def self.info bin_number
10
- default_settings = { proxy_host: nil, proxy_port: nil }
11
- self.new(default_settings).info bin_number
13
+ self.new(bin_number).fetch_info
12
14
  end
13
15
 
14
- def initialize(settings)
16
+ def initialize(bin_number, settings=DEFAULT_SETTINGS)
15
17
  self.settings = settings
18
+ self.bin_number = bin_number
16
19
  end
17
20
 
18
21
  def proxy_host
@@ -27,8 +30,8 @@ module Binocular
27
30
  self.settings[:timeout] ? self.settings[:timeout] : 20
28
31
  end
29
32
 
30
- def info(bin_number)
31
- uri = URI.parse("http://www.binlist.net/json/#{bin_number}")
33
+ def fetch_info
34
+ uri = URI.parse("http://www.binlist.net/json/#{self.bin_number}")
32
35
 
33
36
  http = Net::HTTP.new(uri.host, uri.port, self.proxy_host, self.proxy_port)
34
37
  http.use_ssl = false
@@ -37,7 +40,7 @@ module Binocular
37
40
 
38
41
  request = Net::HTTP::Get.new(uri.request_uri)
39
42
  response = http.request(request)
40
- puts response.body
43
+ @info = JSON.parse response.body
41
44
  end
42
45
 
43
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binocular
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andri Setiawan