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

Added CDC for Item #222

Merged
merged 4 commits into from
Feb 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,19 +456,29 @@ changed = service.since(Time.now.utc - 5 days)

see: https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/change_data_capture for more information.

##Change Data Capture For Customers and Vendors
##Change Data Capture For Customers, Vendors and Items

It is possible to find out which Customer or Vendor Entries has recently changed.
It is possible to find out which Customer, Vendor or Item Entries has recently changed.
It is possible to request changes up to 30 days ago.

```ruby
customer_service = Quickbooks::Service::CustomerChange.new
...
customer_changed = customer_service.since(Time.now.utc - 5 days)
```

```ruby
vendor_service = Quickbooks::Service::VendorChange.new
...
vendor_changed = vendor_service.since(Time.now.utc - 5 days)
```

```ruby
item_service = Quickbooks::Service::ItemChange.new
...
item_changed = item_service.since(Time.now.utc - 5 days)
```



see: https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/change_data_capture for more information.
Expand Down
2 changes: 2 additions & 0 deletions lib/quickbooks-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
require 'quickbooks/model/invoice_change'
require 'quickbooks/model/customer_change'
require 'quickbooks/model/vendor_change'
require 'quickbooks/model/item_change'


#== Services
Expand Down Expand Up @@ -125,6 +126,7 @@
require 'quickbooks/service/invoice_change'
require 'quickbooks/service/customer_change'
require 'quickbooks/service/vendor_change'
require 'quickbooks/service/item_change'

module Quickbooks
@@sandbox_mode = false
Expand Down
12 changes: 12 additions & 0 deletions lib/quickbooks/model/item_change.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Quickbooks
module Model
# Refer to: https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/change_data_capture
class ItemChange < BaseModel
XML_NODE = "Item"

xml_accessor :id, :from => 'Id', :as => Integer
xml_accessor :status, :from => '@status'
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
end
end
end
23 changes: 23 additions & 0 deletions lib/quickbooks/service/item_change.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Quickbooks
module Service
class ItemChange < BaseService

def url_for_query(query = nil, start_position = 1, max_results = 20)
q = "Item"
q = "#{q}&#{query}" if query.present?

"#{url_for_base}/cdc?entities=#{q}"
end

def since(timestamp)
query("changedSince=#{URI.encode_www_form_component(timestamp.iso8601)}")
end

private

def model
Quickbooks::Model::ItemChange
end
end
end
end
6 changes: 6 additions & 0 deletions spec/fixtures/item_change.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Item domain="QBO" status="Deleted">
<Id>39</Id>
<MetaData>
<LastUpdatedTime>2014-12-08T19:36:24-08:00</LastUpdatedTime>
</MetaData>
</Item>
12 changes: 12 additions & 0 deletions spec/fixtures/item_changes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-12-08T19:36:36.977-08:00">
<CDCResponse>
<QueryResponse maxResults="1" totalCount="1">
<Item domain="QBO" status="Deleted">
<Id>39</Id>
<MetaData>
<LastUpdatedTime>2014-12-08T19:36:24-08:00</LastUpdatedTime>
</MetaData>
</Item>
</QueryResponse>
</CDCResponse>
</IntuitResponse>
13 changes: 13 additions & 0 deletions spec/lib/quickbooks/model/item_change_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'nokogiri'

describe "Quickbooks::Model::ItemChange" do
it "parse from XML" do
xml = fixture("item_change.xml")
item = Quickbooks::Model::ItemChange.from_xml(xml)
item.status.should == 'Deleted'
item.id.should == 39

item.meta_data.should_not be_nil
item.meta_data.last_updated_time.should == DateTime.parse("2014-12-08T19:36:24-08:00")
end
end
22 changes: 22 additions & 0 deletions spec/lib/quickbooks/service/item_change_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe "Quickbooks::Service::ItemChange" do
before(:all) do
construct_service :item_change
end

it "can query for items" do
xml = fixture("item_changes.xml")
model = Quickbooks::Model::ItemChange

stub_request(:get, @service.url_for_query, ["200", "OK"], xml)
items = @service.query
items.entries.count.should == 1

first_item = items.entries.first
first_item.status.should == 'Deleted'
first_item.id.should == 39

first_item.meta_data.should_not be_nil
first_item.meta_data.last_updated_time.should == DateTime.parse("2014-12-08T19:36:24-08:00")
end

end