frecon 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/frecon/base/variables.rb +1 -1
- data/lib/frecon/scraper.rb +13 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57bd9b7c1164b8eb8fd9e832ac615281a0ae0921
|
4
|
+
data.tar.gz: 3c24af5efdef6fc97d60148a7daceb0d8f61c4f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 632ff7d628bfafa97051643b7553939598a84d3aacd84927d5393b5ec18e8b980ee00379204b0a6dd45ef7c1ef9628019d2f698511e1656b13c5c2ef5ec17c2c
|
7
|
+
data.tar.gz: a39cf27d21e8747472bbfcfe98fd153e67473977f248baf65ab1723c587c52135a69ed1bf4070cce990978d50e4e6a0de6b7b6934d2398cfc4701a015da3f262
|
data/lib/frecon/scraper.rb
CHANGED
@@ -23,6 +23,12 @@ module FReCon
|
|
23
23
|
# `data` will be a string, so we need to convert it from JSON.
|
24
24
|
data = JSON.parse(data)
|
25
25
|
|
26
|
+
if context[:type] == :single && data.empty?
|
27
|
+
return [404, "Could not find a model with that query."]
|
28
|
+
elsif
|
29
|
+
puts "Just a heads up: you are importing an empty array of data."
|
30
|
+
end
|
31
|
+
|
26
32
|
# Here we want `context` to tell us what model we are making.
|
27
33
|
if context[:model]
|
28
34
|
result = context[:model].controller.create(nil, nil, data)
|
@@ -57,14 +63,17 @@ module FReCon
|
|
57
63
|
route_name = model.name.gsub(/FReCon::/, "").downcase.pluralize if model
|
58
64
|
|
59
65
|
if !model && query.empty?
|
60
|
-
|
66
|
+
type = :dump
|
67
|
+
data = HTTParty.get("http://#{@base_uri}/dump")
|
61
68
|
elsif model && query.empty?
|
62
|
-
|
69
|
+
type = :index
|
70
|
+
data = HTTParty.get("http://#{@base_uri}/#{route_name}")
|
63
71
|
else
|
64
|
-
|
72
|
+
type = :single
|
73
|
+
data = HTTParty.get("http://#{@base_uri}/#{route_name}", { query: query })
|
65
74
|
end
|
66
75
|
|
67
|
-
read data.body, model: model
|
76
|
+
read data.body, model: model, type: type
|
68
77
|
end
|
69
78
|
end
|
70
79
|
end
|