kounta_rest 0.1.7 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +67 -36
  3. data/lib/kounta/address.rb +14 -17
  4. data/lib/kounta/break.rb +6 -0
  5. data/lib/kounta/category.rb +12 -15
  6. data/lib/kounta/company.rb +59 -50
  7. data/lib/kounta/customer.rb +33 -32
  8. data/lib/kounta/errors.rb +8 -7
  9. data/lib/kounta/inventory.rb +5 -7
  10. data/lib/kounta/line.rb +18 -21
  11. data/lib/kounta/order.rb +45 -49
  12. data/lib/kounta/payment.rb +14 -17
  13. data/lib/kounta/person.rb +21 -24
  14. data/lib/kounta/price_list.rb +7 -9
  15. data/lib/kounta/product.rb +25 -27
  16. data/lib/kounta/register.rb +11 -14
  17. data/lib/kounta/resource.rb +105 -93
  18. data/lib/kounta/rest/client.rb +177 -79
  19. data/lib/kounta/shift.rb +25 -0
  20. data/lib/kounta/site.rb +46 -38
  21. data/lib/kounta/staff.rb +30 -0
  22. data/lib/kounta/tax.rb +7 -9
  23. data/lib/kounta/version.rb +1 -1
  24. data/lib/kounta/webhook.rb +16 -0
  25. data/lib/kounta.rb +42 -72
  26. metadata +77 -145
  27. data/.gitignore +0 -20
  28. data/.gitmodules +0 -3
  29. data/Gemfile +0 -4
  30. data/Rakefile +0 -1
  31. data/console.rb +0 -14
  32. data/kounta.gemspec +0 -33
  33. data/spec/fixtures/address.json +0 -12
  34. data/spec/fixtures/addresses.json +0 -25
  35. data/spec/fixtures/base_price_list.json +0 -52
  36. data/spec/fixtures/categories.json +0 -217
  37. data/spec/fixtures/category.json +0 -11
  38. data/spec/fixtures/companies_me.json +0 -45
  39. data/spec/fixtures/customer.json +0 -39
  40. data/spec/fixtures/customers.json +0 -26
  41. data/spec/fixtures/inventory.json +0 -10
  42. data/spec/fixtures/line.json +0 -7
  43. data/spec/fixtures/order.json +0 -67
  44. data/spec/fixtures/orders.json +0 -134
  45. data/spec/fixtures/payment.json +0 -6
  46. data/spec/fixtures/people.json +0 -20
  47. data/spec/fixtures/person.json +0 -41
  48. data/spec/fixtures/price_list.json +0 -52
  49. data/spec/fixtures/price_lists.json +0 -12
  50. data/spec/fixtures/product.json +0 -25
  51. data/spec/fixtures/products.json +0 -119
  52. data/spec/fixtures/site.json +0 -6
  53. data/spec/fixtures/sites.json +0 -14
  54. data/spec/fixtures/tax.json +0 -7
  55. data/spec/fixtures/taxes.json +0 -16
  56. data/spec/helper.rb +0 -28
  57. data/spec/kounta/address_spec.rb +0 -11
  58. data/spec/kounta/category_spec.rb +0 -11
  59. data/spec/kounta/company_spec.rb +0 -24
  60. data/spec/kounta/customer_spec.rb +0 -15
  61. data/spec/kounta/kounta_spec.rb +0 -21
  62. data/spec/kounta/line_spec.rb +0 -14
  63. data/spec/kounta/order_spec.rb +0 -37
  64. data/spec/kounta/payment_spec.rb +0 -14
  65. data/spec/kounta/person_spec.rb +0 -15
  66. data/spec/kounta/product_spec.rb +0 -16
  67. data/spec/kounta/resource_spec.rb +0 -95
  68. data/spec/kounta/rest/client_spec.rb +0 -38
  69. data/spec/kounta/site_spec.rb +0 -11
  70. data/spec/support/endpoints.rb +0 -72
