Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global minorversion #518

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/quickbooks-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
module Quickbooks
@@sandbox_mode = false
@@logger = nil
@@minorversion = 47

class << self
def sandbox_mode
Expand All @@ -201,6 +202,14 @@ def sandbox_mode=(sandbox_mode)
@@sandbox_mode = sandbox_mode
end

def minorversion=(v)
@@minorversion = v
end

def minorversion
@@minorversion
end

def logger
@@logger ||= ::Logger.new($stdout) # TODO: replace with a real log file
end
Expand Down
1 change: 0 additions & 1 deletion lib/quickbooks/model/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Account < BaseModel
XML_COLLECTION_NODE = "Account"
XML_NODE = "Account"
REST_RESOURCE = 'account'
MINORVERSION = 13

ASSET = 'Asset'
EQUITY = 'Equity'
Expand Down
2 changes: 0 additions & 2 deletions lib/quickbooks/model/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class Customer < BaseModel
include NameEntity::Quality
include NameEntity::PermitAlterations

MINORVERSION = 33

xml_name XML_NODE
xml_accessor :id, :from => 'Id'
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
Expand Down
1 change: 0 additions & 1 deletion lib/quickbooks/model/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Invoice < BaseModel
XML_COLLECTION_NODE = "Invoice"
XML_NODE = "Invoice"
EMAIL_STATUS_NEED_TO_SEND = 'NeedToSend'
MINORVERSION = 37

xml_accessor :id, :from => 'Id'
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
Expand Down
1 change: 0 additions & 1 deletion lib/quickbooks/model/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Item < BaseModel
XML_COLLECTION_NODE = "Item"
XML_NODE = "Item"
REST_RESOURCE = 'item'
MINORVERSION = 47

INVENTORY_TYPE = 'Inventory'
NON_INVENTORY_TYPE = 'NonInventory'
Expand Down
1 change: 0 additions & 1 deletion lib/quickbooks/model/preferences.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Preferences < BaseModel
XML_COLLECTION_NODE = "Preferences"
XML_NODE = "Preferences"
REST_RESOURCE = 'preferences'
MINORVERSION = 32

xml_name XML_NODE

Expand Down
1 change: 0 additions & 1 deletion lib/quickbooks/model/purchase_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class PurchaseOrder < BaseModel
REST_RESOURCE = 'purchaseorder'
XML_COLLECTION_NODE = "PurchaseOrder"
XML_NODE = "PurchaseOrder"
MINORVERSION = 45

xml_accessor :id, :from => 'Id'
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
Expand Down
3 changes: 2 additions & 1 deletion lib/quickbooks/service/access_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def renew
def disconnect
conn = Faraday.new
conn.basic_auth oauth.client.id, oauth.client.secret
response = conn.post(DISCONNECT_URL, token: oauth.refresh_token || oauth.token)
url = "#{DISCONNECT_URL}?minorversion=#{Quickbooks.minorversion}"
response = conn.post(url, token: oauth.refresh_token || oauth.token)

if response.success?
Quickbooks::Model::AccessTokenResponse.new(error_code: "0")
Expand Down
5 changes: 0 additions & 5 deletions lib/quickbooks/service/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ def delete(account)
update(account, :sparse => true)
end

def url_for_query(query = nil, start_position = 1, max_results = 20, options = {})
url = super(query, start_position, max_results, options)
"#{url}&minorversion=#{Quickbooks::Model::Account::MINORVERSION}"
end

private

def model
Expand Down
6 changes: 5 additions & 1 deletion lib/quickbooks/service/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ def do_http_file_upload(uploadIO, url, metadata = nil)
body['file_metadata_0'] = param_part
end

url = add_query_string_to_url(url, {})

do_http(:upload, url, body, headers)
end

Expand Down Expand Up @@ -292,7 +294,9 @@ def oauth_post_with_multipart(url, body, headers)
@oauth.post_with_multipart(url, headers: headers, body: body, raise_errors: false)
end

