cccode 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cccode.gemspec +48 -0
- data/lib/cccode.rb +61 -0
- data/lib/cccode/models/country_code.rb +19 -0
- data/lib/cccode/version.rb +3 -0
- data/lib/generators/cccode/install_generator.rb +41 -0
- data/lib/generators/templates/create_country_codes.rb +11 -0
- data/lib/misc.rb +33 -0
- data/lib/soap.rb +117 -0
- data/vendor/cache/actioncable-5.0.1.gem +0 -0
- data/vendor/cache/actionmailer-5.0.1.gem +0 -0
- data/vendor/cache/actionpack-5.0.1.gem +0 -0
- data/vendor/cache/actionview-5.0.1.gem +0 -0
- data/vendor/cache/activejob-5.0.1.gem +0 -0
- data/vendor/cache/activemodel-5.0.1.gem +0 -0
- data/vendor/cache/activerecord-5.0.1.gem +0 -0
- data/vendor/cache/activesupport-5.0.1.gem +0 -0
- data/vendor/cache/akami-1.3.1.gem +0 -0
- data/vendor/cache/arel-7.1.4.gem +0 -0
- data/vendor/cache/builder-3.2.3.gem +0 -0
- data/vendor/cache/coderay-1.1.1.gem +0 -0
- data/vendor/cache/concurrent-ruby-1.0.4.gem +0 -0
- data/vendor/cache/diff-lcs-1.2.5.gem +0 -0
- data/vendor/cache/erubis-2.7.0.gem +0 -0
- data/vendor/cache/globalid-0.3.7.gem +0 -0
- data/vendor/cache/gyoku-1.3.1.gem +0 -0
- data/vendor/cache/httpi-2.4.2.gem +0 -0
- data/vendor/cache/i18n-0.7.0.gem +0 -0
- data/vendor/cache/loofah-2.0.3.gem +0 -0
- data/vendor/cache/mail-2.6.4.gem +0 -0
- data/vendor/cache/method_source-0.8.2.gem +0 -0
- data/vendor/cache/mime-types-3.1.gem +0 -0
- data/vendor/cache/mime-types-data-3.2016.0521.gem +0 -0
- data/vendor/cache/mini_portile2-2.1.0.gem +0 -0
- data/vendor/cache/minitest-5.10.1.gem +0 -0
- data/vendor/cache/nio4r-1.2.1.gem +0 -0
- data/vendor/cache/nokogiri-1.7.0.1.gem +0 -0
- data/vendor/cache/nori-2.6.0.gem +0 -0
- data/vendor/cache/pry-0.10.4.gem +0 -0
- data/vendor/cache/rack-2.0.1.gem +0 -0
- data/vendor/cache/rack-test-0.6.3.gem +0 -0
- data/vendor/cache/rails-5.0.1.gem +0 -0
- data/vendor/cache/rails-dom-testing-2.0.2.gem +0 -0
- data/vendor/cache/rails-html-sanitizer-1.0.3.gem +0 -0
- data/vendor/cache/railties-5.0.1.gem +0 -0
- data/vendor/cache/rake-10.5.0.gem +0 -0
- data/vendor/cache/rspec-3.5.0.gem +0 -0
- data/vendor/cache/rspec-core-3.5.4.gem +0 -0
- data/vendor/cache/rspec-expectations-3.5.0.gem +0 -0
- data/vendor/cache/rspec-mocks-3.5.0.gem +0 -0
- data/vendor/cache/rspec-support-3.5.0.gem +0 -0
- data/vendor/cache/savon-2.11.1.gem +0 -0
- data/vendor/cache/slop-3.6.0.gem +0 -0
- data/vendor/cache/socksify-1.7.0.gem +0 -0
- data/vendor/cache/sprockets-3.7.1.gem +0 -0
- data/vendor/cache/sprockets-rails-3.2.0.gem +0 -0
- data/vendor/cache/thor-0.19.4.gem +0 -0
- data/vendor/cache/thread_safe-0.3.5.gem +0 -0
- data/vendor/cache/tzinfo-1.2.2.gem +0 -0
- data/vendor/cache/wasabi-3.5.0.gem +0 -0
- data/vendor/cache/websocket-driver-0.6.4.gem +0 -0
- data/vendor/cache/websocket-extensions-0.1.2.gem +0 -0
- metadata +286 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e75204879d5defbe6df1af03d94d5c7f88a301ae
|
4
|
+
data.tar.gz: 1839c41b0f761b7d3a2e7941758837150ba2ee7e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2faf806877c69b26a396c42bf2feee6c99c8be5677635ac1928188dcfe99fc84cc00c1c2c42fac60621da70fee1ef952aff72b8b8942b4027421523c21ad729d
|
7
|
+
data.tar.gz: 7c05d7c93285b8d5a9d7914de1a77b70c50b91cdade7da7a7a310c07f23b13b8f9319f8774a13ae604048572bffe8c1d45a180ed5c5d5824834f59dd185070af
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
cccode
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.0
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at info@cherrystoned.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 kirsche
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Cccode
|
2
|
+
|
3
|
+
Country and Currency Code provides quick access to country and currency data via SOAP webservice provided by http://www.webservicex.net.
|
4
|
+
|
5
|
+
The data of all countries can be accessed directly via SOAP or be persisted and used via local database access.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'cccode'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install cccode
|
22
|
+
|
23
|
+
After the gem is installed you need to create the country_codes table via the gem`s generator:
|
24
|
+
|
25
|
+
$ rails g cccode:install
|
26
|
+
$ rake db:migrate
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
Enable usage by adding this to your class/ ruby file:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'Cccode'
|
33
|
+
```
|
34
|
+
|
35
|
+
### Soap
|
36
|
+
This section explains how to call the web service via SOAP directly. For quick access via local db see next section 'Database'.
|
37
|
+
|
38
|
+
__Get all countries as an array:__
|
39
|
+
|
40
|
+
Cccode.get_countries
|
41
|
+
|
42
|
+
__Get country code by country:__
|
43
|
+
|
44
|
+
Cccode.get_country_code(<country name>)
|
45
|
+
|
46
|
+
__Get currency by country:__
|
47
|
+
|
48
|
+
Cccode.get_currency(<country name>)
|
49
|
+
|
50
|
+
__Get currency code by currency:__
|
51
|
+
|
52
|
+
Cccode.get_currency_code(<currency name>)
|
53
|
+
|
54
|
+
Note: all these actions __DO NOT__ persist the data. To achieve that see 'Database' section!
|
55
|
+
|
56
|
+
|
57
|
+
### Database
|
58
|
+
To get all available data at once and fill the database (reset is executed upfront):
|
59
|
+
|
60
|
+
Cccode.get_all
|
61
|
+
|
62
|
+
__Reset (truncate) conutry_codes table:__
|
63
|
+
|
64
|
+
Cccode.reset
|
65
|
+
|
66
|
+
|
67
|
+
__Check if data exists:__
|
68
|
+
|
69
|
+
Cccode::CountryCode.exists?
|
70
|
+
|
71
|
+
__Get all data for a country:__
|
72
|
+
|
73
|
+
data = Cccode::Codes.new(<country name>)
|
74
|
+
|
75
|
+
__Example: data = Cccode::Codes.new('Germany') returns:__
|
76
|
+
|
77
|
+
data.country = 'Germany'
|
78
|
+
data.country_code = 'de'
|
79
|
+
data.currency = 'Mark'
|
80
|
+
data.currency_code = 'DEM'
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cherrystoned/cccode.
|
87
|
+
|
88
|
+
## License
|
89
|
+
|
90
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cccode"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/cccode.gemspec
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#lib = File.expand_path('../lib', __FILE__)
|
3
|
+
#$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
$:.push File.expand_path('../lib', __FILE__)
|
5
|
+
require 'cccode/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'cccode'
|
9
|
+
spec.version = Cccode::VERSION
|
10
|
+
spec.authors = ['kirsche']
|
11
|
+
spec.email = ['info@cherrystoned.com']
|
12
|
+
|
13
|
+
spec.summary = 'Country and currency codes'
|
14
|
+
spec.description = 'Fetches and persists country and currency codes via SOAP'
|
15
|
+
spec.homepage = 'https://github.com/cherrystoned/cccode'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
22
|
+
else
|
23
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
24
|
+
'public gem pushes.'
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
30
|
+
spec.bindir = 'exe'
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ['lib']
|
33
|
+
|
34
|
+
spec.add_dependency 'nori'
|
35
|
+
spec.add_dependency 'socksify'
|
36
|
+
spec.add_dependency 'httpi'
|
37
|
+
spec.add_dependency 'gyoku'
|
38
|
+
spec.add_dependency 'akami'
|
39
|
+
spec.add_dependency 'savon'
|
40
|
+
|
41
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
42
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
43
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
44
|
+
spec.add_development_dependency 'activerecord', '>= 4.0.0'
|
45
|
+
spec.add_development_dependency 'sqlite3'
|
46
|
+
spec.add_development_dependency 'rails', '>= 4.0'
|
47
|
+
|
48
|
+
end
|
data/lib/cccode.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'cccode/version'
|
3
|
+
require 'cccode/models/country_code'
|
4
|
+
require 'soap'
|
5
|
+
|
6
|
+
module Cccode
|
7
|
+
|
8
|
+
# database data
|
9
|
+
class Codes
|
10
|
+
|
11
|
+
attr_accessor :country, :country_code, :currency, :currency_code
|
12
|
+
|
13
|
+
# Cccode::Codes.new('Germany')
|
14
|
+
def initialize(country)
|
15
|
+
record = Cccode::CountryCode.where(country: country).first
|
16
|
+
if record
|
17
|
+
@country = record.country
|
18
|
+
@country_code = record.country_code
|
19
|
+
@currency = record.currency
|
20
|
+
@currency_code = record.currency_code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
## database actions
|
26
|
+
# Cccode.reset
|
27
|
+
def self.reset
|
28
|
+
Cccode::CountryCode.destroy_all
|
29
|
+
end
|
30
|
+
|
31
|
+
# Cccode.get_all
|
32
|
+
def self.get_all
|
33
|
+
Cccode::CountryCode.destroy_all
|
34
|
+
s = Soap.new
|
35
|
+
s.get_all
|
36
|
+
end
|
37
|
+
|
38
|
+
## SOAP actions
|
39
|
+
# Cccode.get_countries
|
40
|
+
def self.get_countries
|
41
|
+
s = Soap.new
|
42
|
+
s.countries
|
43
|
+
end
|
44
|
+
|
45
|
+
# Cccode.get_country_code('Spain')
|
46
|
+
def self.get_country_code(country)
|
47
|
+
s = Soap.new
|
48
|
+
s.country_code(country)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.get_currency(country)
|
52
|
+
s = Soap.new
|
53
|
+
s.currency(country)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.get_currency_code(currency)
|
57
|
+
s = Soap.new
|
58
|
+
s.currency_code(currency)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module Cccode
|
4
|
+
class CountryCode < ActiveRecord::Base
|
5
|
+
|
6
|
+
def self.insert_all(xml)
|
7
|
+
xml.css('Table').each_with_index do |_, idx|
|
8
|
+
CountryCode.create(
|
9
|
+
country: xml.css('Table/Name')[idx].text.strip,
|
10
|
+
country_code: xml.css('Table/CountryCode')[idx].text.strip,
|
11
|
+
currency: xml.css('Table/Currency')[idx].text.strip,
|
12
|
+
currency_code: xml.css('Table/CurrencyCode')[idx].text.strip,
|
13
|
+
)
|
14
|
+
end
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Cccode
|
4
|
+
module Generators
|
5
|
+
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
source_root File.expand_path('../../templates', __FILE__)
|
9
|
+
|
10
|
+
desc "Creates a Cccode initializer and copy locale files to your application."
|
11
|
+
def hi
|
12
|
+
puts "hi am Cccode installer running fine ..."
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "add the migrations"
|
16
|
+
def self.next_migration_number(path)
|
17
|
+
unless @prev_migration_nr
|
18
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
19
|
+
else
|
20
|
+
@prev_migration_nr += 1
|
21
|
+
end
|
22
|
+
@prev_migration_nr.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def copy_migrations
|
26
|
+
copy_migration 'create_country_codes'
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def copy_migration(filename)
|
32
|
+
if self.class.migration_exists?("db/migrate", "#{filename}")
|
33
|
+
say_status("skipped", "Migration #{filename}.rb already exists")
|
34
|
+
else
|
35
|
+
migration_template "#{filename}.rb", "db/migrate/#{filename}.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/misc.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
class Cccode::Misc
|
2
|
+
|
3
|
+
require 'pry'
|
4
|
+
require 'active_support/core_ext/object/try'
|
5
|
+
|
6
|
+
def self.nested_keys(source_hash, *target_keys)
|
7
|
+
begin
|
8
|
+
new_keys = target_keys
|
9
|
+
new_hash = source_hash
|
10
|
+
while new_keys.present?
|
11
|
+
return nil unless valid_key?(new_keys[0], new_hash)
|
12
|
+
|
13
|
+
chk_try = new_hash.try(:[], new_keys[0])
|
14
|
+
if chk_try
|
15
|
+
new_hash = new_hash[new_keys[0]]
|
16
|
+
new_keys.delete_at(0)
|
17
|
+
return chk_try if new_keys.blank?
|
18
|
+
else
|
19
|
+
return nil
|
20
|
+
end
|
21
|
+
end if new_keys && new_hash
|
22
|
+
new_hash
|
23
|
+
rescue StandardError => e
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.valid_key?(k, source=nil)
|
29
|
+
key_valid = k.is_a?(String) || k.is_a?(Integer) || k.is_a?(Symbol)
|
30
|
+
ar_valid = source ? (source.is_a?(Array) ? k.is_a?(Integer) : true) : true
|
31
|
+
key_valid && ar_valid
|
32
|
+
end
|
33
|
+
end
|
data/lib/soap.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
class Cccode::Soap
|
2
|
+
|
3
|
+
require 'pry'
|
4
|
+
require 'savon'
|
5
|
+
require 'misc'
|
6
|
+
|
7
|
+
WSDL = 'http://www.webservicex.net/country.asmx?WSDL'
|
8
|
+
|
9
|
+
attr_accessor :client, :countries, :response, :result, :xml,
|
10
|
+
:command, :result_keys, :message,
|
11
|
+
:country_code, :country, :currency, :currency_code,
|
12
|
+
:currencies
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
end
|
16
|
+
|
17
|
+
# todo: needed here? only model direct?
|
18
|
+
def table_empty?
|
19
|
+
Cccode::Soap.table_empty?
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.table_empty?
|
23
|
+
!Cccode::CountryCode.exists?
|
24
|
+
end
|
25
|
+
|
26
|
+
def client
|
27
|
+
@client ||= Savon.client(wsdl: WSDL)
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_all
|
31
|
+
get_xml(:get_currency_code)
|
32
|
+
Cccode::CountryCode.insert_all(@xml)
|
33
|
+
end
|
34
|
+
|
35
|
+
def countries
|
36
|
+
get_xml(:get_countries)
|
37
|
+
@countries = @xml.css('Table').map{|e| e.content.strip}
|
38
|
+
end
|
39
|
+
|
40
|
+
def country_code(country=nil)
|
41
|
+
@country = country if country
|
42
|
+
get_xml(:get_iso_country_code_by_county_name)
|
43
|
+
@country_code = get_content('Table/CountryCode')
|
44
|
+
end
|
45
|
+
|
46
|
+
def currency(country=nil)
|
47
|
+
@country = country if country
|
48
|
+
get_xml(:get_currency_by_country)
|
49
|
+
@currency = get_content('Table/Currency')
|
50
|
+
end
|
51
|
+
|
52
|
+
def currency_code(currency=nil)
|
53
|
+
@currency = currency if currency
|
54
|
+
get_xml(:get_currency_code_by_currency_name)
|
55
|
+
@currency_code = get_content('Table/CurrencyCode')
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def get_content(css)
|
61
|
+
@xml.css(css).first.present? ? @xml.css(css).first.content : nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def set_mode(mode)
|
65
|
+
@command = mode
|
66
|
+
@message = nil
|
67
|
+
case mode
|
68
|
+
when :get_countries
|
69
|
+
@result_keys = [
|
70
|
+
:envelope, :body, :get_countries_response, :get_countries_result
|
71
|
+
]
|
72
|
+
when :get_iso_country_code_by_county_name
|
73
|
+
@result_keys = [
|
74
|
+
:envelope, :body, :get_iso_country_code_by_county_name_response,
|
75
|
+
:get_iso_country_code_by_county_name_result
|
76
|
+
]
|
77
|
+
@message = {"CountryName" => @country}
|
78
|
+
when :get_currency_by_country
|
79
|
+
@result_keys = [
|
80
|
+
:envelope, :body, :get_currency_by_country_response,
|
81
|
+
:get_currency_by_country_result
|
82
|
+
]
|
83
|
+
@message = {"CountryName" => @country}
|
84
|
+
when :get_currency_code_by_currency_name
|
85
|
+
@result_keys = [
|
86
|
+
:envelope, :body, :get_currency_code_by_currency_name_response,
|
87
|
+
:get_currency_code_by_currency_name_result
|
88
|
+
]
|
89
|
+
@message = {"CurrencyName" => @currency}
|
90
|
+
when :get_currency_code
|
91
|
+
@result_keys = [
|
92
|
+
:envelope, :body, :get_currency_code_response,
|
93
|
+
:get_currency_code_result
|
94
|
+
]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def get_xml(mode)
|
99
|
+
set_mode(mode)
|
100
|
+
call
|
101
|
+
result
|
102
|
+
end
|
103
|
+
|
104
|
+
def call
|
105
|
+
begin
|
106
|
+
@response = self.client.call(@command, :message => @message)
|
107
|
+
rescue Savon::HTTPError => e
|
108
|
+
raise "savon call error, call failed: #{e.http.code}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def result
|
113
|
+
@result = Cccode::Misc.nested_keys(@response.hash, *@result_keys)
|
114
|
+
@xml = Nokogiri::XML(@result)
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,286 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cccode
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kirsche
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nori
|
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
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: socksify
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httpi
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: gyoku
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: akami
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: savon
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.13'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.13'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: activerecord
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 4.0.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 4.0.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sqlite3
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rails
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '4.0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '4.0'
|
181
|
+
description: Fetches and persists country and currency codes via SOAP
|
182
|
+
email:
|
183
|
+
- info@cherrystoned.com
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".gitignore"
|
189
|
+
- ".rspec"
|
190
|
+
- ".ruby-gemset"
|
191
|
+
- ".ruby-version"
|
192
|
+
- ".travis.yml"
|
193
|
+
- CODE_OF_CONDUCT.md
|
194
|
+
- Gemfile
|
195
|
+
- LICENSE.txt
|
196
|
+
- README.md
|
197
|
+
- Rakefile
|
198
|
+
- bin/console
|
199
|
+
- bin/setup
|
200
|
+
- cccode.gemspec
|
201
|
+
- lib/cccode.rb
|
202
|
+
- lib/cccode/models/country_code.rb
|
203
|
+
- lib/cccode/version.rb
|
204
|
+
- lib/generators/cccode/install_generator.rb
|
205
|
+
- lib/generators/templates/create_country_codes.rb
|
206
|
+
- lib/misc.rb
|
207
|
+
- lib/soap.rb
|
208
|
+
- vendor/cache/actioncable-5.0.1.gem
|
209
|
+
- vendor/cache/actionmailer-5.0.1.gem
|
210
|
+
- vendor/cache/actionpack-5.0.1.gem
|
211
|
+
- vendor/cache/actionview-5.0.1.gem
|
212
|
+
- vendor/cache/activejob-5.0.1.gem
|
213
|
+
- vendor/cache/activemodel-5.0.1.gem
|
214
|
+
- vendor/cache/activerecord-5.0.1.gem
|
215
|
+
- vendor/cache/activesupport-5.0.1.gem
|
216
|
+
- vendor/cache/akami-1.3.1.gem
|
217
|
+
- vendor/cache/arel-7.1.4.gem
|
218
|
+
- vendor/cache/builder-3.2.3.gem
|
219
|
+
- vendor/cache/coderay-1.1.1.gem
|
220
|
+
- vendor/cache/concurrent-ruby-1.0.4.gem
|
221
|
+
- vendor/cache/diff-lcs-1.2.5.gem
|
222
|
+
- vendor/cache/erubis-2.7.0.gem
|
223
|
+
- vendor/cache/globalid-0.3.7.gem
|
224
|
+
- vendor/cache/gyoku-1.3.1.gem
|
225
|
+
- vendor/cache/httpi-2.4.2.gem
|
226
|
+
- vendor/cache/i18n-0.7.0.gem
|
227
|
+
- vendor/cache/loofah-2.0.3.gem
|
228
|
+
- vendor/cache/mail-2.6.4.gem
|
229
|
+
- vendor/cache/method_source-0.8.2.gem
|
230
|
+
- vendor/cache/mime-types-3.1.gem
|
231
|
+
- vendor/cache/mime-types-data-3.2016.0521.gem
|
232
|
+
- vendor/cache/mini_portile2-2.1.0.gem
|
233
|
+
- vendor/cache/minitest-5.10.1.gem
|
234
|
+
- vendor/cache/nio4r-1.2.1.gem
|
235
|
+
- vendor/cache/nokogiri-1.7.0.1.gem
|
236
|
+
- vendor/cache/nori-2.6.0.gem
|
237
|
+
- vendor/cache/pry-0.10.4.gem
|
238
|
+
- vendor/cache/rack-2.0.1.gem
|
239
|
+
- vendor/cache/rack-test-0.6.3.gem
|
240
|
+
- vendor/cache/rails-5.0.1.gem
|
241
|
+
- vendor/cache/rails-dom-testing-2.0.2.gem
|
242
|
+
- vendor/cache/rails-html-sanitizer-1.0.3.gem
|
243
|
+
- vendor/cache/railties-5.0.1.gem
|
244
|
+
- vendor/cache/rake-10.5.0.gem
|
245
|
+
- vendor/cache/rspec-3.5.0.gem
|
246
|
+
- vendor/cache/rspec-core-3.5.4.gem
|
247
|
+
- vendor/cache/rspec-expectations-3.5.0.gem
|
248
|
+
- vendor/cache/rspec-mocks-3.5.0.gem
|
249
|
+
- vendor/cache/rspec-support-3.5.0.gem
|
250
|
+
- vendor/cache/savon-2.11.1.gem
|
251
|
+
- vendor/cache/slop-3.6.0.gem
|
252
|
+
- vendor/cache/socksify-1.7.0.gem
|
253
|
+
- vendor/cache/sprockets-3.7.1.gem
|
254
|
+
- vendor/cache/sprockets-rails-3.2.0.gem
|
255
|
+
- vendor/cache/thor-0.19.4.gem
|
256
|
+
- vendor/cache/thread_safe-0.3.5.gem
|
257
|
+
- vendor/cache/tzinfo-1.2.2.gem
|
258
|
+
- vendor/cache/wasabi-3.5.0.gem
|
259
|
+
- vendor/cache/websocket-driver-0.6.4.gem
|
260
|
+
- vendor/cache/websocket-extensions-0.1.2.gem
|
261
|
+
homepage: https://github.com/cherrystoned/cccode
|
262
|
+
licenses:
|
263
|
+
- MIT
|
264
|
+
metadata:
|
265
|
+
allowed_push_host: https://rubygems.org
|
266
|
+
post_install_message:
|
267
|
+
rdoc_options: []
|
268
|
+
require_paths:
|
269
|
+
- lib
|
270
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
271
|
+
requirements:
|
272
|
+
- - ">="
|
273
|
+
- !ruby/object:Gem::Version
|
274
|
+
version: '0'
|
275
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
276
|
+
requirements:
|
277
|
+
- - ">="
|
278
|
+
- !ruby/object:Gem::Version
|
279
|
+
version: '0'
|
280
|
+
requirements: []
|
281
|
+
rubyforge_project:
|
282
|
+
rubygems_version: 2.6.8
|
283
|
+
signing_key:
|
284
|
+
specification_version: 4
|
285
|
+
summary: Country and currency codes
|
286
|
+
test_files: []
|