Class: Recurring
Instance Attribute Summary collapse
-
#currency_code ⇒ Object
Returns the value of attribute currency_code.
-
#customer_costcenter_id ⇒ Object
Returns the value of attribute customer_costcenter_id.
-
#customer_id ⇒ Object
Returns the value of attribute customer_id.
-
#delivery_date ⇒ Object
Returns the value of attribute delivery_date.
-
#email_notify ⇒ Object
Returns the value of attribute email_notify.
-
#eu_delivery ⇒ Object
Returns the value of attribute eu_delivery.
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#id ⇒ Object
Returns the value of attribute id.
-
#introtext ⇒ Object
Returns the value of attribute introtext.
-
#invoice_items ⇒ Object
Returns the value of attribute invoice_items.
-
#invoice_number ⇒ Object
Returns the value of attribute invoice_number.
-
#invoice_type ⇒ Object
Returns the value of attribute invoice_type.
-
#is_new ⇒ Object
Returns the value of attribute is_new.
-
#occurences ⇒ Object
Returns the value of attribute occurences.
-
#output_type ⇒ Object
Returns the value of attribute output_type.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#template_id ⇒ Object
Returns the value of attribute template_id.
-
#vat_items ⇒ Object
Returns the value of attribute vat_items.
Instance Method Summary collapse
- #delete! ⇒ Object
- #get(id = nil) ⇒ Object
- #hydrate(body) ⇒ Object
-
#initialize(auth = nil) ⇒ Recurring
constructor
A new instance of Recurring.
- #parse_date(date) ⇒ Object
- #save! ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(auth = nil) ⇒ Recurring
Returns a new instance of Recurring.
7 8 9 10 |
# File 'lib/fastbill/recurring.rb', line 7 def initialize(auth = nil) @auth = auth @is_new = true end |
Instance Attribute Details
#currency_code ⇒ Object
Returns the value of attribute currency_code.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def currency_code @currency_code end |
#customer_costcenter_id ⇒ Object
Returns the value of attribute customer_costcenter_id.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def customer_costcenter_id @customer_costcenter_id end |
#customer_id ⇒ Object
Returns the value of attribute customer_id.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def customer_id @customer_id end |
#delivery_date ⇒ Object
Returns the value of attribute delivery_date.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def delivery_date @delivery_date end |
#email_notify ⇒ Object
Returns the value of attribute email_notify.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def email_notify @email_notify end |
#eu_delivery ⇒ Object
Returns the value of attribute eu_delivery.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def eu_delivery @eu_delivery end |
#frequency ⇒ Object
Returns the value of attribute frequency.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def frequency @frequency end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def id @id end |
#introtext ⇒ Object
Returns the value of attribute introtext.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def introtext @introtext end |
#invoice_items ⇒ Object
Returns the value of attribute invoice_items.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def invoice_items @invoice_items end |
#invoice_number ⇒ Object
Returns the value of attribute invoice_number.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def invoice_number @invoice_number end |
#invoice_type ⇒ Object
Returns the value of attribute invoice_type.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def invoice_type @invoice_type end |
#is_new ⇒ Object
Returns the value of attribute is_new.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def is_new @is_new end |
#occurences ⇒ Object
Returns the value of attribute occurences.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def occurences @occurences end |
#output_type ⇒ Object
Returns the value of attribute output_type.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def output_type @output_type end |
#start_date ⇒ Object
Returns the value of attribute start_date.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def start_date @start_date end |
#template_id ⇒ Object
Returns the value of attribute template_id.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def template_id @template_id end |
#vat_items ⇒ Object
Returns the value of attribute vat_items.
5 6 7 |
# File 'lib/fastbill/recurring.rb', line 5 def vat_items @vat_items end |
Instance Method Details
#delete! ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/fastbill/recurring.rb', line 84 def delete! = { :basic_auth => @auth, :headers => { "Content-Type" => "application/xml" }, :body => '<?xml version="1.0" encoding="utf-8"?><FBAPI><SERVICE>recurring.delete</SERVICE><DATA><INVOICE_ID>' + @id + '</INVOICE_ID></DATA></FBAPI>' } r = self.class.post('/api/0.1/api.php', ) body = Crack::XML.parse r.body if !body['FBAPI']["RESPONSE"]["STATUS"].nil? && body['FBAPI']["RESPONSE"]["STATUS"] == "success" true else false end end |
#get(id = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fastbill/recurring.rb', line 12 def get(id = nil) body = '<?xml version="1.0" encoding="utf-8"?><FBAPI><SERVICE>recurring.get</SERVICE>' if id body = body + "<FILTER><INVOICE_ID>#{id}</INVOICE_ID></FILTER>" end body = body + "</FBAPI>" = { :basic_auth => @auth, :headers => { "Content-Type" => "application/xml" }, :body => body } r = self.class.post('/api/0.1/api.php', ) body = Crack::XML.parse r.body invoices = [] if body['FBAPI']["RESPONSE"]["INVOICES"]["INVOICE"].class.to_s == 'Hash' inv = Recurring.new(@auth) inv.hydrate(body['FBAPI']["RESPONSE"]["INVOICES"]["INVOICE"]) invoices.push inv else for invoice in body['FBAPI']["RESPONSE"]["INVOICES"]["INVOICE"].each inv = Recurring.new(@auth) inv.hydrate(invoice) invoices.push inv end end invoices end |
#hydrate(body) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/fastbill/recurring.rb', line 154 def hydrate(body) @is_new = false @id = body["INVOICE_ID"] @invoice_type = body["INVOICE_TYPE"] @customer_id = body["CUSTOMER_ID"] @customer_costcenter_id = body["CUSTOMER_COSTCENTER_ID"] @currency_code = body["CURRENCY_CODE"] @template_id = body["TEMPLATE_ID"] @occurances = body["OCCURANCES"] @frequency = body["FREQUENCY"] @start_date = parse_date body["START_DATE"] @email_notify = body["EMAIL_NOTIFY"] @output_type = body["OUTPUT_TYPE"] @introtext = body["INTROTEXT"] #@delivery_date = parse_date body["DELIVERY_DATE"] @sub_total = body["SUB_TOTAL"] @vat_total = body["VAT_TOTAL"] #@eu_delivery = body["EU_DELIVERY"] == "1" ? true : false @vat_items = [] @total = body["TOTAL"] for vat_item in body["VAT_ITEMS"].each @vat_items.push InvoiceVatItem.new vat_item.last end @invoice_items = [] for item in body["ITEMS"].each begin i = InvoiceItem.new(@auth) i.hydrate(item.last) @invoice_items.push i rescue end end end |
#parse_date(date) ⇒ Object
187 188 189 190 191 192 193 |
# File 'lib/fastbill/recurring.rb', line 187 def parse_date(date) if date != nil && date != "0000-00-00 00:00:00" Time.parse date else false end end |
#save! ⇒ Object
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fastbill/recurring.rb', line 41 def save! if @is_new #create = { :basic_auth => @auth, :headers => { "Content-Type" => "application/xml" }, :body => '<?xml version="1.0" encoding="utf-8"?><FBAPI><SERVICE>recurring.create</SERVICE><DATA>' + self.to_xml + '</DATA></FBAPI>' } r = self.class.post('/api/0.1/api.php', ) body = Crack::XML.parse r.body if !body['FBAPI']["RESPONSE"]["STATUS"].nil? && body['FBAPI']["RESPONSE"]["STATUS"] == "success" unless body['FBAPI']["RESPONSE"]["STATUS"]["INVOICE_ID"].nil? @id = body['FBAPI']["RESPONSE"]["STATUS"]["INVOICE_ID"] end @is_new = false self else false end else #update = { :basic_auth => @auth, :headers => { "Content-Type" => "application/xml" }, :body => '<?xml version="1.0" encoding="utf-8"?><FBAPI><SERVICE>recurring.update</SERVICE><DATA>' + self.to_xml + '</DATA></FBAPI>' } r = self.class.post('/api/0.1/api.php', ) body = Crack::XML.parse r.body if !body['FBAPI']["RESPONSE"]["STATUS"].nil? && body['FBAPI']["RESPONSE"]["STATUS"] == "success" unless body['FBAPI']["RESPONSE"]["STATUS"]["INVOICE_ID"].nil? @id = body['FBAPI']["RESPONSE"]["STATUS"]["INVOICE_ID"] end @is_new = false self else false end end end |
#to_xml ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/fastbill/recurring.rb', line 100 def to_xml xml = "" unless @id.nil? xml = xml + "<INVOICE_ID>#{@id}</INVOICE_ID>" end unless @customer_id.nil? xml = xml + "<CUSTOMER_ID>#{@customer_id}</CUSTOMER_ID>" end unless @customer_costcenter_id.nil? xml = xml + "<CUSTOMER_COSTCENTER_ID>#{@customer_costcenter_id}</CUSTOMER_COSTCENTER_ID>" end unless @currency_code.nil? xml = xml + "<CURRENCY_CODE>#{@currency_code}</CURRENCY_CODE>" end unless @template_id.nil? xml = xml + "<TEMPLATE_ID>#{@template_id}</TEMPLATE_ID>" end unless @invoice_number.nil? xml = xml + "<INVOICE_NUMBER>#{@invoice_number}</INVOICE_NUMBER>" end unless @introtext.nil? xml = xml + "<INTROTEXT>#{@introtext}</INTROTEXT>" end if @start_date xml = xml + "<START_DATE>#{@start_date.strftime("%Y-%m-%d")}</START_DATE>" end unless @frequency.nil? xml = xml + "<FREQUENCY>#{@frequency}</FREQUENCY>" end unless @occurrences.nil? xml = xml + "<OCCURENCES>#{@occurences}</OCCURENCES>" end unless @output_type.nil? xml = xml + "<OUTPUT_TYPE>#{@output_type}</OUTPUT_TYPE>" end unless @email_notify.nil? xml = xml + "<EMAIL_NOTIFY>#{@email_notify}</EMAIL_NOTIFY>" end unless @delivery_date.nil? xml = xml + "<DELIVERY_DATE>#{@delivery_date.strftime("%Y-%m-%d")}</DELIVERY_DATE>" end unless @eu_delivery.nil? eu = @eu_delivery ? 1 : 0 xml = xml + "<EU_DELIVERY>#{@eu}</EU_DELIVERY>" end unless @invoice_items.length == 0 xml = xml + "<ITEMS>" for item in @invoice_items.each xml = xml + item.to_xml end xml = xml + "</ITEMS>" end xml end |