def add_query_string_to_url(url, params)
def add_query_string_to_url(url, params = {})
params ||= {}
params['minorversion'] = Quickbooks.minorversion
if params.is_a?(Hash) && !params.empty?
keyvalues = params.collect { |k| "#{k.first}=#{k.last}" }.join("&")
delim = url.index("?") != nil ? "&" : "?"
Expand Down
12 changes: 1 addition & 11 deletions lib/quickbooks/service/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,11 @@ def delete(customer)
update(customer, :sparse => true)
end

def url_for_resource(resource)
url = super(resource)
"#{url}?minorversion=#{Quickbooks::Model::Customer::MINORVERSION}"
end

def fetch_by_id(id, params = {})
url = "#{url_for_base}/customer/#{id}?minorversion=#{Quickbooks::Model::Customer::MINORVERSION}"
url = "#{url_for_base}/customer/#{id}"
fetch_object(model, url, params)
end

def url_for_query(query = nil, start_position = 1, max_results = 20, options = {})
url = super(query, start_position, max_results, options)
"#{url}&minorversion=#{Quickbooks::Model::Customer::MINORVERSION}"
end

private

def model
Expand Down
11 changes: 1 addition & 10 deletions lib/quickbooks/service/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,11 @@ def delete(invoice)
delete_by_query_string(invoice)
end

def url_for_resource(resource)
url = super(resource)
end

def fetch_by_id(id, params = {})
url = "#{url_for_base}/invoice/#{id}?minorversion=#{Quickbooks::Model::Invoice::MINORVERSION}"
url = "#{url_for_base}/invoice/#{id}"
fetch_object(model, url, params)
end

def url_for_query(query = nil, start_position = 1, max_results = 20, options = {})
url = super(query, start_position, max_results, options)
"#{url}&minorversion=#{Quickbooks::Model::Invoice::MINORVERSION}"
end

def send(invoice, email_address=nil)
query = email_address.present? ? "?sendTo=#{email_address}" : ""
url = "#{url_for_resource(model::REST_RESOURCE)}/#{invoice.id}/send#{query}"
Expand Down
12 changes: 1 addition & 11 deletions lib/quickbooks/service/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,11 @@ def delete(item)
update(item, :sparse => true)
end

def url_for_resource(resource)
url = super(resource)
"#{url}?minorversion=#{Quickbooks::Model::Item::MINORVERSION}"
end

def fetch_by_id(id, params = {})
url = "#{url_for_base}/item/#{id}?minorversion=#{Quickbooks::Model::Item::MINORVERSION}"
url = "#{url_for_base}/item/#{id}"
fetch_object(model, url, params)
end

def url_for_query(query = nil, start_position = 1, max_results = 20, options = {})
url = super(query, start_position, max_results, options)
"#{url}&minorversion=#{Quickbooks::Model::Item::MINORVERSION}"
end

private

def model
Expand Down
5 changes: 0 additions & 5 deletions lib/quickbooks/service/preferences.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ module Quickbooks
module Service
class Preferences < BaseService

def url_for_query(query = nil, start_position = 1, max_results = 20, options = {})
url = super(query, start_position, max_results, options)
"#{url}&minorversion=#{Quickbooks::Model::Preferences::MINORVERSION}"
end

private

def model
Expand Down
2 changes: 1 addition & 1 deletion lib/quickbooks/service/service_crud_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def fetch_by_id(id, params = {})

def create(entity, options = {})
raise Quickbooks::InvalidModelException.new(entity.errors.full_messages.join(',')) unless entity.valid?
response = do_http(:post, url_for_resource(model.resource_for_singular), entity.to_json, options)
response = do_http_post(url_for_resource(model.resource_for_singular), entity.to_json, options)
if response.code.to_i == 200
JSON.parse(response.plain_body)
else
Expand Down
1 change: 1 addition & 0 deletions spec/lib/quickbooks/service/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

it "can query for accounts" do
xml = fixture("accounts.xml")

