turkish_banks 0.6.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 507f9a4bb17809fdf68a95947bb937759701a2f4f0267df1efb769187bdcfee8
4
- data.tar.gz: 5a6d1c8c8fe43d984b7028f0c41526a898a730bac0dee0b8c1814d02b33b255f
3
+ metadata.gz: 5a4a1e3454cffe707870cf8ad1b4ae3cd0158b40ff58c3251028063e57c94c85
4
+ data.tar.gz: '09afc7a80cbb76814f595ebd89113697d28ab8e77a912fff8205a8ed4c2542b1'
5
5
  SHA512:
6
- metadata.gz: '08c7a3f09d95afef0e09da7c5980e392e0b8768e9e3ed2e179ea0af90380fa7ae3f986c8b60f5aefea59f5d288121618e7280bb83d3023e67a620ffb606ba893'
7
- data.tar.gz: 0163fc54c49b07bb180b940ad2d3219fde863ce77beba7e54c4b2a2677441d24faff68e2ccc24df897ae5dd76dda92bd0ee662a273ec062afc0ffebe13af8313
6
+ metadata.gz: 8552c337e65bb399cb91cb844d4ee5197e7314b854b59052719741bd84ea2b1ac6ebda409349d54cd43612dc825a310c55b53725243a1c0a2fd1db85d3c123a8
7
+ data.tar.gz: 636f245cc55b582d2539999788b653515322ff22a238eda3d73c59391eccadfe05a189bc55d1754153a9b25266bb7cd58592ff82fea59777839358f975a42831
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /.idea/
data/README.md CHANGED
@@ -24,25 +24,34 @@ Or install it yourself as:
24
24
  ## Usage
25
25
 
26
26
  ```ruby
27
- # Creates a TurkishBank object
28
- turkish_bank = TurkishBanks::TurkishBank.new
29
-
30
27
  # Gets last update date
31
- turkish_bank.last_update_date
28
+ TurkishBanks::LAST_UPDATE
32
29
 
33
30
  # Gets all banks
34
- turkish_bank.banks
31
+ TurkishBanks.banks
32
+
33
+ # Create a bank from its name
34
+ bank = TurkishBanks::Bank.new("türkiye cumhuriyeti ziraat bankası a.ş.")
35
+ bank.name # => "TÜRKİYE CUMHURİYETİ ZIRAAT BANKASI A.Ş."
35
36
 
36
- # Returns a bank object
37
- bank = turkish_bank.get_information_of "türkiye cumhuriyeti ziraat bankası a.ş."
38
- bank.name # => TÜRKİYE CUMHURİYETİ ZIRAAT BANKASI A.Ş.
37
+ # Get a collection of branch objects
38
+ branches = bank.branches
39
+ branches.first.name # => "MERKEZ/ANKARA ŞUBESİ"
40
+ branches.size # => 1791
41
+ ```
39
42
 
40
- # Returns a collection of branch objectes
41
- branches = turkish_bank.get_branches_of "türkiye cumhuriyeti ziraat bankası a.ş."
42
- branches.first.name # => "ANKARA ŞUBESİ"
43
- ```
43
+ ## Exception Handling
44
44
 
45
- ## TODO
45
+ If you pass the wrong bank name to `Bank#new`, it raises `TurkishBanks::BankNotFoundError` exception. You can rescue this error, then do something else.
46
46
 
47
+ ```ruby
48
+ begin
49
+ TurkishBanks::Bank.new('fake bank')
50
+ rescue TurkishBanks::BankNotFoundError
51
+ # do something here
52
+ end
53
+ ```
54
+
55
+ ## TODO
47
56
  * Improve search part.
48
57
  * New features. Please send some pull-request.
@@ -1,13 +1,13 @@
1
- require "active_support/core_ext/hash"
1
+ require 'active_support/core_ext/hash'
2
2
 
3
- require "rubygems"
4
- require "open-uri"
5
- require "nokogiri"
6
- require "turkish_banks/version"
3
+ require 'rubygems'
4
+ require 'open-uri'
5
+ require 'nokogiri'
6
+ require 'turkish_banks/version'
7
7
 
8
- require "turkish_banks/turkish_bank"
9
- require "turkish_banks/bank"
10
- require "turkish_banks/branch"
8
+ require 'turkish_banks/turkish_banks'
9
+ require 'turkish_banks/branch'
10
+ require 'turkish_banks/bank'
11
11
 
12
12
  module TurkishBanks
13
13
  end
@@ -1,12 +1,21 @@
1
1
  module TurkishBanks
2
- class Bank < TurkishBank
3
- attr_accessor :name, :code, :city, :address
2
+ class Bank
3
+ attr_reader :name, :code, :city, :address
4
4
 
5
- def initialize(bank)
6
- @name = bank["bAd"]
7
- @code = bank["bKd"]
8
- @city = bank["bIlAd"]
9
- @address = bank["adr"]
5
+ def initialize(bank_name)
6
+ bank_params = TurkishBanks.get_bank_params(bank_name)
7
+ @name = bank_params['bAd']
8
+ @code = bank_params['bKd']
9
+ @city = bank_params['bIlAd']
10
+ @address = bank_params['adr']
11
+ end
12
+
13
+ def branches
14
+ nodes = TurkishBanks::DOC.xpath("//sube[bKd= '#{@code}']")
15
+ nodes.map do |node|
16
+ branch_params = Hash.from_xml(node.to_s)['sube']
17
+ TurkishBanks::Branch.new(branch_params)
18
+ end
10
19
  end
11
20
  end
12
21
  end
@@ -1,16 +1,17 @@
1
1
  module TurkishBanks
