bcurren-rshoeboxed 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Manifest.txt CHANGED
@@ -6,6 +6,7 @@ lib/rshoeboxed.rb
6
6
  lib/rshoeboxed/category.rb
7
7
  lib/rshoeboxed/connection.rb
8
8
  lib/rshoeboxed/list_proxy.rb
9
+ lib/rshoeboxed/parse_error.rb
9
10
  lib/rshoeboxed/receipt.rb
10
11
  script/console
11
12
  script/destroy
data/README.rdoc CHANGED
@@ -15,7 +15,7 @@ AppName provided by shoeboxed. Shoeboxed will redirect back to the return url on
15
15
  authenticates. When the user is redirected back to the return_url, a token will be provided in the url
16
16
  for you to store for future API calls.
17
17
 
18
- RShoeboxed::Connection.authentication_url("Outright", "http://example.com")
18
+ RShoeboxed::Connection.authentication_url("Outright", "http://example.com")
19
19
 
20
20
  === Get a list of all receipts
21
21
 
@@ -23,18 +23,18 @@ The api_token is provided by shoeboxed when you setup your API account. The user
23
23
  sending a user to authentication_url so they can log in to shoeboxed. On success, they will be redirected
24
24
  to the return_url with the user_token.
25
25
 
26
- connection = RShoeboxed::Connection.new("api_token", "user_token")
27
- receipts = connection.get_receipt_call(Date.new(2008, 1, 1), Date.new(2008, 12, 29))
26
+ connection = RShoeboxed::Connection.new("api_token", "user_token")
27
+ receipts = connection.get_receipt_call(Date.new(2008, 1, 1), Date.new(2008, 12, 29))
28
28
 
29
29
  === Get a particular receipt
30
30
 
31
- connection = RShoeboxed::Connection.new("api_token", "user_token")
32
- receipt = connection.get_category_info_call("2342442424")
31
+ connection = RShoeboxed::Connection.new("api_token", "user_token")
32
+ receipt = connection.get_category_info_call("2342442424")
33
33
 
34
34
  === Get a list of all categories
35
35
 
36
- connection = RShoeboxed::Connection.new("api_token", "user_token")
37
- categories = connection.get_category_call
36
+ connection = RShoeboxed::Connection.new("api_token", "user_token")
37
+ categories = connection.get_category_call
38
38
 
39
39
  == INSTALL:
40
40
 
@@ -8,11 +8,19 @@ module RShoeboxed
8
8
  document = REXML::Document.new(xml)
9
9
  document.elements.collect("//Category") do |category_element|
10
10
  category = Category.new
11
- category.id = category_element.attributes["id"]
12
- category.name = category_element.attributes["name"]
11
+ begin
12
+ category.id = category_element.attributes["id"]
13
+ category.name = category_element.attributes["name"]
14
+ rescue => e
15
+ raise RShoeboxed::ParseError.new(e, category_element.to_s, "Error parsing category.")
16
+ end
13
17
  category
14
18
  end
15
19
  end
20
+
21
+ def ==(category)
22
+ self.id == category.id && self.name == category.name
23
+ end
16
24
 
17
25
  end
18
26
  end
@@ -0,0 +1,19 @@
1
+ module RShoeboxed
2
+ class ParseError < StandardError
3
+ attr_accessor :original_error, :xml
4
+
5
+ def initialize(original_error, xml, msg = nil)
6
+ @original_error = original_error
7
+ @xml = xml
8
+ super(msg)
9
+ end
10
+
11
+ def to_s
12
+ message = super
13
+
14
+ "Original Error: #{original_error.to_s}\n" +
15
+ "XML: #{xml.to_s}\n" +
16
+ "Message: #{message}\n"
17
+ end
18
+ end
19
+ end
@@ -4,28 +4,32 @@ require 'rexml/document'
4
4
 
5
5
  module RShoeboxed
6
6
  class Receipt
7
- attr_accessor :id, :store, :image_url, :category_id
8
- attr_reader :date, :total
7
+ attr_accessor :id, :store, :image_url, :categories
8
+ attr_reader :sell_date, :created_date, :modified_date, :total
9
9
 
10
10
  def self.parse(xml)
11
11
  document = REXML::Document.new(xml)
12
12
  document.elements.collect("//Receipt") do |receipt_element|
13
13
  receipt = Receipt.new
