turkish_banks 0.2.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
- SHA1:
3
- metadata.gz: 5029ddc0ebe347cd8ad48c7c875fbdbb8a060cf5
4
- data.tar.gz: 2ebfbeeb4f1f4aa5eaba5f693023f639b8274b09
2
+ SHA256:
3
+ metadata.gz: 5a4a1e3454cffe707870cf8ad1b4ae3cd0158b40ff58c3251028063e57c94c85
4
+ data.tar.gz: '09afc7a80cbb76814f595ebd89113697d28ab8e77a912fff8205a8ed4c2542b1'
5
5
  SHA512:
6
- metadata.gz: d20970cd9349b14f3ef7101116e859499ab1d9a855047c3f55b5df3120d76b93cf08ced2606b63863f9169aa9591c2c44f8d20efee148d11e46b3997686de330
7
- data.tar.gz: c352d024b79c74fa5ac2ebc9df2a38a0433e9533c14b7d56911d7018800247c482ee7116d57353988d7e9ff073b49a62a96db4d8c685152fb701a1218a26ca3a
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/
@@ -1,3 +1,9 @@
1
1
  language: ruby
2
+ dist: trusty
2
3
  rvm:
3
- - 2.2.0
4
+ - 2.5.5
5
+ - 2.6.3
6
+ - 2.7.0
7
+ before_install:
8
+ - gem install bundler
9
+ script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -4,6 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development, :test do
7
- gem 'pry', '~> 0.9.12'
8
- gem 'rspec', '>= 2.14'
7
+ gem 'pry', '~> 0.13.1'
8
+ gem 'rspec', '>= 3.9.0'
9
9
  end
data/README.md CHANGED
@@ -24,33 +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
35
32
 
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.Ş.
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.Ş."
39
36
 
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
- ```
37
+ # Get a collection of branch objects
38
+ branches = bank.branches
39
+ branches.first.name # => "MERKEZ/ANKARA ŞUBESİ"
40
+ branches.size # => 1791
41
+ ```
44
42
 
45
- ## TODO
43
+ ## Exception Handling
46
44
 
47
- * Improve search part.
48
- * New features. Please send some pull-request.
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.
49
46
 
50
- ## Contributing
47
+ ```ruby
48
+ begin
49
+ TurkishBanks::Bank.new('fake bank')
50
+ rescue TurkishBanks::BankNotFoundError
51
+ # do something here
52
+ end
53
+ ```
51
54
 
