inegi_ruby 0.1.1
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/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +60 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/inegi_ruby.gemspec +33 -0
- data/lib/inegi_ruby.rb +74 -0
- data/lib/inegi_ruby/version.rb +3 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6496d569a6a61b9b87893b678cc84004851cd0cb
|
4
|
+
data.tar.gz: fec85f48da9ce9da86fe8415a4cccec74f3df811
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fef588e3a1d6d881e72e2d179cb3da32e9da7c5e0b018202b6f158b5daadfa5e31bbd797d7821fb93102659ece316287627f7988c30823eb877071aa53553e7f
|
7
|
+
data.tar.gz: da2af27f48fbcdadbde46539ec365d21a1f5f954fcfc1672d94eed77055d36af212592e91e28894bb7f99f22a847a515623d7885ec89912fd8d543039feceb45
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# inegi_ruby
|
2
|
+
|
3
|
+
Inegifacil's REST service wrapper for Ruby apps
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'inegi_ruby'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install inegi_ruby
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
inegi = Inegi::Client.new
|
25
|
+
|
26
|
+
# Returns information for aggregated Mexican population
|
27
|
+
puts inegi.indexes "1002000001"
|
28
|
+
# {
|
29
|
+
# indicator: "1002000001",
|
30
|
+
# values: [
|
31
|
+
# {
|
32
|
+
# period: "1990",
|
33
|
+
# value: "91829",
|
34
|
+
# units: "Número de personas"
|
35
|
+
# },
|
36
|
+
# ...
|
37
|
+
# ]
|
38
|
+
# }
|
39
|
+
|
40
|
+
# Returns information for population in specific location (Puebla)
|
41
|
+
puts inegi.indexes "1002000001", "21000"
|
42
|
+
# {
|
43
|
+
# indicator: "1002000001",
|
44
|
+
# values: [
|
45
|
+
# {
|
46
|
+
# period: "1990",
|
47
|
+
# value: "9182",
|
48
|
+
# units: "Número de personas"
|
49
|
+
# },
|
50
|
+
# ...
|
51
|
+
# ]
|
52
|
+
# }
|
53
|
+
```
|
54
|
+
|
55
|
+
## Changelog
|
56
|
+
|
57
|
+
#### 0.1.0
|
58
|
+
* Get indexes for an indicator
|
59
|
+
* `#indexes` accepts both an indicator and an optional location
|
60
|
+
* Indicators and locations are validated
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "inegi_ruby"
|
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/inegi_ruby.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'inegi_ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "inegi_ruby"
|
8
|
+
spec.version = InegiRuby::VERSION
|
9
|
+
spec.authors = ["Daniel Olivares"]
|
10
|
+
spec.email = ["danieloddl2@hotmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{INEGI's REST service wrapper}
|
13
|
+
spec.description = %q{INEGI's REST service wrapper}
|
14
|
+
spec.homepage = "https://github.com/K1N5L4Y3R/inegi_ruby"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "minitest", "~> 5.9"
|
32
|
+
spec.add_development_dependency "httparty", "~> 0.14.0"
|
33
|
+
end
|
data/lib/inegi_ruby.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "inegi_ruby/version"
|
2
|
+
require "httparty"
|
3
|
+
|
4
|
+
module Inegi
|
5
|
+
class Client
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
base_uri "http://inegifacil.com/rest/indice"
|
9
|
+
|
10
|
+
##
|
11
|
+
# Validates that an indicator adheres to INEGI's format
|
12
|
+
# It looks like indicators have a format of 10 digits
|
13
|
+
# @example
|
14
|
+
# validate_indicator("5300000041") # true
|
15
|
+
# validate_indicator("53000000412") # false
|
16
|
+
# validate_indicator("") # false
|
17
|
+
# validate_indicator("a") # false
|
18
|
+
# @param indicator [String] Indicator to be evaluated
|
19
|
+
def self.validate_indicator(indicator)
|
20
|
+
i_regex = /\A\d{10}\z/
|
21
|
+
indicator =~ i_regex || raise(ArgumentError.new("Given indicator is not valid"))
|
22
|
+
end
|
23
|
+
|
24
|
+
# Validates that a location adheres to INEGI's format
|
25
|
+
# It looks like locations have a format of 5 digits
|
26
|
+
# @example
|
27
|
+
# validate_indicator("53000") # true
|
28
|
+
# validate_indicator("53000000412") # false
|
29
|
+
# validate_indicator("") # false
|
30
|
+
# validate_indicator("a") # false
|
31
|
+
# @param location [String] Location to be evaluated
|
32
|
+
def self.validate_location(location)
|
33
|
+
l_regex = /\A\d{5}\z/
|
34
|
+
location =~ l_regex || raise(ArgumentError.new("Given location is not valid"))
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# After validating indicator, call Inegifacil's service and return indexes.
|
39
|
+
# @example
|
40
|
+
# indexes("5300000041") # HTTParty::Response[...]
|
41
|
+
# @param indicator [String] 10 digits indicator
|
42
|
+
# @param location [String] 5 digits location indicator
|
43
|
+
def indexes(indicator, location = nil)
|
44
|
+
self.class.validate_indicator indicator
|
45
|
+
self.class.validate_location location if location
|
46
|
+
path = "/#{indicator}/#{location}"
|
47
|
+
indexes = self.class.get path
|
48
|
+
self.class.format_indexes indexes
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# From a hash with Inegifacil's structure, return a more readable one
|
53
|
+
# @example
|
54
|
+
# hash = { "header": { "INDICADOR": "XXXXXXXXXX" },
|
55
|
+
# "indices": [{ "TIME_PERIOD": "YYYY", "OBS_VALUE": "Z" }] }
|
56
|
+
#
|
57
|
+
# format_indexes(hash) # { indicator: "XXXXXXXXXX", values: [..] }
|
58
|
+
# # +values+ contains +period+, +value+ and +units+
|
59
|
+
# @param hash [Hash] A hash containing results from service
|
60
|
+
# @see http://inegifacil.com/rest/indice/1002000001
|
61
|
+
def self.format_indexes(hash)
|
62
|
+
result = { indicator: hash["header"]["INDICADOR"] }
|
63
|
+
values = hash["indices"].map do |v|
|
64
|
+
{
|
65
|
+
period: v["TIME_PERIOD"],
|
66
|
+
value: v["OBS_VALUE"],
|
67
|
+
units: v["OBS_UNIT"]
|
68
|
+
}
|
69
|
+
end
|
70
|
+
values = { values: values }
|
71
|
+
result.merge values
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inegi_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Olivares
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.14.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.14.0
|
69
|
+
description: INEGI's REST service wrapper
|
70
|
+
email:
|
71
|
+
- danieloddl2@hotmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- bin/console
|
81
|
+
- bin/setup
|
82
|
+
- inegi_ruby.gemspec
|
83
|
+
- lib/inegi_ruby.rb
|
84
|
+
- lib/inegi_ruby/version.rb
|
85
|
+
homepage: https://github.com/K1N5L4Y3R/inegi_ruby
|
86
|
+
licenses: []
|
87
|
+
metadata:
|
88
|
+
allowed_push_host: https://rubygems.org
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.4.5.1
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: INEGI's REST service wrapper
|
109
|
+
test_files: []
|