Class: BlueStateDigital::Dataset
- Inherits:
-
ApiDataModel
- Object
- ApiDataModel
- BlueStateDigital::Dataset
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/blue_state_digital/dataset.rb
Constant Summary collapse
- UPLOAD_ENDPOINT =
'/cons/upload_dataset'- DELETE_ENDPOINT =
'/cons/delete_dataset'- FIELDS =
[ :dataset_id, :map_type, :slug, :rows ]
Constants inherited from ApiDataModel
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#data_header ⇒ Object
readonly
Returns the value of attribute data_header.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Attributes inherited from ApiDataModel
Class Method Summary collapse
Instance Method Summary collapse
- #add_data_header(header_row) ⇒ Object
- #add_data_row(row) ⇒ Object
- #delete ⇒ Object
-
#initialize(args = {}) ⇒ Dataset
constructor
A new instance of Dataset.
- #read_attribute_for_validation(attr) ⇒ Object
- #save ⇒ Object
Methods inherited from ApiDataModel
Constructor Details
#initialize(args = {}) ⇒ Dataset
Returns a new instance of Dataset.
22 23 24 25 26 27 |
# File 'lib/blue_state_digital/dataset.rb', line 22 def initialize(args={}) super @data = [] @data_header = nil @errors = ActiveModel::Errors.new(self) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
17 18 19 |
# File 'lib/blue_state_digital/dataset.rb', line 17 def data @data end |
#data_header ⇒ Object (readonly)
Returns the value of attribute data_header.
17 18 19 |
# File 'lib/blue_state_digital/dataset.rb', line 17 def data_header @data_header end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
17 18 19 |
# File 'lib/blue_state_digital/dataset.rb', line 17 def errors @errors end |
Class Method Details
.human_attribute_name(attr, options = {}) ⇒ Object
90 91 92 |
# File 'lib/blue_state_digital/dataset.rb', line 90 def self.human_attribute_name(attr, = {}) attr end |
.lookup_ancestors ⇒ Object
93 94 95 |
# File 'lib/blue_state_digital/dataset.rb', line 93 def self.lookup_ancestors [self] end |
Instance Method Details
#add_data_header(header_row) ⇒ Object
34 35 36 |
# File 'lib/blue_state_digital/dataset.rb', line 34 def add_data_header(header_row) @data_header = header_row end |
#add_data_row(row) ⇒ Object
31 32 33 |
# File 'lib/blue_state_digital/dataset.rb', line 31 def add_data_row(row) @data.push row end |
#delete ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/blue_state_digital/dataset.rb', line 63 def delete if dataset_id.nil? errors.add(:dataset_id,"is missing") return false end if connection response = connection.perform_request_raw( DELETE_ENDPOINT, {api_ver: 2}, "POST", {dataset_id: dataset_id}.to_json ) if(response.status==200) true else errors.add(:web_service,"#{response.body}") false end else errors.add(:connection,"is missing") false end end |
#read_attribute_for_validation(attr) ⇒ Object
87 88 89 |
# File 'lib/blue_state_digital/dataset.rb', line 87 def read_attribute_for_validation(attr) send(attr) end |
#save ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/blue_state_digital/dataset.rb', line 37 def save #errors.add(:data, "cannot be blank") if @data.blank? if valid? if connection response = connection.perform_request_raw( UPLOAD_ENDPOINT, {api_ver: 2, slug: slug, map_type: map_type, content_type: 'text/csv', accept: 'application/json'}, "PUT", csv_payload ) if(response.status == 202) true else errors.add(:web_service,"#{response.body}") false end else errors.add(:connection,"is missing") false end else false end end |