Skip to content

Commit

Permalink
* Implemented a global MINORVERSION; see #517
Browse files Browse the repository at this point in the history
* QueryBuilder refactor for handling argument values of all types (not just strings). Thank you @jethrodaniel
  • Loading branch information
ruckus committed May 27, 2020
1 parent 54f4c69 commit e76e9db
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 58 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.9 (2020-05-27)

* Implemented a global MINORVERSION; see https://github.com/ruckus/quickbooks-ruby/issues/517
* QueryBuilder refactor for handling argument values of all types (not just strings). Thank you @jethrodaniel

## 1.0.8 (2020-05-14)

* Added ClassRef attribute to Item model; bumped minorversion to 47 (required for Item#ClassRef)
Expand Down
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
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
2 changes: 1 addition & 1 deletion lib/quickbooks/service/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def url_for_query(query = nil, start_position = 1, max_results = 20, options = {
query ||= default_model_query
query = "#{query} STARTPOSITION #{start_position} MAXRESULTS #{max_results}"

"#{url_for_base}/query?query=#{CGI.escape(query)}"
"#{url_for_base}/query?query=#{CGI.escape(query)}&minorversion=#{Quickbooks.minorversion}"
end

private
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/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Quickbooks

VERSION = "1.0.8"
VERSION = "1.0.9"

end
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
3 changes: 2 additions & 1 deletion 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}&minorversion=#{Quickbooks.minorversion}"
stub_http_request(:get, url, ["200", "OK"], xml)
invoices = @service.query
expect(invoices.entries.count).to eq 1

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

0 comments on commit e76e9db

Please sign in to comment.