world_bank 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +1 -0
- data/.gemtest +0 -0
- data/.gitignore +41 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/.yardopts +3 -0
- data/Gemfile +4 -0
- data/LICENSE.md +10 -0
- data/README.md +131 -0
- data/Rakefile +18 -0
- data/country_aliases +257 -0
- data/lib/world_bank/client.rb +88 -0
- data/lib/world_bank/country.rb +35 -0
- data/lib/world_bank/income_level.rb +30 -0
- data/lib/world_bank/indicator.rb +36 -0
- data/lib/world_bank/lending_type.rb +30 -0
- data/lib/world_bank/query.rb +107 -0
- data/lib/world_bank/region.rb +29 -0
- data/lib/world_bank/source.rb +31 -0
- data/lib/world_bank/topic.rb +32 -0
- data/lib/world_bank/version.rb +3 -0
- data/lib/world_bank.rb +19 -0
- data/notes +33 -0
- data/notes_part_2 +108 -0
- data/projects_notes +11 -0
- data/spec/fixtures/brazil.json +43 -0
- data/spec/fixtures/countries.json +2 -0
- data/spec/fixtures/countries_india.json +2 -0
- data/spec/fixtures/income_level_lmc.json +1 -0
- data/spec/fixtures/income_levels.json +2 -0
- data/spec/fixtures/indicators.json +2 -0
- data/spec/fixtures/indicators_tractors.json +1 -0
- data/spec/fixtures/lending_type_idb.json +1 -0
- data/spec/fixtures/lending_types.json +1 -0
- data/spec/fixtures/regions.json +2 -0
- data/spec/fixtures/regions_world.json +1 -0
- data/spec/fixtures/source_21.json +2 -0
- data/spec/fixtures/sources.json +1 -0
- data/spec/fixtures/topic_6.json +2 -0
- data/spec/fixtures/topics.json +2 -0
- data/spec/helper.rb +48 -0
- data/spec/world_bank/client_spec.rb +85 -0
- data/spec/world_bank/country_spec.rb +47 -0
- data/spec/world_bank/income_level_spec.rb +33 -0
- data/spec/world_bank/indicator_spec.rb +38 -0
- data/spec/world_bank/lending_type_spec.rb +32 -0
- data/spec/world_bank/query_spec.rb +114 -0
- data/spec/world_bank/region_spec.rb +29 -0
- data/spec/world_bank/source_spec.rb +38 -0
- data/spec/world_bank/topic_spec.rb +41 -0
- data/spec/world_bank_spec.rb +9 -0
- data/world_bank.gemspec +31 -0
- metadata +261 -0
data/.autotest
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'autotest/bundler'
|
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
!.gitignore
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.sw[a-p]
|
5
|
+
*.tmproj
|
6
|
+
*.tmproject
|
7
|
+
*.un~
|
8
|
+
*~
|
9
|
+
.DS_Store
|
10
|
+
.Spotlight-V100
|
11
|
+
.Trashes
|
12
|
+
._*
|
13
|
+
.bundle
|
14
|
+
.config
|
15
|
+
.directory
|
16
|
+
.elc
|
17
|
+
.redcar
|
18
|
+
.yardoc
|
19
|
+
/.emacs.desktop
|
20
|
+
/.emacs.desktop.lock
|
21
|
+
Desktop.ini
|
22
|
+
Gemfile.lock
|
23
|
+
Icon?
|
24
|
+
InstalledFiles
|
25
|
+
Session.vim
|
26
|
+
Thumbs.db
|
27
|
+
\#*\#
|
28
|
+
_yardoc
|
29
|
+
auto-save-list
|
30
|
+
coverage
|
31
|
+
doc/
|
32
|
+
lib/bundler/man
|
33
|
+
pkg
|
34
|
+
pkg/*
|
35
|
+
rdoc
|
36
|
+
spec/reports
|
37
|
+
test/tmp
|
38
|
+
test/version_tmp
|
39
|
+
tmp
|
40
|
+
tmtags
|
41
|
+
tramp
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
Copyright (c) 2011, Code for America
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
5
|
+
|
6
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
7
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
8
|
+
* Neither the name of Code for America nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
9
|
+
|
10
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# WorldBank
|
2
|
+
|
3
|
+
A wrapper for the World Bank's Development Indicators API sponsored by Code for America.
|
4
|
+
|
5
|
+
Please see the World Bank's data [[developer's page](http://data.worldbank.org/developers/)] for more info on the data sources.
|
6
|
+
|
7
|
+
Does your project or organization use this gem?
|
8
|
+
------------------------------------------
|
9
|
+
Add it to the [apps](http://github.com/codeforamerica/world_bank_ruby/wiki/apps) wiki!
|
10
|
+
|
11
|
+
Continuous Integration
|
12
|
+
----------------------
|
13
|
+
[![Build Status](https://secure.travis-ci.org/codeforamerica/world_bank_ruby.png)](http://travis-ci.org/codeforamerica/world_bank_ruby)
|
14
|
+
|
15
|
+
|
16
|
+
Usage
|
17
|
+
-----
|
18
|
+
```ruby
|
19
|
+
|
20
|
+
require 'world_bank'
|
21
|
+
|
22
|
+
#
|
23
|
+
# WorldBank will delegate to the client allowing top level look-ups of their catalog
|
24
|
+
#
|
25
|
+
WorldBank.sources # => ['Doing Business', 'Something Else'...]
|
26
|
+
# array of 16 sources of information the bank used
|
27
|
+
|
28
|
+
WorldBank.income_levels # => { HIC: 'High Income', HPC: 'Heavily Indebted Poor Countries (HIPC)'...}
|
29
|
+
# hash of 9 income levels the bank assigns
|
30
|
+
|
31
|
+
WorldBank.lending_types # => [ { id: 'IBD', value: 'IBRD' }... ] an array of key: value pairs of
|
32
|
+
# the 4 lending types
|
33
|
+
|
34
|
+
WorldBank.topics # => the 18 high level topics that indicators are grouped into
|
35
|
+
WorldBank.regions # =>
|
36
|
+
WorldBank.countries # => same as Country.all
|
37
|
+
WorldBank.indicators # => same as Indicator.all
|
38
|
+
WorldBank.topics # => same as Topic.all
|
39
|
+
|
40
|
+
#
|
41
|
+
# Topics
|
42
|
+
#
|
43
|
+
@environment = Topic.find(6)
|
44
|
+
@environment.id # => 6
|
45
|
+
@environment.name # => 'Environment'
|
46
|
+
@environment.note # => 'Natural and man-made environmental resources – fresh...'
|
47
|
+
|
48
|
+
#
|
49
|
+
# Countries
|
50
|
+
#
|
51
|
+
@brazil = Country.find('br')
|
52
|
+
@brazil = Country.find('bra')
|
53
|
+
@brazil.name # => 'Brazil'
|
54
|
+
#
|
55
|
+
# note: only low and middle income countries are classified by region...
|
56
|
+
#
|
57
|
+
@brazil.region # => <WorldBank::Region @name="Latin America & Caribbean (all income levels)" ....>
|
58
|
+
@brazil.capital # => 'Brasilia'
|
59
|
+
@brazil.lending_type # => <WorldBank::LendingType>
|
60
|
+
|
61
|
+
#
|
62
|
+
# Indicators
|
63
|
+
#
|
64
|
+
@tractors = Indicator.find('AG.AGR.TRAC.NO')
|
65
|
+
@tractors.id # => 'AG.AGR.TRAC.NO'
|
66
|
+
@tractors.name # => 'Agricultural Machinery, tractors'
|
67
|
+
@tractors.source # => { id: 2, value: 'World Development Indicators' }
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
Contributing
|
73
|
+
------------
|
74
|
+
In the spirit of [free
|
75
|
+
software](http://www.fsf.org/licensing/essays/free-sw.html),
|
76
|
+
**everyone** is encouraged to help improve this project.
|
77
|
+
|
78
|
+
Here are some ways *you* can contribute:
|
79
|
+
|
80
|
+
* by using alpha, beta, and prerelease versions
|
81
|
+
* by reporting bugs
|
82
|
+
* by suggesting new features
|
83
|
+
* by writing or editing documentation
|
84
|
+
* by writing specifications
|
85
|
+
* by writing code (**no patch is too small**: fix typos, add comments,
|
86
|
+
clean up inconsistent whitespace)
|
87
|
+
* by refactoring code
|
88
|
+
* by resolving [issues](https://github.com/codeforamerica/world_bank_ruby/issues)
|
89
|
+
* by reviewing patches
|
90
|
+
|
91
|
+
Submitting an Issue
|
92
|
+
-------------------
|
93
|
+
We use the [GitHub issue
|
94
|
+
tracker](https://github.com/codeforamerica/fed_spending_ruby/issues) to track bugs and
|
95
|
+
features. Before submitting a bug report or feature request, check to
|
96
|
+
make sure it hasn't already
|
97
|
+
been submitted. You can indicate support for an existing issuse by
|
98
|
+
voting it up. When submitting a
|
99
|
+
bug report, please include a [Gist](https://gist.github.com/) that
|
100
|
+
includes a stack trace and any
|
101
|
+
details that may be necessary to reproduce the bug, including your gem
|
102
|
+
version, Ruby version, and
|
103
|
+
operating system. Ideally, a bug report should include a pull request
|
104
|
+
with failing specs.
|
105
|
+
|
106
|
+
Submitting a Pull Request
|
107
|
+
-------------------------
|
108
|
+
1. Fork the project.
|
109
|
+
2. Create a topic branch.
|
110
|
+
3. Implement your feature or bug fix.
|
111
|
+
4. Add documentation for your feature or bug fix.
|
112
|
+
5. Run <tt>bundle exec rake doc:yard</tt>. If your changes are not 100%
|
113
|
+
documented, go back to step 4.
|
114
|
+
6. Add specs for your feature or bug fix.
|
115
|
+
7. Run <tt>bundle exec rake spec</tt>. If your changes are not 100%
|
116
|
+
covered, go back to step 6.
|
117
|
+
8. Commit and push your changes.
|
118
|
+
9. Submit a pull request. Please do not include changes to the gemspec,
|
119
|
+
version, or history file. (If you want to create your own version for
|
120
|
+
some reason, please do so in a separate commit.)
|
121
|
+
|
122
|
+
Copyright
|
123
|
+
---------
|
124
|
+
Copyright (c) 2011 Code for America
|
125
|
+
See
|
126
|
+
[LICENSE](https://github.com/codeforamerica/world_bank_ruby/blob/master/LICENSE.md)
|
127
|
+
for details.
|
128
|
+
|
129
|
+
[![Code for America
|
130
|
+
Tracker](http://stats.codeforamerica.org/codeforamerica/code_for_america_tracking.png)](http://stats.codeforamerica.org/)
|
131
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
task :default => :spec
|
10
|
+
task :test => :spec
|
11
|
+
|
12
|
+
require 'yard'
|
13
|
+
namespace :doc do
|
14
|
+
YARD::Rake::YardocTask.new do |task|
|
15
|
+
task.files = ['LICENSE.md', 'lib/**/*.rb']
|
16
|
+
task.options = ['--markup', 'markdown']
|
17
|
+
end
|
18
|
+
end
|
data/country_aliases
ADDED
@@ -0,0 +1,257 @@
|
|
1
|
+
:AW ABW: :aruba
|
2
|
+
:AF AFG: :afganistan
|
3
|
+
:AO AGO: :angola
|
4
|
+
:AI AIA: :anguilla
|
5
|
+
:AX ALA: :aland_islands
|
6
|
+
:AL ALB: :albania
|
7
|
+
:AD AND: :andorra
|
8
|
+
:AE ARE: :united_arab_emirates
|
9
|
+
:AR ARG: :argentina
|
10
|
+
:AM ARM: :armenia
|
11
|
+
:AS ASM: :american_samoa
|
12
|
+
:AQ ATA: :antarctica
|
13
|
+
:TF ATF: :french_southern_territories
|
14
|
+
:AG ATG: :antigua_and_barbuda
|
15
|
+
:AU AUS: :australia
|
16
|
+
:AT AUT: :austria
|
17
|
+
:AZ AZE: :azerbaijan
|
18
|
+
:BI BDI: :burundi
|
19
|
+
:BE BEL: :belgium
|
20
|
+
:BJ BEN: :benin
|
21
|
+
:BQ BES: :bonaire_saint_eustatius_and_saba
|
22
|
+
:BF BFA: :burkina_faso
|
23
|
+
:BD BGD: :bangladesh
|
24
|
+
:BG BGR: :bulgaria
|
25
|
+
:BH BHR: :bahrain
|
26
|
+
:BS BHS: :bahamas
|
27
|
+
:BA BIH: :bosnia_and_herzegovina
|
28
|
+
:BL BLM: :saint_barthelemy
|
29
|
+
:BY BLR: :belarus
|
30
|
+
:BZ BLZ: :belize
|
31
|
+
:BM BMU: :bermuda
|
32
|
+
:BO BOL: :plurinational_state_of_bolivia
|
33
|
+
:BR BRA: :brazil
|
34
|
+
:BB BRB: :barbados
|
35
|
+
:BN BRN: :brunei_darussalam
|
36
|
+
:BT BTN: :bhutan
|
37
|
+
:BV BVT: :bouvet_island
|
38
|
+
:BW BWA: :botswana
|
39
|
+
:CF CAF: :central_african_republic
|
40
|
+
:CA CAN: :canada
|
41
|
+
:CC CCK: :cocos_keeling_islands
|
42
|
+
:CH CHE: :switzerland
|
43
|
+
:CL CHL: :chile
|
44
|
+
:CN CHN: :china
|
45
|
+
:CI CIV: :cote_divoire
|
46
|
+
:CM CMR: :cameroon
|
47
|
+
:CD COD: :democratic_republic_of_the_congo
|
48
|
+
:CG COG: :congo
|
49
|
+
:CK COK: :cook_islands
|
50
|
+
:CO COL: :colombia
|
51
|
+
:KM COM: :comoros
|
52
|
+
:CV CPV: :cape_verde
|
53
|
+
:CR CRI: :costa_rica
|
54
|
+
:CU CUB: :cuba
|
55
|
+
:CW CUW: :curacao
|
56
|
+
:CX CXR: :christmas_island
|
57
|
+
:KY CYM: :cayman_islands
|
58
|
+
:CY CYP: :cyprus
|
59
|
+
:CZ CZE: :czech_republic
|
60
|
+
:DE DEU: :germany
|
61
|
+
:DJ DJI: :djibouti
|
62
|
+
:DM DMA: :dominca
|
63
|
+
:DK DNK: :denmark
|
64
|
+
:DO DOM: :dominican_republic
|
65
|
+
:DZ DZA: :algeria
|
66
|
+
:EC ECU: :ecuador
|
67
|
+
:EG EGY: :egypt
|
68
|
+
:ER ERI: :eritrea
|
69
|
+
:EH ESH: :western_sahara
|
70
|
+
:ES ESP: :spain
|
71
|
+
:EE EST: :estonia
|
72
|
+
:ET ETH: :ethiopia
|
73
|
+
:FI FIN: :finland
|
74
|
+
:FJ FJI: :fiji
|
75
|
+
:FK FLK: :falkland_islands_malvinas
|
76
|
+
:FR FRA: :france
|
77
|
+
:FO FRO: :faroe_islands
|
78
|
+
:FM FSM: :federated_states_of_micronesia
|
79
|
+
:GA GAB: :gabon
|
80
|
+
:GB GBR: :united_kingdom
|
81
|
+
:GE GEO: :georgia
|
82
|
+
:GG GGY: :guernsey
|
83
|
+
:GH GHA: :ghana
|
84
|
+
:GI GIB: :gibraltar
|
85
|
+
:GN GIN: :guinea
|
86
|
+
:GP GLP: :guadeloupe
|
87
|
+
:GM GMB: :gambia
|
88
|
+
:GW GNB: :guinea_bissau
|
89
|
+
:GQ GNQ: :equatorial_guinea
|
90
|
+
:GR GRC: :greece
|
91
|
+
:GD GRD: :grenada
|
92
|
+
:GL GRL: :greenland
|
93
|
+
:GT GTM: :guatemala
|
94
|
+
:GF GUF: :french_guiana
|
95
|
+
:GU GUM: :guam
|
96
|
+
:GY GUY: :guyana
|
97
|
+
:HK HKG: :hong_kong
|
98
|
+
:HM HMD: :heard_island_mcdonald_islands
|
99
|
+
:HN HND: :honduras
|
100
|
+
:HR HRV: :croatia
|
101
|
+
:HT HTI: :haiti
|
102
|
+
:HU HUN: :hungary
|
103
|
+
:ID IDN: :indonesia
|
104
|
+
:IM IMN: :isle_of_man
|
105
|
+
:IN IND: :india
|
106
|
+
:IO IOT: :british_indian_ocean_territory
|
107
|
+
:IE IRL: :ireland
|
108
|
+
:IR IRN: :islamic_republic_of_iran
|
109
|
+
:IQ IRQ: :iraq
|
110
|
+
:IS ISL: :iceland
|
111
|
+
:IL ISR: :israel
|
112
|
+
:IT ITA: :italy
|
113
|
+
:JM JAM: :jamaica
|
114
|
+
:JE JEY: :jersey
|
115
|
+
:JO JOR: :jordan
|
116
|
+
:JP JPN: :japan
|
117
|
+
:KZ KAZ: :kazakhstan
|
118
|
+
:KE KEN: :kenya
|
119
|
+
:KG KGZ: :kyrgyzstan
|
120
|
+
:KH KHM: :cambodia
|
121
|
+
:KI KIR: :kiribati
|
122
|
+
:KN KNA: :saint_kitts_and_nevis
|
123
|
+
:KR KOR: :republic_of_korea
|
124
|
+
:KW KWT: :kuwait
|
125
|
+
:LA LAO: :lao_peoples_democratic_republic
|
126
|
+
:LB LBN: :lebanon
|
127
|
+
:LR LBR: :liberia
|
128
|
+
:LY LBY: :libyan_arab_jamahiriya
|
129
|
+
:LC LCA: :saint_lucia
|
130
|
+
:LI LIE: :liechtenstein
|
131
|
+
:LK LKA: :sri_lanka
|
132
|
+
:LS LSO: :lesotho
|
133
|
+
:LT LTU: :lithuania
|
134
|
+
:LU LUX: :luxembourg
|
135
|
+
:LV LVA: :latvia
|
136
|
+
:MO MAC: :macao
|
137
|
+
:MF MAF: :saint_martin
|
138
|
+
:MA MAR: :morocco
|
139
|
+
:MC MCO: :monaco
|
140
|
+
:MD MDA: :republic_of_moldova
|
141
|
+
:MG MDG: :madagascar
|
142
|
+
:MV MDV: :maldives
|
143
|
+
:MX MEX: :mexico
|
144
|
+
:MH MHL: :marshall_islands
|
145
|
+
:MK MKD: :the_former_yugoslav_republic_of_macedonia
|
146
|
+
:ML MLI: :mali
|
147
|
+
:MT MLT: :malta
|
148
|
+
:MM MMR: :myanmar
|
149
|
+
:ME MNE: :montenegro
|
150
|
+
:MN MNG: :mongolia
|
151
|
+
:MP MNP: :northern_mariana_islands
|
152
|
+
:MZ MOZ: :mozambique
|
153
|
+
:MR MRT: :mauritania
|
154
|
+
:MS MSR: :montserrat
|
155
|
+
:MQ MTQ: :martinique
|
156
|
+
:MU MUS: :mauritius
|
157
|
+
:MW MWI: :malawi
|
158
|
+
:MY MYS: :malaysia
|
159
|
+
:YT MYT: :mayotte
|
160
|
+
:NA NAM: :namibia
|
161
|
+
:NC NCL: :new_caledonia
|
162
|
+
:NE NER: :niger
|
163
|
+
:NF NFK: :norfolk_island
|
164
|
+
:NG NGA: :nigeria
|
165
|
+
:NI NIC: :nicaragua
|
166
|
+
:NU NIU: :niue
|
167
|
+
:NL NLD: :netherlands
|
168
|
+
:NO NOR: :norway
|
169
|
+
:NP NPL: :nepal
|
170
|
+
:NR NRU: :nauru
|
171
|
+
:NZ NZL: :new_zealand
|
172
|
+
:OM OMN: :oman
|
173
|
+
:PK PAK: :pakistan
|
174
|
+
:PA PAN: :panama
|
175
|
+
:PN PCN: :pitcairn
|
176
|
+
:PE PER: :peru
|
177
|
+
:PH PHL: :philippines
|
178
|
+
:PW PLW: :palau
|
179
|
+
:PG PNG: :papua_new_guinea
|
180
|
+
:PL POL: :poland
|
181
|
+
:PR PRI: :puerto_rico
|
182
|
+
:KP PRK: :democratic_peoples_republic_of_korea
|
183
|
+
:PT PRT: :portugal
|
184
|
+
:PY PRY: :paraguay
|
185
|
+
:PS PSE: :occupied_palestinian_territory
|
186
|
+
:PF PYF: :french_polynesia
|
187
|
+
:QA QAT: :qatar
|
188
|
+
:RE REU: :reunion
|
189
|
+
:RO ROU: :romania
|
190
|
+
:RU RUS: :russian_federation
|
191
|
+
:RW RWA: :rwanda
|
192
|
+
:SA SAU: :saudi_arabia
|
193
|
+
:SD SDN: :sudan
|
194
|
+
:SN SEN: :senegal
|
195
|
+
:SG SGP: :singapore
|
196
|
+
:GS SGS: :south_georgia_and_the_south_sandwich_islands
|
197
|
+
:SH SHN: :saint_helena_ascension_and_tristan_da_cunha
|
198
|
+
:SJ SJM: :svalbard_and_jan_mayen
|
199
|
+
:SB SLB: :soloman_islands
|
200
|
+
:SL SLE: :sierra_leone
|
201
|
+
:SV SLV: :el_salvador
|
202
|
+
:SM SMR: :san_marino
|
203
|
+
:SO SOM: :somalia
|
204
|
+
:PM SPM: :saint_pierre_and_miquelon
|
205
|
+
:RS SRB: :serbia
|
206
|
+
:ST STP: :sao_tome_and_principe
|
207
|
+
:SR SUR: :suriname
|
208
|
+
:SK SVK: :slovakia
|
209
|
+
:SI SVN: :slovenia
|
210
|
+
:SE SWE: :sweden
|
211
|
+
:SZ SWZ: :swaziland
|
212
|
+
:SX SXM: :sint_maarten
|
213
|
+
:SC SYC: :seychelles
|
214
|
+
:SY SYR: :syrian_arab_republic
|
215
|
+
:TC TCA: :turks_caicos_islands
|
216
|
+
:TD TCD: :chad
|
217
|
+
:TG TGO: :togo
|
218
|
+
:TH THA: :thailand
|
219
|
+
:TJ TJK: :tajikistan
|
220
|
+
:TK TKL: :tokelau
|
221
|
+
:TM TKM: :turkmenistan
|
222
|
+
:TL TLS: :timor_leste
|
223
|
+
:TO TON: :tonga
|
224
|
+
:TT TTO: :trinidad_and_tobago
|
225
|
+
:TN TUN: :tunisia
|
226
|
+
:TR TUR: :turkey
|
227
|
+
:TU TUV: :tuvalu
|
228
|
+
:TW TWN: :taiwan_provice_of_china
|
229
|
+
:TZ TZA: :united_republic_of_tanzania
|
230
|
+
:UG UGA: :uganda
|
231
|
+
:UA UKR: :ukraine
|
232
|
+
:UM UMI: :united_states_minor_outlying_islands
|
233
|
+
:UY URY: :uruguay
|
234
|
+
:US USA: :united_states
|
235
|
+
:UZ UZB: :uzbekistan
|
236
|
+
:VA VAT; :holy_see_vatican_city
|
237
|
+
:VC VCT: :saint_vincent_and_the_grenadines
|
238
|
+
:VE VEN: :bolivarian_republic_of_venezuela
|
239
|
+
:VG VGB: :british_virgin_islands
|
240
|
+
:VI VIR: :us_virgin_islands
|
241
|
+
:VN VNM: :viet_nam
|
242
|
+
:VU VUT: :vanuatu
|
243
|
+
:WF WLF: :wallis_and_futuna
|
244
|
+
:WS WSM: :samoa
|
245
|
+
:YE YEM: :yemen
|
246
|
+
:ZA ZAF: :south_africa
|
247
|
+
:ZM ZMB: :zambia
|
248
|
+
:ZW ZWE: :zimbabwe
|
249
|
+
|
250
|
+
The World Bank uses both these 3 and 2 letter abbr. except:
|
251
|
+
alternative 3 letter codes for:
|
252
|
+
Andorra (listed and seems to be accurate), dem. rep. of congo(listed and seems to be accurate), isle of man (not listed at all), romania (not listed at all), timor-leste (ditto), west bank and gaza (ditto)
|
253
|
+
|
254
|
+
alternative 2 letter codes for:
|
255
|
+
dem. rep. of congo(listed and seems to be accurate), serbia, timor-leste, yemen, west bank and gaza
|
256
|
+
|
257
|
+
channel islands (which the world bank lists as JG, CHI, and channel_islands) and kosovo (and isn't listed) do not have iso codes (2 or 3 letters)
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/source'))
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/income_level'))
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/lending_type'))
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/country'))
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/indicator'))
|
7
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/topic'))
|
8
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'region'))
|
9
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'query'))
|
10
|
+
|
11
|
+
module WorldBank
|
12
|
+
class Client
|
13
|
+
|
14
|
+
attr_accessor :query
|
15
|
+
|
16
|
+
def initialize(options={})
|
17
|
+
@format = options[:format] || 'json'
|
18
|
+
@query = {:params => {}, :dirs => []}
|
19
|
+
@query[:params][:format] = @format
|
20
|
+
end
|
21
|
+
|
22
|
+
def sources
|
23
|
+
WorldBank::Source.all(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def income_levels
|
27
|
+
WorldBank::IncomeLevel.all(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def lending_types
|
31
|
+
WorldBank::LendingType.all(self)
|
32
|
+
end
|
33
|
+
|
34
|
+
def countries
|
35
|
+
WorldBank::Country.all(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
def indicators
|
39
|
+
WorldBank::Indicator.all(self)
|
40
|
+
end
|
41
|
+
|
42
|
+
def regions
|
43
|
+
WorldBank::Region.all(self)
|
44
|
+
end
|
45
|
+
|
46
|
+
def topics
|
47
|
+
WorldBank::Topic.all(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_query
|
51
|
+
@path = @query[:dirs].join('/')
|
52
|
+
@path += '?'
|
53
|
+
params = []
|
54
|
+
@query[:params].each do |key, value|
|
55
|
+
params << "#{key.to_s}=#{value.to_s}"
|
56
|
+
end
|
57
|
+
@path += params.join('&')
|
58
|
+
get(@path)
|
59
|
+
end
|
60
|
+
|
61
|
+
def get(path, headers={})
|
62
|
+
response = connection.get do |request|
|
63
|
+
request.url(path, headers)
|
64
|
+
end
|
65
|
+
response.body
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def connection
|
71
|
+
Faraday.new(:url => 'http://api.worldbank.org/') do |connection|
|
72
|
+
connection.use Faraday::Request::UrlEncoded
|
73
|
+
connection.use Faraday::Response::RaiseError
|
74
|
+
connection.use Faraday::Response::Mashify
|
75
|
+
case @format.to_s.downcase
|
76
|
+
when 'json'
|
77
|
+
connection.use Faraday::Response::ParseJson
|
78
|
+
when 'jsonp'
|
79
|
+
connection.use Faraday::Response::ParseJson
|
80
|
+
when 'xml'
|
81
|
+
connection.use Faraday::Response::ParseXml
|
82
|
+
when 'raw'
|
83
|
+
end
|
84
|
+
connection.adapter(Faraday.default_adapter)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module WorldBank
|
2
|
+
|
3
|
+
class Country
|
4
|
+
|
5
|
+
attr_reader :raw, :name, :iso2_code, :iso3_code, :region, :income_level, :lending_type, :capital, :type
|
6
|
+
|
7
|
+
def self.client
|
8
|
+
@client ||= WorldBank::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.all(client)
|
12
|
+
client.query[:dirs] = ['countries']
|
13
|
+
client.get_query
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find(id)
|
17
|
+
client.query[:dirs] = ['countries', id.to_s]
|
18
|
+
result = client.get_query
|
19
|
+
new(result[1][0])
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(values={})
|
23
|
+
@raw = values
|
24
|
+
@name = values['name']
|
25
|
+
@iso2_code = values['iso2Code']
|
26
|
+
@iso3_code = values['id']
|
27
|
+
@region = WorldBank::Region.new(values['region'])
|
28
|
+
@income_level = WorldBank::IncomeLevel.new(values['incomeLevel'])
|
29
|
+
@lending_type = WorldBank::LendingType.new(values['lendingType'])
|
30
|
+
@capital = values['capitalCity']
|
31
|
+
@type = 'countries'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module WorldBank
|
2
|
+
|
3
|
+
class IncomeLevel
|
4
|
+
|
5
|
+
attr_reader :raw, :id, :name, :type
|
6
|
+
|
7
|
+
def self.client
|
8
|
+
@client ||= WorldBank::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.all(client)
|
12
|
+
client.query[:dirs] = ['incomeLevels']
|
13
|
+
client.get_query
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find(id)
|
17
|
+
client.query[:dirs] = ['incomeLevels', id.to_s]
|
18
|
+
result = client.get_query
|
19
|
+
new(result[1][0])
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(values={})
|
23
|
+
@raw = values
|
24
|
+
@id = values['id']
|
25
|
+
@name = values['value']
|
26
|
+
@type = 'incomeLevels'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module WorldBank
|
2
|
+
|
3
|
+
class Indicator
|
4
|
+
|
5
|
+
attr_reader :raw, :id, :name, :source, :note, :organization, :topics, :type
|
6
|
+
def self.client
|
7
|
+
@client ||= WorldBank::Client.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.all(client)
|
11
|
+
client.query[:dirs] = ['indicators']
|
12
|
+
client.get_query
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find(id)
|
16
|
+
client.query[:dirs] = ['indicators', id]
|
17
|
+
result = client.get_query
|
18
|
+
new(result[1][0])
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(values={})
|
22
|
+
@raw = values
|
23
|
+
@id = values['id']
|
24
|
+
@name = values['name']
|
25
|
+
@source = WorldBank::Source.new(values['source'])
|
26
|
+
@note = values['sourceNote']
|
27
|
+
@organization = values['sourceOrganization']
|
28
|
+
@topics = []
|
29
|
+
values['topics'].each do |topic|
|
30
|
+
@topics << WorldBank::Topic.new(topic)
|
31
|
+
end
|
32
|
+
@type = 'indicators'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|