Class: Aceitafacil::Vendor
- Inherits:
-
Object
- Object
- Aceitafacil::Vendor
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/aceitafacil/vendor.rb
Instance Attribute Summary collapse
-
#bank ⇒ Object
Returns the value of attribute bank.
-
#email ⇒ Object
Returns the value of attribute email.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Vendor
constructor
A new instance of Vendor.
- #params ⇒ Object
- #save ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Vendor
Returns a new instance of Vendor.
11 12 13 14 15 16 17 18 |
# File 'lib/aceitafacil/vendor.rb', line 11 def initialize(params = {}) @connection = Aceitafacil::Connection.new self.id = params[:id] self.name = params[:name] self.email = params[:email] self.bank = params[:bank] end |
Instance Attribute Details
#bank ⇒ Object
Returns the value of attribute bank.
9 10 11 |
# File 'lib/aceitafacil/vendor.rb', line 9 def bank @bank end |
#email ⇒ Object
Returns the value of attribute email.
9 10 11 |
# File 'lib/aceitafacil/vendor.rb', line 9 def email @email end |
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/aceitafacil/vendor.rb', line 9 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/aceitafacil/vendor.rb', line 9 def name @name end |
Class Method Details
.find(vendor_id) ⇒ 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 61 62 63 64 65 66 67 68 |
# File 'lib/aceitafacil/vendor.rb', line 37 def self.find(vendor_id) return nil if vendor_id.nil? @connection = Aceitafacil::Connection.new find_params = {} find_params["vendor[id]"] = vendor_id response = @connection.get("vendor", find_params) json = JSON.parse(response.body) bank = { code: json["vendor"]["bank"][0]["code"], agency: json["vendor"]["bank"][0]["agency"], account_type: json["vendor"]["bank"][0]["account_type"], account_number: json["vendor"]["bank"][0]["account_number"], account_holder_name: json["vendor"]["bank"][0]["account_holder_name"], account_holder_document_type: json["vendor"]["bank"][0]["account_holder_document_type"], account_holder_document_number: json["vendor"]["bank"][0]["account_holder_document_number"] } vendor = Aceitafacil::Vendor.new( id: json["vendor"]["id"], name: json["vendor"]["name"], email: json["vendor"]["email"], bank: bank ) return vendor end |
Instance Method Details
#params ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/aceitafacil/vendor.rb', line 20 def params params = {} params["vendor[id]"] = self.id params["vendor[name]"] = self.name params["vendor[email]"] = self.email params["vendor[bank][code]"] = self.bank.code params["vendor[bank][agency]"] = self.bank.agency params["vendor[bank][account_type]"] = self.bank.account_type params["vendor[bank][account_number]"] = self.bank.account_number params["vendor[bank][account_holder_name]"] = self.bank.account_holder_name params["vendor[bank][account_holder_document_type]"] = self.bank.account_holder_document_type params["vendor[bank][account_holder_document_number]"] = self.bank.account_holder_document_number return params end |
#save ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/aceitafacil/vendor.rb', line 76 def save return false if not self.valid? or not self.bank.valid? response = @connection.post("vendor", params) return response end |
#update ⇒ Object
70 71 72 73 74 |
# File 'lib/aceitafacil/vendor.rb', line 70 def update response = @connection.put("vendor", params) return response end |