worldbank_as_dataframe 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 +7 -0
- data/.autotest +1 -0
- data/.gemtest +0 -0
- data/.gitignore +42 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/.yardopts +3 -0
- data/Changelog +6 -0
- data/Gemfile +4 -0
- data/LICENSE.md +10 -0
- data/README.md +164 -0
- data/Rakefile +16 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/worldbank_as_dataframe/client.rb +69 -0
- data/lib/worldbank_as_dataframe/country.rb +326 -0
- data/lib/worldbank_as_dataframe/data.rb +47 -0
- data/lib/worldbank_as_dataframe/data_query.rb +82 -0
- data/lib/worldbank_as_dataframe/income_level.rb +23 -0
- data/lib/worldbank_as_dataframe/indicator.rb +42 -0
- data/lib/worldbank_as_dataframe/lending_type.rb +23 -0
- data/lib/worldbank_as_dataframe/param_query.rb +51 -0
- data/lib/worldbank_as_dataframe/queriable.rb +39 -0
- data/lib/worldbank_as_dataframe/query.rb +213 -0
- data/lib/worldbank_as_dataframe/region.rb +22 -0
- data/lib/worldbank_as_dataframe/source.rb +25 -0
- data/lib/worldbank_as_dataframe/topic.rb +25 -0
- data/lib/worldbank_as_dataframe/version.rb +3 -0
- data/lib/worldbank_as_dataframe.rb +21 -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/worldbank_as_dataframe/client_spec.rb +23 -0
- data/spec/worldbank_as_dataframe/country_spec.rb +35 -0
- data/spec/worldbank_as_dataframe/data_query_spec.rb +38 -0
- data/spec/worldbank_as_dataframe/data_spec.rb +26 -0
- data/spec/worldbank_as_dataframe/income_level_spec.rb +26 -0
- data/spec/worldbank_as_dataframe/indicator_spec.rb +38 -0
- data/spec/worldbank_as_dataframe/lending_type_spec.rb +26 -0
- data/spec/worldbank_as_dataframe/param_query_spec.rb +45 -0
- data/spec/worldbank_as_dataframe/query_spec.rb +83 -0
- data/spec/worldbank_as_dataframe/region_spec.rb +29 -0
- data/spec/worldbank_as_dataframe/source_spec.rb +32 -0
- data/spec/worldbank_as_dataframe/topic_spec.rb +35 -0
- data/spec/worldbank_as_dataframe_spec.rb +9 -0
- data/worldbank_as_dataframe.gemspec +30 -0
- metadata +274 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 59487af1b64af251dfd64fbad71b7604e388fea72a76c69035d114d0dd8d2ffb
|
4
|
+
data.tar.gz: 834b1f92659fc7202e6f635874c786fa941fb121bf00060dcdd3a5d3788b2829
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57fd9508264cfbe7e580ff439abcb3662e4ed7e246e10d3f3fe213b3fb7658d4477e41ffde0508e2c15d55db8be86dde0995105fda44067a5dab8335e59d48ad
|
7
|
+
data.tar.gz: 89928d424ddce5bf4787deb19c91483fafc380c49996ba5c67a117a5268c3853ff1f9240b047d64594cd7c115757cd3ed3b9783529de3373f7e6b3c350a1d6e4
|
data/.autotest
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'autotest/bundler'
|
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
!.gitignore
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.sw[a-p]
|
5
|
+
*.tmproj
|
6
|
+
*.tmproject
|
7
|
+
*.un~
|
8
|
+
*~
|
9
|
+
.rvmrc
|
10
|
+
.DS_Store
|
11
|
+
.Spotlight-V100
|
12
|
+
.Trashes
|
13
|
+
._*
|
14
|
+
.bundle
|
15
|
+
.config
|
16
|
+
.directory
|
17
|
+
.elc
|
18
|
+
.redcar
|
19
|
+
.yardoc
|
20
|
+
/.emacs.desktop
|
21
|
+
/.emacs.desktop.lock
|
22
|
+
Desktop.ini
|
23
|
+
Gemfile.lock
|
24
|
+
Icon?
|
25
|
+
InstalledFiles
|
26
|
+
Session.vim
|
27
|
+
Thumbs.db
|
28
|
+
\#*\#
|
29
|
+
_yardoc
|
30
|
+
auto-save-list
|
31
|
+
coverage
|
32
|
+
doc/
|
33
|
+
lib/bundler/man
|
34
|
+
pkg
|
35
|
+
pkg/*
|
36
|
+
rdoc
|
37
|
+
spec/reports
|
38
|
+
test/tmp
|
39
|
+
test/version_tmp
|
40
|
+
tmp
|
41
|
+
tmtags
|
42
|
+
tramp
|
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
worldbank
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.2
|
data/.yardopts
ADDED
data/Changelog
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,164 @@
|
|
1
|
+
# WorldbankAsDataframe
|
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
|
+
|
8
|
+
|
9
|
+
Continuous Integration
|
10
|
+
----------------------
|
11
|
+
|
12
|
+
You can see the World Bank Gem's build status at
|
13
|
+
http:ci.codeforamerica.org or on Travis:
|
14
|
+
|
15
|
+
[](http://travis-ci.org/codeforamerica/worldbank_as_dataframe_ruby)
|
16
|
+
|
17
|
+
|
18
|
+
Usage
|
19
|
+
-----
|
20
|
+
```ruby
|
21
|
+
|
22
|
+
require 'worldbank_as_dataframe'
|
23
|
+
|
24
|
+
WorldbankAsDataframe::Source.all.fetch # => ['Doing Business', 'Something Else'...]
|
25
|
+
# array of 16 sources of information the bank used
|
26
|
+
|
27
|
+
WorldbankAsDataframe::IncomeLevel..all.fetch # => { HIC: 'High Income', HPC: 'Heavily Indebted Poor Countries (HIPC)'...}
|
28
|
+
# hash of 9 income levels the bank assigns
|
29
|
+
|
30
|
+
WorldbankAsDataframe::LendingType.all.fetch # => [ { id: 'IBD', value: 'IBRD' }... ] an array of key: value pairs of
|
31
|
+
# the 4 lending types
|
32
|
+
|
33
|
+
WorldbankAsDataframe::Topic.all.fetch # => the 18 high level topics that indicators are grouped into
|
34
|
+
|
35
|
+
WorldbankAsDataframe::Region.all.fetch # => returns all the regions the World Bank can classify a country as
|
36
|
+
|
37
|
+
WorldbankAsDataframe::Country.all.fetch # => returns all countries the World Bank tracks
|
38
|
+
|
39
|
+
WorldbankAsDataframe::Indicator.all.fetch # => returns all the indicators the World Bank uses
|
40
|
+
|
41
|
+
WorldbankAsDataframe::Indicator.featured # => returns the featured indicators
|
42
|
+
|
43
|
+
WorldbankAsDataframe::Topic.all.fetch # => returns all the topics the World Bank catagorizes its indicators into
|
44
|
+
|
45
|
+
|
46
|
+
include WorldbankAsDataframe
|
47
|
+
#
|
48
|
+
# Topics
|
49
|
+
#
|
50
|
+
@environment = Topic.find(6).fetch
|
51
|
+
@environment.id # => 6
|
52
|
+
@environment.name # => 'Environment'
|
53
|
+
@environment.note # => 'Natural and man-made environmental resources – fresh...'
|
54
|
+
|
55
|
+
#
|
56
|
+
# Countries
|
57
|
+
#
|
58
|
+
@brazil = Country.find('br').fetch
|
59
|
+
@brazil = Country.find('bra').fetch
|
60
|
+
@brazil.name # => 'Brazil'
|
61
|
+
#
|
62
|
+
# note: only low and middle income countries are classified by region...
|
63
|
+
#
|
64
|
+
@brazil.region # => <WorldbankAsDataframe::Region @name="Latin America & Caribbean (all income levels)" ....>
|
65
|
+
@brazil.capital # => 'Brasilia'
|
66
|
+
@brazil.lending_type # => <WorldbankAsDataframe::LendingType>
|
67
|
+
|
68
|
+
#
|
69
|
+
# Indicators
|
70
|
+
#
|
71
|
+
@tractors = Indicator.find('AG.AGR.TRAC.NO').fetch
|
72
|
+
@tractors.id # => 'AG.AGR.TRAC.NO'
|
73
|
+
@tractors.name # => 'Agricultural Machinery, tractors'
|
74
|
+
@tractors.source # => { id: 2, value: 'World Development Indicators' }
|
75
|
+
|
76
|
+
#
|
77
|
+
# Data
|
78
|
+
#
|
79
|
+
@results = WorldbankAsDataframe::Data.country('brazil').indicator('NY.GDP.MKTP.CD').dates('2000:2008').fetch
|
80
|
+
# returns an array of WorldbankAsDataframe::Data objects that correspond to
|
81
|
+
# Brazil's Yearly Gross Domestic Product as MarKeT Prices in Current U.S.
|
82
|
+
# Dollars from 2000 to 2008
|
83
|
+
|
84
|
+
puts @results.first.name
|
85
|
+
@results.each {|d| puts d.date + ': $' + d.value }
|
86
|
+
# =>
|
87
|
+
# GDP (current US$)
|
88
|
+
# 2008: $1652632229227.61
|
89
|
+
# 2007: $1365982651542.37
|
90
|
+
# 2006: $1088917279411.76
|
91
|
+
# 2005: $882185291700.904
|
92
|
+
# 2004: $663760000000
|
93
|
+
# 2003: $552469288267.793
|
94
|
+
# 2002: $504221228974.035
|
95
|
+
# 2001: $553582178386.192
|
96
|
+
# 2000: $644701831101.394
|
97
|
+
#
|
98
|
+
# The WorldbankAsDataframe::Data can have have methods matching any of the World Bank API's
|
99
|
+
# modifiers (like #dates above) called as class methods or chained in a query.
|
100
|
+
#
|
101
|
+
|
102
|
+
```
|
103
|
+
|
104
|
+
|
105
|
+
Contributing
|
106
|
+
------------
|
107
|
+
In the spirit of [free
|
108
|
+
software](http://www.fsf.org/licensing/essays/free-sw.html),
|
109
|
+
**everyone** is encouraged to help improve this project.
|
110
|
+
|
111
|
+
Here are some ways *you* can contribute:
|
112
|
+
|
113
|
+
* by using alpha, beta, and prerelease versions
|
114
|
+
* by reporting bugs
|
115
|
+
* by suggesting new features
|
116
|
+
* by writing or editing documentation
|
117
|
+
* by writing specifications
|
118
|
+
* by writing code (**no patch is too small**: fix typos, add comments,
|
119
|
+
clean up inconsistent whitespace)
|
120
|
+
* by refactoring code
|
121
|
+
* by resolving [issues](https://github.com/codeforamerica/worldbank_as_dataframe_ruby/issues)
|
122
|
+
* by reviewing patches
|
123
|
+
|
124
|
+
Submitting an Issue
|
125
|
+
-------------------
|
126
|
+
We use the [GitHub issue
|
127
|
+
tracker](https://github.com/codeforamerica/fed_spending_ruby/issues) to track bugs and
|
128
|
+
features. Before submitting a bug report or feature request, check to
|
129
|
+
make sure it hasn't already
|
130
|
+
been submitted. You can indicate support for an existing issuse by
|
131
|
+
voting it up. When submitting a
|
132
|
+
bug report, please include a [Gist](https://gist.github.com/) that
|
133
|
+
includes a stack trace and any
|
134
|
+
details that may be necessary to reproduce the bug, including your gem
|
135
|
+
version, Ruby version, and
|
136
|
+
operating system. Ideally, a bug report should include a pull request
|
137
|
+
with failing specs.
|
138
|
+
|
139
|
+
Submitting a Pull Request
|
140
|
+
-------------------------
|
141
|
+
1. Fork the project.
|
142
|
+
2. Create a topic branch.
|
143
|
+
3. Implement your feature or bug fix.
|
144
|
+
4. Add documentation for your feature or bug fix.
|
145
|
+
5. Run <tt>bundle exec rake doc:yard</tt>. If your changes are not 100%
|
146
|
+
documented, go back to step 4.
|
147
|
+
6. Add specs for your feature or bug fix.
|
148
|
+
7. Run <tt>bundle exec rake spec</tt>. If your changes are not 100%
|
149
|
+
covered, go back to step 6.
|
150
|
+
8. Commit and push your changes.
|
151
|
+
9. Submit a pull request. Please do not include changes to the gemspec,
|
152
|
+
version, or history file. (If you want to create your own version for
|
153
|
+
some reason, please do so in a separate commit.)
|
154
|
+
|
155
|
+
Copyright
|
156
|
+
---------
|
157
|
+
Copyright (c) 2011 Code for America
|
158
|
+
See
|
159
|
+
[LICENSE](https://github.com/codeforamerica/worldbank_as_dataframe_ruby/blob/master/LICENSE.md)
|
160
|
+
for details.
|
161
|
+
|
162
|
+
[](http://stats.codeforamerica.org/)
|
164
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
task :test => :spec
|
9
|
+
|
10
|
+
require 'yard'
|
11
|
+
namespace :doc do
|
12
|
+
YARD::Rake::YardocTask.new do |task|
|
13
|
+
task.files = ['LICENSE.md', 'lib/**/*.rb']
|
14
|
+
task.options = ['--markup', 'markdown']
|
15
|
+
end
|
16
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "worldbank_as_dataframe"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'httparty'
|
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
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'data'))
|
11
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'param_query'))
|
12
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'data_query'))
|
13
|
+
|
14
|
+
module WorldbankAsDataframe
|
15
|
+
class Client
|
16
|
+
include HTTParty
|
17
|
+
# base_uri 'https://api.worldbank.org/v2/'
|
18
|
+
|
19
|
+
|
20
|
+
attr_accessor :query
|
21
|
+
|
22
|
+
def initialize(query, raw)
|
23
|
+
@query = query
|
24
|
+
@raw = raw
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_query
|
28
|
+
@path = 'https://api.worldbank.org/v2/' + @query[:dirs].map(&:downcase).join('/')
|
29
|
+
@path += '?'
|
30
|
+
params = []
|
31
|
+
@query[:params].each do |key, value|
|
32
|
+
params << "#{key.to_s}=#{value.to_s}"
|
33
|
+
end
|
34
|
+
@path += params.join('&')
|
35
|
+
get(@path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def get(path, headers={})
|
39
|
+
begin
|
40
|
+
# puts "#{__FILE__}:#{__LINE__} path = #{path.inspect}"
|
41
|
+
response = self.class.get(path, headers)
|
42
|
+
# puts "#{__FILE__}:#{__LINE__} response = #{response.inspect}"
|
43
|
+
|
44
|
+
response.parsed_response
|
45
|
+
rescue
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# def connection
|
53
|
+
# Faraday.new(:url => 'http://api.worldbank.org/v2') do |connection|
|
54
|
+
# connection.use Faraday::Request::UrlEncoded
|
55
|
+
# connection.use Faraday::Response::RaiseError
|
56
|
+
# connection.use Faraday::Response::Mashify
|
57
|
+
# unless @raw
|
58
|
+
# case @query[:params][:format].to_s.downcase
|
59
|
+
# when 'json'
|
60
|
+
# connection.use Faraday::Response::ParseJson
|
61
|
+
# when 'xml'
|
62
|
+
# connection.use Faraday::Response::ParseXml
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
# connection.adapter(Faraday.default_adapter)
|
66
|
+
# end
|
67
|
+
# end
|
68
|
+
end
|
69
|
+
end
|