Class: PapierkramApi::V1::Endpoints::Income::Invoices
- Defined in:
- lib/papierkram_api/v1/endpoints/income/invoices.rb
Overview
This class is responsible for all the API calls related to income invoices.
Constant Summary collapse
- ALLOWED_SEND_VIA =
%i[email pdf].freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#all(page: 1, page_size: 100, order_by: nil, order_direction: nil, creditor_id: nil, project_id: nil, document_date_range_start: nil, document_date_range_end: nil) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #archive_by(id:) ⇒ Object
- #cancel_by(id:) ⇒ Object
-
#create(name:, line_items:, payment_term_id:, description: nil, flagged: nil, document_date: nil, supply_date: nil, customer_id: nil, contact_person_id: nil, project_id: nil, custom_template_id: nil, billing_company: nil, billing_department: nil, billing_contact_person: nil, billing_street: nil, billing_zip: nil, billing_city: nil, billing_country: nil, billing_ust_idnr: nil, billing_email: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
- #delete_by(id:) ⇒ Object
-
#deliver_by(id:, email_recipient: nil, email_subject: nil, email_body: nil, send_via: :pdf) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #find_by(id:, pdf: false) ⇒ Object
- #unarchive_by(id:) ⇒ Object
-
#update_by(id:, name: nil, line_items: nil, payment_term_id: nil, description: nil, flagged: nil, document_date: nil, supply_date: nil, customer_id: nil, contact_person_id: nil, project_id: nil, custom_template_id: nil, billing_company: nil, billing_department: nil, billing_contact_person: nil, billing_street: nil, billing_zip: nil, billing_city: nil, billing_country: nil, billing_ust_idnr: nil, billing_email: nil) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/ParameterLists.
Methods inherited from Base
#http_delete, #http_get, #http_patch, #http_post, #http_put, #initialize, #remaining_quota
Constructor Details
This class inherits a constructor from PapierkramApi::V1::Endpoints::Base
Instance Method Details
#all(page: 1, page_size: 100, order_by: nil, order_direction: nil, creditor_id: nil, project_id: nil, document_date_range_start: nil, document_date_range_end: nil) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/papierkram_api/v1/endpoints/income/invoices.rb', line 23 def all( # rubocop:disable Metrics/CyclomaticComplexity page: 1, page_size: 100, order_by: nil, order_direction: nil, creditor_id: nil, project_id: nil, document_date_range_start: nil, document_date_range_end: nil ) query = { page: page, page_size: page_size } query[:order_by] = order_by if order_by query[:order_direction] = order_direction if order_direction query[:creditor_id] = creditor_id if creditor_id query[:project_id] = project_id if project_id query[:document_date_range_start] = document_date_range_start if document_date_range_start if document_date_range_end && document_date_range_start query[:document_date_range_end] = document_date_range_end end http_get("#{@url_api_path}/income/invoices", query) end |
#archive_by(id:) ⇒ Object
180 181 182 |
# File 'lib/papierkram_api/v1/endpoints/income/invoices.rb', line 180 def archive_by(id:) http_post("#{@url_api_path}/income/invoices/#{id}/archive") end |
#cancel_by(id:) ⇒ Object
188 189 190 |
# File 'lib/papierkram_api/v1/endpoints/income/invoices.rb', line 188 def cancel_by(id:) http_post("#{@url_api_path}/income/invoices/#{id}/cancel") end |
#create(name:, line_items:, payment_term_id:, description: nil, flagged: nil, document_date: nil, supply_date: nil, customer_id: nil, contact_person_id: nil, project_id: nil, custom_template_id: nil, billing_company: nil, billing_department: nil, billing_contact_person: nil, billing_street: nil, billing_zip: nil, billing_city: nil, billing_country: nil, billing_ust_idnr: nil, billing_email: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/papierkram_api/v1/endpoints/income/invoices.rb', line 50 def create( # rubocop:disable Metrics/ParameterLists,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity name:, line_items:, payment_term_id:, description: nil, flagged: nil, document_date: nil, supply_date: nil, customer_id: nil, contact_person_id: nil, project_id: nil, custom_template_id: nil, billing_company: nil, billing_department: nil, billing_contact_person: nil, billing_street: nil, billing_zip: nil, billing_city: nil, billing_country: nil, billing_ust_idnr: nil, billing_email: nil ) body = {} body[:name] = name body[:line_items] = line_items body[:payment_term] = { id: payment_term_id } body[:description] = description if description body[:flagged] = flagged if flagged body[:document_date] = document_date if document_date body[:supply_date] = supply_date if supply_date body[:customer] = { id: customer_id } if customer_id body[:customer][:contact_person] = { id: contact_person_id } if contact_person_id body[:customer][:project] = { id: project_id } if project_id body[:custom_template] = { id: custom_template_id } if custom_template_id body[:billing] = {} body[:billing][:company] = billing_company if billing_company body[:billing][:department] = billing_department if billing_department body[:billing][:contact_person] = billing_contact_person if billing_contact_person body[:billing][:street] = billing_street if billing_street body[:billing][:zip] = billing_zip if billing_zip body[:billing][:city] = billing_city if billing_city body[:billing][:country] = billing_country if billing_country body[:billing][:ust_idnr] = billing_ust_idnr if billing_ust_idnr body[:billing][:email] = billing_email if billing_email http_post("#{@url_api_path}/income/invoices", body) end |
#delete_by(id:) ⇒ Object
176 177 178 |
# File 'lib/papierkram_api/v1/endpoints/income/invoices.rb', line 176 def delete_by(id:) http_delete("#{@url_api_path}/income/invoices/#{id}") end |
#deliver_by(id:, email_recipient: nil, email_subject: nil, email_body: nil, send_via: :pdf) ⇒ Object
rubocop:disable Metrics/AbcSize
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/papierkram_api/v1/endpoints/income/invoices.rb', line 149 def deliver_by( # rubocop:disable Metrics/AbcSize id:, email_recipient: nil, email_subject: nil, email_body: nil, send_via: :pdf ) raise ArgumentError, 'send_via must be :email or :pdf' unless ALLOWED_SEND_VIA.include?(send_via) body = {} body[:send_via] = send_via if send_via == :email if email_recipient.nil? || email_subject.nil? || email_body.nil? raise ArgumentError, 'email_recipient, email_subject and email_body must be set' end body[:email] = {} body[:email][:recipient] = email_recipient body[:email][:subject] = email_subject body[:email][:body] = email_body end http_post("#{@url_api_path}/income/invoices/#{id}/deliver", body) end |
#find_by(id:, pdf: false) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/papierkram_api/v1/endpoints/income/invoices.rb', line 11 def find_by(id:, pdf: false) if pdf == true return http_get( "#{@url_api_path}/income/invoices/#{id}/pdf", nil, { headers: { 'Content-Type' => 'application/pdf' } } ) end http_get("#{@url_api_path}/income/invoices/#{id}") end |
#unarchive_by(id:) ⇒ Object
184 185 186 |
# File 'lib/papierkram_api/v1/endpoints/income/invoices.rb', line 184 def unarchive_by(id:) http_post("#{@url_api_path}/income/invoices/#{id}/unarchive") end |
#update_by(id:, name: nil, line_items: nil, payment_term_id: nil, description: nil, flagged: nil, document_date: nil, supply_date: nil, customer_id: nil, contact_person_id: nil, project_id: nil, custom_template_id: nil, billing_company: nil, billing_department: nil, billing_contact_person: nil, billing_street: nil, billing_zip: nil, billing_city: nil, billing_country: nil, billing_ust_idnr: nil, billing_email: nil) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/ParameterLists
99 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 |
# File 'lib/papierkram_api/v1/endpoints/income/invoices.rb', line 99 def update_by( # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/ParameterLists id:, name: nil, line_items: nil, payment_term_id: nil, description: nil, flagged: nil, document_date: nil, supply_date: nil, customer_id: nil, contact_person_id: nil, project_id: nil, custom_template_id: nil, billing_company: nil, billing_department: nil, billing_contact_person: nil, billing_street: nil, billing_zip: nil, billing_city: nil, billing_country: nil, billing_ust_idnr: nil, billing_email: nil ) body = {} body[:name] = name if name body[:line_items] = line_items if line_items body[:payment_term] = { id: payment_term_id } if payment_term_id body[:description] = description if description body[:flagged] = flagged if flagged body[:document_date] = document_date if document_date body[:supply_date] = supply_date if supply_date body[:customer] = { id: customer_id } if customer_id body[:customer][:contact_person] = { id: contact_person_id } if contact_person_id body[:customer][:project] = { id: project_id } if project_id body[:custom_template] = { id: custom_template_id } if custom_template_id body[:billing] = {} body[:billing][:company] = billing_company if billing_company body[:billing][:department] = billing_department if billing_department body[:billing][:contact_person] = billing_contact_person if billing_contact_person body[:billing][:street] = billing_street if billing_street body[:billing][:zip] = billing_zip if billing_zip body[:billing][:city] = billing_city if billing_city body[:billing][:country] = billing_country if billing_country body[:billing][:ust_idnr] = billing_ust_idnr if billing_ust_idnr body[:billing][:email] = billing_email if billing_email http_put("#{@url_api_path}/income/invoices/#{id}", body) end |