Module: SurveyGizmo::Resource

Extended by:
ActiveSupport::Concern
Included in:
API::AccountTeams, API::Campaign, API::Contact, API::EmailMessage, API::Option, API::Page, API::Question, API::Response, API::Survey
Defined in:
lib/survey_gizmo/resource.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descendantsObject



16
17
18
# File 'lib/survey_gizmo/resource.rb', line 16

def self.descendants
  @descendants ||= Set.new
end

Instance Method Details

#destroyObject

Delete the Resource from Survey Gizmo



151
152
153
154
# File 'lib/survey_gizmo/resource.rb', line 151

def destroy
  fail "No id; can't delete #{self.inspect}!" unless id
  Connection.delete(create_route(:delete))
end

#inspectObject



156
157
158
159
160
161
162
163
164
# File 'lib/survey_gizmo/resource.rb', line 156

def inspect
  attribute_strings = self.class.attribute_set.map do |attrib|
    value = self.send(attrib.name)
    value = value.is_a?(Hash) ? value.inspect : value.to_s
    "  \"#{attrib.name}\" => \"#{value}\"\n" unless value.strip.blank?
  end.compact

  "#<#{self.class.name}:#{self.object_id}>\n#{attribute_strings.join}"
end

#reloadObject

Repopulate the attributes based on what is on SurveyGizmo’s servers



145
146
147
148
# File 'lib/survey_gizmo/resource.rb', line 145

def reload
  self.attributes = Connection.get(create_route(:get)).body['data']
  self
end

#saveObject

If we have an id, it’s an update because we already know the surveygizmo assigned id Returns itself if successfully saved, but with attributes (like id) added by SurveyGizmo



138
139
140
141
142
# File 'lib/survey_gizmo/resource.rb', line 138

def save
  method, path = id ? [:post, :update] : [:put, :create]
  self.attributes = Connection.send(method, create_route(path), attributes_without_blanks).body['data']
  self
end