Class: BeautydateApi::Business

Inherits:
APIResource show all
Defined in:
lib/beautydate_api/business.rb

Instance Attribute Summary

Attributes inherited from Object

#errors, #id

Instance Method Summary collapse

Methods inherited from APIResource

endpoint_url, #is_new?, object_base_uri, relative_url, url

Methods inherited from Object

#add_accessor, #attributes, #initialize, #set_attributes, #unsaved_attributes, #unsaved_data

Constructor Details

This class inherits a constructor from BeautydateApi::Object

Instance Method Details

#add_trial_days(days, update_data = false) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/beautydate_api/business.rb', line 36

def add_trial_days(days, update_data=false)
  APIRequest.request("POST", "#{self.class.url(self.id)}/add_trial_days/#{days}")
  self.errors = nil
  refresh if update_data
  true
rescue BeautydateApi::RequestWithErrors => e
  self.errors = e.errors
  false
end

#create(attributes) ⇒ Object

commercial_name, type, zipcode, street, street_number, neighborhood, city, state, phone, description, az_id



16
17
18
19
20
21
22
23
24
# File 'lib/beautydate_api/business.rb', line 16

def create(attributes)
  result = APIRequest.request("POST", "#{self.class.endpoint_url}", { type: "businesses", attributes: attributes })
  self.errors = nil
  update_attributes_from_result result
  true
rescue BeautydateApi::RequestWithErrors => e
  self.errors = e.errors
  false
end

#manual_payment(status, update_data = false) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/beautydate_api/business.rb', line 46

def manual_payment(status, update_data=false)
  status = !!status ? 'enable' : 'disable'
  APIRequest.request("PUT", "#{self.class.url(self.id)}/manual_payment/#{status}")
  refresh if update_data
  self.errors = nil
  true
rescue BeautydateApi::RequestWithErrors => e
  self.errors = e.errors
  false
end

#refreshObject

Update object data from Beauty Data



5
6
7
8
9
10
11
12
13
# File 'lib/beautydate_api/business.rb', line 5

def refresh
  result = APIRequest.request("GET", "#{self.class.url(self.id)}")
  self.errors = nil
  update_attributes_from_result result
  true
rescue BeautydateApi::RequestWithErrors => e
  self.errors = e.errors
  false
end

#updateObject



26
27
28
29
30
31
32
33
34
# File 'lib/beautydate_api/business.rb', line 26

def update
  result = APIRequest.request("PUT", "#{self.class.url(self.id)}", { type: "businesses", id: self.id, attributes: unsaved_data })
  self.errors = nil
  update_attributes_from_result result
  true
rescue BeautydateApi::RequestWithErrors => e
  self.errors = e.errors
  false
end