precog 1.0.0.pre2 → 1.0.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/precog.rb +28 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0f07093cd36069946ad7110456b91cc58ba009a8
4
- data.tar.gz: e756fc697131e4a30341836595b3bb1a5a2c21fa
5
2
  SHA512:
6
- metadata.gz: 206dfe29cdd566d09404b9b9af31f9f346dfb71086f3db615a7b22c9f2e7ce9e97df792b0f442a2839074b3df7bc002199df9b169772eb12c29229d4dee507de
7
- data.tar.gz: 9ce1006e3aeb2385fbc5ebbd6e5ec580c9745dc51dedbf2925193c8e17ca1e69bbafb670bb57ee7da9ad3d66cc4833f7a57bd9172040541c570920bc7785c9ae
3
+ metadata.gz: db0c18eabde299256e7b91e025d4c3f2610b363252811faa036093b4bfd22dc8daff31c2c564d39f61001a94a06ebfd8af2f25c320f73e6dff3c9cd480443a88
4
+ data.tar.gz: f6e0ea056eef9891ca98a0dee71fc0459b4cfda5a1c4b03afd41b5f23a5f8d7c1bac3acb8a4256d784cfa2ab0654caf2ad1c17565e20020d08e31301d83e0d75
5
+ SHA1:
6
+ metadata.gz: 5cdd69c13a65be70bd4a2e702063490eba0e72da
7
+ data.tar.gz: 2642a661bc90722028ae2d94816e886c2da80dce
data/lib/precog.rb CHANGED
@@ -25,6 +25,14 @@ module Precog
25
25
  # Struct used to return account information from the Client class.
26
26
  AccountInfo = Struct.new :api_key, :account_id, :email
27
27
 
28
+ # Represents an error or warning returned from the Precog API. The position
29
+ # information is optional, and is reprensented by an instance of +Position+
30
+ # when present.
31
+ Info = Struct.new :message, :position
32
+
33
+ # Represents a location within a Quirrel source fragment.
34
+ Position = Struct.new :line_num, :column_num, :line_text
35
+
28
36
  # A simple REST client for storing data in Precog and querying it with Quirrel.
29
37
  #
30
38
  # This provides methods to upload files to
@@ -253,13 +261,19 @@ module Precog
253
261
  # interrupted, there will be no way to retrieve the results of the query.
254
262
  #
255
263
  # Returns a triple of errors, warnings and an +Array+ of data representing
256
- # the query results.
264
+ # the query results. The errors and warnings are represented as +Array+(s)
265
+ # of +Info+ objects.
257
266
  def query(path, query)
258
267
  path = relativize_path path
259
268
  params = { :apiKey => api_key, :q => query, :format => 'detailed' }
260
269
  resp = Precog.get(self, "/analytics/v#{VERSION}/fs/#{path}", { 'Content-Type' => 'application/json' }, params)
261
270
  output = JSON.parse resp.body
262
- [output["errors"], output["warnings"], output["data"]]
271
+
272
+ [
273
+ output["errors"].select { |i| !i.nil? }.map { |i| Precog.parse_info i },
274
+ output["warnings"].select { |i| !i.nil? }.map { |i| Precog.parse_info i },
275
+ output["data"]
276
+ ]
263
277
  end
264
278
 
265
279
  # Runs an asynchronous query against Precog. An async query is a query
@@ -331,12 +345,23 @@ module Precog
331
345
 
332
346
  if data
333
347
  output = JSON.parse data
334
- [output["errors"], output["warnings"], output["data"]]
348
+
349
+ [
350
+ output["errors"].select { |i| !i.nil? }.map { |i| Precog.parse_info i },
351
+ output["warnings"].select { |i| !i.nil? }.map { |i| Precog.parse_info i },
352
+ output["data"]
353
+ ]
335
354
  end
336
355
  end
337
356
  end
338
357
 
339
358
  class << self
359
+ def parse_info(info) # :nodoc:
360
+ pos_hash = info['position']
361
+ pos = Position.new pos_hash['line'].to_i, pos_hash['column'].to_i, pos_hash['text'] unless pos_hash.nil?
362
+ Info.new info['message'], pos
363
+ end
364
+
340
365
  def post(client, path, body, header, params = {}) # :nodoc:
341
366
  connect client do |http|
342
367
  uri = Addressable::URI.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: precog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre2
4
+ version: 1.0.0.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Spiewak