stub_http_request(:get, @service.url_for_query, ["200", "OK"], xml, {}, true)

accounts = @service.query
Expand Down
9 changes: 6 additions & 3 deletions spec/lib/quickbooks/service/base_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@
end

it "calls before_request" do
v = Quickbooks.minorversion
output_string = "BEFORE REQUEST:\nurl: https://quickbooks.api.intuit.com/v3/company/9991111222/query?query=SE"\
"LECT+%2A+FROM+Vendor+STARTPOSITION+1+MAXRESULTS+20\nheaders: {\"Content-Type\"=>\"applicatio"\
"LECT+%2A+FROM+Vendor+STARTPOSITION+1+MAXRESULTS+20&minorversion=#{v}\nheaders: {\"Content-Type\"=>\"applicatio"\
"n/xml\", \"Accept\"=>\"application/xml\", \"Accept-Encoding\"=>\"gzip, deflate\"}\nbody: {}"\
"\nmethod: get\n"

Expand All @@ -247,8 +248,9 @@
end

it "calls after_request" do
v = Quickbooks.minorversion
output_string = "AFTER REQUEST:\nurl: https://quickbooks.api.intuit.com/v3/company/9991111222/query?query=SEL"\
"ECT+%2A+FROM+Vendor+STARTPOSITION+1+MAXRESULTS+20\nheaders: {\"Content-Type\"=>\"application"\
"ECT+%2A+FROM+Vendor+STARTPOSITION+1+MAXRESULTS+20&minorversion=#{v}\nheaders: {\"Content-Type\"=>\"application"\
"/xml\", \"Accept\"=>\"application/xml\", \"Accept-Encoding\"=>\"gzip, deflate\", \"Authoriza"\
"tion\"=>\"Bearer token\"}\nbody: {}\nmethod: get\nresponse: <IntuitResponse xmlns=\"http://s"\
"chema.intuit.com/finance/v3\" time=\"2013-04-23T08:55:53.298-07:00\">\n<QueryResponse startP"\
Expand Down Expand Up @@ -296,8 +298,9 @@
end

it "calls around_request" do
v = Quickbooks.minorversion
output_string = "AROUND REQUEST (BEFORE CALL):\nurl: https://quickbooks.api.intuit.com/v3/company/9991111222/"\
"query?query=SELECT+%2A+FROM+Vendor+STARTPOSITION+1+MAXRESULTS+20\nheaders: {\"Content-Type\""\
"query?query=SELECT+%2A+FROM+Vendor+STARTPOSITION+1+MAXRESULTS+20&minorversion=#{v}\nheaders: {\"Content-Type\""\
"=>\"application/xml\", \"Accept\"=>\"application/xml\", \"Accept-Encoding\"=>\"gzip, deflate"\
"\"}\nbody: {}\nmethod: get\nAROUND REQUEST (AFTER CALL):\nresponse: <IntuitResponse xmlns=\""\
"http://schema.intuit.com/finance/v3\" time=\"2013-04-23T08:55:53.298-07:00\">\n<QueryRespons"\
Expand Down
4 changes: 3 additions & 1 deletion spec/lib/quickbooks/service/customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
it "can fetch a customer by ID" do
xml = fixture("fetch_customer_by_id.xml")
model = Quickbooks::Model::Customer
stub_http_request(:get, "#{@service.url_for_base}/customer/1?minorversion=#{Quickbooks::Model::Customer::MINORVERSION}", ["200", "OK"], xml)

url = "#{@service.url_for_base}/customer/1"
stub_http_request(:get, url, ["200", "OK"], xml)

customer = @service.fetch_by_id(1)
expect(customer.fully_qualified_name).to eq("Thrifty Meats")
Expand Down
15 changes: 11 additions & 4 deletions spec/lib/quickbooks/service/invoice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
xml = fixture("invoices.xml")
model = Quickbooks::Model::Invoice

stub_http_request(:get, @service.url_for_query, ["200", "OK"], xml)
url = @service.url_for_query
stub_http_request(:get, url, ["200", "OK"], xml)
invoices = @service.query
expect(invoices.entries.count).to eq 1

