bws 0.2.1.pre

Sign up to get free protection for your applications and to get access to all the features.
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
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source :gemcutter
2
+
3
+ gem 'httparty', '>= 0.6.1'
4
+ gem 'builder', '>= 2.1.2'
5
+ gem 'activesupport'
6
+ gem 'i18n'
7
+
8
+ group :development do
9
+ gem 'rake', '>= 0.9.2.2'
10
+ gem 'jeweler', '>= 1.6.4'
11
+ end
12
+
13
+ group :test do
14
+ gem 'shoulda', '2.11.3'
15
+ gem 'mocha', '0.9.8'
16
+ gem 'fakeweb', '1.3.0'
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.3)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ builder (3.0.0)
8
+ crack (0.1.8)
9
+ fakeweb (1.3.0)
10
+ git (1.2.5)
11
+ httparty (0.6.1)
12
+ crack (= 0.1.8)
13
+ i18n (0.6.0)
14
+ jeweler (1.6.4)
15
+ bundler (~> 1.0)
16
+ git (>= 1.2.5)
17
+ rake
18
+ mocha (0.9.8)
19
+ rake
20
+ multi_json (1.3.5)
21
+ rake (0.9.2.2)
22
+ shoulda (2.11.3)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ activesupport
29
+ builder (>= 2.1.2)
30
+ fakeweb (= 1.3.0)
31
+ httparty (>= 0.6.1)
32
+ i18n
33
+ jeweler (>= 1.6.4)
34
+ mocha (= 0.9.8)
35
+ rake (>= 0.9.2.2)
36
+ shoulda (= 2.11.3)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-11 Bookrenter Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,116 @@
1
+ == This Branch will be used by the half.com project. The changes will not be merged back to master unless requested by Bookrenter
2
+
3
+ = Bookrenter Web Services Client
4
+
5
+ The Bookrenter Web Services Client will let you connect and work with Bookrenter.com as an inventory provider and order fulfiller. This is a very early version of this library that has not yet been used in production.
6
+
7
+ == Brief Info
8
+
9
+ First, setup your client:
10
+
11
+ bws = BWSClient.new('api_key')
12
+
13
+ If you want to test on a different URL than the default of https://bws.bookrenter.com/v1, then you can pass in a separate base_uri like so:
14
+
15
+ bws = BWSClient.new('api_key', 'https://some.other-endpoint.com')
16
+
17
+ === Get Unacknowledged Orders
18
+
19
+ bws.unacknowledged_orders(page=1)
20
+
21
+ Returns an instance of BWS::UnacknowledgedOrders which you can then call .orders on to get the raw order hash, or .pages to get the total pages count
22
+
23
+ TBD
24
+ * Return an actual array of BWS::Order objects instead of the hash
25
+
26
+ === Get fillable orders
27
+
28
+ bws.fillable_orders(page=1)
29
+
30
+ Returns an instance of BWS::FillableOrders which you can then call .orders on to get the raw order hash, or .pages to get the total pages count
31
+
32
+ TBD
33
+ * Return an actual array of BWS::Order objects instead of the hash
34
+
35
+ === Get Order
36
+
37
+ bws.order(public_id)
38
+
39
+ Returns a BWS::Order instance, which you can call .order on to get the actual data
40
+
41
+ TBD
42
+ * Make this not so redundant (eg my_order.order)
43
+ * Return an actual BWS::Order object
44
+
45
+ === Acknowledge an Order
46
+
47
+ bws.acknowledge_order(order_hash)
48
+
49
+ Returns a BWS::AcknowledgeOrder object which you can call .result? on to get success or failure
50
+
51
+ order_hash should look like this:
52
+
53
+ {
54
+ "public_id"=>"BR-857D3F832",
55
+ "distributor_identifier" => 'your-order-id', # Optional
56
+ "distributor_line_items"=> {
57
+ "distributor_line_item"=> [
58
+ {
59
+ "public_id"=>"2FCA83283",
60
+ "status"=>"accepted",
61
+ "reject_reason"=>"Some reason", # Only required if status is rejected
62
+ "distributor_identifier" => 'your-line-item-id', # Optional
63
+ "estimated_ship_date" => "2010-08-09T17:23:12Z" # Optional
64
+ },
65
+ .... # more line items as needed
66
+ ]
67
+ }
68
+ }
69
+
70
+ Additional keys will be ignored. See the API documentation for more detail on the allowed values.
71
+
72
+ === Create a shipment
73
+
74
+ bws.create_shipment(shipment_hash)
75
+
76
+ Returns a BWS::CreateShipment object which you can call .result? on to get success or failure
77
+
78
+ shipment_hash should look like this:
79
+
80
+ {
81
+ "public_id" => 'BR-A06028299',
82
+ 'estimated_delivery_date' => "2010-08-09T17:23:12Z", # Optional
83
+ 'shipping_method' => 'Ground',
84
+ 'shipped_at' => "2010-08-09T17:23:12Z", # Optional
85
+ 'cost_cents' => '1000', # Optional
86
+ 'carrier' => 'UPS',
87
+ 'tracking_number' => '1Z12390128398123', # Optional
88
+ 'distributor_line_items' => [{'public_id' => 'AB9DD69A4'}]
89
+ }
90
+
91
+ Additional keys will be ignored. See the API documentation for more detail on the allowed values.
92
+
93
+ === Reject a Line Item
94
+
95
+ bws.reject_line_item(line_item_hash)
96
+
97
+ Returns a BWS::RejectLineItem object which you can call .result? on to get success or failure
98
+
99
+ line_item_hash should look like this:
100
+
101
+ {
102
+ "public_id" => '1234',
103
+ 'reject_reason' => "Some Reason"
104
+ }
105
+
106
+ Additional keys will be ignored. See the API documentation for more detail on the allowed values.
107
+
108
+
109
+ == Running Tests
110
+
111
+ gem install activesupport
112
+ gem install i18n
113
+
114
+ == Copyright
115
+
116
+ Copyright (c) 2010-11 Bookrenter Inc. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ begin
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ gem.name = "bws"
16
+ gem.summary = %Q{Interact with the Bookrenter Web Services API}
17
+ gem.description = %Q{Interact with the Bookrenter Web Services API}
18
+ gem.email = ["cameron.booth@bookrenter.com", "paolo.resmini@bookrenter.com"]
19
+ gem.homepage = "http://github.com/bkr/bws"
20
+ gem.authors = ["Cameron Booth", "Paolo Resmini"]
21
+ gem.add_dependency "httparty", ">= 0.6.1"
22
+ gem.add_dependency "builder", ">= 2.1.2"
23
+ gem.add_development_dependency "shoulda", ">= 0"
24
+ gem.add_development_dependency "fakeweb", ">= 0"
25
+ gem.add_development_dependency "mocha", ">= 0"
26
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
27
+ end
28
+ Jeweler::GemcutterTasks.new
29
+ rescue LoadError
30
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
31
+ end
32
+
33
+ Jeweler::GemcutterTasks.new
34
+ Jeweler::RubygemsDotOrgTasks.new
35
+
36
+ require 'rake/testtask'
37
+
38
+ [{:type => "test:all", :folder => '**'}, {:type => "test:units", :folder => 'unit'}, {:type => "test:integration", :folder => 'integration'}, {:type => "test:functionals", :folder => 'functional'}].each do |test|
39
+ Rake::TestTask.new(test[:type]) do |t|
40
+ t.libs << 'lib' << 'test'
41
+ t.pattern = "test/#{test[:folder]}/test_*.rb"
42
+ t.verbose = true
43
+ end
44
+ end
45
+
46
+ task :default => ["test:all"]
47
+
48
+ require 'rdoc/task'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "bws #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/bws.gemspec ADDED
@@ -0,0 +1,133 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "bws"
8
+ s.version = "0.2.1.pre"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Cameron Booth", "Paolo Resmini"]
12
+ s.date = "2013-11-27"
13
+ s.description = "Interact with the Bookrenter Web Services API"
14
+ s.email = ["cameron.booth@bookrenter.com", "paolo.resmini@bookrenter.com"]
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "bws.gemspec",
28
+ "lib/bws.rb",
29
+ "lib/bws/acknowledge_order.rb",
30
+ "lib/bws/active_isbn_report.rb",
31
+ "lib/bws/checkout.rb",
32
+ "lib/bws/client.rb",
33
+ "lib/bws/create_shipment.rb",
34
+ "lib/bws/fillable_orders.rb",
35
+ "lib/bws/inventory.rb",
36
+ "lib/bws/order.rb",
37
+ "lib/bws/order_events.rb",
38
+ "lib/bws/orders.rb",
39
+ "lib/bws/reject_line_item.rb",
40
+ "lib/bws/response.rb",
41
+ "lib/bws/unacknowledged_orders.rb",
42
+ "test/fixtures/acknowledge_success.xml",
43
+ "test/fixtures/active_isbn_report_with_one_isbn_request_body.xml",
44
+ "test/fixtures/active_isbn_report_with_one_isbn_success.xml",
45
+ "test/fixtures/active_isbn_report_with_two_isbns_request_body.xml",
46
+ "test/fixtures/active_isbn_report_with_two_isbns_success.xml",
47
+ "test/fixtures/cancel_line_item_success.xml",
48
+ "test/fixtures/create_order_request_body.xml",
49
+ "test/fixtures/create_order_response_success.xml",
50
+ "test/fixtures/create_shipment_success.xml",
51
+ "test/fixtures/fillable_success.xml",
52
+ "test/fixtures/inventory_by_isbn_success.xml",
53
+ "test/fixtures/inventory_success.xml",
54
+ "test/fixtures/order_events_by_order_success.xml",
55
+ "test/fixtures/order_events_success.xml",
56
+ "test/fixtures/order_success.xml",
57
+ "test/fixtures/orders_show_success.xml",
58
+ "test/fixtures/price_order_request_body.xml",
59
+ "test/fixtures/price_order_response_success.xml",
60
+ "test/fixtures/single_post_create_order_request_body.xml",
61
+ "test/fixtures/single_post_create_order_response_success.xml",
62
+ "test/fixtures/unacknowledged_success.xml",
63
+ "test/fixtures/unacknowledged_success_0_orders.xml",
64
+ "test/fixtures/unacknowledged_success_1_order.xml",
65
+ "test/fixtures/validate_credit_card_request_body.xml",
66
+ "test/fixtures/validate_credit_card_response_success.xml",
67
+ "test/helper.rb",
68
+ "test/integration/test_bws_active_isbn_report.rb",
69
+ "test/integration/test_bws_retrieve_inventory.rb",
70
+ "test/unit/test_bws_acknowledge_order.rb",
71
+ "test/unit/test_bws_active_isbn_report.rb",
72
+ "test/unit/test_bws_checkout.rb",
73
+ "test/unit/test_bws_client.rb",
74
+ "test/unit/test_bws_create_shipment.rb",
75
+ "test/unit/test_bws_fillable_orders.rb",
76
+ "test/unit/test_bws_order.rb",
77
+ "test/unit/test_bws_reject_line_item.rb",
78
+ "test/unit/test_bws_response.rb",
79
+ "test/unit/test_bws_retrieve_inventory.rb",
80
+ "test/unit/test_bws_retrieve_inventory_by_isbn.rb",
81
+ "test/unit/test_bws_retrieve_order_events.rb",
82
+ "test/unit/test_bws_retrieve_order_events_by_order.rb",
83
+ "test/unit/test_bws_unacknowledged_orders.rb",
84
+ "test/unit/test_retrieve_orders_show.rb"
85
+ ]
86
+ s.homepage = "http://github.com/bkr/bws"
87
+ s.require_paths = ["lib"]
88
+ s.rubygems_version = "1.8.24"
89
+ s.summary = "Interact with the Bookrenter Web Services API"
90
+
91
+ if s.respond_to? :specification_version then
92
+ s.specification_version = 3
93
+
94
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
95
+ s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
96
+ s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
97
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
98
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
99
+ s.add_development_dependency(%q<rake>, [">= 0.9.2.2"])
100
+ s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
101
+ s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
102
+ s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
103
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
104
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
105
+ s.add_development_dependency(%q<mocha>, [">= 0"])
106
+ else
107
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
108
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
109
+ s.add_dependency(%q<activesupport>, [">= 0"])
110
+ s.add_dependency(%q<i18n>, [">= 0"])
111
+ s.add_dependency(%q<rake>, [">= 0.9.2.2"])
112
+ s.add_dependency(%q<jeweler>, [">= 1.6.4"])
113
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
114
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
115
+ s.add_dependency(%q<shoulda>, [">= 0"])
116
+ s.add_dependency(%q<fakeweb>, [">= 0"])
117
+ s.add_dependency(%q<mocha>, [">= 0"])
118
+ end
119
+ else
120
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
121
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
122
+ s.add_dependency(%q<activesupport>, [">= 0"])
123
+ s.add_dependency(%q<i18n>, [">= 0"])
124
+ s.add_dependency(%q<rake>, [">= 0.9.2.2"])
125
+ s.add_dependency(%q<jeweler>, [">= 1.6.4"])
126
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
127
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
128
+ s.add_dependency(%q<shoulda>, [">= 0"])
129
+ s.add_dependency(%q<fakeweb>, [">= 0"])
130
+ s.add_dependency(%q<mocha>, [">= 0"])
131
+ end
132
+ end
133
+
data/lib/bws.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'bws/client'
2
+ require 'bws/response'
3
+ require 'bws/unacknowledged_orders'
4
+ require 'bws/fillable_orders'
5
+ require 'bws/order'
6
+ require 'bws/acknowledge_order'
7
+ require 'bws/create_shipment'
8
+ require 'bws/reject_line_item'
9
+ require 'bws/inventory'
10
+ require 'bws/order_events'
11
+ require 'bws/checkout'
12
+ require 'bws/orders'
13
+ require 'bws/active_isbn_report'
@@ -0,0 +1,11 @@
1
+ class BWS::AcknowledgeOrder < BWS::Response
2
+
3
+ def result
4
+ base.nil?
5
+ end
6
+
7
+ private
8
+ def base
9
+ response.parsed_response['envelope']['body']['distributor_orders_acknowledge']
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ class BWS::ActiveIsbnReport < BWS::Response
2
+ def result
3
+ base.nil?
4
+ end
5
+
6
+ def active_isbns
7
+ return active_isbn_report['active_isbns']['active_isbn'] if active_isbn_report && active_isbn_report['active_isbns'] && active_isbn_report['active_isbns']['active_isbn'].class == Array
8
+
9
+ return [ active_isbn_report['active_isbns']['active_isbn'] ] if active_isbn_report && active_isbn_report['active_isbns'] && active_isbn_report['active_isbns']['active_isbn'].class == Hash
10
+
11
+ return []
12
+ end
13
+
14
+ def pagination
15
+ base['pagination']
16
+ end
17
+
18
+ private
19
+
20
+ def active_isbn_report
21
+ base['active_isbn_report']
22
+ end
23
+
24
+ def base
25
+ response.parsed_response['envelope']['body']['reports_active_isbn_report']
26
+ end
27
+ end