freebase-importers 0.0.1 → 0.0.2
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.
- data/README.md +15 -0
- data/lib/freebase_importers/base.rb +12 -0
- data/lib/freebase_importers/query.rb +2 -2
- data/lib/freebase_importers/version.rb +1 -1
- data/spec/integration_spec.rb +15 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -39,6 +39,21 @@ Then define a model to make that query and load accessors with results.
|
|
39
39
|
|
40
40
|
*add_method* just adds a method.
|
41
41
|
|
42
|
+
After defining a model, you query it like:
|
43
|
+
|
44
|
+
# "all" is a bit of a misnomer, actually just
|
45
|
+
# makes one query for a default of 100 records
|
46
|
+
Book.all do |book|
|
47
|
+
puts "#{book.name}, #{book.date_of_first_publication}"
|
48
|
+
end
|
49
|
+
|
50
|
+
# endless is not a misnomer ...
|
51
|
+
# records will keep coming until Google quits sending them
|
52
|
+
# The argument indicates the duration to pause between requests.
|
53
|
+
Book.endless(7) do |book|
|
54
|
+
puts "#{book.name}, #{book.date_of_first_publication}"
|
55
|
+
end
|
56
|
+
|
42
57
|
## Contributing
|
43
58
|
|
44
59
|
1. Fork it
|
@@ -31,6 +31,18 @@ module FreebaseImporters
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def self.endless(pause = 1)
|
35
|
+
q = query
|
36
|
+
while q do
|
37
|
+
q.each do |result|
|
38
|
+
yield new(result)
|
39
|
+
end
|
40
|
+
puts "Getting some more in #{pause} seconds."
|
41
|
+
sleep pause
|
42
|
+
q = q.next
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
34
46
|
def self.first
|
35
47
|
all {|m| break(m) }
|
36
48
|
end
|
@@ -20,8 +20,8 @@ module FreebaseImporters
|
|
20
20
|
|
21
21
|
# https://developers.google.com/freebase/v1/mql-overview#querying-with-cursor-paging-results
|
22
22
|
def next
|
23
|
-
if (
|
24
|
-
self.class.new(mql,
|
23
|
+
if (new_cursor = response["cursor"])
|
24
|
+
self.class.new(mql, new_cursor)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
data/spec/integration_spec.rb
CHANGED
@@ -20,6 +20,21 @@ describe FreebaseImporters do
|
|
20
20
|
expect(car.thumbnail_urls).not_to be_empty
|
21
21
|
expect(car.image_urls).not_to be_empty
|
22
22
|
end
|
23
|
+
|
24
|
+
describe :endless do
|
25
|
+
it "should return a second page of results" do
|
26
|
+
counter = 0
|
27
|
+
images = []
|
28
|
+
FreebaseImporters::Car.endless do |car|
|
29
|
+
counter += 1
|
30
|
+
images << car.image_url if counter < 50
|
31
|
+
if counter > 120
|
32
|
+
expect(images).not_to include(car.image_url)
|
33
|
+
break
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
23
38
|
end
|
24
39
|
|
25
40
|
describe FreebaseImporters::Person do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freebase-importers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -164,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
164
|
version: '0'
|
165
165
|
segments:
|
166
166
|
- 0
|
167
|
-
hash:
|
167
|
+
hash: 3609189692260758964
|
168
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
169
|
none: false
|
170
170
|
requirements:
|
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
173
|
version: '0'
|
174
174
|
segments:
|
175
175
|
- 0
|
176
|
-
hash:
|
176
|
+
hash: 3609189692260758964
|
177
177
|
requirements: []
|
178
178
|
rubyforge_project:
|
179
179
|
rubygems_version: 1.8.23
|