Expand All @@ -18,7 +19,10 @@
it "can fetch an Invoice by ID" do
xml = fixture("fetch_invoice_by_id.xml")
model = Quickbooks::Model::Invoice
stub_http_request(:get, %r{#{@service.url_for_resource(model::REST_RESOURCE)}/1}, ["200", "OK"], xml)

url = "#{@service.url_for_base}/invoice/1"
stub_http_request(:get, url, ["200", "OK"], xml)

invoice = @service.fetch_by_id(1)
expect(invoice.doc_number).to eq "1001"
end
Expand Down Expand Up @@ -247,7 +251,9 @@

it "can read line items from a bundle" do
xml = fixture("invoice_with_bundle_line_item.xml")
stub_http_request(:get, %r{#{@service.url_for_resource(Quickbooks::Model::Invoice::REST_RESOURCE)}/186}, ["200", "OK"], xml)
url = "#{@service.url_for_base}/invoice/186"

stub_http_request(:get, url, ["200", "OK"], xml)
invoice = @service.fetch_by_id(186)
expect(invoice.valid?).to be true

Expand Down Expand Up @@ -290,7 +296,8 @@

it "can sparse update an Invoice containing a bundle" do
xml = fixture("invoice_with_bundle_line_item.xml")
stub_http_request(:get, %r{#{@service.url_for_resource(Quickbooks::Model::Invoice::REST_RESOURCE)}/186}, ["200", "OK"], xml)
url = "#{@service.url_for_base}/invoice/186"
stub_http_request(:get, url, ["200", "OK"], xml)
invoice = @service.fetch_by_id(186)

invoice.line_items.each do |l|
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/quickbooks/service/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
it "can fetch an Item by ID" do
xml = fixture("fetch_item_by_id.xml")
model = Quickbooks::Model::Item
stub_http_request(:get, "#{@service.url_for_base}/item/2?minorversion=#{Quickbooks::Model::Item::MINORVERSION}", ["200", "OK"], xml)
stub_http_request(:get, "#{@service.url_for_base}/item/2", ["200", "OK"], xml)
item = @service.fetch_by_id(2)
expect(item.name).to eq("Plush Baby Doll")
end
Expand Down Expand Up @@ -52,7 +52,7 @@
xml = fixture("fetch_item_by_id.xml")
model = Quickbooks::Model::Item

url = "#{@service.url_for_resource(model::REST_RESOURCE)}&requestid=123"
url = "#{@service.url_for_resource(model::REST_RESOURCE)}?requestid=123"
stub_http_request(:post, url, ["200", "OK"], xml)

item = Quickbooks::Model::Item.new
Expand Down
7 changes: 5 additions & 2 deletions spec/lib/quickbooks/service/purchase_order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
construct_service :purchase_order
end

it "can delete a vendor" do
it "can delete a purchase order" do
model = Quickbooks::Model::PurchaseOrder
purchase_order = model.new
xml = fixture("deleted_purchase_order.xml")
stub_http_request(:post, %r{#{@service.url_for_resource(model::REST_RESOURCE)}}, ["200", "OK"], xml, {}, false)

url = "#{@service.url_for_resource(model::REST_RESOURCE)}?operation=delete"

stub_http_request(:post, url, ["200", "OK"], xml, {}, false)
expect(@service.delete(purchase_order)).to eq true

end
Expand Down
8 changes: 8 additions & 0 deletions spec/support/net_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
module NetHelpers
def stub_http_request(method, url, status = ["200", "OK"], body = nil, headers = {}, strict = true)
unless url.index('minorversion')
if url.index('?')
url = "#{url}&minorversion=#{Quickbooks.minorversion}"
else
url = "#{url}?minorversion=#{Quickbooks.minorversion}"
end
end
#puts "URL: #{url}"
stub_request(method, url).to_return(body: body, status: status)
end
end
Expand Down