module DaisybillApi::Ext::CRUD::InstanceMethods

@private

Public Instance Methods

destroyed?() click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 100
def destroyed?
  !!@destroyed
end
new_record?() click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 96
def new_record?
  id.nil?
end

Protected Instance Methods

data() click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 115
def data
  { self.class.singular_key => to_params }
end
index_path() click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 106
def index_path
  params = self.class.path_prefix? ? [self.send(self.class.prefix_property)] : []
  self.class.index_path(*params)
end
show_path() click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 111
def show_path
  self.class.show_path(id)
end

Private Instance Methods

client(method, path, params = {}) click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 121
def client(method, path, params = {})
  self.class.client method, path, params
end
process_response(client) click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 130
def process_response(client)
  if client.success?
    response = client.response.clone
    self.links = response.delete "links"
    self.attributes = response
    true
  elsif client.bad_request?
    self.external_errors = client.response["errors"]
    self.valid?
  else
    false
  end
end
send_data(method, url) click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 125
def send_data(method, url)
  self.external_errors = nil
  valid? && process_response(client method, url, data)
end