envia_ya 0.0.1
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 +7 -0
- data/lib/envia_ya.rb +20 -0
- data/lib/modules/rates/application/commands/create_rate_command.rb +24 -0
- data/lib/modules/rates/domain/dtos/create_rate_dto.rb +54 -0
- data/lib/modules/rates/domain/repositories/create_rate_repository.rb +15 -0
- data/lib/modules/rates/infrastructure/repositories/create_rate_repository/create_rate_http_repository.rb +29 -0
- data/lib/modules/shared/domain/connectors/http_connector.rb +13 -0
- data/lib/modules/shared/domain/entities/accounts_entity.rb +30 -0
- data/lib/modules/shared/domain/entities/direction_entity.rb +82 -0
- data/lib/modules/shared/domain/entities/parcel_entity.rb +58 -0
- data/lib/modules/shared/domain/entities/rate_entity.rb +109 -0
- data/lib/modules/shared/domain/entities/shipment_entity.rb +119 -0
- data/lib/modules/shared/domain/entities/surcharge_entity.rb +35 -0
- data/lib/modules/shared/domain/value_objects/dimension_unit_value_object.rb +21 -0
- data/lib/modules/shared/domain/value_objects/http_method_value_object.rb +21 -0
- data/lib/modules/shared/domain/value_objects/label_file_type_value_object.rb +21 -0
- data/lib/modules/shared/domain/value_objects/label_format_value_object.rb +17 -0
- data/lib/modules/shared/domain/value_objects/postal_code_value_object.rb +21 -0
- data/lib/modules/shared/domain/value_objects/shipment_type_value_object.rb +21 -0
- data/lib/modules/shared/domain/value_objects/weight_unit_value_object.rb +21 -0
- data/lib/modules/shared/infrastructure/connectors/http_connector/http_net_connector.rb +31 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 795a6d50587b4e31457975726b56498f596f677d00d4547145ba5cb04c341551
|
4
|
+
data.tar.gz: fa3de350b735faee19461e630c1162f5d8513d1592ba9b9c848c0b67113cefa2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e03a22e3b3b6253867f9b12c996d061b99186c1da1c2ae2fa143270e8398fd598607e30f2435f9dd3483b4756bb677b3ae039176e343d69611a933c2a795606
|
7
|
+
data.tar.gz: 76449491079363e762a9cca318594bce8fb28edb01903206ba1802aab3033f62f28894b2cddb9ba10af5c91b47c65b317401dbca28f7f7a10364172f86965b08
|
data/lib/envia_ya.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require_relative './modules/rates/application/commands/create_rate_command.rb'
|
3
|
+
|
4
|
+
module EnviaYa
|
5
|
+
include Rates::Application::Commands
|
6
|
+
|
7
|
+
class Config
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
attr_accessor :api_key
|
11
|
+
|
12
|
+
def self.api_key=(api_key)
|
13
|
+
instance.api_key = api_key
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.api_key
|
17
|
+
instance.api_key
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative '../../domain/dtos/create_rate_dto.rb'
|
2
|
+
require_relative '../../domain/repositories/create_rate_repository.rb'
|
3
|
+
|
4
|
+
module EnviaYa
|
5
|
+
module Rates
|
6
|
+
module Application
|
7
|
+
module Commands
|
8
|
+
class CreateRateCommand
|
9
|
+
def initialize(repository:)
|
10
|
+
raise TypeError, "repository expected CreateRateRepository but got: #{repository.class}" unless repository.is_a?(::EnviaYa::Rates::Domain::Repositories::CreateRateRepository)
|
11
|
+
|
12
|
+
@repository = repository
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute(create_rate_dto)
|
16
|
+
raise TypeError, "create_rate_dto expected CreateRateDto but got: #{create_rate_dto.class}" unless create_rate_dto.is_a?(::EnviaYa::Rates::Domain::Dtos::CreateRateDto)
|
17
|
+
|
18
|
+
@repository.execute(create_rate_dto)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative '../../../shared/domain/entities/direction_entity.rb'
|
2
|
+
require_relative '../../../shared/domain/entities/shipment_entity.rb'
|
3
|
+
require_relative '../../../shared/domain/entities/accounts_entity.rb'
|
4
|
+
|
5
|
+
module EnviaYa
|
6
|
+
module Rates
|
7
|
+
module Domain
|
8
|
+
module Dtos
|
9
|
+
class CreateRateDto
|
10
|
+
attr_reader :origin_direction,
|
11
|
+
:destination_direction,
|
12
|
+
:shipment,
|
13
|
+
:accounts,
|
14
|
+
:order_total_amount,
|
15
|
+
:intelligent_filtering
|
16
|
+
|
17
|
+
def initialize(
|
18
|
+
origin_direction: nil,
|
19
|
+
destination_direction: nil,
|
20
|
+
shipment:,
|
21
|
+
accounts: nil,
|
22
|
+
order_total_amount: nil,
|
23
|
+
intelligent_filtering: nil
|
24
|
+
)
|
25
|
+
raise TypeError, "origin_direction expected a DirectionEntity or NilClass but got: #{origin_direction.class}" unless origin_direction.is_a?(::EnviaYa::Shared::Domain::Entities::DirectionEntity) || origin_direction.is_a?(NilClass)
|
26
|
+
raise TypeError, "destination_direction expected a DirectionEntity or NilClass but got: #{destination_direction.class}" unless destination_direction.is_a?(::EnviaYa::Shared::Domain::Entities::DirectionEntity) || destination_direction.is_a?(NilClass)
|
27
|
+
raise TypeError, "shipment expected a DirectionEntity but got: #{shipment.class}" unless shipment.is_a?(::EnviaYa::Shared::Domain::Entities::ShipmentEntity)
|
28
|
+
raise TypeError, "accounts expected an AccountsEntity or NilClass but got: #{accounts.class}" unless accounts.is_a?(::EnviaYa::Shared::Domain::Entities::AccountsEntity) || accounts.is_a?(NilClass)
|
29
|
+
raise TypeError, "order_total_amount expected an Integer or NilClass but got: #{order_total_amount.class}" unless order_total_amount.is_a?(Integer) || order_total_amount.is_a?(NilClass)
|
30
|
+
raise TypeError, "intelligent_filtering expected a TrueClass, FalseClass or NilClass but got: #{intelligent_filtering.class}" unless intelligent_filtering.is_a?(TrueClass) || intelligent_filtering.is_a?(FalseClass) || intelligent_filtering.is_a?(NilClass)
|
31
|
+
|
32
|
+
@origin_direction = origin_direction
|
33
|
+
@destination_direction = destination_direction
|
34
|
+
@shipment = shipment
|
35
|
+
@accounts = accounts
|
36
|
+
@order_total_amount = order_total_amount
|
37
|
+
@intelligent_filtering = intelligent_filtering
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_hash
|
41
|
+
{
|
42
|
+
origin_direction: @origin_direction&.to_hash,
|
43
|
+
destination_direction: @destination_direction&.to_hash,
|
44
|
+
shipment: @shipment.to_hash,
|
45
|
+
accounts: @accounts&.to_hash,
|
46
|
+
order_total_amount: @order_total_amount,
|
47
|
+
intelligent_filtering: @intelligent_filtering,
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative '../dtos/create_rate_dto.rb'
|
2
|
+
|
3
|
+
module EnviaYa
|
4
|
+
module Rates
|
5
|
+
module Domain
|
6
|
+
module Repositories
|
7
|
+
class CreateRateRepository
|
8
|
+
def execute(create_rate_dto)
|
9
|
+
raise NotImplementedError, "method not implemented yet"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require_relative '../../../../shared/infrastructure/connectors/http_connector/http_net_connector.rb'
|
5
|
+
require_relative '../../../domain/repositories/create_rate_repository.rb'
|
6
|
+
require_relative '../../../domain/dtos/create_rate_dto.rb'
|
7
|
+
require_relative '../../../../shared/domain/value_objects/http_method_value_object.rb'
|
8
|
+
|
9
|
+
module EnviaYa
|
10
|
+
module Rates
|
11
|
+
module Infrastructure
|
12
|
+
module Repositories
|
13
|
+
module CreateRateRepository
|
14
|
+
class CreateRateHttpRepository < ::EnviaYa::Rates::Domain::Repositories::CreateRateRepository
|
15
|
+
def initialize
|
16
|
+
@http_connector = ::EnviaYa::Shared::Infrastructure::Connectors::HttpConnector::HttpNetConnector.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute(create_rate_dto)
|
20
|
+
raise TypeError, "create_rate_repository expected a CreateRateDto but got: #{create_rate_dto.class}" unless create_rate_dto.is_a?(::EnviaYa::Rates::Domain::Dtos::CreateRateDto)
|
21
|
+
|
22
|
+
@http_connector.execute(URI('https://enviaya.com.mx/api/v1/rates'), method: ::EnviaYa::Shared::Domain::ValueObjects::HttpMethodValueObject.new('POST'), body: create_rate_dto.to_hash)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module EnviaYa
|
2
|
+
module Shared
|
3
|
+
module Domain
|
4
|
+
module Entities
|
5
|
+
class AccountsEntity
|
6
|
+
attr_reader :enviaya_account,
|
7
|
+
:carrier_account
|
8
|
+
|
9
|
+
def initialize(
|
10
|
+
enviaya_account: nil,
|
11
|
+
carrier_account: nil
|
12
|
+
)
|
13
|
+
raise TypeError, "enviaya_account expected a String or NilClass but got: #{enviaya_account.class}" unless enviaya_account.is_a?(String) || enviaya_account.is_a?(NilClass)
|
14
|
+
raise TypeError, "carrier_account expected a String or NilClass but got: #{carrier_account.class}" unless carrier_account.is_a?(String) || carrier_account.is_a?(NilClass)
|
15
|
+
|
16
|
+
@enviaya_account = enviaya_account
|
17
|
+
@carrier_account = carrier_account
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_hash
|
21
|
+
{
|
22
|
+
enviaya_account: @enviaya_account,
|
23
|
+
carrier_account: @carrier_account
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require_relative '../value_objects/postal_code_value_object.rb'
|
2
|
+
|
3
|
+
module EnviaYa
|
4
|
+
module Shared
|
5
|
+
module Domain
|
6
|
+
module Entities
|
7
|
+
class DirectionEntity
|
8
|
+
attr_reader :full_name,
|
9
|
+
:company,
|
10
|
+
:direction_1,
|
11
|
+
:direction_2,
|
12
|
+
:postal_code,
|
13
|
+
:neighborhood,
|
14
|
+
:district,
|
15
|
+
:city,
|
16
|
+
:state_code,
|
17
|
+
:country_code,
|
18
|
+
:phone,
|
19
|
+
:emai
|
20
|
+
|
21
|
+
def initialize(
|
22
|
+
full_name:,
|
23
|
+
company: nil,
|
24
|
+
direction_1:,
|
25
|
+
direction_2: nil,
|
26
|
+
postal_code:,
|
27
|
+
neighborhood: nil,
|
28
|
+
district: nil,
|
29
|
+
city:,
|
30
|
+
state_code: nil,
|
31
|
+
country_code:,
|
32
|
+
phone:,
|
33
|
+
email: nil
|
34
|
+
)
|
35
|
+
raise TypeError, "full_name expected a String or NilClass but got: #{full_name.class}" unless full_name.is_a?(String)
|
36
|
+
raise TypeError, "company expected a String or NilClass but got: #{company.class}" unless company.is_a?(String) || company.is_a?(NilClass)
|
37
|
+
raise TypeError, "direction_1 expected a String but got: #{direction_1.class}" unless direction_1.is_a?(String)
|
38
|
+
raise TypeError, "direction_1 expected a String or NilClass but got: #{direction_2.class}" unless direction_2.is_a?(String) || direction_2.is_a?(NilClass)
|
39
|
+
raise TypeError, "postal_code expected a PostalCodeValueObject but got: #{postal_code.class}" unless postal_code.is_a?(::EnviaYa::Shared::Domain::ValueObjects::PostalCodeValueObject)
|
40
|
+
raise TypeError, "neighborhood expected a String or NilClass but got: #{neighborhood.class}" unless neighborhood.is_a?(String) || neighborhood.is_a?(NilClass)
|
41
|
+
raise TypeError, "district expected a String or NilClass but got: #{district.class}" unless district.is_a?(String) || district.is_a?(NilClass)
|
42
|
+
raise TypeError, "city expected a String but got: #{city.class}" unless city.is_a?(String)
|
43
|
+
raise TypeError, "state_code expected a String or NilClass but got: #{state_code.class}" unless state_code.is_a?(String) || state_code.is_a?(NilClass)
|
44
|
+
raise TypeError, "country_code expected a String but got: #{country_code.class}" unless country_code.is_a?(String)
|
45
|
+
raise TypeError, "phone expected a String but got: #{phone.class}" unless phone.is_a?(String)
|
46
|
+
raise TypeError, "email expected a String or NilClass but got: #{email.class}" unless email.is_a?(String) || email.is_a?(NilClass)
|
47
|
+
|
48
|
+
@full_name = full_name
|
49
|
+
@company = company
|
50
|
+
@direction_1 = direction_1
|
51
|
+
@direction_2 = direction_2
|
52
|
+
@postal_code = postal_code
|
53
|
+
@neighborhood = neighborhood
|
54
|
+
@district = district
|
55
|
+
@city = city
|
56
|
+
@state_code = state_code
|
57
|
+
@country_code = country_code
|
58
|
+
@phone = phone
|
59
|
+
@email = email
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_hash
|
63
|
+
{
|
64
|
+
full_name: @full_name,
|
65
|
+
company: @company,
|
66
|
+
direction_1: @direction_1,
|
67
|
+
direction_2: @direction_2,
|
68
|
+
postal_code: @postal_code.to_s,
|
69
|
+
neighborhood: @neighborhood,
|
70
|
+
district: @district,
|
71
|
+
city: @city,
|
72
|
+
state_code: @state_code,
|
73
|
+
country_code: @country_code,
|
74
|
+
phone: @phone,
|
75
|
+
email: @email
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative '../value_objects/weight_unit_value_object.rb'
|
2
|
+
require_relative '../value_objects/dimension_unit_value_object.rb'
|
3
|
+
|
4
|
+
module EnviaYa
|
5
|
+
module Shared
|
6
|
+
module Domain
|
7
|
+
module Entities
|
8
|
+
class ParcelEntity
|
9
|
+
attr_reader :quantity,
|
10
|
+
:weight,
|
11
|
+
:weight_unit,
|
12
|
+
:height,
|
13
|
+
:length,
|
14
|
+
:width,
|
15
|
+
:dimension_unit
|
16
|
+
|
17
|
+
def initialize(
|
18
|
+
quantity:,
|
19
|
+
weight:,
|
20
|
+
weight_unit:,
|
21
|
+
height:,
|
22
|
+
length:,
|
23
|
+
width:,
|
24
|
+
dimension_unit:
|
25
|
+
)
|
26
|
+
raise TypeError, "quantity expected an Integer but got: #{quantity.class}" unless quantity.is_a?(Integer)
|
27
|
+
raise TypeError, "weight expected a Float but got: #{weight.class}" unless weight.is_a?(Float)
|
28
|
+
raise TypeError, "weight_unit expected a WeightUnitValueObject but got: #{weight_unit.class}" unless weight_unit.is_a?(::EnviaYa::Shared::Domain::ValueObjects::WeightUnitValueObject)
|
29
|
+
raise TypeError, "height expected a Float but got: #{height.class}" unless height.is_a?(Float)
|
30
|
+
raise TypeError, "length expected a Float but got: #{length.class}" unless length.is_a?(Float)
|
31
|
+
raise TypeError, "width expected a Float but got: #{width.class}" unless width.is_a?(Float)
|
32
|
+
raise TypeError, "dimension_unit expected a DimensionUnitValueObject but got: #{dimension_unit}" unless dimension_unit.is_a?(::EnviaYa::Shared::Domain::ValueObjects::DimensionUnitValueObject)
|
33
|
+
|
34
|
+
@quantity = quantity
|
35
|
+
@weight = weight
|
36
|
+
@weight_unit = weight_unit
|
37
|
+
@height = height
|
38
|
+
@length = length
|
39
|
+
@width = width
|
40
|
+
@dimension_unit = dimension_unit
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_hash
|
44
|
+
{
|
45
|
+
quantity: @quantity,
|
46
|
+
weight: @weight,
|
47
|
+
weight_unit: @weight_unit.to_s,
|
48
|
+
height: @height,
|
49
|
+
length: @length,
|
50
|
+
width: @width,
|
51
|
+
dimension_unit: @dimension_unit.to_s
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require_relative './surcharge_entity.rb'
|
2
|
+
|
3
|
+
module EnviaYa
|
4
|
+
module Shared
|
5
|
+
module Domain
|
6
|
+
module Entities
|
7
|
+
class RateEntity
|
8
|
+
attr_reader :id,
|
9
|
+
:date,
|
10
|
+
:carrier,
|
11
|
+
:carrier_service_name,
|
12
|
+
:carrier_service_code,
|
13
|
+
:carrier_logo_url,
|
14
|
+
:carrier_logo_url_svg,
|
15
|
+
:estimated_delivery,
|
16
|
+
:net_shipping_amount,
|
17
|
+
:net_surcharges_amount,
|
18
|
+
:net_total_amount,
|
19
|
+
:vat_amount,
|
20
|
+
:vat_rate,
|
21
|
+
:total_amount,
|
22
|
+
:public_total_amount,
|
23
|
+
:public_total_amount_currency,
|
24
|
+
:currency,
|
25
|
+
:surcharges,
|
26
|
+
:service_terms,
|
27
|
+
:enviaya_service_name,
|
28
|
+
:enviaya_service_code
|
29
|
+
|
30
|
+
def initialize(
|
31
|
+
id: nil,
|
32
|
+
date: nil,
|
33
|
+
carrier:,
|
34
|
+
carrier_service_name: nil,
|
35
|
+
carrier_service_code: nil,
|
36
|
+
carrier_logo_url: nil,
|
37
|
+
carrier_logo_url_svg: nil,
|
38
|
+
estimated_delivery: nil,
|
39
|
+
net_shipping_amount: nil,
|
40
|
+
net_surcharges_amount: nil,
|
41
|
+
net_total_amount: nil,
|
42
|
+
vat_amount: nil,
|
43
|
+
vat_rate: nil,
|
44
|
+
total_amount: nil,
|
45
|
+
public_total_amount: nil,
|
46
|
+
public_total_amount_currency: nil,
|
47
|
+
currency: nil,
|
48
|
+
surcharges: nil,
|
49
|
+
service_terms: nil,
|
50
|
+
enviaya_service_name: nil,
|
51
|
+
enviaya_service_code: nil
|
52
|
+
)
|
53
|
+
raise TypeError, "id expected an Integer or NilClass but got: #{id.class}" unless id.is_a?(Integer) || id.is_a?(NilClass)
|
54
|
+
raise TypeError, "date expected a DateTime or NilClass but got: #{date.class}" unless data.is_a?(DateTime) || date.is_a?(NilClass)
|
55
|
+
raise TypeError, "carrier expected a String but got: #{carrier.class}" unless carrier.is_a?(String)
|
56
|
+
raise TypeError, "carrier_service_name expected a String or NilClass but got: #{carrier_service_name.class}" unless carrier_service_name.is_a?(String) || carrier_service_name.is_a?(NilClass)
|
57
|
+
raise TypeError, "carrier_service_code expected a String or NilClass but got: #{carrier_service_code.class}" unless carrier_service_code.is_a?(String) || carrier_service_code.is_a?(NilClass)
|
58
|
+
raise TypeError, "carrier_logo_url expected a String or NilClass but got: #{carrier_logo_url.class}" unless carrier_logo_url.is_a?(String) || carrier_logo_url.is_a?(NilClass)
|
59
|
+
raise TypeError, "carrier_logo_url_svg expected a String or NilClass but got: #{carrier_logo_url_svg.class}" unless carrier_logo_url_svg.is_a?(String) || carrier_logo_url_svg.is_a?(NilClass)
|
60
|
+
raise TypeError, "estimated_delivery expected a DateTime or NilClass but got: #{estimated_delivery.class}" unless estimated_delivery.is_a?(DateTime) || estimated_delivery.is_a?(NilClass)
|
61
|
+
raise TypeError, "net_shipping_amount expected a Float or NilClass but got: #{net_shipping_amount.class}" unless net_shipping_amount.is_a?(Float) || net_shipping_amount.is_a?(NilClass)
|
62
|
+
raise TypeError, "net_surcharges_amount expected a Float or NilClass but got: #{net_surcharges_amount.class}" unless net_surcharges_amount.is_a?(Float) || net_surcharges_amount.is_a?(NilClass)
|
63
|
+
raise TypeError, "net_total_amount expected a Float or NilClass but got: #{net_total_amount.class}" unless net_total_amount.is_a?(Float) || net_total_amount.is_a?(NilClass)
|
64
|
+
raise TypeError, "vat_amount expected a Float or NilClass but got: #{vat_amount.class}" unless vat_amount.is_a?(Float) || vat_amount.is_a?(NilClass)
|
65
|
+
raise TypeError, "vat_rate expected a Float or NilClass but got: #{vat_rate.class}" unless vat_rate.is_a?(Float) || vat_rate.is_a?(NilClass)
|
66
|
+
raise TypeError, "total_amount expected a Float or NilClass but got: #{total_amount.class}" unless total_amount.is_a?(Float) || total_amount.is_a?(NilClass)
|
67
|
+
raise TypeError, "public_total_amount expected a Float or NilClass but got: #{public_total_amount.class}" unless public_total_amount.is_a?(Float) || public_total_amount.is_a?(NilClass)
|
68
|
+
raise TypeError, "public_total_amount_currency expected a String or NilClass but got: #{public_total_amount_currency.class}" unless public_total_amount_currency.is_a?(String) || public_total_amount_currency.is_a?(NilClass)
|
69
|
+
raise TypeError, "currency expected a String or NilClass but got: #{currency.class}" unless currency.is_a?(String) || currency.is_a?(NilClass)
|
70
|
+
|
71
|
+
unless surcharges.is_a?(NilClass)
|
72
|
+
raise TypeError, "surcharges expected an Array<SurchargeEntity> or NilClass but got: #{surcharges.class}" unless surcharges.is_a?(Array)
|
73
|
+
|
74
|
+
surcharges.each do |surcharge|
|
75
|
+
raise TypeError, "item in surcharges array expected to be a SurchargeEntity but got: #{surcharge.class}" unless surcharge.is_a?(::EnviaYa::Shared::Domain::Entities::SurchargeEntity)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
raise TypeError, "service_terms expected a String or NilClass but got: #{service_terms.class}" unless service_terms.is_a?(String) || service_terms.is_a?(NilClass)
|
80
|
+
raise TypeError, "enviaya_service_name expected a String or NilClass but got: #{enviaya_service_name.class}" unless enviaya_service_name.is_a?(String) || enviaya_service_name.is_a?(NilClass)
|
81
|
+
raise TypeError, "enviaya_service_code expected a String or NilClass but got: #{enviaya_service_code.class}" unless enviaya_service_code.is_a?(String) || enviaya_service_code.is_a?(NilClass)
|
82
|
+
|
83
|
+
@id = id
|
84
|
+
@date = date
|
85
|
+
@carrier = carrier
|
86
|
+
@carrier_service_name = carrier_service_name
|
87
|
+
@carrier_service_code = carrier_service_code
|
88
|
+
@carrier_logo_url = carrier_logo_url
|
89
|
+
@carrier_logo_url_svg = carrier_logo_url_svg
|
90
|
+
@estimated_delivery = estimated_delivery
|
91
|
+
@net_shipping_amount = net_shipping_amount
|
92
|
+
@net_surcharges_amount = net_surcharges_amount
|
93
|
+
@net_total_amount = net_total_amount
|
94
|
+
@vat_amount = vat_amount
|
95
|
+
@vat_rate = vat_rate
|
96
|
+
@total_amount = total_amount
|
97
|
+
@public_total_amount = public_total_amount
|
98
|
+
@public_total_amount_currency = public_total_amount_currency
|
99
|
+
@currency = currency
|
100
|
+
@surcharges = surcharges
|
101
|
+
@service_terms = service_terms
|
102
|
+
@enviaya_service_name = enviaya_service_name
|
103
|
+
@enviaya_service_code = enviaya_service_code
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'date'
|
2
|
+
require_relative './parcel_entity.rb'
|
3
|
+
require_relative './rate_entity.rb'
|
4
|
+
require_relative './accounts_entity.rb'
|
5
|
+
require_relative '../value_objects/label_format_value_object.rb'
|
6
|
+
require_relative '../value_objects/label_file_type_value_object.rb'
|
7
|
+
require_relative '../value_objects/shipment_type_value_object.rb'
|
8
|
+
|
9
|
+
module EnviaYa
|
10
|
+
module Shared
|
11
|
+
module Domain
|
12
|
+
module Entities
|
13
|
+
class ShipmentEntity
|
14
|
+
attr_reader :shipment_type,
|
15
|
+
:parcels,
|
16
|
+
:insured_value,
|
17
|
+
:insured_value_currency,
|
18
|
+
:content,
|
19
|
+
:shipment_date,
|
20
|
+
:carrier,
|
21
|
+
:carrier_service_code,
|
22
|
+
:enviaya_service_code,
|
23
|
+
:enviaya_shipment_number,
|
24
|
+
:carrier_shipment_number,
|
25
|
+
:label,
|
26
|
+
:label_format,
|
27
|
+
:label_file_type,
|
28
|
+
:label_url,
|
29
|
+
:rate,
|
30
|
+
:accounts
|
31
|
+
|
32
|
+
def initialize(
|
33
|
+
shipment_type: nil,
|
34
|
+
parcels:,
|
35
|
+
insured_value: nil,
|
36
|
+
insured_value_currency: nil,
|
37
|
+
content: nil,
|
38
|
+
shipment_date: nil,
|
39
|
+
carrier: nil,
|
40
|
+
carrier_service_code: nil,
|
41
|
+
enviaya_service_code: nil,
|
42
|
+
enviaya_shipment_number: nil,
|
43
|
+
carrier_shipment_number: nil,
|
44
|
+
label: nil,
|
45
|
+
label_format: nil,
|
46
|
+
label_file_type: nil,
|
47
|
+
label_url: nil,
|
48
|
+
rate: nil,
|
49
|
+
accounts: nil
|
50
|
+
)
|
51
|
+
unless shipment_type.is_a?(::EnviaYa::Shared::Domain::ValueObjects::ShipmentTypeValueObject) || shipment_type.is_a?(NilClass)
|
52
|
+
raise TypeError, "shipment_type expected a ShipmentTypeValueObject but got: #{shipment_type.class}"
|
53
|
+
end
|
54
|
+
|
55
|
+
raise TypeError, "parcels expected an Array<ParcelEntity> but got: #{parcels.class}" unless parcels.is_a?(Array)
|
56
|
+
|
57
|
+
parcels.each do |parcel|
|
58
|
+
raise TypeError, "item in parcels array expected to be a ParcelEntity but got: #{parcel.class}" unless parcel.is_a?(::EnviaYa::Shared::Domain::Entities::ParcelEntity)
|
59
|
+
end
|
60
|
+
|
61
|
+
raise TypeError, "insured_value expected a Float but got: #{insured_value.class}" unless insured_value.class.is_a?(Float) || insured_value.is_a?(NilClass)
|
62
|
+
raise TypeError, "insured_value_currency expected a String but got: #{insured_value_currency.class}" if insured_value && !insured_value_currency.is_a?(String)
|
63
|
+
raise TypeError, "content expected a String or NilClass but got: #{content.class}" unless content.is_a?(String) || content.is_a?(NilClass)
|
64
|
+
raise TypeError, "shipment_date expected a Date or NilClass but got: #{shipment_date.class}" unless shipment_date.is_a?(Date) || shipment_date.is_a?(NilClass)
|
65
|
+
raise TypeError, "carrier expected a String or NilClass but got: #{carrier.class}" unless carrier.is_a?(String) || carrier.is_a?(NilClass)
|
66
|
+
raise TypeError, "carrier_service_code expected a String or NilClass but got: #{carrier_service_code.class}" unless carrier_service_code.is_a?(String) || carrier_service_code.is_a?(NilClass)
|
67
|
+
raise TypeError, "enviaya_service_code expected a String or NilClass but got: #{enviaya_service_code.class}" unless enviaya_service_code.is_a?(String) || enviaya_service_code.is_a?(NilClass)
|
68
|
+
raise TypeError, "enviaya_shipment_number expected a String or NilClass but got: #{enviaya_shipment_number.class}" unless enviaya_shipment_number.is_a?(String) || enviaya_shipment_number.is_a?(NilClass)
|
69
|
+
raise TypeError, "carrier_shipment_number expected a String or NilClass but got: #{carrier_shipment_number.class}" unless carrier_shipment_number.is_a?(String) || carrier_shipment_number.is_a?(NilClass)
|
70
|
+
raise TypeError, "label expected a String or NilClass but got: #{label.class}" unless label.is_a?(String) || label.is_a?(NilClass)
|
71
|
+
raise TypeError, "label_format expected a LabelFormatValueObject or NilClass but got: #{label_format.class}" unless label_format.is_a?(::EnviaYa::Shared::Domain::ValueObjects::LabelFormatValueObject) || label_format.is_a?(NilClass)
|
72
|
+
raise TypeError, "label_file_type expected a LabelFileTypeValueObject or NilClass but got: #{label_file_type.class}" unless label_file_type.is_a?(::EnviaYa::Shared::Domain::ValueObjects::LabelFileTypeValueObject) || label_file_type.is_a?(NilClass)
|
73
|
+
raise TypeError, "label_url expected a String or NilClass but got: #{label_url.class}" unless label_url.is_a?(String) || label_url.is_a?(NilClass)
|
74
|
+
raise TypeError, "rate expected a RateEntity or NilClass but got: #{rate.class}" unless rate.is_a?(::EnviaYa::Shared::Domain::Entities::RateEntity) || rate.is_a?(NilClass)
|
75
|
+
raise TypeError, "accounts expected a AccountsEntity or NilClass but got: #{accounts.class}" unless accounts.is_a?(::EnviaYa::Shared::Domain::Entities::AccountsEntity) || accounts.is_a?(NilClass)
|
76
|
+
|
77
|
+
@shipment_type = shipment_type
|
78
|
+
@parcels = parcels
|
79
|
+
@insured_value = insured_value
|
80
|
+
@insured_value_currency = insured_value_currency
|
81
|
+
@content = content
|
82
|
+
@shipment_date = shipment_date
|
83
|
+
@carrier = carrier
|
84
|
+
@carrier_service_code = carrier_service_code
|
85
|
+
@enviaya_service_code = enviaya_service_code
|
86
|
+
@carrier_shipment_number = carrier_shipment_number
|
87
|
+
@label = label
|
88
|
+
@label_format = label_format
|
89
|
+
@label_file_type = label_file_type
|
90
|
+
@label_url = label_url
|
91
|
+
@rate = rate
|
92
|
+
@accounts = accounts
|
93
|
+
end
|
94
|
+
|
95
|
+
def to_hash
|
96
|
+
{
|
97
|
+
shipment_type: @shipment_type.to_s,
|
98
|
+
parcels: @parcels.map { |parcel| parcel.to_hash },
|
99
|
+
insured_value: @insured_value,
|
100
|
+
insured_value_currency: @insured_value_currency,
|
101
|
+
content: @content,
|
102
|
+
shipment_date: @shipment_date,
|
103
|
+
carrier: @carrier,
|
104
|
+
carrier_service_code: @carrier_service_code,
|
105
|
+
enviaya_service_code: @enviaya_service_code,
|
106
|
+
carrier_shipment_number: @carrier_shipment_number,
|
107
|
+
label: @label,
|
108
|
+
label_format: @label_format,
|
109
|
+
label_file_type: @label_file_type.to_s,
|
110
|
+
label_url: @label_url,
|
111
|
+
rate: @rate,
|
112
|
+
accounts: @accounts&.to_hash
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module EnviaYa
|
2
|
+
module Shared
|
3
|
+
module Domain
|
4
|
+
module Entities
|
5
|
+
class SurchargeEntity
|
6
|
+
attr_reader :name,
|
7
|
+
:net_amount,
|
8
|
+
:vat_amount,
|
9
|
+
:vat_rate,
|
10
|
+
:total_amount
|
11
|
+
|
12
|
+
def initialize(
|
13
|
+
name: nil,
|
14
|
+
net_amount: nil,
|
15
|
+
vat_amount: nil,
|
16
|
+
vat_rate: nil,
|
17
|
+
total_amount: nil
|
18
|
+
)
|
19
|
+
raise TypeError, "name expected a String or NilClass but got: #{name.class}" unless name.is_a?(String) || name.is_a?(NilClass)
|
20
|
+
raise TypeError, "net_amount expected a Float or NilClass but got: #{net_amount.class}" unless net_amount.is_a?(Float) || net_amount.is_a?(NilClass)
|
21
|
+
raise TypeError, "vat_amount expected a Float or NilClass but got: #{vat_amount.class}" unless vat_amount.is_a?(Float) || vat_amount.is_a?(NilClass)
|
22
|
+
raise TypeError, "vat_rate expected a Float or NilClass but got: #{vat_rate.class}" unless vat_rate.is_a?(Float) || vat_rate.is_a?(NilClass)
|
23
|
+
raise TypeError, "total_amount, expected a Float or NilClass but got: #{total_amount.class}" unless total_amount.is_a?(Float) || total_amount.is_a?(NilClass)
|
24
|
+
|
25
|
+
@name = name
|
26
|
+
@net_amount = net_amount
|
27
|
+
@vat_amount = vat_amount
|
28
|
+
@vat_rate = vat_rate
|
29
|
+
@total_amount = total_amount
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EnviaYa
|
2
|
+
module Shared
|
3
|
+
module Domain
|
4
|
+
module ValueObjects
|
5
|
+
class DimensionUnitValueObject
|
6
|
+
def initialize(dimension_unit)
|
7
|
+
unless ['cm', 'in'].include?(dimension_unit)
|
8
|
+
raise ArgumentError, "Invalid dimension_unit: #{dimension_unit}"
|
9
|
+
end
|
10
|
+
|
11
|
+
@value = dimension_unit
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
@value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EnviaYa
|
2
|
+
module Shared
|
3
|
+
module Domain
|
4
|
+
module ValueObjects
|
5
|
+
class HttpMethodValueObject
|
6
|
+
def initialize(http_method)
|
7
|
+
unless ['GET', 'POST', 'PATCH', 'PUT'].include?(http_method)
|
8
|
+
raise ArgumentError, "Invalid http_method: #{http_method}"
|
9
|
+
end
|
10
|
+
|
11
|
+
@value = http_method
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
@value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EnviaYa
|
2
|
+
module Shared
|
3
|
+
module Domain
|
4
|
+
module ValueObjects
|
5
|
+
class LabelFileTypeValueObject
|
6
|
+
def initialize(label_file_type)
|
7
|
+
unless ['PDF', 'JPG', 'GIF'].include?(label_file_type)
|
8
|
+
raise ArgumentError, "Invalid label_file_type: #{label_file_type}"
|
9
|
+
end
|
10
|
+
|
11
|
+
@value = label_file_type
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
@value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module EnviaYa
|
2
|
+
module Shared
|
3
|
+
module Domain
|
4
|
+
module ValueObjects
|
5
|
+
class LabelFormatValueObject
|
6
|
+
def initialize(label_format)
|
7
|
+
unless ['Letter', 'ZPL', 'EPL'].include?(label_format)
|
8
|
+
raise ArgumentError, "Invalid label_format: #{label_format}"
|
9
|
+
end
|
10
|
+
|
11
|
+
@value = label_format
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EnviaYa
|
2
|
+
module Shared
|
3
|
+
module Domain
|
4
|
+
module ValueObjects
|
5
|
+
class PostalCodeValueObject
|
6
|
+
def initialize(postal_code)
|
7
|
+
unless postal_code.match(/\A[0-9]{5}\z/)
|
8
|
+
raise ArgumentError, "Invalid postal code: #{postal_code}"
|
9
|
+
end
|
10
|
+
|
11
|
+
@value = postal_code
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
@value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EnviaYa
|
2
|
+
module Shared
|
3
|
+
module Domain
|
4
|
+
module ValueObjects
|
5
|
+
class ShipmentTypeValueObject
|
6
|
+
def initialize(shipment_type)
|
7
|
+
unless ['Document', 'Package'].include?(shipment_type)
|
8
|
+
raise ArgumentError, "Invalid shipment_type: #{shipment_type}"
|
9
|
+
end
|
10
|
+
|
11
|
+
@value = shipment_type
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
@value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EnviaYa
|
2
|
+
module Shared
|
3
|
+
module Domain
|
4
|
+
module ValueObjects
|
5
|
+
class WeightUnitValueObject
|
6
|
+
def initialize(weight_unit)
|
7
|
+
unless ['kg', 'lbs'].include?(weight_unit)
|
8
|
+
raise ArgumentError, "Invalid weight_unit: #{weight_unit}"
|
9
|
+
end
|
10
|
+
|
11
|
+
@value = weight_unit
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
@value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require_relative '../../../domain/value_objects/http_method_value_object.rb'
|
5
|
+
require_relative '../../../domain/connectors/http_connector.rb'
|
6
|
+
|
7
|
+
module EnviaYa
|
8
|
+
module Shared
|
9
|
+
module Infrastructure
|
10
|
+
module Connectors
|
11
|
+
module HttpConnector
|
12
|
+
class HttpNetConnector < ::EnviaYa::Shared::Domain::Connectors::HttpConnector
|
13
|
+
def execute(uri, method: ::EnviaYa::Shared::Domain::ValueObjects::HttpMethodValueObject.new('GET'), body: {})
|
14
|
+
raise TypeError, "uri expected URI but got: #{uri.class}" unless uri.is_a?(URI)
|
15
|
+
raise TypeError, "method expected HttpMethodValueObject but got: #{method.class}" unless method.is_a?(::EnviaYa::Shared::Domain::ValueObjects::HttpMethodValueObject)
|
16
|
+
raise TypeError, "body expected Hash but got: #{body.class}" unless body.is_a?(Hash)
|
17
|
+
|
18
|
+
case method.to_s
|
19
|
+
when 'POST'
|
20
|
+
return Net::HTTP.post(uri, body.to_json, {
|
21
|
+
'Content-Type': 'application/json',
|
22
|
+
'Authorization': "Bearer #{EnviaYa::Config.api_key}"
|
23
|
+
})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: envia_ya
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simply Development
|
8
|
+
- Jorge Castillo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2021-10-10 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email:
|
16
|
+
- hello@simply-development.com
|
17
|
+
- j@simply-development.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/envia_ya.rb
|
23
|
+
- lib/modules/rates/application/commands/create_rate_command.rb
|
24
|
+
- lib/modules/rates/domain/dtos/create_rate_dto.rb
|
25
|
+
- lib/modules/rates/domain/repositories/create_rate_repository.rb
|
26
|
+
- lib/modules/rates/infrastructure/repositories/create_rate_repository/create_rate_http_repository.rb
|
27
|
+
- lib/modules/shared/domain/connectors/http_connector.rb
|
28
|
+
- lib/modules/shared/domain/entities/accounts_entity.rb
|
29
|
+
- lib/modules/shared/domain/entities/direction_entity.rb
|
30
|
+
- lib/modules/shared/domain/entities/parcel_entity.rb
|
31
|
+
- lib/modules/shared/domain/entities/rate_entity.rb
|
32
|
+
- lib/modules/shared/domain/entities/shipment_entity.rb
|
33
|
+
- lib/modules/shared/domain/entities/surcharge_entity.rb
|
34
|
+
- lib/modules/shared/domain/value_objects/dimension_unit_value_object.rb
|
35
|
+
- lib/modules/shared/domain/value_objects/http_method_value_object.rb
|
36
|
+
- lib/modules/shared/domain/value_objects/label_file_type_value_object.rb
|
37
|
+
- lib/modules/shared/domain/value_objects/label_format_value_object.rb
|
38
|
+
- lib/modules/shared/domain/value_objects/postal_code_value_object.rb
|
39
|
+
- lib/modules/shared/domain/value_objects/shipment_type_value_object.rb
|
40
|
+
- lib/modules/shared/domain/value_objects/weight_unit_value_object.rb
|
41
|
+
- lib/modules/shared/infrastructure/connectors/http_connector/http_net_connector.rb
|
42
|
+
homepage:
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message: "Developed with \U0001F9E1 by Simply Development"
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubygems_version: 3.2.22
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Ruby implementation of EnviaYa! shipping service.
|
65
|
+
test_files: []
|