2
- class Branch < TurkishBank
3
- attr_accessor :name, :code, :bank_code, :city_code, :city, :district_code, :district, :phone
2
+ class Branch
3
+ attr_reader :name, :code, :bank_code, :city_code,
4
+ :city, :district_code, :district, :phone
4
5
 
5
- def initialize(branch)
6
- @name = branch["sAd"]
7
- @code = branch["sKd"]
8
- @bank_code = branch["bKd"]
9
- @city_code = branch["sIlKd"]
10
- @city = branch["sIlAd"]
11
- @district_code = branch["sIlcKd"]
12
- @district = branch["sIlcAd"]
13
- @phone = branch["tlf"]
6
+ def initialize(branch_params)
7
+ @name = branch_params['sAd']
8
+ @code = branch_params['sKd']
9
+ @bank_code = branch_params['bKd']
10
+ @city_code = branch_params['sIlKd']
11
+ @city = branch_params['sIlAd']
12
+ @district_code = branch_params['sIlcKd']
13
+ @district = branch_params['sIlcAd']
14
+ @phone = branch_params['tlf']
14
15
  end
15
16
  end
16
17
  end
@@ -0,0 +1,25 @@
1
+ module TurkishBanks
2
+ class BankNotFoundError < StandardError
3
+ def message
4
+ 'Banka bulunamadı.'
5
+ end
6
+ end
7
+
8
+ BANKS_URL = 'http://eftemkt.tcmb.gov.tr/bankasubelistesi/bankaSubeTumListe.xml'.freeze
9
+ DOC = Nokogiri
10
+ .XML(::OpenURI.open_uri(BANKS_URL), nil, 'UTF-8')
11
+ .remove_namespaces!.freeze
12
+ LAST_UPDATE = DOC.at_xpath('//bankaSubeTumListe')['tarih'].freeze
13
+
14
+ def self.get_bank_params(bank_name)
15
+ node = DOC.at_xpath("//banka[bAd= '#{bank_name.upcase(:turkic)}']")
16
+ raise BankNotFoundError if node.nil?
17
+
18
+ Hash.from_xml(node.to_s)['banka']
19
+ end
20
+
21
+ def self.banks
22
+ nodes = DOC.xpath('//banka')
23
+ nodes.each.map { |node| Hash.from_xml(node.to_s)['banka'] }
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module TurkishBanks
2
- VERSION = "0.6.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
- spec.add_development_dependency "activesupport", "~> 6.0.2.2"
27
+ spec.add_development_dependency "activesupport", ">= 6.0.3.1"
28
28
  spec.add_development_dependency "bundler", "~> 2.1.4"
29
29
  spec.add_development_dependency "nokogiri", "~> 1.10.9"
30
30
  spec.add_development_dependency "rake", "~> 13.0.0"
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turkish_banks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ender Ahmet Yurt
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-24 00:00:00.000000000 Z
11
+ date: 2020-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 6.0.2.2
19
+ version: 6.0.3.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 6.0.2.2
26
+ version: 6.0.3.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ files:
86
86
  - lib/turkish_banks.rb
87
87
  - lib/turkish_banks/bank.rb
88
88
  - lib/turkish_banks/branch.rb
89
- - lib/turkish_banks/turkish_bank.rb
89
+ - lib/turkish_banks/turkish_banks.rb
90
90
  - lib/turkish_banks/version.rb
91
91
  - turkish_banks.gemspec
92
92
  homepage: https://github.com/enderahmetyurt/turkish_banks
93
93
  licenses:
94
94
  - MIT
95
95
  metadata: {}
96
- post_install_message:
96
+ post_install_message:
97
97
  rdoc_options: []
98
98
  require_paths:
99
99
  - lib
@@ -108,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.1.2
112
- signing_key:
111
+ rubygems_version: 3.1.4
112
+ signing_key:
113
113
  specification_version: 4
114
114
  summary: Fetch Turkish Banks and their branches.
115
115
  test_files: []
@@ -1,39 +0,0 @@
1
- module TurkishBanks
2
- class TurkishBank
3
- attr_accessor :last_update_date, :banks
4
-
5
- BANKS_URL = "http://eftemkt.tcmb.gov.tr/bankasubelistesi/bankaSubeTumListe.xml".freeze
6
-
7
- def initialize
8
- doc = Nokogiri.XML(::OpenURI.open_uri(BANKS_URL), nil, 'UTF-8')
9
- doc.remove_namespaces!
10
- response = Hash.from_xml(doc.to_s)
11
- @last_update_date = response["bankaSubeTumListe"]["tarih"]
12
- @banks = response["bankaSubeTumListe"]["bankaSubeleri"]
13
- end
14
-
15
- def get_information_of(bank_name)
16
- return "#{bank_name} isminde bir banka bulunamadı." if get_bank(bank_name).empty?
17
-
18
- bank = get_bank(bank_name).first["banka"]
19
- TurkishBanks::Bank.new bank
20
- end
21
-
22
- def get_branches_of(bank_name)
23
- return "#{bank_name} isminde bir bankaya ait şube bilgisi bulunamadı." if get_bank(bank_name).empty?
24
-
25
- bank_branches = []
26
- branches = get_bank(bank_name).first["sube"]
27
- branches.each do |branch|
28
- bank_branches << TurkishBanks::Branch.new(branch)
29
- end
30
- bank_branches
31
- end
32
-
33
- private
34
-
35
- def get_bank(bank_name)
36
- @banks.select {|b| b["banka"]["bAd"] == bank_name.upcase(:turkic)}
37
- end
38
- end
39
- end