14
-
15
- receipt.id = receipt_element.attributes["id"]
16
- receipt.store = receipt_element.attributes["store"]
17
- receipt.date = receipt_element.attributes["date"]
18
- receipt.total = receipt_element.attributes["total"]
19
- receipt.image_url = receipt_element.attributes["imgurl"]
20
- receipt.category_id = receipt_element.attributes["category"]
21
-
14
+ begin
15
+ receipt.id = receipt_element.attributes["id"]
16
+ receipt.store = receipt_element.attributes["store"]
17
+ receipt.sell_date = receipt_element.attributes["selldate"]
18
+ receipt.created_date = receipt_element.attributes["createdDate"]
19
+ receipt.modified_date = receipt_element.attributes["modifiedDate"]
20
+ receipt.total = receipt_element.attributes["total"]
21
+ receipt.image_url = receipt_element.attributes["imgurl"]
22
+
23
+ # Get the categories elements and have Category parse them
24
+ category_element = receipt_element.elements["Categories"]
25
+ receipt.categories = category_element ? Category.parse(category_element.to_s) : []
26
+ rescue => e
27
+ raise RShoeboxed::ParseError.new(e, receipt_element.to_s, "Error parsing receipt.")
28
+ end
22
29
  receipt
23
30
  end
24
31
  end
25
32
 
26
- def initialize
27
- end
28
-
29
33
  def total=(total)
30
34
  total.gsub!(/[^\d|.]/, "") if total.is_a?(String)
31
35
  total = BigDecimal.new(total) unless total.is_a?(BigDecimal)
@@ -33,9 +37,26 @@ module RShoeboxed
33
37
  @total = total
34
38
  end
35
39
 
36
- def date=(date)
40
+ def sell_date=(date)
41
+ date = Date.parse(date) if date.is_a?(String)
42
+ @sell_date = date
43
+ end
44
+
45
+ def created_date=(date)
37
46
  date = Date.parse(date) if date.is_a?(String)
38
- @date = date
47
+ @created_date = date
48
+ end
49
+
50
+ def modified_date=(date)
51
+ date = Date.parse(date) if date.is_a?(String)
52
+ @modified_date = date
53
+ end
54
+
55
+ def ==(receipt)
56
+ self.id == receipt.id && self.store == receipt.store && self.image_url == receipt.image_url &&
57
+ self.categories == receipt.categories && self.sell_date == receipt.sell_date &&
58
+ self.modified_date == receipt.modified_date && self.created_date == receipt.created_date &&
59
+ self.total == receipt.total
39
60
  end
40
61
  end
41
62
  end
data/lib/rshoeboxed.rb CHANGED
@@ -6,7 +6,8 @@ require 'rshoeboxed/receipt'
6
6
  require 'rshoeboxed/category'
7
7
  require 'rshoeboxed/connection'
8
8
  require 'rshoeboxed/list_proxy'
9
+ require 'rshoeboxed/parse_error'
9
10
 
10
11
  module RShoeboxed
11
- VERSION = '0.0.1'
12
- end
12
+ VERSION = '0.0.4'
13
+ end
@@ -1 +1,5 @@
1
- <Receipt store="Morgan Imports" id="1" total="$1,929.00" date="5/12/2008" imgurl="http://www.shoeboxed.com/receipt.jpeg" category="1" />
1
+ <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">
2
+ <Categories>
3
+ <Category name="Category 1" id="1"/>
4
+ </Categories>
5
+ </Receipt>
@@ -1,6 +1,14 @@
1
1
  <GetReceiptCallResponse>
2
2
  <Receipts count="2">
3
- <Receipt store="Great Plains Trust Company" id="23984923842" total="$3,378.30" date="5/12/2008" imgurl="http://www.shoeboxed.com/receipt1.jpeg" category="1"/>
4
- <Receipt store="RadioShack" id="39239293" total="$3.51" date="5/12/2008" imgurl="http://www.shoeboxed.com/receipt2.jpeg" category="2"/>
3
+ <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">
4
+ <Categories>
5
+ <Category name="Category 1" id="1"/>
6
+ </Categories>
7
+ </Receipt>
8
+ <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">
9
+ <Categories>
10
+ <Category name="Category 2" id="2"/>
11
+ </Categories>
12
+ </Receipt>
5
13
  </Receipts>
6
14
  </GetReceiptCallResponse>
@@ -5,6 +5,14 @@ class TestConnection < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
7
  @conn = Connection.new("api_key", "user_token")
8
+
9
+ @category1 = Category.new
10
+ @category1.id = "1"
11
+ @category1.name = "Category 1"
12
+
13
+ @category2 = Category.new
14
+ @category2.id = "2"
15
+ @category2.name = "Category 2"
8
16
  end
9
17
 
10
18
  def test_authenticate__connection_failures
@@ -39,10 +47,12 @@ class TestConnection < Test::Unit::TestCase
39
47
  assert_not_nil receipt
40
48
  assert_equal "1", receipt.id
41
49
  assert_equal "Morgan Imports", receipt.store
42
- assert_equal Date.new(2008, 5, 12), receipt.date
50
+ assert_equal Date.new(2008, 5, 12), receipt.sell_date
51
+ assert_equal Date.new(2008, 4, 12), receipt.created_date
52
+ assert_equal Date.new(2008, 4, 20), receipt.modified_date
43
53
  assert_equal BigDecimal.new("1929.00"), receipt.total
