rimac 0.0.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.
Files changed (5) hide show
  1. data/README.md +11 -0
  2. data/lib/rimac/version.rb +3 -0
  3. data/lib/rimac.rb +70 -0
  4. data/rimac.gemspec +21 -0
  5. metadata +49 -0
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ Rimac - Ruby client for Municipalidad Metropolitana de Lima API ([http://lima.datosabiertos.pe/](http://lima.datosabiertos.pe/))
2
+ ====
3
+
4
+ Rimac is a client for Municipalidad Metropolitana de Lima API ([http://lima.datosabiertos.pe/](http://lima.datosabiertos.pe/)). More information [here](http://lima.datosabiertos.pe/developers/).
5
+
6
+ Usage
7
+ ----
8
+ ```ruby
9
+ client = Rimac::API.new("e1fcb8366d2e470c2a41711c912edbc98404c623")
10
+ client.get("MUSEO-DE-LIMA")
11
+ ```
@@ -0,0 +1,3 @@
1
+ module Rimac
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rimac.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'rimac/version'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json'
5
+
6
+ module Rimac
7
+ class API
8
+
9
+ BASE_URL = "http://apisandbox.junar.com/datastreams/"
10
+
11
+ attr_accessor :api_key
12
+
13
+ def initialize(api_key)
14
+ self.api_key = api_key
15
+ end
16
+
17
+ def get(resource)
18
+ options = {}
19
+ options[:output] = "json_array"
20
+
21
+ url = url_for('invoke', resource, options)
22
+
23
+ response = JSON.parse(Net::HTTP.get_response(URI.parse(url)).body)
24
+
25
+ original_result = response["result"]
26
+ headers = original_result.shift
27
+
28
+ results = []
29
+
30
+ original_result.each do |row|
31
+ result = {}
32
+
33
+ headers.each_index do |i|
34
+ result[headers[i].to_s.downcase.gsub(" ", "_")] = row[i]
35
+ end
36
+
37
+ results << result
38
+ end
39
+
40
+ response["result"] = results
41
+
42
+ response
43
+ end
44
+
45
+ def search(query, options = {})
46
+ options ||= {}
47
+ options.delete(:query)
48
+ options[:query] = query
49
+
50
+ url = url_for('search', resource, options)
51
+
52
+ response = JSON.parse(Net::HTTP.get_response(URI.parse(url)).body)
53
+ end
54
+
55
+ private
56
+
57
+ def url_for(method, resource, options = {})
58
+ raise "API Key is required" if self.api_key.nil?
59
+
60
+ url = BASE_URL + method + "/" + resource + "?auth_key=#{self.api_key}"
61
+
62
+ options.each do |key, value|
63
+ url = url + "&#{key}=#{value}"
64
+ end
65
+
66
+ url
67
+ end
68
+
69
+ end
70
+ end
data/rimac.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # encoding: UTF-8
2
+ # -*- encoding: utf-8 -*-
3
+
4
+ $:.push File.expand_path("../lib", __FILE__)
5
+ require "rimac/version"
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "rimac"
9
+ gem.require_paths = ["lib"]
10
+ gem.authors = ["Gustavo Leon"]
11
+ gem.email = ["gustavo@xenda.pe"]
12
+ gem.description = "Ruby client for Municipalidad Metropolitana de Lima API (http://lima.datosabiertos.pe/)"
13
+ gem.summary = "Ruby client for Municipalidad Metropolitana de Lima API (http://lima.datosabiertos.pe/)"
14
+
15
+ gem.platform = Gem::Platform::RUBY
16
+ gem.version = Rimac::VERSION
17
+
18
+ gem.files = `git ls-files`.split("\n").sort
19
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rimac
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gustavo Leon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-15 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Ruby client for Municipalidad Metropolitana de Lima API (http://lima.datosabiertos.pe/)
15
+ email:
16
+ - gustavo@xenda.pe
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - lib/rimac.rb
23
+ - lib/rimac/version.rb
24
+ - rimac.gemspec
25
+ homepage:
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ none: false
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ none: false
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.23
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: Ruby client for Municipalidad Metropolitana de Lima API (http://lima.datosabiertos.pe/)
49
+ test_files: []