michael-ken 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +70 -22
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/examples/artist.rb +2 -2
- data/examples/artist_links.rb +28 -0
- data/ken.gemspec +82 -0
- data/lib/ken/attribute.rb +16 -7
- data/lib/ken/collection.rb +0 -8
- data/lib/ken/property.rb +5 -0
- data/lib/ken/resource.rb +17 -14
- data/lib/ken/session.rb +34 -11
- data/lib/ken/type.rb +17 -2
- data/lib/ken/view.rb +13 -0
- data/lib/ken.rb +4 -10
- data/rails/init.rb +2 -0
- data/tasks/ken.rb +4 -0
- data/tasks/spec.rb +1 -1
- data/{spec → test}/fixtures/music_artist.json +1 -0
- data/test/fixtures/the_police.json +940 -0
- data/{spec/integration/ken_spec.rb → test/integration/ken_test.rb} +33 -28
- data/test/test_helper.rb +51 -0
- data/test/unit/attribute_test.rb +48 -0
- data/test/unit/property_test.rb +27 -0
- data/test/unit/resource_test.rb +48 -0
- data/test/unit/session_test.rb +27 -0
- data/test/unit/type_test.rb +35 -0
- data/test/unit/view_test.rb +48 -0
- metadata +38 -26
- data/lib/ken/version.rb +0 -3
- data/spec/fixtures/the_police.json +0 -891
- data/spec/spec.opts +0 -3
- data/spec/spec_helper.rb +0 -40
- data/spec/unit/attribute_spec.rb +0 -50
- data/spec/unit/property_spec.rb +0 -30
- data/spec/unit/resource_spec.rb +0 -63
- data/spec/unit/session_spec.rb +0 -18
- data/spec/unit/type_spec.rb +0 -21
- data/spec/unit/view_spec.rb +0 -28
data/lib/ken.rb
CHANGED
@@ -8,7 +8,6 @@ require 'addressable/uri'
|
|
8
8
|
|
9
9
|
dir = Pathname(__FILE__).dirname.expand_path + 'ken'
|
10
10
|
|
11
|
-
require dir + 'version'
|
12
11
|
require dir + 'util'
|
13
12
|
require dir + 'resource'
|
14
13
|
require dir + 'type'
|
@@ -26,10 +25,8 @@ Ken::Logger.new(STDOUT, :error)
|
|
26
25
|
Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
|
27
26
|
|
28
27
|
module Ken
|
29
|
-
|
30
28
|
extend Extlib::Assertions
|
31
29
|
|
32
|
-
|
33
30
|
# store query as a constant here.
|
34
31
|
# if the hash gets updated using
|
35
32
|
# #merge! or #update, this will mean
|
@@ -62,6 +59,7 @@ module Ken
|
|
62
59
|
# Executes an Mql Query against the Freebase API and returns the result as
|
63
60
|
# a <tt>Collection</tt> of <tt>Resources</tt>.
|
64
61
|
#
|
62
|
+
# performs a cursored query unless there's a limit specified
|
65
63
|
# == Examples
|
66
64
|
#
|
67
65
|
# Ken.all(:name => "Apple", :type => "/music/album")
|
@@ -76,8 +74,8 @@ module Ken
|
|
76
74
|
# @api public
|
77
75
|
def self.all(options = {})
|
78
76
|
assert_kind_of 'options', options, Hash
|
79
|
-
query = { :name => nil }.merge!(options).merge!(:id => nil)
|
80
|
-
result = Ken.session.mqlread([ query ])
|
77
|
+
query = { :name => nil }.merge!(options).merge!(:id => nil)
|
78
|
+
result = Ken.session.mqlread([ query ], :cursor => !options[:limit])
|
81
79
|
Ken::Collection.new(result.map { |r| Ken::Resource.new(r) })
|
82
80
|
end
|
83
81
|
|
@@ -91,13 +89,9 @@ module Ken
|
|
91
89
|
# @api public
|
92
90
|
def self.get(id)
|
93
91
|
assert_kind_of 'id', id, String
|
94
|
-
raise ArgumentError, "id must be in /type/object/id format" unless valid_id_attribute?(id)
|
95
92
|
result = Ken.session.mqlread(QUERY.merge!(:id => id))
|
93
|
+
raise ResourceNotFound unless result
|
96
94
|
Ken::Resource.new(result)
|
97
95
|
end
|
98
96
|
|
99
|
-
def self.valid_id_attribute?(id)
|
100
|
-
id =~ /\/\w+/
|
101
|
-
end
|
102
|
-
|
103
97
|
end # module Ken
|
data/rails/init.rb
ADDED
data/tasks/ken.rb
ADDED
data/tasks/spec.rb
CHANGED