cq-spree-api-client 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +11 -0
  6. data/CONTRIBUTING.md +8 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE +22 -0
  9. data/README.md +61 -0
  10. data/Rakefile +7 -0
  11. data/fixtures/cassette_library/Spree_API_Client_Addresses/address/should_load_address.yml +59 -0
  12. data/fixtures/cassette_library/Spree_API_Client_Addresses/update_address/should_update_address.yml +61 -0
  13. data/fixtures/cassette_library/Spree_API_Client_Shipments/shipment_ready/should_set_a_shipment_to_ready.yml +55 -0
  14. data/fixtures/cassette_library/Spree_API_Client_Shipments/shipment_ready/should_set_a_shipment_to_ship.yml +56 -0
  15. data/fixtures/cassette_library/countries.yml +62 -0
  16. data/fixtures/cassette_library/orders.yml +55 -0
  17. data/fixtures/cassette_library/payments.yml +48 -0
  18. data/fixtures/cassette_library/products.yml +241 -0
  19. data/fixtures/cassette_library/properties.yml +56 -0
  20. data/fixtures/cassette_library/request.yml +241 -0
  21. data/fixtures/cassette_library/return_authorizations.yml +48 -0
  22. data/fixtures/cassette_library/stock_items.yml +1950 -0
  23. data/fixtures/cassette_library/taxonomies.yml +62 -0
  24. data/fixtures/cassette_library/taxons.yml +60 -0
  25. data/fixtures/cassette_library/variants.yml +58 -0
  26. data/fixtures/cassette_library/zones.yml +49 -0
  27. data/lib/spree-api-client.rb +65 -0
  28. data/lib/spree-api-client/addresses.rb +20 -0
  29. data/lib/spree-api-client/adjustments.rb +23 -0
  30. data/lib/spree-api-client/checkouts.rb +27 -0
  31. data/lib/spree-api-client/connection.rb +27 -0
  32. data/lib/spree-api-client/countries.rb +15 -0
  33. data/lib/spree-api-client/credit_cards.rb +20 -0
  34. data/lib/spree-api-client/error.rb +47 -0
  35. data/lib/spree-api-client/line_items.rb +19 -0
  36. data/lib/spree-api-client/option_types.rb +31 -0
  37. data/lib/spree-api-client/option_values.rb +31 -0
  38. data/lib/spree-api-client/orders.rb +56 -0
  39. data/lib/spree-api-client/payments.rb +44 -0
  40. data/lib/spree-api-client/products.rb +31 -0
  41. data/lib/spree-api-client/promotions.rb +15 -0
  42. data/lib/spree-api-client/properties.rb +31 -0
  43. data/lib/spree-api-client/request.rb +59 -0
  44. data/lib/spree-api-client/return_authorizations.rb +31 -0
  45. data/lib/spree-api-client/shipments.rb +15 -0
  46. data/lib/spree-api-client/stock_items.rb +31 -0
  47. data/lib/spree-api-client/stock_locations.rb +31 -0
  48. data/lib/spree-api-client/taxonomies.rb +31 -0
  49. data/lib/spree-api-client/taxons.rb +36 -0
  50. data/lib/spree-api-client/users.rb +31 -0
  51. data/lib/spree-api-client/variants.rb +31 -0
  52. data/lib/spree-api-client/version.rb +7 -0
  53. data/lib/spree-api-client/zones.rb +31 -0
  54. data/spec/addresses_spec.rb +21 -0
  55. data/spec/client_spec.rb +32 -0
  56. data/spec/countries_spec.rb +12 -0
  57. data/spec/orders_spec.rb +12 -0
  58. data/spec/payments_spec.rb +12 -0
  59. data/spec/products_spec.rb +12 -0
  60. data/spec/properties_spec.rb +12 -0
  61. data/spec/return_authorizations_spec.rb +12 -0
  62. data/spec/shipments_spec.rb +19 -0
  63. data/spec/spec_helper.rb +80 -0
  64. data/spec/stock_items_spec.rb +12 -0
  65. data/spec/support/vcr.rb +9 -0
  66. data/spec/taxonomies_spec.rb +12 -0
  67. data/spec/taxons_spec.rb +12 -0
  68. data/spec/variants_spec.rb +12 -0
  69. data/spec/zones_spec.rb +12 -0
  70. data/spree-api-client.gemspec +33 -0
  71. metadata +268 -0
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Taxonomies
5
+ def taxonomies(options={})
6
+ get('taxonomies', options)['taxonomies']
7
+ end
8
+
9
+ def taxonomy(id, options={})
10
+ get("taxonomies/#{id}", options)
11
+ end
12
+
13
+ def new_taxonomy(options={})
14
+ get("taxonomies/#{id}/new", options)
15
+ end
16
+
17
+ def create_taxonomy(options={})
18
+ post("taxonomies", options)
19
+ end
20
+
21
+ def update_taxonomy(id, options={})
22
+ put("taxonomies/#{id}", options)
23
+ end
24
+
25
+ def delete_taxonomy(id, options={})
26
+ delete("taxonomies/#{id}", options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Taxons
5
+ def taxons(options={})
6
+ get("taxons", options)['taxons']
7
+ end
8
+
9
+ def taxon(taxon_ids, options={})
10
+ return [] unless taxon_ids.length
11
+ get("taxons/?ids=#{taxon_ids.join(',')}", options)
12
+ end
13
+
14
+ def taxonomy_taxons(taxonomy_id, options={})
15
+ get("taxonomies/#{taxonomy_id}/taxons", options)['taxons']
16
+ end
17
+
18
+ def taxonomy_taxon(taxonomy_id, taxon_id, options={})
19
+ get("taxonomies/#{taxonomy_id}/taxons/#{taxon_id}", options)
20
+ end
21
+
22
+ def create_taxon(taxonomy_id, options={})
23
+ post("taxonomies/#{taxonomy_id}/taxons/", options)
24
+ end
25
+
26
+ def update_taxon(taxonomy_id, taxon_id, options={})
27
+ put("taxonomies/#{taxonomy_id}/taxons/#{taxon_id}", options)
28
+ end
29
+
30
+ def delete_taxon(taxonomy_id, taxon_id, options={})
31
+ delete("taxonomies/#{taxonomy_id}/taxons/#{taxon_id}", options)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Users
5
+ def users(options={})
6
+ get('users', options)['users']
7
+ end
8
+
9
+ def user(user_id, options={})
10
+ get("users/#{user_id}", options)
11
+ end
12
+
13
+ def create_user(options={})
14
+ post("users", options)
15
+ end
16
+
17
+ def delete_user(id, options={})
18
+ delete("users/#{id}", options)
19
+ end
20
+
21
+ def update_users(user_id, options={})
22
+ put("users/#{user_id}", options)
23
+ end
24
+
25
+ def create_anonymous_user(options={})
26
+ post("anonymous_users", options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Variants
5
+ def variants(product_id, options={})
6
+ get("products/#{product_id}/variants", options)['variants']
7
+ end
8
+
9
+ def variant(product_id, variant_id, options={})
10
+ get("products/#{product_id}/variants/#{variant_id}", options)
11
+ end
12
+
13
+ def new_variant(product_id, options={})
14
+ get("products/#{product_id}/variants/new", options)
15
+ end
16
+
17
+ def create_variant(product_id, options={})
18
+ post("products/#{product_id}/variants/", options)
19
+ end
20
+
21
+ def update_variant(product_id, variant_id, options={})
22
+ put("products/#{product_id}/variants/#{variant_id}", options)
23
+ end
24
+
25
+ def delete_variant(product_id, variant_id, options={})
26
+ delete("products/#{product_id}/variants/#{variant_id}", options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ VERSION = "0.0.5"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Zones
5
+ def zones(options={})
6
+ get('zones', options)['zones']
7
+ end
8
+
9
+ def zone(id, options={})
10
+ get("zones/#{id}", options)
11
+ end
12
+
13
+ def new_zone(options={})
14
+ get("zones/#{id}/new", options)
15
+ end
16
+
17
+ def create_zone(options={})
18
+ post("zones", options)
19
+ end
20
+
21
+ def update_zone(id, options={})
22
+ put("zones/#{id}", options)
23
+ end
24
+
25
+ def delete_zone(id, options={})
26
+ delete("zones/#{id}", options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::API::Client::Addresses do
4
+ # vcr_options = { :cassette_name => "addresss" }
5
+ describe 'address', :vcr do
6
+ it 'should load address' do
7
+ client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
8
+ address = client.address('R123456789', 2)
9
+ address.should be_a(Hashie::Mash)
10
+ end
11
+ end
12
+
13
+ describe 'update_address', :vcr do
14
+ it 'should update address' do
15
+ client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
16
+ address = client.update_address('R123456789', 2, address: {city: 'Abernathy City'})
17
+ address.should be_a(Hashie::Mash)
18
+ address.city eq 'Abernathy City'
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::API::Client do
4
+ describe ".new" do
5
+ it "is a Spree::API::Client" do
6
+ Spree::API::Client.new('http://example.com/api', 'randomtokenstring').should be_a(Spree::API::Client)
7
+ end
8
+ end
9
+
10
+ describe 'api_endpoint' do
11
+ it 'should be stored' do
12
+ client = Spree::API::Client.new('http://example.com/api', 'randomtokenstring')
13
+ client.api_endpoint.should eql('http://example.com/api')
14
+ end
15
+ end
16
+
17
+ describe 'api_token' do
18
+ it 'should be stored' do
19
+ client = Spree::API::Client.new('http://example.com/api', 'randomtokenstring')
20
+ client.api_token.should eql('randomtokenstring')
21
+ end
22
+ end
23
+
24
+ describe 'request' do
25
+ vcr_options = { :cassette_name => "request" }
26
+ it 'should load stuff from the api', vcr: vcr_options do
27
+ client = Spree::API::Client.new('http://localhost:4000/store/api', 'randomtokenstring')
28
+ response = client.request(:get, 'products')
29
+ response.should be_a(Faraday::Response)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::API::Client::Countries do
4
+ vcr_options = { :cassette_name => "countries" }
5
+ describe 'countries', vcr: vcr_options do
6
+ it 'should load countries' do
7
+ client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
8
+ countries = client.countries
9
+ countries.should be_a(Array)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::API::Client::Orders do
4
+ vcr_options = { :cassette_name => "orders" }
5
+ describe 'orders', vcr: vcr_options do
6
+ it 'should load orders' do
7
+ client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
8
+ orders = client.orders
9
+ orders.should be_a(Array)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::API::Client::Payments do
4
+ vcr_options = { :cassette_name => "payments" }
5
+ describe 'payments', vcr: vcr_options do
6
+ it 'should load payments' do
7
+ client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
8
+ payments = client.payments('R610162112')
9
+ payments.should be_a(Array)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::API::Client::Products do
4
+ vcr_options = { :cassette_name => "products" }
5
+ describe 'products', vcr: vcr_options do
6
+ it 'should load products' do
7
+ client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
8
+ products = client.products
9
+ products.should be_a(Array)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::API::Client::Properties do
4
+ vcr_options = { :cassette_name => "properties" }
5
+ describe 'properties', vcr: vcr_options do
6
+ it 'should load properties' do
7
+ client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
8
+ properties = client.properties(1)
9
+ properties.should be_a(Array)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::API::Client::ReturnAuthorizations do
4
+ vcr_options = { :cassette_name => "return_authorizations" }
5
+ describe 'return_authorizations', vcr: vcr_options do
6
+ it 'should load return_authorizations' do
7
+ client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
8
+ return_authorizations = client.return_authorizations('R781501551')
9
+ return_authorizations.should be_a(Array)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::API::Client::Shipments do
4
+ describe 'shipment_ready', :vcr do
5
+ it 'should set a shipment to ready' do
6
+ pending "spree sample data is not happy with this request"
7
+ client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
8
+ shipment = client.shipment_ready(2)
9
+ shipment.should be_a(Hashie::Mash)
10
+ end
11
+
12
+ it 'should set a shipment to ship' do
13
+ pending "spree sample data is not happy with this request"
14
+ client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
15
+ shipment = client.ship_shipment(2)
16
+ shipment.should be_a(Hashie::Mash)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,80 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'spree-api-client'
4
+ require 'rspec'
5
+ require 'webmock/rspec'
6
+ require 'support/vcr'
7
+
8
+ RSpec.configure do |config|
9
+ # rspec-expectations config goes here. You can use an alternate
10
+ # assertion/expectation library such as wrong or the stdlib/minitest
11
+ # assertions if you prefer.
12
+ config.expect_with :rspec do |expectations|
13
+ # This option will default to `true` in RSpec 4. It makes the `description`
14
+ # and `failure_message` of custom matchers include text for helper methods
15
+ # defined using `chain`, e.g.:
16
+ # be_bigger_than(2).and_smaller_than(4).description
17
+ # # => "be bigger than 2 and smaller than 4"
18
+ # ...rather than:
19
+ # # => "be bigger than 2"
20
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
21
+ end
22
+
23
+ # rspec-mocks config goes here. You can use an alternate test double
24
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
25
+ config.mock_with :rspec do |mocks|
26
+ # Prevents you from mocking or stubbing a method that does not exist on
27
+ # a real object. This is generally recommended, and will default to
28
+ # `true` in RSpec 4.
29
+ mocks.verify_partial_doubles = true
30
+ end
31
+
32
+ # The settings below are suggested to provide a good initial experience
33
+ # with RSpec, but feel free to customize to your heart's content.
34
+
35
+ # These two settings work together to allow you to limit a spec run
36
+ # to individual examples or groups you care about by tagging them with
37
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
38
+ # get run.
39
+ config.filter_run :focus
40
+ config.run_all_when_everything_filtered = true
41
+
42
+ # Limits the available syntax to the non-monkey patched syntax that is
43
+ # recommended. For more details, see:
44
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
45
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
46
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
47
+ # config.disable_monkey_patching!
48
+
49
+ # This setting enables warnings. It's recommended, but in some cases may
50
+ # be too noisy due to issues in dependencies.
51
+ config.warnings = true
52
+
53
+ # Many RSpec users commonly either run the entire suite or an individual
54
+ # file, and it's useful to allow more verbose output when running an
55
+ # individual spec file.
56
+ if config.files_to_run.one?
57
+ # Use the documentation formatter for detailed output,
58
+ # unless a formatter has already been configured
59
+ # (e.g. via a command-line flag).
60
+ config.default_formatter = 'doc'
61
+ end
62
+
63
+ # Print the 10 slowest examples and example groups at the
64
+ # end of the spec run, to help surface which specs are running
65
+ # particularly slow.
66
+ # config.profile_examples = 2
67
+
68
+ # Run specs in random order to surface order dependencies. If you find an
69
+ # order dependency and want to debug it, you can fix the order by providing
70
+ # the seed, which is printed after each run.
71
+ # --seed 1234
72
+ config.order = :random
73
+
74
+ # Seed global randomization in this process using the `--seed` CLI option.
75
+ # Setting this allows you to use `--seed` to deterministically reproduce
76
+ # test failures related to randomization by passing the same `--seed` value
77
+ # as the one that triggered the failure.
78
+ Kernel.srand config.seed
79
+
80
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::API::Client::StockItems do
4
+ vcr_options = { :cassette_name => "stock_items" }
5
+ describe 'stock_items', vcr: vcr_options do
6
+ it 'should load stock_items' do
7
+ client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
8
+ stock_items = client.stock_items(1)
9
+ stock_items.stock_items.should be_a(Array)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.cassette_library_dir = 'fixtures/cassette_library'
5
+ c.hook_into :webmock
6
+ c.ignore_localhost = false
7
+ c.configure_rspec_metadata!
8
+ c.default_cassette_options = { :record => :new_episodes }
9
+ end