Class: GoogleDataSource::DataSource::JsonData

Inherits:
Base
  • Object
show all
Defined in:
lib/google_data_source/json_data.rb

Instance Attribute Summary

Attributes inherited from Base

#callback, #column_labels, #errors, #export_filename, #formatters, #reporting, #virtual_columns, #xml_class

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #add_error, #column_ids, #columns, #columns=, #data, #data=, #format, #formatter, from_gdata_params, from_params, #guess_columns, #has_formatter?, #is_virtual_column?, #required_columns, #set, #set_required_columns, #valid?, #validate, #virtual_column

Constructor Details

#initialize(gdata_params) ⇒ JsonData

Returns a new instance of JsonData.



5
6
7
8
# File 'lib/google_data_source/json_data.rb', line 5

def initialize(gdata_params)
  super(gdata_params)
  @responseHandler = "google.visualization.Query.setResponse"
end

Instance Method Details

#responseObject

Returns the datasource in JSON format. It supports the responseHandler parameter. All the errors are returned with the invalid_request key. Warnings are unsupported (yet).



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/google_data_source/json_data.rb', line 13

def response
  rsp = {}
  rsp[:version] = @version
  rsp[:reqId] = @params[:reqId] if @params.key?(:reqId)
  if valid?
    rsp[:status] = "ok"
    rsp[:table] = datatable unless data.nil?      
  else
    rsp[:status] = "error"
    rsp[:errors] = @errors.values.collect do |error|
      { :reason => "invalid_request" , :message => error }
    end
  end
  "#{@params[:responseHandler] || @responseHandler}(#{rsp.to_json});#{callback}"
end