michael-ken 0.0.3 → 0.1.0

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/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) # collection queries MUST have :id => nil, no?
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
@@ -0,0 +1,2 @@
1
+ # when used as a rails plugin
2
+ require 'ken'
data/tasks/ken.rb ADDED
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ken do
3
+ # # Task goes here
4
+ # end
data/tasks/spec.rb CHANGED
@@ -22,4 +22,4 @@ begin
22
22
  end
23
23
  rescue LoadError
24
24
  # rspec not installed
25
- end
25
+ end
@@ -1,3 +1,4 @@
1
+
1
2
  {
2
3
  "id" : "/music/artist",
3
4
  "name" : "Musical Artist",