52
- 1. Fork it ( https://github.com/[my-github-username]/turkish_banks/fork )
53
- 2. Create your feature branch (`git checkout -b my-new-feature`)
54
- 3. Commit your changes (`git commit -am 'Add some feature'`)
55
- 4. Push to the branch (`git push origin my-new-feature`)
56
- 5. Create a new Pull Request
55
+ ## TODO
56
+ * Improve search part.
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
4
-
5
- def initialize bank
6
- @name = bank["bAd"]
7
- @code = bank["bKd"]
8
- @city = bank["bIlAd"]
9
- @address = bank["adr"]
2
+ class Bank
3
+ attr_reader :name, :code, :city, :address
4
+
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
- end
21
+ end
@@ -1,12 +1,17 @@
1
1
  module TurkishBanks
2
- class Branch < TurkishBank
3
- attr_accessor :name, :code, :bank_code, :city
4
-
5
- def initialize branch
6
- @name = branch["sAd"]
7
- @code = branch["sKd"]
8
- @bank_code = branch["bKd"]
9
- @city = branch["bIlAd"]
2
+ class Branch
3
+ attr_reader :name, :code, :bank_code, :city_code,
4
+ :city, :district_code, :district, :phone
5
+
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']
10
15
  end
11
16
  end
12
- end
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.2.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -4,10 +4,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'turkish_banks/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "turkish_banks"
8
- spec.version = TurkishBanks::VERSION
9
- spec.authors = ["Ender Ahmet Yurt"]
10
- spec.email = ["enderyurt@gmail.com"]
7
+ spec.name = "turkish_banks"
8
+ spec.version = TurkishBanks::VERSION
9
+ spec.required_ruby_version = '>= 2.5.1'
10
+ spec.authors = ["Ender Ahmet Yurt"]
11
+ spec.email = ["enderyurt@gmail.com"]
11
12
 
12
13
  # if spec.respond_to?(:metadata)
13
14
  # spec.metadata['allowed_push_host'] = ""
@@ -23,9 +24,8 @@ Gem::Specification.new do |spec|
23
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
25
  spec.require_paths = ["lib"]
25
26
 
26
- spec.add_development_dependency "bundler", "~> 1.8"
27
- spec.add_development_dependency "rake", "~> 10.0"
28
- spec.add_development_dependency "nokogiri", "~> 1.6.0"
29
- spec.add_development_dependency "activesupport"
30
- spec.add_development_dependency "turkish_support"
27
+ spec.add_development_dependency "activesupport", ">= 6.0.3.1"
28
+ spec.add_development_dependency "bundler", "~> 2.1.4"
29
+ spec.add_development_dependency "nokogiri", "~> 1.10.9"
30
+ spec.add_development_dependency "rake", "~> 13.0.0"
31
31
  end
metadata CHANGED
@@ -1,85 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turkish_banks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.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: 2015-03-05 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
- name: bundler
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
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: '1.8'
26
+ version: 6.0.3.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 2.1.4
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 2.1.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.6.0
47
+ version: 1.10.9
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.6.0
55
- - !ruby/object:Gem::Dependency
56
- name: activesupport
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
54
+ version: 1.10.9
69
55
  - !ruby/object:Gem::Dependency
70
- name: turkish_support
56
+ name: rake
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - ">="
59
+ - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '0'
61
+ version: 13.0.0
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ">="
66
+ - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '0'
68
+ version: 13.0.0
83
69
  description: Fetch the all data about Turkish Banks and their branches.
84
70
  email:
85
71
  - enderyurt@gmail.com
@@ -100,15 +86,14 @@ files:
100
86
  - lib/turkish_banks.rb
101
87
  - lib/turkish_banks/bank.rb
102
88
  - lib/turkish_banks/branch.rb
103
- - lib/turkish_banks/turkish_bank.rb
89
+ - lib/turkish_banks/turkish_banks.rb
104
90
  - lib/turkish_banks/version.rb
105
- - turkish_banks-0.1.0.gem
106
91
  - turkish_banks.gemspec
107
92
  homepage: https://github.com/enderahmetyurt/turkish_banks
108
93
  licenses:
109
94
  - MIT
110
95
  metadata: {}
111
- post_install_message:
96
+ post_install_message:
112
97
  rdoc_options: []
113
98
  require_paths:
114
99
  - lib
@@ -116,17 +101,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
101
  requirements:
117
102
  - - ">="
118
103
  - !ruby/object:Gem::Version
119
- version: '0'
104
+ version: 2.5.1
120
105
  required_rubygems_version: !ruby/object:Gem::Requirement
121
106
  requirements:
122
107
  - - ">="
123
108
  - !ruby/object:Gem::Version
124
109
  version: '0'
125
110
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.2.1
128
- signing_key:
111
+ rubygems_version: 3.1.4
112
+ signing_key:
129
113
  specification_version: 4
130
114
  summary: Fetch Turkish Banks and their branches.
131
115
  test_files: []
132
- has_rdoc:
@@ -1,36 +0,0 @@
1
- require "turkish_support"
2
-
3
- module TurkishBanks
4
- class TurkishBank
5
- using TurkishSupport
6
- attr_accessor :last_update_date, :banks
7
-
8
- BANKS_URL = "http://eft.tcmb.gov.tr/bankasubelistesi/bankaSubeTumListe.xml"
9
-
10
- def initialize
11
- doc = Nokogiri.XML(open(BANKS_URL), nil, 'UTF-8')
12
- doc.remove_namespaces!
13
- response = Hash.from_xml(doc.to_s)
14
- @last_update_date = response["bankaSubeTumListe"]["tarih"]
15
- @banks = response["bankaSubeTumListe"]["bankaSubeleri"]
16
- end
17
-
18
- def get_information_of bank_name
19
- bank = get_bank(bank_name).first["banka"]
20
- TurkishBanks::Bank.new bank
21
- end
22
-
23
- def get_branches_of bank_name
24
- branches = get_bank(bank_name).first["sube"]
25
- branches.each do |branch|
26
- TurkishBanks::Branch.new branch
27
- end
28
- end
29
-
30
- private
31
-
32
- def get_bank bank_name
33
- @banks.select {|b| b["banka"]["bAd"] == bank_name.upcase}
34
- end
35
- end
36
- end
Binary file