erp_integration 0.5.5 → 0.6.0
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 346594300ff75a2d7f21a9e226287fe43b8b4765105d80d73840e4ff8fd9c355
|
4
|
+
data.tar.gz: 67b680a54fec9cb91866b6d9658dc7eeb4a63168f76826a7bba421148c0a77a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e36d2c2d1b0c5f231cef0477a5154fe4a101f262d9171f20cbb3fc051df8feff4655dcd9f5265634f241056a35a8562ca2caa580488b49d6c4c865fa4456aa1
|
7
|
+
data.tar.gz: b6dcd7aa6843c5e8686a2489ea88ba80c3a2ba543b941d00f652ef0621b0a6feaebc93c4ae9dcbab78f199e139fa7900060b46c7b812a96cffa0022821f3f36f
|
@@ -17,6 +17,12 @@ module ErpIntegration
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
class ResourceNotFound < Error
|
21
|
+
def initialize
|
22
|
+
super "[ERP Integration] Couldn't find the requested resource."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
20
26
|
class HttpError < Faraday::Error
|
21
27
|
class BadRequest < HttpError; end
|
22
28
|
class AuthorizationRequired < HttpError; end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'finder_methods'
|
3
4
|
require_relative 'query_methods'
|
4
5
|
|
5
6
|
module ErpIntegration
|
6
7
|
module Fulfil
|
7
8
|
class ApiResource
|
8
9
|
include Enumerable
|
10
|
+
include FinderMethods
|
9
11
|
include QueryMethods
|
10
12
|
|
11
13
|
attr_accessor :resource_klass
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
module Fulfil
|
5
|
+
# The `FinderMethods` add various, simplistic lookup methods to find API resources.
|
6
|
+
# These methods should be the last method in the chain as it will invoke the HTTP
|
7
|
+
# request to Fulfil immediately.
|
8
|
+
#
|
9
|
+
# If you need more attributes than the default ID attribute for an ApiResource
|
10
|
+
# to be returned, add the `select` method before the finder method is being called
|
11
|
+
# in your application code.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# $ ErpIntegration::SalesOrder.select(:id, :product).find(100)
|
15
|
+
# => <ErpIntegration::SalesOrder @id=100 @product=10 />
|
16
|
+
module FinderMethods
|
17
|
+
# Looks up an individual resource based on resource's ID.
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# $ ErpIntegration::SalesOrder.find(100)
|
21
|
+
# => <ErpIntegration::SalesOrder @id=100 />
|
22
|
+
#
|
23
|
+
# @param id [Integer] The ID of the API resource.
|
24
|
+
# @return [ApiResource] The found resource in Fulfil.
|
25
|
+
def find(id)
|
26
|
+
find_by!(id: id) || raise(ResourceNotFound)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Looks up an individual resource based on the given attributes.
|
30
|
+
#
|
31
|
+
# @example
|
32
|
+
# $ ErpIntegration::SalesOrder.find_by(product: 10)
|
33
|
+
# => <ErpIntegration::SalesOrder @id=100 />
|
34
|
+
#
|
35
|
+
# @return [ApiResource|nil] The found resource in Fulfil.
|
36
|
+
def find_by(args)
|
37
|
+
where(args).first
|
38
|
+
end
|
39
|
+
|
40
|
+
# Looks up an individual resource based on the given attributes and raises
|
41
|
+
# an `ErpIntegration::ResourceNotFound` when the resource doesn't exist.
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
# $ ErpIntegration::SalesOrder.find_by!(product: 10)
|
45
|
+
# => ErpIntegration::ResourceNotFound
|
46
|
+
#
|
47
|
+
# @return [ApiResource|nil] The found resource in Fulfil.
|
48
|
+
def find_by!(args)
|
49
|
+
find_by(args) || raise(ResourceNotFound)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -12,7 +12,7 @@ module ErpIntegration
|
|
12
12
|
# @param sku [String] The product's SKU.
|
13
13
|
# @return [Boolean] Whether it's a BOM or not.
|
14
14
|
def bom?(sku)
|
15
|
-
select(:boms).
|
15
|
+
select(:boms).find_by!(code: sku).boms.any?
|
16
16
|
end
|
17
17
|
alias billing_of_materials? bom?
|
18
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erp_integration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Vermaas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -266,6 +266,7 @@ files:
|
|
266
266
|
- lib/erp_integration/errors.rb
|
267
267
|
- lib/erp_integration/fulfil/api_resource.rb
|
268
268
|
- lib/erp_integration/fulfil/client.rb
|
269
|
+
- lib/erp_integration/fulfil/finder_methods.rb
|
269
270
|
- lib/erp_integration/fulfil/query.rb
|
270
271
|
- lib/erp_integration/fulfil/query_methods.rb
|
271
272
|
- lib/erp_integration/fulfil/resources/bill_of_material.rb
|