Class: BlueStateDigital::Datasets

Inherits:
CollectionResource show all
Defined in:
lib/blue_state_digital/dataset.rb

Constant Summary collapse

FETCH_ENDPOINT =
'/cons/list_datasets'

Instance Attribute Summary

Attributes inherited from CollectionResource

#connection

Instance Method Summary collapse

Methods inherited from CollectionResource

#initialize

Constructor Details

This class inherits a constructor from BlueStateDigital::CollectionResource

Instance Method Details

#get_datasetsObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/blue_state_digital/dataset.rb', line 117

def get_datasets
  if connection
    response = connection.perform_request FETCH_ENDPOINT, { api_ver: 2 }, "GET"

    # TODO: Should check response's status code
    begin
      parsed_response = JSON.parse(response)

      data = parsed_response['data']
      if(data)
        data.map {|dataset| Dataset.new(dataset) }
      else
        nil
      end
    rescue Exception => e
      raise FetchFailureException.new(e)
    end
  else
    raise NoConnectionException.new
  end
end