bws 0.2.1.pre

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.
Files changed (66) hide show
  1. data/.document +5 -0
  2. data/Gemfile +17 -0
  3. data/Gemfile.lock +36 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +116 -0
  6. data/Rakefile +56 -0
  7. data/VERSION +1 -0
  8. data/bws.gemspec +133 -0
  9. data/lib/bws.rb +13 -0
  10. data/lib/bws/acknowledge_order.rb +11 -0
  11. data/lib/bws/active_isbn_report.rb +27 -0
  12. data/lib/bws/checkout.rb +30 -0
  13. data/lib/bws/client.rb +807 -0
  14. data/lib/bws/create_shipment.rb +11 -0
  15. data/lib/bws/fillable_orders.rb +15 -0
  16. data/lib/bws/inventory.rb +58 -0
  17. data/lib/bws/order.rb +10 -0
  18. data/lib/bws/order_events.rb +28 -0
  19. data/lib/bws/orders.rb +14 -0
  20. data/lib/bws/reject_line_item.rb +11 -0
  21. data/lib/bws/response.rb +8 -0
  22. data/lib/bws/unacknowledged_orders.rb +23 -0
  23. data/test/fixtures/acknowledge_success.xml +11 -0
  24. data/test/fixtures/active_isbn_report_with_one_isbn_request_body.xml +13 -0
  25. data/test/fixtures/active_isbn_report_with_one_isbn_success.xml +38 -0
  26. data/test/fixtures/active_isbn_report_with_two_isbns_request_body.xml +16 -0
  27. data/test/fixtures/active_isbn_report_with_two_isbns_success.xml +57 -0
  28. data/test/fixtures/cancel_line_item_success.xml +11 -0
  29. data/test/fixtures/create_order_request_body.xml +70 -0
  30. data/test/fixtures/create_order_response_success.xml +14 -0
  31. data/test/fixtures/create_shipment_success.xml +11 -0
  32. data/test/fixtures/fillable_success.xml +127 -0
  33. data/test/fixtures/inventory_by_isbn_success.xml +36 -0
  34. data/test/fixtures/inventory_success.xml +54 -0
  35. data/test/fixtures/order_events_by_order_success.xml +68 -0
  36. data/test/fixtures/order_events_success.xml +65 -0
  37. data/test/fixtures/order_success.xml +37 -0
  38. data/test/fixtures/orders_show_success.xml +37 -0
  39. data/test/fixtures/price_order_request_body.xml +46 -0
  40. data/test/fixtures/price_order_response_success.xml +63 -0
  41. data/test/fixtures/single_post_create_order_request_body.xml +62 -0
  42. data/test/fixtures/single_post_create_order_response_success.xml +13 -0
  43. data/test/fixtures/unacknowledged_success.xml +122 -0
  44. data/test/fixtures/unacknowledged_success_0_orders.xml +12 -0
  45. data/test/fixtures/unacknowledged_success_1_order.xml +37 -0
  46. data/test/fixtures/validate_credit_card_request_body.xml +39 -0
  47. data/test/fixtures/validate_credit_card_response_success.xml +14 -0
  48. data/test/helper.rb +23 -0
  49. data/test/integration/test_bws_active_isbn_report.rb +28 -0
  50. data/test/integration/test_bws_retrieve_inventory.rb +31 -0
  51. data/test/unit/test_bws_acknowledge_order.rb +24 -0
  52. data/test/unit/test_bws_active_isbn_report.rb +45 -0
  53. data/test/unit/test_bws_checkout.rb +117 -0
  54. data/test/unit/test_bws_client.rb +370 -0
  55. data/test/unit/test_bws_create_shipment.rb +26 -0
  56. data/test/unit/test_bws_fillable_orders.rb +41 -0
  57. data/test/unit/test_bws_order.rb +25 -0
  58. data/test/unit/test_bws_reject_line_item.rb +26 -0
  59. data/test/unit/test_bws_response.rb +7 -0
  60. data/test/unit/test_bws_retrieve_inventory.rb +42 -0
  61. data/test/unit/test_bws_retrieve_inventory_by_isbn.rb +25 -0
  62. data/test/unit/test_bws_retrieve_order_events.rb +42 -0
  63. data/test/unit/test_bws_retrieve_order_events_by_order.rb +37 -0
  64. data/test/unit/test_bws_unacknowledged_orders.rb +74 -0
  65. data/test/unit/test_retrieve_orders_show.rb +27 -0
  66. metadata +293 -0
