Module: SurveyGizmo::Resource
- Extended by:
- ActiveSupport::Concern
- Included in:
- API::Contact, API::EmailMessage, API::Option, API::Page, API::Question, API::Response, API::Survey, API::SurveyCampaign
- Defined in:
- lib/survey_gizmo/resource.rb
Defined Under Namespace
Modules: ClassMethods Classes: Response
Class Method Summary collapse
-
.descendants ⇒ Set
Every class that includes SurveyGizmo::Resource.
Instance Method Summary collapse
-
#destroy ⇒ Boolean
Deleted the Resource from Survey Gizmo.
-
#errors ⇒ Array
Any errors returned by Survey Gizmo.
-
#new? ⇒ Boolean
private
The state of the current Resource.
-
#raw_response ⇒ Hash
The raw JSON returned by Survey Gizmo.
-
#reload ⇒ self, false
fetch resource from SurveyGizmo and reload the attributes.
-
#save ⇒ Boolean
Save the instance to Survey Gizmo.
-
#to_param_options ⇒ Hash
Sets the hash that will be used to interpolate values in routes.
-
#update(attributes = {}) ⇒ Boolean
Updates attributes and saves this Resource instance.
Class Method Details
.descendants ⇒ Set
Returns Every class that includes SurveyGizmo::Resource.
16 17 18 |
# File 'lib/survey_gizmo/resource.rb', line 16 def self.descendants @descendants ||= Set.new end |
Instance Method Details
#destroy ⇒ Boolean
Deleted the Resource from Survey Gizmo
187 188 189 190 191 192 |
# File 'lib/survey_gizmo/resource.rb', line 187 def destroy return false if new? || destroyed? handle_response SurveyGizmo.delete(handle_route(:delete)) do _response.ok? ? destroyed! : false end end |
#errors ⇒ Array
Any errors returned by Survey Gizmo
229 230 231 |
# File 'lib/survey_gizmo/resource.rb', line 229 def errors @errors ||= [] end |
#new? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The state of the current Resource
196 197 198 |
# File 'lib/survey_gizmo/resource.rb', line 196 def new? @_state.nil? end |
#raw_response ⇒ Hash
Returns The raw JSON returned by Survey Gizmo.
234 235 236 |
# File 'lib/survey_gizmo/resource.rb', line 234 def raw_response _response.response if _response end |
#reload ⇒ self, false
fetch resource from SurveyGizmo and reload the attributes
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/survey_gizmo/resource.rb', line 174 def reload handle_response SurveyGizmo.get(handle_route(:get)) do if _response.ok? self.attributes = _response.data clean! else false end end end |
#save ⇒ Boolean
Save the instance to Survey Gizmo
161 162 163 164 165 166 167 168 169 |
# File 'lib/survey_gizmo/resource.rb', line 161 def save if new? _create else handle_response SurveyGizmo.post(handle_route(:update), :query => self.attributes_without_blanks) do _response.ok? ? saved! : false end end end |
#to_param_options ⇒ Hash
Sets the hash that will be used to interpolate values in routes. It needs to be defined per model.
223 224 225 |
# File 'lib/survey_gizmo/resource.rb', line 223 def raise "Define #to_param_options in #{self.class.name}" end |
#update(attributes = {}) ⇒ Boolean
Updates attributes and saves this Resource instance
152 153 154 155 |
# File 'lib/survey_gizmo/resource.rb', line 152 def update(attributes = {}) self.attributes = attributes self.save end |