chillon 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/lib/chillon.rb +6 -12
- data/lib/chillon/handler.rb +29 -0
- data/lib/chillon/parser.rb +42 -0
- data/lib/chillon/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bf793c5add66c192f01241787d4265f8a6ac40c
|
4
|
+
data.tar.gz: b99122a143860b73ebf1f1b262c41d81bab124ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 828c9e66547b04d41e9257f2fe841d4115fc2d5733dfff1f7576247a47217e8bbdda59433ddc25cb6c20aab2edbdd009ec7e14b3d0f1fea4d2ecf4bcae44afdf
|
7
|
+
data.tar.gz: 98dde8bbaa19814701b14a39833b96194faa5420e4f6e6e59084e4a23889107f5de6319ad397c9dfda3ace98c819c1b812a8417e1f31f0b9f252301d9d25d665
|
data/README.md
CHANGED
@@ -20,13 +20,25 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
Just create a Request object and ask for it to get you some delicious data. Yummy!
|
22
22
|
|
23
|
-
open_data = Chillon::Request("
|
24
|
-
|
23
|
+
open_data = Chillon::Request.new("e1fcb8366d2e470c2a41711c912edbc98404c623")
|
24
|
+
open_data.get_museo_de_lima
|
25
25
|
|
26
26
|
Chillon will interpret that call and transform the method to the -arguibly- ugly GUID code of "MUSEO-DE-LIMA"
|
27
27
|
|
28
|
+
Want more? Oh boy, you are for a treat. Let's say, you want to pull data from some museums. But also more data. Well, just ask for it:
|
29
|
+
|
30
|
+
results = open_data.get_museo_de_lima_and_licen_de_funci_2013
|
31
|
+
|
32
|
+
Now you've got a hash filled with some neat info, ready to be perused. Just access if through their IDs:
|
33
|
+
|
34
|
+
results["MUSEO-DE-LIMA"]
|
35
|
+
results["LICEN-DE-FUNCI-2013"]
|
36
|
+
|
37
|
+
You can chain any number of calls to the server. Just, you know, don't abuse it.
|
38
|
+
|
28
39
|
So, chill and relax: Chillon's got your back, yo.
|
29
40
|
|
41
|
+
|
30
42
|
## Contributing
|
31
43
|
|
32
44
|
1. Fork it
|
data/lib/chillon.rb
CHANGED
@@ -1,29 +1,23 @@
|
|
1
1
|
require_relative "chillon/version"
|
2
|
-
|
2
|
+
require_relative "chillon/parser"
|
3
|
+
require_relative "chillon/handler"
|
3
4
|
|
4
5
|
module Chillon
|
5
6
|
|
6
7
|
class Request
|
7
8
|
|
8
9
|
def initialize(token = "NEED_A_TOKEN")
|
9
|
-
@
|
10
|
+
@handler = Handler.new(token)
|
10
11
|
end
|
11
12
|
|
12
13
|
def method_missing(*args)
|
13
|
-
|
14
|
-
if
|
15
|
-
|
16
|
-
name = transform_callee_to_guid(callee)
|
17
|
-
@access.get(name)
|
14
|
+
parser = Parser.new(*args)
|
15
|
+
if parser.match?
|
16
|
+
@handler.process(parser)
|
18
17
|
else
|
19
18
|
super(*args)
|
20
19
|
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
20
|
|
25
|
-
def transform_callee_to_guid(guid) #museo_de_lima
|
26
|
-
guid.upcase.gsub("_", "-")
|
27
21
|
end
|
28
22
|
|
29
23
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rimac'
|
2
|
+
|
3
|
+
module Chillon
|
4
|
+
class Handler
|
5
|
+
|
6
|
+
def initialize(token)
|
7
|
+
@access = Rimac::API.new(token)
|
8
|
+
end
|
9
|
+
|
10
|
+
def process(parser)
|
11
|
+
|
12
|
+
if parser.multiple_results?
|
13
|
+
results = Hash.new
|
14
|
+
parser.guids.map do |guid|
|
15
|
+
results[guid] = get_from_access(guid)
|
16
|
+
end
|
17
|
+
results
|
18
|
+
else
|
19
|
+
get_from_access(parser.guid)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_from_access(guid)
|
25
|
+
@access.get(guid)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Chillon
|
2
|
+
|
3
|
+
class Parser
|
4
|
+
|
5
|
+
attr_accessor :guid, :guids
|
6
|
+
|
7
|
+
def initialize(args)
|
8
|
+
name, attrs = args
|
9
|
+
|
10
|
+
if name =~ /get_(.*)_and_(.*)/
|
11
|
+
|
12
|
+
callees = name.to_s.gsub("get_", "").split("_and_")
|
13
|
+
@guids = callees.map{|guid| transform_callee_to_guid(guid) }
|
14
|
+
puts @guids.inspect
|
15
|
+
elsif name =~ /get_(.*)/
|
16
|
+
callee = $1
|
17
|
+
@guid = transform_callee_to_guid(callee)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def match?
|
23
|
+
@guids || @guid
|
24
|
+
end
|
25
|
+
|
26
|
+
def multiple_results?
|
27
|
+
@guids
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def transform_callee_to_guid(guid) #museo_de_lima
|
33
|
+
guid.upcase.gsub("_", "-")
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# "LICEN-DE-FUNCI-2013"
|
data/lib/chillon/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chillon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alvaro Pereyra
|
@@ -66,6 +66,8 @@ files:
|
|
66
66
|
- Rakefile
|
67
67
|
- chillon.gemspec
|
68
68
|
- lib/chillon.rb
|
69
|
+
- lib/chillon/handler.rb
|
70
|
+
- lib/chillon/parser.rb
|
69
71
|
- lib/chillon/version.rb
|
70
72
|
homepage: https://github.com/xenda/chillon
|
71
73
|
licenses:
|