44
54
  assert_equal "http://www.shoeboxed.com/receipt.jpeg", receipt.image_url
45
- assert_equal "1", receipt.category_id
55
+ assert_equal [@category1], receipt.categories
46
56
  end
47
57
 
48
58
  def test_build_receipt_info_call_request
@@ -66,18 +76,22 @@ class TestConnection < Test::Unit::TestCase
66
76
  receipt = receipts[0]
67
77
  assert_equal "23984923842", receipt.id
68
78
  assert_equal "Great Plains Trust Company", receipt.store
69
- assert_equal Date.new(2008, 5, 12), receipt.date
79
+ assert_equal Date.new(2008, 5, 12), receipt.sell_date
80
+ assert_equal Date.new(2008, 4, 12), receipt.created_date
81
+ assert_equal Date.new(2008, 4, 20), receipt.modified_date
70
82
  assert_equal BigDecimal.new("3378.30"), receipt.total
71
83
  assert_equal "http://www.shoeboxed.com/receipt1.jpeg", receipt.image_url
72
- assert_equal "1", receipt.category_id
84
+ assert_equal [@category1], receipt.categories
73
85
 
74
86
  receipt = receipts[1]
75
87
  assert_equal "39239293", receipt.id
76
88
  assert_equal "RadioShack", receipt.store
77
- assert_equal Date.new(2008, 5, 12), receipt.date
89
+ assert_equal Date.new(2008, 5, 12), receipt.sell_date
90
+ assert_equal Date.new(2008, 4, 12), receipt.created_date
91
+ assert_equal Date.new(2008, 4, 20), receipt.modified_date
78
92
  assert_equal BigDecimal.new("3.51"), receipt.total
79
93
  assert_equal "http://www.shoeboxed.com/receipt2.jpeg", receipt.image_url
80
- assert_equal "2", receipt.category_id
94
+ assert_equal [@category2], receipt.categories
81
95
  end
82
96
 
83
97
  def test_build_receipt_request
data/test/test_receipt.rb CHANGED
@@ -4,6 +4,9 @@ class TestReceipt < Test::Unit::TestCase
4
4
  include RShoeboxed
5
5
 
6
6
  def setup
7
+ @category1 = Category.new
8
+ @category1.id = "1"
9
+ @category1.name = "Category 1"
7
10
  end
8
11
 
9
12
  def test_initialize_parse_xml
@@ -14,10 +17,12 @@ class TestReceipt < Test::Unit::TestCase
14
17
  receipt = receipts.first
15
18
  assert_equal "1", receipt.id
16
19
  assert_equal "Morgan Imports", receipt.store
17
- assert_equal Date.new(2008, 5, 12), receipt.date
20
+ assert_equal Date.new(2008, 5, 12), receipt.sell_date
21
+ assert_equal Date.new(2008, 4, 12), receipt.created_date
22
+ assert_equal Date.new(2008, 4, 20), receipt.modified_date
18
23
  assert_equal BigDecimal.new("1929.00"), receipt.total
19
24
  assert_equal "http://www.shoeboxed.com/receipt.jpeg", receipt.image_url
20
- assert_equal "1", receipt.category_id
25
+ assert_equal [@category1], receipt.categories
21
26
  end
22
27
 
23
28
  def test_receipt__accessors
@@ -33,13 +38,21 @@ class TestReceipt < Test::Unit::TestCase
33
38
  receipt.total = '$1,000.19'
34
39
  assert_equal BigDecimal.new('1000.19'), receipt.total
35
40
 
36
- receipt.date = '1/1/2001'
37
- assert_equal Date.parse('1/1/2001'), receipt.date
41
+ receipt.created_date = '1/2/2001'
42
+ assert_equal Date.parse('1/2/2001'), receipt.created_date
43
+
44
+ receipt.modified_date = '1/3/2001'
45
+ assert_equal Date.parse('1/3/2001'), receipt.modified_date
38
46
 
39
47
  receipt.image_url = "http://www.example.com/one.image"
40
48
  assert_equal "http://www.example.com/one.image", receipt.image_url
41
49
 
42
- receipt.category_id = "2"
43
- assert_equal "2", receipt.category_id
50
+ receipt.categories = [@category1]
51
+ assert_equal [@category1], receipt.categories
52
+ end
53
+
54
+ def test_equal
55
+ # lame test but at least execute the code
56
+ assert_equal Receipt.new, Receipt.new
44
57
  end
45
- end
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcurren-rshoeboxed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Curren
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-21 00:00:00 -08:00
12
+ date: 2009-02-13 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -68,6 +68,7 @@ files:
68
68
  - lib/rshoeboxed/category.rb
69
69
  - lib/rshoeboxed/connection.rb
70
70
  - lib/rshoeboxed/list_proxy.rb
71
+ - lib/rshoeboxed/parse_error.rb
71
72
  - lib/rshoeboxed/receipt.rb
72
73
  - script/console
73
74
  - script/destroy