@@ -0,0 +1,11 @@
1
+ class BWS::CreateShipment < BWS::Response
2
+
3
+ def result
4
+ base.nil?
5
+ end
6
+
7
+ private
8
+ def base
9
+ response.parsed_response['envelope']['body']['distributor_outbound_shipments_create']
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ class BWS::FillableOrders < BWS::Response
2
+
3
+ def orders
4
+ base['distributor_order']
5
+ end
6
+
7
+ def pages
8
+ base['total_pages'].to_i
9
+ end
10
+
11
+ private
12
+ def base
13
+ response.parsed_response['envelope']['body']['distributor_orders_fillable']['distributor_orders']
14
+ end
15
+ end
@@ -0,0 +1,58 @@
1
+ class BWS::Inventory < BWS::Response
2
+ def result
3
+ base.nil?
4
+ end
5
+
6
+ def book
7
+ base['inventory_book']
8
+ end
9
+
10
+ def books
11
+ return base['inventory_books']['inventory_book'] if base['inventory_books'] && base['inventory_books']['inventory_book'].class == Array
12
+
13
+ return [ base['inventory_books']['inventory_book'] ] if base['inventory_books'] && base['inventory_books']['inventory_book'].class == Hash
14
+ end
15
+
16
+ def pagination
17
+ base['pagination']
18
+ end
19
+
20
+ #TODO It must be replaced by page and then removed. I guess it is not been used anywhere.
21
+ def pages
22
+ (base['pagination']['page']).to_i if pagination
23
+ end
24
+
25
+ def page
26
+ (base['pagination']['page']).to_i if pagination
27
+ end
28
+
29
+ def total_items
30
+ (base['pagination']['total_items']).to_i if pagination
31
+ end
32
+
33
+ def items_per_page
34
+ (base['pagination']['items_per_page']).to_i if pagination
35
+ end
36
+
37
+ def in_store
38
+ base['in_store']
39
+ end
40
+
41
+ def delta_range_start_date
42
+ base['delta_range_start_date']
43
+ end
44
+
45
+ def delta_range_end_date
46
+ base['delta_range_end_date']
47
+ end
48
+
49
+
50
+ private
51
+ def base
52
+ inventory_books_index = response.parsed_response['envelope']['body']['inventory_books_index']
53
+ return inventory_books_index if inventory_books_index
54
+
55
+ inventory_books_show = response.parsed_response['envelope']['body']['inventory_books_show']
56
+ return inventory_books_show if inventory_books_show
57
+ end
58
+ end
data/lib/bws/order.rb ADDED
@@ -0,0 +1,10 @@
1
+ class BWS::Order < BWS::Response
2
+ def order
3
+ base
4
+ end
5
+
6
+ private
7
+ def base
8
+ response.parsed_response['envelope']['body']['distributor_orders_show']['distributor_order']
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ class BWS::OrderEvents < BWS::Response
2
+ def result
3
+ base.nil?
4
+ end
5
+
6
+ def events
7
+ return base['order_events']['order_event'] if base['order_events'] && base['order_events']['order_event'].class == Array
8
+
9
+ return [ base['order_events']['order_event'] ] if base['order_events'] && base['order_events']['order_event'].class == Hash
10
+ end
11
+
12
+ def pages
13
+ (base['pagination']['page']).to_i if base['pagination']
14
+ end
15
+
16
+ def pagination
17
+ base['pagination']
18
+ end
19
+
20
+ private
21
+ def base
22
+ order_events_index = response.parsed_response['envelope']['body']['order_events_index']
23
+ return order_events_index if order_events_index
24
+
25
+ order_events_show = response.parsed_response['envelope']['body']['order_events_show']
26
+ return order_events_show if order_events_show
27
+ end
28
+ end
data/lib/bws/orders.rb ADDED
@@ -0,0 +1,14 @@
1
+ class BWS::Orders < BWS::Response
2
+ def result
3
+ base.nil?
4
+ end
5
+
6
+ def order
7
+ base['order']
8
+ end
9
+
10
+ private
11
+ def base
12
+ response.parsed_response['envelope']['body']['orders_show']
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ class BWS::RejectLineItem < BWS::Response
2
+
3
+ def result
4
+ base.nil?
5
+ end
6
+
7
+ private
8
+ def base
9
+ response.parsed_response['envelope']['body']['distributor_line_items_reject']
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module BWS
2
+ class Response
3
+ attr_accessor :response
4
+ def initialize(response)
5
+ self.response = response
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ class BWS::UnacknowledgedOrders < BWS::Response
2
+
3
+ def orders
4
+ return [] if base['distributor_order'].nil?
5
+
6
+ distributor_orders = [base['distributor_order']].flatten # Make hash results an array
7
+ orders = distributor_orders.collect do |order|
8
+ if order["distributor_line_items"]["distributor_line_item"].is_a?(Hash)
9
+ order["distributor_line_items"]["distributor_line_item"] = [order["distributor_line_items"]["distributor_line_item"]]
10
+ end
11
+ order
12
+ end
13
+ end
14
+
15
+ def pages
16
+ base['total_pages'].to_i
17
+ end
18
+
19
+ private
20
+ def base
21
+ response.parsed_response['envelope']['body']['distributor_orders_unacknowledged']['distributor_orders']
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <envelope>
3
+ <header>
4
+ <response_id>1281477072_95</response_id>
5
+ </header>
6
+ <body>
7
+ <distributor_orders_acknowledge>
8
+ </distributor_orders_acknowledge>
9
+ </body>
10
+ </envelope>
11
+
@@ -0,0 +1,13 @@
1
+ <reports_active_isbn_report>
2
+ <pagination>
3
+ <page>1</page>
4
+ <items_per_page>50</items_per_page>
5
+ </pagination>
6
+ <active_isbn_report>
7
+ <active_isbns>
8
+ <active_isbn>
9
+ <isbn>9780073526706</isbn>
10
+ </active_isbn>
11
+ </active_isbns>
12
+ </active_isbn_report>
13
+ </reports_active_isbn_report>
@@ -0,0 +1,38 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <envelope>
3
+ <header>
4
+ <response_id>1281477072_95</response_id>
5
+ </header>
6
+ <body>
7
+ <reports_active_isbn_report>
8
+ <pagination>
9
+ <page>1</page>
10
+ <items_per_page>50</items_per_page>
11
+ <total_items>1</total_items>
12
+ </pagination>
13
+ <active_isbn_report>
14
+ <active_isbns>
15
+ <active_isbn>
16
+ <isbn>9780073526706</isbn>
17
+ <retail_price>15299</retail_price>
18
+ <title>Managerial Accounting</title>
19
+ <authors>
20
+ <author>Ray Garrison</author>
21
+ <author>Peter Brewer</author>
22
+ <author>Eric Noreen</author>
23
+ </authors>
24
+ <publisher>McGraw-Hill/Irwin</publisher>
25
+ <edition>3rd</edition>
26
+ <book_binding>Paperback</book_binding>
27
+ <dimensions>
28
+ <width>890</width>
29
+ <height>1090</height>
30
+ <depth>110</depth>
31
+ <weight>450</weight>
32
+ </dimensions>
33
+ </active_isbn>
34
+ </active_isbns>
35
+ </active_isbn_report>
36
+ </reports_active_isbn_report>
37
+ </body>
38
+ </envelope>
@@ -0,0 +1,16 @@
1
+ <reports_active_isbn_report>
2
+ <pagination>
3
+ <page>1</page>
4
+ <items_per_page>50</items_per_page>
5
+ </pagination>
6
+ <active_isbn_report>
7
+ <active_isbns>
8
+ <active_isbn>
9
+ <isbn>9780073526706</isbn>
10
+ </active_isbn>
11
+ <active_isbn>
12
+ <isbn>9780073526707</isbn>
13
+ </active_isbn>
14
+ </active_isbns>
15
+ </active_isbn_report>
16
+ </reports_active_isbn_report>
@@ -0,0 +1,57 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <envelope>
3
+ <header>
4
+ <response_id>1281477072_95</response_id>
5
+ </header>
6
+ <body>
7
+ <reports_active_isbn_report>
8
+ <pagination>
9
+ <page>1</page>
10
+ <items_per_page>50</items_per_page>
11
+ <total_items>2</total_items>
12
+ </pagination>
13
+ <active_isbn_report>
14
+ <active_isbns>
15
+ <active_isbn>
16
+ <isbn>9780073526706</isbn>
17
+ <retail_price>15299</retail_price>
18
+ <title>Managerial Accounting</title>
19
+ <authors>
20
+ <author>Ray Garrison</author>
21
+ <author>Peter Brewer</author>
22
+ <author>Eric Noreen</author>
23
+ </authors>
24
+ <publisher>McGraw-Hill/Irwin</publisher>
25
+ <edition>3rd</edition>
26
+ <book_binding>Paperback</book_binding>
27
+ <dimensions>
28
+ <width>890</width>
29
+ <height>1090</height>
30
+ <depth>110</depth>
31
+ <weight>450</weight>
32
+ </dimensions>
33
+ </active_isbn>
34
+ <active_isbn>
35
+ <isbn>9780073526707</isbn>
36
+ <retail_price>15299</retail_price>
37
+ <title>Managerial Accounting II</title>
38
+ <authors>
39
+ <author>Ray Garrison</author>
40
+ <author>Peter Brewer</author>
41
+ <author>Eric Noreen</author>
42
+ </authors>
43
+ <publisher>McGraw-Hill/Irwin</publisher>
44
+ <edition>3rd</edition>
45
+ <book_binding>Paperback</book_binding>
46
+ <dimensions>
47
+ <width>890</width>
48
+ <height>1090</height>
49
+ <depth>110</depth>
50
+ <weight>450</weight>
51
+ </dimensions>
52
+ </active_isbn>
53
+ </active_isbns>
54
+ </active_isbn_report>
55
+ </reports_active_isbn_report>
56
+ </body>
57
+ </envelope>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <envelope>
3
+ <header>
4
+ <response_id>1281477072_95</response_id>
5
+ </header>
6
+ <body>
7
+ <distributor_line_items_reject>
8
+ </distributor_line_items_reject>
9
+ </body>
10
+ </envelope>
11
+
@@ -0,0 +1,70 @@
1
+ <checkout_create_order>
2
+ <checkout_verification_code>CQ4LJqg9bhpzHxu0Q1tKR2KIpF3</checkout_verification_code>
3
+ <charge_amount_cents>15913</charge_amount_cents>
4
+ <external_order_id>BOOK-INC-ORDER-1234567</external_order_id>
5
+ <customer>
6
+ <customer_verification_code>VE9iKgC8hzOmNuEv0brni6oip3L</customer_verification_code>
7
+ <email>dorothea@toydurgan.us</email>
8
+ <external_user_id>6370931058</external_user_id>
9
+ <mobile_phone_number></mobile_phone_number>
10
+ </customer>
11
+ <product_list>
12
+ <product_list_verification_code>KD0zWURC0kR92JHGpQqRTciiWEn</product_list_verification_code>
13
+ <segment>SEGMENT</segment>
14
+ <products>
15
+ <product>
16
+ <product_id>9780006552192</product_id>
17
+ <product_type>book</product_type>
18
+ <quantity>2</quantity>
19
+ <rental_period>90</rental_period>
20
+ <external_line_item_ids>
21
+ <external_line_item_id>BOOK-INC-LINE-ITEM-123001</external_line_item_id>
22
+ <external_line_item_id>BOOK-INC-LINE-ITEM-123002</external_line_item_id>
23
+ </external_line_item_ids>
24
+ </product>
25
+ <product>
26
+ <product_id>9780007138210</product_id>
27
+ <product_type>book</product_type>
28
+ <quantity>1</quantity>
29
+ <rental_period>90</rental_period>
30
+ <external_line_item_ids>
31
+ <external_line_item_id>BOOK-INC-LINE-ITEM-123003</external_line_item_id>
32
+ </external_line_item_ids>
33
+ </product>
34
+ </products>
35
+ </product_list>
36
+ <billing_address>
37
+ <billing_address_verification_code>1hurmIO77c3eaX3ClSlDvC5eV3B</billing_address_verification_code>
38
+ <first_name>Rhiannon</first_name>
39
+ <last_name>Okuneva</last_name>
40
+ <street_address>31189 ZackRapid</street_address>
41
+ <street_address_2></street_address_2>
42
+ <city>Lake Jedediah</city>
43
+ <state>TX</state>
44
+ <zip>83492-3353</zip>
45
+ <country>USA</country>
46
+ </billing_address>
47
+ <shipping_address>
48
+ <shipping_address_verification_code>FvBC0zj7YCZUCtbcrh4AGJEdGEk</shipping_address_verification_code>
49
+ <first_name>Rhiannon</first_name>
50
+ <last_name>Okuneva</last_name>
51
+ <street_address>31189 ZackRapid</street_address>
52
+ <street_address_2></street_address_2>
53
+ <city>Lake Jedediah</city>
54
+ <state>TX</state>
55
+ <zip>83492-3353</zip>
56
+ <country>USA</country>
57
+ </shipping_address>
58
+ <credit_card>
59
+ <credit_card_verification_code>XDSniGxMu0apA07i9yFJSplgNRZ</credit_card_verification_code>
60
+ <number>4111 1111 1111 1111</number>
61
+ <month>12</month>
62
+ <year>2011</year>
63
+ <verification_value>123</verification_value>
64
+ <type>visa</type>
65
+ </credit_card>
66
+ <shipping_option>
67
+ <shipping_option_verification_code>VdLvju6FoyYJCGQRxyt3uLfs7RS</shipping_option_verification_code>
68
+ <method_name>Ground</method_name>
69
+ </shipping_option>
70
+ </checkout_create_order>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <envelope>
3
+ <header>
4
+ <response_id>1281477072_95</response_id>
5
+ </header>
6
+ <body>
7
+ <checkout_create_order>
8
+ <checkout_verification_code>CQ4LJqg9bhpzHxu0Q1tKR2KIpF3</checkout_verification_code>
9
+ <order>
10
+ <public_id>BR-D69A780BA</public_id>
11
+ </order>
12
+ </checkout_create_order>
13
+ </body>
14
+ </envelope>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <envelope>
3
+ <header>
4
+ <response_id>1281477072_95</response_id>
5
+ </header>
6
+ <body>
7
+ <distributor_outbound_shipments_create>
8
+ </distributor_outbound_shipments_create>
9
+ </body>
10
+ </envelope>
11
+