Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'jimmytang-api_update'

  • Loading branch information...
commit b0041e4f1ea3c18b46c7c2c9187aaca7f2e1c347 2 parents 436ad3a + bb68736
Jimmy Tang authored
View
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in rshoeboxed.gemspec
+gemspec
View
2  Rakefile
@@ -9,7 +9,7 @@ $hoe = Hoe.new('rshoeboxed', RShoeboxed::VERSION) do |p|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
p.rubyforge_name = p.name # TODO this is default value
p.extra_deps = [
- ['builder','>= 2.1.2'],
+ ['builder','~> 2.1.2'],
]
p.extra_dev_deps = [
['newgem', ">= #{::Newgem::VERSION}"],
View
4 lib/rshoeboxed/connection.rb
@@ -1,5 +1,3 @@
-gem "builder"
-require "builder"
require "cgi"
require "net/https"
require 'rexml/document'
@@ -221,4 +219,4 @@ def append_credentials(xml)
end
end
end
-end
+end
View
31 lib/rshoeboxed/receipt.rb
@@ -4,9 +4,8 @@
module RShoeboxed
class Receipt
- attr_accessor :id, :store, :image_url, :categories
- attr_reader :sell_date, :created_date, :modified_date, :total
-
+ attr_accessor :id, :store, :image_url, :categories, :account_currency
+ attr_reader :sell_date, :created_date, :modified_date, :converted_total
def self.parse(xml)
document = REXML::Document.new(xml)
document.elements.collect("//Receipt") do |receipt_element|
@@ -17,9 +16,10 @@ def self.parse(xml)
receipt.sell_date = receipt_element.attributes["selldate"]
receipt.created_date = receipt_element.attributes["createdDate"]
receipt.modified_date = receipt_element.attributes["modifiedDate"]
- receipt.total = receipt_element.attributes["total"]
+ receipt.converted_total = receipt_element.attributes["convertedTotal"]
+ receipt.account_currency = receipt_element.attributes["accountCurrency"]
receipt.image_url = receipt_element.attributes["imgurl"]
-
+
# Get the categories elements and have Category parse them
category_element = receipt_element.elements["Categories"]
receipt.categories = category_element ? Category.parse(category_element.to_s) : []
@@ -29,12 +29,21 @@ def self.parse(xml)
receipt
end
end
+
+ def converted_total=(unprocessed_converted_total)
+ unprocessed_converted_total.gsub!(/[^\d|.]/, "") if unprocessed_converted_total.is_a?(String)
+ unprocessed_converted_total = BigDecimal.new(unprocessed_converted_total) unless unprocessed_converted_total.is_a?(BigDecimal)
+ @converted_total = unprocessed_converted_total
+ end
+
+ def total
+ warn "DEPRECATION WARNING: `total` is deprecated. Please use `converted_total`"
+ converted_total
+ end
- def total=(total)
- total.gsub!(/[^\d|.]/, "") if total.is_a?(String)
- total = BigDecimal.new(total) unless total.is_a?(BigDecimal)
-
- @total = total
+ def total=(unprocessed_converted_total)
+ warn "DEPRECATION WARNING: `total=` is deprecated. Please use `converted_total=`"
+ self.converted_total = unprocessed_converted_total
end
def sell_date=(date)
@@ -56,7 +65,7 @@ def ==(receipt)
self.id == receipt.id && self.store == receipt.store && self.image_url == receipt.image_url &&
self.categories == receipt.categories && self.sell_date == receipt.sell_date &&
self.modified_date == receipt.modified_date && self.created_date == receipt.created_date &&
- self.total == receipt.total
+ self.converted_total == receipt.converted_total && self.account_currency == receipt.account_currency
end
end
end
View
3  lib/rshoeboxed/version.rb
@@ -0,0 +1,3 @@
+module RShoeboxed
+ VERSION = "0.0.8"
+end
View
31 rshoeboxed.gemspec
@@ -1,42 +1,47 @@
# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "rshoeboxed/version"
Gem::Specification.new do |s|
s.name = %q{rshoeboxed}
- s.version = "0.0.7"
+ s.version = RShoeboxed::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Ben Curren"]
+ s.email = ["ben@outright.com"]
+ s.homepage = %q{http://github.com/jimmytang/rshoeboxed}
+ s.summary = %q{Ruby wrapper for the Shoeboxed API.}
+ s.description = %q{Ruby wrapper for the Shoeboxed API.}
+
+ s.rubyforge_project = %q{rshoeboxed}
+
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "lib/rshoeboxed.rb", "lib/rshoeboxed/category.rb", "lib/rshoeboxed/connection.rb", "lib/rshoeboxed/list_proxy.rb", "lib/rshoeboxed/parse_error.rb", "lib/rshoeboxed/receipt.rb", "script/console", "script/destroy", "script/generate", "test/fixtures/category_request.xml", "test/fixtures/category_response.xml", "test/fixtures/receipt_info_request.xml", "test/fixtures/receipt_info_response.xml", "test/fixtures/receipt_request.xml", "test/fixtures/receipt_response.xml", "test/fixtures/receipt_response_bad_credentials.xml", "test/fixtures/receipt_response_internal_error.xml", "test/fixtures/receipt_response_restricted_ip.xml", "test/fixtures/receipt_response_unknown_api_call.xml", "test/fixtures/receipt_response_xml_validation.xml", "test/fixtures/receipt_with_category_id_request.xml", "test/test_category.rb", "test/test_connection.rb", "test/test_helper.rb", "test/test_list_proxy.rb", "test/test_receipt.rb"]
+ s.test_files = ["test/test_category.rb", "test/test_connection.rb", "test/test_helper.rb", "test/test_list_proxy.rb", "test/test_receipt.rb"]
+ s.require_paths = ["lib"]
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Ben Curren"]
s.date = %q{2010-02-15}
- s.description = %q{Ruby wrapper for the Shoeboxed API.}
- s.email = ["ben@gobootstrap.com"]
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
- s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "lib/rshoeboxed.rb", "lib/rshoeboxed/category.rb", "lib/rshoeboxed/connection.rb", "lib/rshoeboxed/list_proxy.rb", "lib/rshoeboxed/parse_error.rb", "lib/rshoeboxed/receipt.rb", "script/console", "script/destroy", "script/generate", "test/fixtures/category_request.xml", "test/fixtures/category_response.xml", "test/fixtures/receipt_info_request.xml", "test/fixtures/receipt_info_response.xml", "test/fixtures/receipt_request.xml", "test/fixtures/receipt_response.xml", "test/fixtures/receipt_response_bad_credentials.xml", "test/fixtures/receipt_response_internal_error.xml", "test/fixtures/receipt_response_restricted_ip.xml", "test/fixtures/receipt_response_unknown_api_call.xml", "test/fixtures/receipt_response_xml_validation.xml", "test/fixtures/receipt_with_category_id_request.xml", "test/test_category.rb", "test/test_connection.rb", "test/test_helper.rb", "test/test_list_proxy.rb", "test/test_receipt.rb"]
s.has_rdoc = true
- s.homepage = %q{http://github.com/bcurren/rshoeboxed}
s.rdoc_options = ["--main", "README.rdoc"]
- s.require_paths = ["lib"]
- s.rubyforge_project = %q{rshoeboxed}
s.rubygems_version = %q{1.3.1}
- s.summary = %q{Ruby wrapper for the Shoeboxed API.}
- s.test_files = ["test/test_category.rb", "test/test_connection.rb", "test/test_helper.rb", "test/test_list_proxy.rb", "test/test_receipt.rb"]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
+ s.add_runtime_dependency(%q<builder>, ["~> 2.1.2"])
s.add_development_dependency(%q<newgem>, [">= 1.1.0"])
s.add_development_dependency(%q<mocha>, [">= 0.9.4"])
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
else
- s.add_dependency(%q<builder>, [">= 2.1.2"])
+ s.add_dependency(%q<builder>, ["~> 2.1.2"])
s.add_dependency(%q<newgem>, [">= 1.1.0"])
s.add_dependency(%q<mocha>, [">= 0.9.4"])
s.add_dependency(%q<hoe>, [">= 1.8.0"])
end
else
- s.add_dependency(%q<builder>, [">= 2.1.2"])
+ s.add_dependency(%q<builder>, ["~> 2.1.2"])
s.add_dependency(%q<newgem>, [">= 1.1.0"])
s.add_dependency(%q<mocha>, [">= 0.9.4"])
s.add_dependency(%q<hoe>, [">= 1.8.0"])
View
14 test/fixtures/receipt_info_response.xml
@@ -1,5 +1,9 @@
-<Receipt store="Morgan Imports" id="1" total="$1,929.00" selldate="5/12/2008" createdDate="4/12/2008" modifiedDate="4/20/2008" imgurl="http://www.shoeboxed.com/receipt.jpeg">
- <Categories>
- <Category name="Category 1" id="1"/>
- </Categories>
-</Receipt>
+<GetReceiptInfoCallResponse>
+ <Receipt store="Morgan Imports" id="139595947" total="$1,929.00" documentCurrency="USD" accountCurrency="USD" conversionRate="1" documentTotal="1929.00" convertedTotal="1929.00" formattedDocumentTotal="$1,929.00" formattedConvertedTotal="$1,929.00" documentTax="" convertedTax="" formattedDocumentTax="" formattedConvertedTax="" date="7/12/2008" modifiedDate="7/12/2008" createdDate="7/10/2008" selldate="5/12/2008" imgurl="http://www.shoeboxed.com/receipt.jpeg?rid=139595947&code=1b106d61cbfa5078f53050e2f3bc315f">
+ <Categories>
+ <Category name="Meals / Entertainment" id="23423342"/>
+ <Category name="General Retail" id="9121023"/>
+ <Category name="Fuel" id="18222392"/>
+ </Categories>
+ </Receipt>
+</GetReceiptInfoCallResponse>
View
23 test/fixtures/receipt_response.xml
@@ -1,14 +1,17 @@
<GetReceiptCallResponse>
<Receipts count="2">
- <Receipt store="Great Plains Trust Company" id="23984923842" total="$3,378.30" selldate="5/12/2008" createdDate="4/12/2008" modifiedDate="4/20/2008" imgurl="http://www.shoeboxed.com/receipt1.jpeg">
- <Categories>
- <Category name="Category 1" id="1"/>
- </Categories>
- </Receipt>
- <Receipt store="RadioShack" id="39239293" total="$3.51" selldate="5/12/2008" createdDate="4/12/2008" modifiedDate="4/20/2008" imgurl="http://www.shoeboxed.com/receipt2.jpeg">
- <Categories>
- <Category name="Category 2" id="2"/>
- </Categories>
- </Receipt>
+ <Receipt store="Great Plains Trust Company" id="23984923842" total="$3,378.30" documentCurrency="USD" accountCurrency="USD" conversionRate="1" documentTotal="3378.30" convertedTotal="3378.30" formattedDocumentTotal="$3,378.30" formattedConvertedTotal="$3,378.30" documentTax="" convertedTax="" formattedDocumentTax="" formattedConvertedTax="" date="7/12/2008" modifiedDate="7/12/2008" createdDate="7/10/2008" selldate="5/12/2008" imgurl="http://www.shoeboxed.com/receipt.jpeg?rid= 23984923842&code=1b106d61cbfa5078f53050e2f3bc315f">
+ <Categories>
+ <Category name="Meals / Entertainment" id="23423342"/>
+ <Category name="General Retail" id="9121023"/>
+ <Category name="Fuel" id="18222392"/>
+ </Categories>
+ </Receipt>
+ <Receipt store="RadioShack" id="39239293" total="$3.51" documentCurrency="USD" accountCurrency="USD" conversionRate="1" documentTotal="3.51" convertedTotal="3.51" formattedDocumentTotal="$3.51" formattedConvertedTotal="$3.51" documentTax="" convertedTax="" formattedDocumentTax="" formattedConvertedTax="" date="7/12/2008" modifiedDate="7/12/2008" createdDate="7/10/2008" selldate="5/12/2008" imgurl="http://www.shoeboxed.com/receipt.jpeg?rid= 39239293&code=1b106d61cbfa5078f53050e2f3bc315f">
+ <Categories>
+ <Category name="Electronics" id="892732"/>
+ </Categories>
+ </Receipt>
</Receipts>
</GetReceiptCallResponse>
+
View
51 test/test_connection.rb
@@ -7,12 +7,20 @@ def setup
@conn = Connection.new("api_key", "user_token")
@category1 = Category.new
- @category1.id = "1"
- @category1.name = "Category 1"
+ @category1.id = "23423342"
+ @category1.name = "Meals / Entertainment"
@category2 = Category.new
- @category2.id = "2"
- @category2.name = "Category 2"
+ @category2.id = "9121023"
+ @category2.name = "General Retail"
+
+ @category3 = Category.new
+ @category3.id = "18222392"
+ @category3.name = "Fuel"
+
+ @category4 = Category.new
+ @category4.id = "892732"
+ @category4.name = "Electronics"
end
def test_authenticate__connection_failures
@@ -45,14 +53,15 @@ def test_get_receipt_info_call__success_getting_one_receipt
receipt = conn.get_receipt_info_call('1')
assert_not_nil receipt
- assert_equal "1", receipt.id
+ assert_equal "139595947", receipt.id
assert_equal "Morgan Imports", receipt.store
assert_equal Date.new(2008, 5, 12), receipt.sell_date
- assert_equal Date.new(2008, 4, 12), receipt.created_date
- assert_equal Date.new(2008, 4, 20), receipt.modified_date
- assert_equal BigDecimal.new("1929.00"), receipt.total
- assert_equal "http://www.shoeboxed.com/receipt.jpeg", receipt.image_url
- assert_equal [@category1], receipt.categories
+ assert_equal Date.new(2008, 7, 10), receipt.created_date
+ assert_equal Date.new(2008, 7, 12), receipt.modified_date
+ assert_equal BigDecimal.new("1929.00"), receipt.converted_total
+ assert_equal "USD", receipt.account_currency
+ assert_equal "http://www.shoeboxed.com/receipt.jpeg?rid=139595947&code=1b106d61cbfa5078f53050e2f3bc315f", receipt.image_url
+ assert_equal [@category1, @category2, @category3], receipt.categories
end
def test_build_receipt_info_call_request
@@ -77,21 +86,23 @@ def test_get_receipt_call__success_getting_two_receipt
assert_equal "23984923842", receipt.id
assert_equal "Great Plains Trust Company", receipt.store
assert_equal Date.new(2008, 5, 12), receipt.sell_date
- assert_equal Date.new(2008, 4, 12), receipt.created_date
- assert_equal Date.new(2008, 4, 20), receipt.modified_date
- assert_equal BigDecimal.new("3378.30"), receipt.total
- assert_equal "http://www.shoeboxed.com/receipt1.jpeg", receipt.image_url
- assert_equal [@category1], receipt.categories
+ assert_equal Date.new(2008, 7, 10), receipt.created_date
+ assert_equal Date.new(2008, 7, 12), receipt.modified_date
+ assert_equal BigDecimal.new("3378.30"), receipt.converted_total
+ assert_equal "USD", receipt.account_currency
+ assert_equal "http://www.shoeboxed.com/receipt.jpeg?rid= 23984923842&code=1b106d61cbfa5078f53050e2f3bc315f", receipt.image_url
+ assert_equal [@category1, @category2, @category3], receipt.categories
receipt = receipts[1]
assert_equal "39239293", receipt.id
assert_equal "RadioShack", receipt.store
assert_equal Date.new(2008, 5, 12), receipt.sell_date
- assert_equal Date.new(2008, 4, 12), receipt.created_date
- assert_equal Date.new(2008, 4, 20), receipt.modified_date
- assert_equal BigDecimal.new("3.51"), receipt.total
- assert_equal "http://www.shoeboxed.com/receipt2.jpeg", receipt.image_url
- assert_equal [@category2], receipt.categories
+ assert_equal Date.new(2008, 7, 10), receipt.created_date
+ assert_equal Date.new(2008, 7, 12), receipt.modified_date
+ assert_equal BigDecimal.new("3.51"), receipt.converted_total
+ assert_equal "USD", receipt.account_currency
+ assert_equal "http://www.shoeboxed.com/receipt.jpeg?rid= 39239293&code=1b106d61cbfa5078f53050e2f3bc315f", receipt.image_url
+ assert_equal [@category4], receipt.categories
end
def test_get_receipt_call__uses_gmt
View
34 test/test_receipt.rb
@@ -5,8 +5,16 @@ class TestReceipt < Test::Unit::TestCase
def setup
@category1 = Category.new
- @category1.id = "1"
- @category1.name = "Category 1"
+ @category1.id = "23423342"
+ @category1.name = "Meals / Entertainment"
+
+ @category2 = Category.new
+ @category2.id = "9121023"
+ @category2.name = "General Retail"
+
+ @category3 = Category.new
+ @category3.id = "18222392"
+ @category3.name = "Fuel"
end
def test_initialize_parse_xml
@@ -15,14 +23,15 @@ def test_initialize_parse_xml
assert_equal 1, receipts.size
receipt = receipts.first
- assert_equal "1", receipt.id
+ assert_equal "139595947", receipt.id
assert_equal "Morgan Imports", receipt.store
assert_equal Date.new(2008, 5, 12), receipt.sell_date
- assert_equal Date.new(2008, 4, 12), receipt.created_date
- assert_equal Date.new(2008, 4, 20), receipt.modified_date
- assert_equal BigDecimal.new("1929.00"), receipt.total
- assert_equal "http://www.shoeboxed.com/receipt.jpeg", receipt.image_url
- assert_equal [@category1], receipt.categories
+ assert_equal Date.new(2008, 7, 10), receipt.created_date
+ assert_equal Date.new(2008, 7, 12), receipt.modified_date
+ assert_equal BigDecimal.new("1929.00"), receipt.converted_total
+ assert_equal "USD", receipt.account_currency
+ assert_equal "http://www.shoeboxed.com/receipt.jpeg?rid=139595947&code=1b106d61cbfa5078f53050e2f3bc315f", receipt.image_url
+ assert_equal [@category1, @category2, @category3], receipt.categories
end
def test_receipt__accessors
@@ -34,9 +43,12 @@ def test_receipt__accessors
receipt.id = "1"
assert_equal "1", receipt.id
+
+ receipt.converted_total = '$1,000.19'
+ assert_equal BigDecimal.new('1000.19'), receipt.converted_total
- receipt.total = '$1,000.19'
- assert_equal BigDecimal.new('1000.19'), receipt.total
+ receipt.account_currency = "USD"
+ assert_equal "USD", receipt.account_currency
receipt.created_date = '1/2/2001'
assert_equal Date.parse('1/2/2001'), receipt.created_date
@@ -50,7 +62,7 @@ def test_receipt__accessors
receipt.categories = [@category1]
assert_equal [@category1], receipt.categories
end
-
+
def test_equal
# lame test but at least execute the code
assert_equal Receipt.new, Receipt.new
Please sign in to comment.
Something went wrong with that request. Please try again.