freight_kit 0.1.21 → 0.1.23
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 +4 -4
- data/README.md +5 -3
- data/Rakefile +1 -3
- data/VERSION +1 -1
- data/freight_kit-0.1.21.gem +0 -0
- data/freight_kit-0.1.22.gem +0 -0
- data/freight_kit.gemspec +8 -19
- data/lib/freight_kit/address_normalizer.rb +1 -3
- data/lib/freight_kit/api_clients/soap_client.rb +30 -5
- data/lib/freight_kit/carrier.rb +36 -7
- data/lib/freight_kit/carriers/a1_express.rb +11 -0
- data/lib/freight_kit/carriers/abf_freight_system.rb +9 -26
- data/lib/freight_kit/carriers/aloha_freight_forwarders.rb +1 -5
- data/lib/freight_kit/carriers/amado_trucking.rb +1 -5
- data/lib/freight_kit/carriers/clear_lane_freight_systems.rb +6 -15
- data/lib/freight_kit/carriers/cpl_express.rb +1 -5
- data/lib/freight_kit/carriers/cross_country_freight_solutions.rb +6 -17
- data/lib/freight_kit/carriers/dependable_highway_express.rb +6 -18
- data/lib/freight_kit/carriers/forward_air.rb +4 -12
- data/lib/freight_kit/carriers/gsp_express.rb +13 -0
- data/lib/freight_kit/carriers/on_trac.rb +7 -25
- data/lib/freight_kit/carriers/peninsula_truck_lines.rb +4 -20
- data/lib/freight_kit/carriers/roadrunner_transportation_services.rb +2 -8
- data/lib/freight_kit/carriers/saia.rb +4 -19
- data/lib/freight_kit/carriers/southeastern_freight_lines.rb +4 -13
- data/lib/freight_kit/carriers/t_force_worldwide.rb +7 -19
- data/lib/freight_kit/carriers/top_ten_express.rb +13 -0
- data/lib/freight_kit/carriers/total_quality_logistics.rb +2 -1
- data/lib/freight_kit/carriers/western_regional_delivery_service.rb +26 -11
- data/lib/freight_kit/carriers/xpo_logistics.rb +5 -17
- data/lib/freight_kit/errors/rate_limit_error.rb +12 -0
- data/lib/freight_kit/errors/unserviceable_accessorials_error.rb +1 -3
- data/lib/freight_kit/helpers/pickupable.rb +1 -10
- data/lib/freight_kit/http_client/httpi_adapter.rb +37 -0
- data/lib/freight_kit/http_client/safe_retries.rb +17 -1
- data/lib/freight_kit/http_client.rb +13 -9
- data/lib/freight_kit/models/credential.rb +2 -15
- data/lib/freight_kit/models/lane.rb +20 -0
- data/lib/freight_kit/models/shipment.rb +1 -8
- data/lib/freight_kit/models/territory.rb +37 -0
- data/lib/freight_kit/package.rb +3 -13
- data/lib/freight_kit/packaging.rb +1 -16
- data/lib/freight_kit/platforms/carrier_logistics.rb +5 -10
- data/lib/freight_kit/platforms/dsdc.rb +82 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/mutation/quote_create.rb +32 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/mutation/shipment_create.rb +29 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/broker_carrier.rb +37 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/broker_carriers.rb +45 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/broker_customer.rb +54 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/broker_customers.rb +62 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/carrier.rb +22 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/carriers.rb +30 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/customer.rb +20 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/customers.rb +28 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/invoice.rb +31 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/invoices.rb +39 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/shipment.rb +102 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/shipment_documents.rb +29 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client/query/shipments.rb +110 -0
- data/lib/freight_kit/platforms/next_tms/graphql_client.rb +22 -0
- data/lib/freight_kit/platforms/next_tms/orm/address.rb +22 -0
- data/lib/freight_kit/platforms/next_tms/orm/base.rb +120 -0
- data/lib/freight_kit/platforms/next_tms/orm/broker_carrier.rb +18 -0
- data/lib/freight_kit/platforms/next_tms/orm/broker_customer.rb +22 -0
- data/lib/freight_kit/platforms/next_tms/orm/carrier.rb +14 -0
- data/lib/freight_kit/platforms/next_tms/orm/collection.rb +335 -0
- data/lib/freight_kit/platforms/next_tms/orm/customer.rb +12 -0
- data/lib/freight_kit/platforms/next_tms/orm/invoice.rb +21 -0
- data/lib/freight_kit/platforms/next_tms/orm/record_not_found_error.rb +9 -0
- data/lib/freight_kit/platforms/next_tms/orm/shipment.rb +50 -0
- data/lib/freight_kit/platforms/next_tms/orm.rb +38 -0
- data/lib/freight_kit/platforms/next_tms.rb +414 -55
- data/lib/freight_kit/platforms/the_great_information_factory.rb +4 -12
- data/lib/freight_kit.rb +19 -0
- data/schemas/next_tms.json +110710 -0
- metadata +86 -5
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module FreightKit
|
|
2
|
+
module Platforms
|
|
3
|
+
class NextTMS
|
|
4
|
+
class GraphQLClient
|
|
5
|
+
module Query
|
|
6
|
+
class Invoices
|
|
7
|
+
DETAILS = Client.parse(<<~GRAPHQL)
|
|
8
|
+
query($filter: InvoiceFilter, $page: Int, $pageSize: Int, $sort: [String!]) {
|
|
9
|
+
invoices(filter: $filter, page: $page, pageSize: $pageSize, sort: $sort) {
|
|
10
|
+
items {
|
|
11
|
+
balanceCents
|
|
12
|
+
balanceCurrency
|
|
13
|
+
dueOn
|
|
14
|
+
id
|
|
15
|
+
issuedOn
|
|
16
|
+
number
|
|
17
|
+
paidAt
|
|
18
|
+
shipment {
|
|
19
|
+
id
|
|
20
|
+
loadId
|
|
21
|
+
}
|
|
22
|
+
totalCents
|
|
23
|
+
totalCurrency
|
|
24
|
+
}
|
|
25
|
+
page
|
|
26
|
+
pageSize
|
|
27
|
+
pages
|
|
28
|
+
totalItems
|
|
29
|
+
updatedAt
|
|
30
|
+
version
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
GRAPHQL
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
module FreightKit
|
|
2
|
+
module Platforms
|
|
3
|
+
class NextTMS
|
|
4
|
+
class GraphQLClient
|
|
5
|
+
module Query
|
|
6
|
+
class Shipment
|
|
7
|
+
DETAILS = Client.parse(<<~GRAPHQL)
|
|
8
|
+
query($id: ID!) {
|
|
9
|
+
shipment(id: $id) {
|
|
10
|
+
bol
|
|
11
|
+
bookedAt
|
|
12
|
+
brokerCarrier {
|
|
13
|
+
account
|
|
14
|
+
carrier {
|
|
15
|
+
id
|
|
16
|
+
mcNumber
|
|
17
|
+
name
|
|
18
|
+
scac
|
|
19
|
+
}
|
|
20
|
+
id
|
|
21
|
+
}
|
|
22
|
+
brokerCustomer {
|
|
23
|
+
customer {
|
|
24
|
+
id
|
|
25
|
+
name
|
|
26
|
+
}
|
|
27
|
+
id
|
|
28
|
+
}
|
|
29
|
+
canceledAt
|
|
30
|
+
createdAt
|
|
31
|
+
customerReference
|
|
32
|
+
deliveredAt
|
|
33
|
+
deliveryAppointmentAt
|
|
34
|
+
deliveryAppointmentOn
|
|
35
|
+
deliveryEtaOn
|
|
36
|
+
departedOriginTerminalAt
|
|
37
|
+
dispatchedAt
|
|
38
|
+
events {
|
|
39
|
+
city
|
|
40
|
+
countryAlpha2
|
|
41
|
+
id
|
|
42
|
+
name
|
|
43
|
+
occurredAt
|
|
44
|
+
regionIso31662
|
|
45
|
+
typeCode
|
|
46
|
+
zipCode
|
|
47
|
+
}
|
|
48
|
+
id
|
|
49
|
+
loadId
|
|
50
|
+
lostOn
|
|
51
|
+
outForDeliveryAt
|
|
52
|
+
pendingAppointmentSince
|
|
53
|
+
pickedUpAt
|
|
54
|
+
pickupDriverAssignedAt
|
|
55
|
+
pickupOn
|
|
56
|
+
pro
|
|
57
|
+
receiverAddress {
|
|
58
|
+
city
|
|
59
|
+
country {
|
|
60
|
+
alpha2Code
|
|
61
|
+
}
|
|
62
|
+
id
|
|
63
|
+
region {
|
|
64
|
+
abbreviation
|
|
65
|
+
}
|
|
66
|
+
street
|
|
67
|
+
street2
|
|
68
|
+
timeZoneName
|
|
69
|
+
zipCode
|
|
70
|
+
}
|
|
71
|
+
receiverName
|
|
72
|
+
shipperAddress {
|
|
73
|
+
city
|
|
74
|
+
country {
|
|
75
|
+
alpha2Code
|
|
76
|
+
}
|
|
77
|
+
id
|
|
78
|
+
region {
|
|
79
|
+
abbreviation
|
|
80
|
+
}
|
|
81
|
+
street
|
|
82
|
+
street2
|
|
83
|
+
timeZoneName
|
|
84
|
+
zipCode
|
|
85
|
+
}
|
|
86
|
+
shipperBol
|
|
87
|
+
shipperName
|
|
88
|
+
shipperReference
|
|
89
|
+
status
|
|
90
|
+
totalChargesCents
|
|
91
|
+
totalChargesCurrency
|
|
92
|
+
truckload
|
|
93
|
+
updatedAt
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
GRAPHQL
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module FreightKit
|
|
2
|
+
module Platforms
|
|
3
|
+
class NextTMS
|
|
4
|
+
class GraphQLClient
|
|
5
|
+
module Query
|
|
6
|
+
# Never cached, since document URLs expire after 5 minutes
|
|
7
|
+
class ShipmentDocuments
|
|
8
|
+
DETAILS = Client.parse(<<~GRAPHQL)
|
|
9
|
+
query($filter: ShipmentFilter, $page: Int, $pageSize: Int) {
|
|
10
|
+
shipments(filter: $filter, page: $page, pageSize: $pageSize) {
|
|
11
|
+
items {
|
|
12
|
+
documents {
|
|
13
|
+
contentType
|
|
14
|
+
filename
|
|
15
|
+
kind
|
|
16
|
+
url
|
|
17
|
+
}
|
|
18
|
+
id
|
|
19
|
+
loadId
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
GRAPHQL
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
module FreightKit
|
|
2
|
+
module Platforms
|
|
3
|
+
class NextTMS
|
|
4
|
+
class GraphQLClient
|
|
5
|
+
module Query
|
|
6
|
+
class Shipments
|
|
7
|
+
DETAILS = Client.parse(<<~GRAPHQL)
|
|
8
|
+
query($filter: ShipmentFilter, $page: Int, $pageSize: Int, $sort: [String!]) {
|
|
9
|
+
shipments(filter: $filter, page: $page, pageSize: $pageSize, sort: $sort) {
|
|
10
|
+
items {
|
|
11
|
+
bol
|
|
12
|
+
bookedAt
|
|
13
|
+
brokerCarrier {
|
|
14
|
+
account
|
|
15
|
+
carrier {
|
|
16
|
+
id
|
|
17
|
+
mcNumber
|
|
18
|
+
name
|
|
19
|
+
scac
|
|
20
|
+
}
|
|
21
|
+
id
|
|
22
|
+
}
|
|
23
|
+
brokerCustomer {
|
|
24
|
+
customer {
|
|
25
|
+
id
|
|
26
|
+
name
|
|
27
|
+
}
|
|
28
|
+
id
|
|
29
|
+
}
|
|
30
|
+
canceledAt
|
|
31
|
+
createdAt
|
|
32
|
+
customerReference
|
|
33
|
+
deliveredAt
|
|
34
|
+
deliveryAppointmentAt
|
|
35
|
+
deliveryAppointmentOn
|
|
36
|
+
deliveryEtaOn
|
|
37
|
+
departedOriginTerminalAt
|
|
38
|
+
dispatchedAt
|
|
39
|
+
events {
|
|
40
|
+
city
|
|
41
|
+
countryAlpha2
|
|
42
|
+
id
|
|
43
|
+
name
|
|
44
|
+
occurredAt
|
|
45
|
+
regionIso31662
|
|
46
|
+
typeCode
|
|
47
|
+
zipCode
|
|
48
|
+
}
|
|
49
|
+
id
|
|
50
|
+
loadId
|
|
51
|
+
lostOn
|
|
52
|
+
outForDeliveryAt
|
|
53
|
+
pendingAppointmentSince
|
|
54
|
+
pickedUpAt
|
|
55
|
+
pickupDriverAssignedAt
|
|
56
|
+
pickupOn
|
|
57
|
+
pro
|
|
58
|
+
receiverAddress {
|
|
59
|
+
city
|
|
60
|
+
country {
|
|
61
|
+
alpha2Code
|
|
62
|
+
}
|
|
63
|
+
id
|
|
64
|
+
region {
|
|
65
|
+
abbreviation
|
|
66
|
+
}
|
|
67
|
+
street
|
|
68
|
+
street2
|
|
69
|
+
timeZoneName
|
|
70
|
+
zipCode
|
|
71
|
+
}
|
|
72
|
+
receiverName
|
|
73
|
+
shipperAddress {
|
|
74
|
+
city
|
|
75
|
+
country {
|
|
76
|
+
alpha2Code
|
|
77
|
+
}
|
|
78
|
+
id
|
|
79
|
+
region {
|
|
80
|
+
abbreviation
|
|
81
|
+
}
|
|
82
|
+
street
|
|
83
|
+
street2
|
|
84
|
+
timeZoneName
|
|
85
|
+
zipCode
|
|
86
|
+
}
|
|
87
|
+
shipperBol
|
|
88
|
+
shipperName
|
|
89
|
+
shipperReference
|
|
90
|
+
status
|
|
91
|
+
totalChargesCents
|
|
92
|
+
totalChargesCurrency
|
|
93
|
+
truckload
|
|
94
|
+
updatedAt
|
|
95
|
+
}
|
|
96
|
+
page
|
|
97
|
+
pageSize
|
|
98
|
+
pages
|
|
99
|
+
totalItems
|
|
100
|
+
updatedAt
|
|
101
|
+
version
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
GRAPHQL
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module FreightKit
|
|
2
|
+
module Platforms
|
|
3
|
+
class NextTMS
|
|
4
|
+
# Parses each `Query::*::DETAILS` document against the Next TMS schema when it loads, so a wrong field or argument
|
|
5
|
+
# fails at boot rather than at request time.
|
|
6
|
+
class GraphQLClient
|
|
7
|
+
# Sends documents to the tenant in `context[:platform]`, so one parsed document serves every tenant.
|
|
8
|
+
class HTTPAdapter
|
|
9
|
+
def execute(document:, context: {}, operation_name: nil, variables: {})
|
|
10
|
+
context.fetch(:platform).execute(document.to_query_string, operation_name:, variables:)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Introspection of the GraphQL API, which every tenant shares
|
|
15
|
+
SCHEMA_PATH = File.expand_path('../../../../schemas/next_tms.json', __dir__).freeze
|
|
16
|
+
|
|
17
|
+
Schema = GraphQL::Client.load_schema(JSON.parse(File.read(SCHEMA_PATH)))
|
|
18
|
+
Client = GraphQL::Client.new(schema: Schema, execute: HTTPAdapter.new)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module FreightKit
|
|
2
|
+
module Platforms
|
|
3
|
+
class NextTMS
|
|
4
|
+
module ORM
|
|
5
|
+
# Embedded in other records, so it has no query of its own and is always loaded.
|
|
6
|
+
class Address < Base
|
|
7
|
+
def city = @city ||= attribute(:city)
|
|
8
|
+
def country = @country ||= attribute(:country)&.dig(:alpha2_code)&.then { |code| ActiveUtils::Country.find(code) }
|
|
9
|
+
def loaded? = true
|
|
10
|
+
def region = @region ||= attribute(:region)&.dig(:abbreviation)
|
|
11
|
+
def street = @street ||= attribute(:street)
|
|
12
|
+
def street2 = @street2 ||= attribute(:street2)
|
|
13
|
+
def time_zone_name = @time_zone_name ||= attribute(:time_zone_name)
|
|
14
|
+
|
|
15
|
+
def to_location = Location.new(address1: street, address2: street2, city:, country:, postal_code: zip_code, province: region)
|
|
16
|
+
|
|
17
|
+
def zip_code = @zip_code ||= attribute(:zip_code)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
module FreightKit
|
|
2
|
+
module Platforms
|
|
3
|
+
class NextTMS
|
|
4
|
+
module ORM
|
|
5
|
+
# A Next TMS record, loaded lazily from the tenant's GraphQL API with the {GraphQLClient::Query} of the same name.
|
|
6
|
+
# Records from a collection are loaded. Records from an association hold only the fields that its query selects
|
|
7
|
+
# for it, and load the rest when one is read.
|
|
8
|
+
class Base
|
|
9
|
+
class << self
|
|
10
|
+
attr_accessor :orm
|
|
11
|
+
|
|
12
|
+
delegate :count,
|
|
13
|
+
:find,
|
|
14
|
+
:find_by,
|
|
15
|
+
:find_by!,
|
|
16
|
+
:first,
|
|
17
|
+
:first!,
|
|
18
|
+
:ids,
|
|
19
|
+
:last,
|
|
20
|
+
:limit,
|
|
21
|
+
:none,
|
|
22
|
+
:not,
|
|
23
|
+
:offset,
|
|
24
|
+
:order,
|
|
25
|
+
:pluck,
|
|
26
|
+
:where,
|
|
27
|
+
to: :all
|
|
28
|
+
|
|
29
|
+
def all = Collection.new(self)
|
|
30
|
+
def association_type_mapping = {}
|
|
31
|
+
|
|
32
|
+
def build_association(name, data)
|
|
33
|
+
return if data&.dig(:id).blank?
|
|
34
|
+
|
|
35
|
+
class_name = association_type_mapping[name.to_sym] || name.to_s.classify
|
|
36
|
+
orm.const_get(class_name).new(data[:id], **data.except(:id))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def build_associations(name, items) = Array(items).filter_map { |data| build_association(name.to_s.singularize, data) }
|
|
40
|
+
|
|
41
|
+
# @return [Symbol] The collection query, e.g. `:broker_carriers` for {GraphQLClient::Query::BrokerCarriers}.
|
|
42
|
+
def collection_operation = graphql_name.pluralize.underscore.to_sym
|
|
43
|
+
|
|
44
|
+
# @return [Symbol] The singular query, e.g. `:broker_carrier` for {GraphQLClient::Query::BrokerCarrier}.
|
|
45
|
+
def element_operation = graphql_name.underscore.to_sym
|
|
46
|
+
|
|
47
|
+
def graphql_name = superclass == Base ? name.demodulize : superclass.graphql_name
|
|
48
|
+
|
|
49
|
+
def platform
|
|
50
|
+
raise ArgumentError, "#{name} is not bound to a tenant, use e.g. FreightKit::Carriers::JFJTransportation::ORM" if orm.nil?
|
|
51
|
+
|
|
52
|
+
orm.platform
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Instance variables that {#reload} keeps, all others memoize attributes
|
|
57
|
+
STATE = %i[@attributes @id @loaded].freeze
|
|
58
|
+
|
|
59
|
+
attr_reader :id
|
|
60
|
+
|
|
61
|
+
delegate :orm, :platform, to: :class
|
|
62
|
+
|
|
63
|
+
def initialize(id, created_at: nil, loaded: false, updated_at: nil, **attributes)
|
|
64
|
+
raise ArgumentError, 'id cannot be blank' if id.blank?
|
|
65
|
+
|
|
66
|
+
@attributes = { created_at:, updated_at: }.compact.merge(attributes)
|
|
67
|
+
# The API returns IDs without leading zeros, so `'01'` and `'1'` are the same record
|
|
68
|
+
@id = id.is_a?(String) && id.match?(/\A\d+\z/) ? id.to_i.to_s : id
|
|
69
|
+
@loaded = loaded
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def ==(other) = other.instance_of?(self.class) && other.id.to_s == id.to_s
|
|
73
|
+
alias eql? ==
|
|
74
|
+
|
|
75
|
+
def attribute(key)
|
|
76
|
+
reload unless @attributes.key?(key) || loaded?
|
|
77
|
+
|
|
78
|
+
@attributes[key]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def attributes
|
|
82
|
+
reload unless loaded?
|
|
83
|
+
|
|
84
|
+
@attributes
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def hash = [self.class, id.to_s].hash
|
|
88
|
+
def inspect = "#<#{self.class.name} id=#{id}>"
|
|
89
|
+
def loaded? = @loaded
|
|
90
|
+
|
|
91
|
+
# Loads every attribute, from {FreightKit.cache} when present.
|
|
92
|
+
def reload = load(cache: true)
|
|
93
|
+
|
|
94
|
+
# Loads every attribute from the API.
|
|
95
|
+
def reload! = load(cache: false)
|
|
96
|
+
|
|
97
|
+
private
|
|
98
|
+
|
|
99
|
+
def date(key) = attribute(key)&.then { |value| Date.iso8601(value) }
|
|
100
|
+
def fetch_association(name) = self.class.build_association(name, attribute(name))
|
|
101
|
+
def fetch_associations(name) = self.class.build_associations(name, attribute(name))
|
|
102
|
+
|
|
103
|
+
def load(cache:)
|
|
104
|
+
operation = self.class.element_operation
|
|
105
|
+
data = platform.query(operation, cache:, id:)[operation]
|
|
106
|
+
raise RecordNotFoundError, "Couldn't find #{self.class.name} with id #{id}" if data.nil?
|
|
107
|
+
|
|
108
|
+
(instance_variables - STATE).each { |variable| remove_instance_variable(variable) }
|
|
109
|
+
@attributes = data.except(:id)
|
|
110
|
+
@loaded = true
|
|
111
|
+
|
|
112
|
+
self
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def time(key) = attribute(key)&.then { |value| Time.iso8601(value) }
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module FreightKit
|
|
2
|
+
module Platforms
|
|
3
|
+
class NextTMS
|
|
4
|
+
module ORM
|
|
5
|
+
class BrokerCarrier < Base
|
|
6
|
+
def account = @account ||= attribute(:account)
|
|
7
|
+
def account_desc = @account_desc ||= attribute(:account_desc)
|
|
8
|
+
def broker_customer = @broker_customer ||= fetch_association(:broker_customer)
|
|
9
|
+
def carrier = @carrier ||= fetch_association(:carrier)
|
|
10
|
+
def create_invoice_on_pickup? = attribute(:create_invoice_on_pickup)
|
|
11
|
+
def days_to_pay_after_invoice_date = @days_to_pay_after_invoice_date ||= attribute(:days_to_pay_after_invoice_date)
|
|
12
|
+
def shipments = @shipments ||= orm::Shipment.where(broker_carrier: self)
|
|
13
|
+
def shipments_count = @shipments_count ||= attribute(:shipments_count)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module FreightKit
|
|
2
|
+
module Platforms
|
|
3
|
+
class NextTMS
|
|
4
|
+
module ORM
|
|
5
|
+
class BrokerCustomer < Base
|
|
6
|
+
class << self
|
|
7
|
+
def association_type_mapping = super.merge(office_address: 'Address', primary_pickup_address: 'Address')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def accounting_customer_id = @accounting_customer_id ||= attribute(:accounting_customer_id)
|
|
11
|
+
def broker_carriers = @broker_carriers ||= orm::BrokerCarrier.where(broker_customer: self)
|
|
12
|
+
def can_quote? = attribute(:can_quote)
|
|
13
|
+
def customer = @customer ||= fetch_association(:customer)
|
|
14
|
+
def office_address = @office_address ||= fetch_association(:office_address)
|
|
15
|
+
def primary_pickup_address = @primary_pickup_address ||= fetch_association(:primary_pickup_address)
|
|
16
|
+
def shipments = @shipments ||= orm::Shipment.where(broker_customer: self)
|
|
17
|
+
def valid_freight_classes = @valid_freight_classes ||= attribute(:valid_freight_classes)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module FreightKit
|
|
2
|
+
module Platforms
|
|
3
|
+
class NextTMS
|
|
4
|
+
module ORM
|
|
5
|
+
class Carrier < Base
|
|
6
|
+
def broker_carriers = @broker_carriers ||= orm::BrokerCarrier.where(carrier: self)
|
|
7
|
+
def mc_number = @mc_number ||= attribute(:mc_number)
|
|
8
|
+
def name = @name ||= attribute(:name)
|
|
9
|
+
def scac = @scac ||= attribute(:scac)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|