@@ -1,16 +0,0 @@
1
- require "helper"
2
-
3
- describe Kounta::Product do
4
-
5
- subject { Kounta::Company.new.site(985).product(1) }
6
-
7
- it "should be able to to test for tags" do
8
- subject.tags_include?("Rosebud").should be(false)
9
- subject.tags_include?("Fragile").should be(true)
10
- end
11
-
12
- it "should have a resource path" do
13
- subject.resource_path.should eq({companies: 162, products: 1})
14
- end
15
-
16
- end
@@ -1,95 +0,0 @@
1
- require "helper"
2
-
3
- describe Kounta::Resource do
4
-
5
- subject { Kounta::Resource }
6
-
7
- before :each do
8
- subject.has_one(:address, Kounta::Address, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, addresses: item_id} })
9
- subject.has_many :addresses, Kounta::Address, {:company_id => :id}, lambda { |klass| {companies: klass.id, addresses: nil} }
10
- @instance = subject.new({:id => 345})
11
- end
12
-
13
- it "should populate details if created with a hash" do
14
- @instance.id.should be(345)
15
- end
16
-
17
- it "should coerce an array of data to itself" do
18
- results = subject.coerce [{:id => 1}, {:id => 2}, {:id => 3}]
19
- results.each do |result|
20
- result.should be_an_instance_of subject
21
- end
22
- end
23
-
24
- it "should create a has_one relationship mapping" do
25
- @instance.should respond_to(:address)
26
- end
27
-
28
- it "should respond with an object when supplied with an id" do
29
- @instance.address(1).should be_an_instance_of Kounta::Address
30
- WebMock.should have_requested(:get, singular_endpoint('addresses'))
31
- end
32
-
33
- it "should be able to create an empty instance of the has_one relationship and apply mappings to it" do
34
- @instance.id = 162
35
- address = @instance.address
36
- address.should be_an_instance_of Kounta::Address
37
- address.company_id.should be(162)
38
- end
39
-
40
- it "should create a has_many relationship mapping" do
41
- @instance.should respond_to(:addresses)
42
- end
43
-
44
- it "should respond with an array of objects" do
45
- @instance.addresses.each do |address|
46
- address.should be_an_instance_of Kounta::Address
47
- end
48
- end
49
-
50
- it "should apply assignments to the has_many relationship" do
51
- @instance.addresses.each do |address|
52
- address.company_id.should be(@instance.id)
53
- end
54
- end
55
-
56
- it "should have a reference to the rest client" do
57
- @instance.client.should be_an_instance_of Kounta::REST::Client
58
- end
59
-
60
- it "should be able to serialise itself to a hash" do
61
- @instance.to_hash.class.should be(Hash)
62
- @instance.to_hash(:merge => "me").should eq(:merge => "me")
63
- end
64
-
65
- it "should raise an error when presented with an unknown attribute" do
66
- expect { subject.new({:id => 345, :new_attribute => 'value'}) }.to raise_error Kounta::Errors::UnknownResourceAttribute
67
- end
68
-
69
- it "should be able to save a new object" do
70
- subject.property :number
71
- subject.property :product_id
72
- subject.property :quantity
73
- subject.property :notes
74
- subject.property :price_variation
75
- instance = subject.new
76
- instance.id = nil
77
- instance.define_singleton_method :resource_path, lambda { {companies: 162, orders: 6789, lines: nil} }
78
- instance.save!.should be_an_instance_of subject
79
- WebMock.should have_requested(:post, group_endpoint('lines'))
80
- end
81
-
82
- it "should be able to update an existing object" do
83
- subject.property :number
84
- subject.property :product_id
85
- subject.property :quantity
86
- subject.property :notes
87
- subject.property :price_variation
88
- instance = subject.new
89
- instance.id = 162
90
- instance.define_singleton_method :resource_path, lambda { {companies: 162, orders: 6789, lines: 2345} }
91
- instance.save!.should be_an_instance_of subject
92
- WebMock.should have_requested(:put, singular_endpoint('lines'))
93
- end
94
-
95
- end
@@ -1,38 +0,0 @@
1
- require "helper"
2
-
3
- describe Kounta::REST::Client do
4
-
5
- subject { Kounta::REST::Client.new }
6
-
7
- it "should throw an error when creating a client without required tokens" do
8
- Kounta.client_token = nil
9
- expect { Kounta::REST::Client.new }.to raise_error Kounta::Errors::MissingOauthDetails
10
- end
11
-
12
- it "should be able to create a new client" do
13
- subject.should be_an_instance_of(Kounta::REST::Client)
14
- end
15
-
16
- it "should be able to generate a url from an ordered hash" do
17
- subject.path_from_hash({companies: 162, products: nil}).should eq("companies/162/products")
18
- subject.path_from_hash({companies: 162, products: 1234}).should eq("companies/162/products/1234")
19
- end
20
-
21
- it "should be able to create objects from a response" do
22
- responses = subject.objects_from_response(Kounta::Product, :get, {companies: 162, products: nil})
23
- responses.each do |response|
24
- response.should be_an_instance_of Kounta::Product
25
- end
26
- end
27
-
28
- it "should be able to create an object from a response" do
29
- subject.object_from_response(Kounta::Product, :get, {companies: 162, products: 555}).should be_an_instance_of Kounta::Product
30
- end
31
-
32
- it "should refresh the token automatically" do
33
- stub_request(:get, group_endpoint('noop')).to_return(:body => {:message => "The access token provided has expired"}, :headers => endpoint_headers, :status => 400)
34
- stub_request(:post, "https://api.kounta.com/v1/token.json")
35
- expect { subject.perform({:company_id => 123, :noop => nil}, :get) }.to raise_error OAuth2::Error
36
- end
37
-
38
- end
@@ -1,11 +0,0 @@
1
- require "helper"
2
-
3
- describe Kounta::Site do
4
-
5
- subject { Kounta::Company.new.site(985) }
6
-
7
- it "should have a resource path" do
8
- subject.resource_path.should eq({companies: 162, sites: 923})
9
- end
10
-
11
- end
@@ -1,72 +0,0 @@
1
- module Helpers
2
-
3
- def company_me_endpoint
4
- /\/.+\/companies\/me\.json/
5
- end
6
-
7
- def base_pricelist_endpoint
8
- /\/.+\/price_lists\/base\.json/
9
- end
10
-
11
- def singular_endpoint(name)
12
- /\/.+\/#{name}\/\d+\.json/
13
- end
14
-
15
- def group_endpoint(name)
16
- /\/.+\/#{name}\.json/
17
- end
18
-
19
- def load_json_from_fixture(filename)
20
- File.read("#{Kounta.root}/spec/fixtures/#{filename}")
21
- end
22
-
23
- def endpoint_headers
24
- {'Content-Type' => 'application/json'}
25
- end
26
-
27
- def stub_endpoints
28
-
29
- # create
30
- stub_request(:post, group_endpoint('products')).to_return(:body => load_json_from_fixture('product.json'), :headers => endpoint_headers)
31
- stub_request(:post, group_endpoint('customers')).to_return(:body => load_json_from_fixture('customer.json'), :headers => endpoint_headers)
32
- stub_request(:post, group_endpoint('people')).to_return(:body => load_json_from_fixture('person.json'), :headers => endpoint_headers)
33
- stub_request(:post, group_endpoint('categories')).to_return(:body => load_json_from_fixture('category.json'), :headers => endpoint_headers)
34
- stub_request(:post, group_endpoint('addresses')).to_return(:body => load_json_from_fixture('address.json'), :headers => endpoint_headers)
35
- stub_request(:post, group_endpoint('payments')).to_return(:body => load_json_from_fixture('payment.json'), :headers => endpoint_headers)
36
- stub_request(:post, group_endpoint('lines')).to_return(:body => load_json_from_fixture('line.json'), :headers => endpoint_headers)
37
- stub_request(:post, group_endpoint('orders')).to_return(:body => load_json_from_fixture('order.json'), :headers => endpoint_headers)
38
-
39
- # read
40
- stub_request(:get, singular_endpoint('categories')).to_return(:body => load_json_from_fixture('category.json'), :headers => endpoint_headers)
41
- stub_request(:get, group_endpoint('categories')).to_return(:body => load_json_from_fixture('categories.json'), :headers => endpoint_headers)
42
- stub_request(:get, singular_endpoint('customers')).to_return(:body => load_json_from_fixture('customer.json'), :headers => endpoint_headers)
43
- stub_request(:get, group_endpoint('customers')).to_return(:body => load_json_from_fixture('customers.json'), :headers => endpoint_headers)
44
- stub_request(:get, singular_endpoint('people')).to_return(:body => load_json_from_fixture('person.json'), :headers => endpoint_headers)
45
- stub_request(:get, group_endpoint('people')).to_return(:body => load_json_from_fixture('people.json'), :headers => endpoint_headers)
46
- stub_request(:get, singular_endpoint('addresses')).to_return(:body => load_json_from_fixture('address.json'), :headers => endpoint_headers)
47
- stub_request(:get, group_endpoint('addresses')).to_return(:body => load_json_from_fixture('addresses.json'), :headers => endpoint_headers)
48
- stub_request(:get, singular_endpoint('products')).to_return(:body => load_json_from_fixture('product.json'), :headers => endpoint_headers)
49
- stub_request(:get, group_endpoint('products')).to_return(:body => load_json_from_fixture('products.json'), :headers => endpoint_headers)
50
- stub_request(:get, singular_endpoint('sites')).to_return(:body => load_json_from_fixture('site.json'), :headers => endpoint_headers)
51
- stub_request(:get, group_endpoint('sites')).to_return(:body => load_json_from_fixture('sites.json'), :headers => endpoint_headers)
52
- stub_request(:get, singular_endpoint('price_lists')).to_return(:body => load_json_from_fixture('price_list.json'), :headers => endpoint_headers)
53
- stub_request(:get, group_endpoint('price_lists')).to_return(:body => load_json_from_fixture('price_lists.json'), :headers => endpoint_headers)
54
- stub_request(:get, base_pricelist_endpoint).to_return(:body => load_json_from_fixture('price_list.json'), :headers => endpoint_headers)
55
- stub_request(:get, company_me_endpoint).to_return(:body => load_json_from_fixture('companies_me.json'), :headers => endpoint_headers)
56
- stub_request(:get, group_endpoint('taxes')).to_return(:body => load_json_from_fixture('taxes.json'), :headers => endpoint_headers)
57
- stub_request(:get, singular_endpoint('orders')).to_return(:body => load_json_from_fixture('order.json'), :headers => endpoint_headers)
58
- stub_request(:get, group_endpoint('orders')).to_return(:body => load_json_from_fixture('orders.json'), :headers => endpoint_headers)
59
- stub_request(:get, group_endpoint('inventory')).to_return(:body => load_json_from_fixture('inventory.json'), :headers => endpoint_headers)
60
-
61
- # update
62
- stub_request(:put, singular_endpoint('products')).to_return(:body => load_json_from_fixture('product.json'), :headers => endpoint_headers)
63
- stub_request(:put, singular_endpoint('customers')).to_return(:body => load_json_from_fixture('customer.json'), :headers => endpoint_headers)
64
- stub_request(:put, singular_endpoint('people')).to_return(:body => load_json_from_fixture('person.json'), :headers => endpoint_headers)
65
- stub_request(:put, singular_endpoint('categories')).to_return(:body => load_json_from_fixture('category.json'), :headers => endpoint_headers)
66
- stub_request(:put, singular_endpoint('addresses')).to_return(:body => load_json_from_fixture('address.json'), :headers => endpoint_headers)
67
- stub_request(:put, singular_endpoint('payments')).to_return(:body => load_json_from_fixture('payment.json'), :headers => endpoint_headers)
68
- stub_request(:put, singular_endpoint('lines')).to_return(:body => load_json_from_fixture('line.json'), :headers => endpoint_headers)
69
- stub_request(:put, singular_endpoint('orders')).to_return(:body => load_json_from_fixture('order.json'), :headers => endpoint_headers)
70
-
71
- end
72
- end