evropochta 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 95c05e20fa1d3a300d89e9364bc7ec5644756a47f617b780746d0fee0e5c6fc8
4
+ data.tar.gz: b225700ca8d1ef4ad165bcfb618be9f62539d13adec52a61c19cdb85f285366a
5
+ SHA512:
6
+ metadata.gz: 5756637c37eb45945dc74356ee99f6d09ec46f29fbd73d291e1208268c2fa0974c4270fb5c0d0edcf23b34cab3f4649c8f8f7e266c8fd7e21a2ed181d927cef9
7
+ data.tar.gz: 60a29f4b2f30602c6fdecb8a4b82facadd1b558398f2bcba957597af824ae1e43d0c44e5ad5913deb0f5202e5c3f57b9bd3a9a49c959f4b63b7242295d9cb975
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Evropochta
2
+ Gem for working with the "Evropochta" delivery service via API
data/exe/evropochta ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "evropochta"
@@ -0,0 +1,21 @@
1
+ module Evropochta
2
+ module Addresses
3
+ module GetAddressId
4
+ module_function
5
+
6
+ def call(address4_id:, address3_name:, address2_name:, address1_name:, porch:, floorx:)
7
+ Services::Shared.request(
8
+ "Addresses.GetAddressId",
9
+ {
10
+ Address4Id: address4_id,
11
+ Address3Name: address3_name,
12
+ Address2Name: address2_name,
13
+ Address1Name: address1_name,
14
+ Porch: porch,
15
+ Floorx: floorx
16
+ }
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ module Evropochta
2
+ module Addresses
3
+ module Search4
4
+ module_function
5
+
6
+ def call(address: "", limit_addresses: 10, address4_id: 0)
7
+ Services::Shared.request(
8
+ "Addresses.Search4",
9
+ {
10
+ Text: address,
11
+ TopN: limit_addresses,
12
+ Address4Id: address4_id
13
+ }
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ module Evropochta
2
+ module Auth
3
+ module JWT
4
+ include Config
5
+ extend Services::ApiService
6
+
7
+ module_function
8
+
9
+ def jwt_token
10
+ @jwt_token ||= handle_response(do_request(post_body: jwt_post_body)).dig(0, "JWT")
11
+ end
12
+
13
+ def jwt_post_body
14
+ {
15
+ CRC: "",
16
+ Packet: {
17
+ JWT: "null",
18
+ MethodName: "GetJWT",
19
+ ServiceNumber: SERVICE_NUMBER,
20
+ Data: {
21
+ LoginName: USER_LOGIN_NAME,
22
+ Password: USER_PASSWORD,
23
+ LoginNameTypeId: USER_LOGIN_NAME_TYPE_ID
24
+ }
25
+ }
26
+ }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,8 @@
1
+ module Evropochta
2
+ module Config
3
+ SERVICE_NUMBER = ENV.fetch("SERVICE_NUMBER", nil).freeze
4
+ USER_LOGIN_NAME = ENV.fetch("USER_LOGIN_NAME", nil).freeze
5
+ USER_PASSWORD = ENV.fetch("USER_PASSWORD", nil).freeze
6
+ USER_LOGIN_NAME_TYPE_ID = ENV.fetch("USER_LOGIN_NAME_TYPE_ID", nil).freeze
7
+ end
8
+ end
@@ -0,0 +1,30 @@
1
+ module Evropochta
2
+ module Postal
3
+ module CalculationTariff
4
+ module_function
5
+
6
+ def call(opts: {})
7
+ Services::Shared.request(
8
+ "Postal.CalculationTariff",
9
+ {
10
+ GoodsId: opts[:goods_id],
11
+ PostDeliveryTypeId: opts[:post_delivery_type_id],
12
+ PostalWeightId: opts[:postal_weight_id],
13
+ IsFragile: opts[:is_fragile],
14
+ IsInventory: opts[:is_inventory],
15
+ IsCompletenessCheck: opts[:is_completeness_check],
16
+ CashOnDeliverySum: opts[:cash_on_delivery_sum],
17
+ CashOnDeliveryDeclareValueSum: opts[:cash_on_delivery_declare_value_sum],
18
+ WarehouseIdFinish: opts[:warehouse_id_finish],
19
+ Adress1IdReciever: opts[:adress1_id_reciever],
20
+ IsJuristic: opts[:is_juristic],
21
+ IsOversize: opts[:is_oversize],
22
+ IsRelabeling: opts[:is_relabeling],
23
+ IsRecieverShipping: opts[:is_reciever_shipping],
24
+ AgreementTypeId: opts[:agreement_type_id]
25
+ }
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ module Evropochta
2
+ module Postal
3
+ module ChangeOrder
4
+ module_function
5
+
6
+ def call(opts: {})
7
+ Services::Shared.request(
8
+ "Postal.ChangeOrder",
9
+ {
10
+ Number: opts[:number],
11
+ PostalItemExternalId: opts[:postal_item_external_id],
12
+ PostDeliveryTypeIdNew: opts[:post_delivery_type_id_new],
13
+ PostalWeightIdNew: opts[:postal_weight_id_new],
14
+ IsFragileNew: opts[:is_fragile_new],
15
+ IsInventoryNew: opts[:is_inventory_new],
16
+ IsCompletenessCheckNew: opts[:is_completeness_check_new],
17
+ CashOnDeliverySumNew: opts[:cash_on_delivery_sum_new],
18
+ CashOnDeliveryDeclareValueSumNew: opts[:cash_on_delivery_declare_value_sum_new],
19
+ WarehouseIdStartNew: opts[:warehouse_id_start_new],
20
+ WarehouseIdFinishNew: opts[:warehouse_id_finish_new],
21
+ Address1IdRecieverNew: opts[:address1_id_reciever_new],
22
+ PhoneNumberRecieverNew: opts[:phone_number_reciever_new],
23
+ EMailRecieverNew: opts[:email_reciever_new],
24
+ Name1RecieverNew: opts[:name1_reciever_new],
25
+ Name2RecieverNew: opts[:name2_reciever_new],
26
+ Name3RecieverNew: opts[:name3_reciever_new],
27
+ CashOnDeliveryMoneyBackIdNew: opts[:cash_on_delivery_money_back_id_new],
28
+ InfoSenderNew: opts[:info_sender_new]
29
+ }
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ module Evropochta
2
+ module Postal
3
+ module DeliveryTime
4
+ module_function
5
+
6
+ def call(track_number: "", address1_id_reciever: "")
7
+ Services::Shared.request(
8
+ "Postal.DeliveryTime",
9
+ Number: track_number,
10
+ Address1IdReciever: address1_id_reciever,
11
+ )
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Evropochta
2
+ module Postal
3
+ module DeliveryTypeDir
4
+ module_function
5
+
6
+ def call(type: 2)
7
+ Services::Shared.request("Postal.DeliveryTypeDir", { IsEnable: type })
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Evropochta
2
+ module Postal
3
+ module GetPdfContent
4
+ module_function
5
+
6
+ def call(serial_numbers: [], postal_item_external_id: [])
7
+ external_ids = postal_item_external_id.map { |external_id| { PostalItemExternalId: external_id } }
8
+ numbers = serial_numbers.map { |serial_number| { SerialNumber: serial_number } }
9
+ Services::Shared.request(
10
+ "Postal.GetPDFContent",
11
+ {
12
+ SerialNumber: numbers,
13
+ PostalItemExternalId: external_ids
14
+ }
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ module Evropochta
2
+ module Postal
3
+ module GroupOrder
4
+ module_function
5
+
6
+ def call(postal_item_external_ids: [], serial_numbers: [], date_transfer: "")
7
+ Services::Shared.request(
8
+ "Postal.GroupOrder",
9
+ {
10
+ PostalItemExternalId: postal_item_external_ids,
11
+ SerialNumber: serial_numbers,
12
+ DateTransfer: date_transfer,
13
+ }
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module Evropochta
2
+ module Postal
3
+ module HistoryOrders
4
+ module_function
5
+
6
+ def call(opts: {})
7
+ Services::Shared.request(
8
+ "Postal.HistoryOrders",
9
+ {
10
+ DateBegin: opts[:date_begin],
11
+ DateEnd: opts[:date_end],
12
+ Number: opts[:number],
13
+ PostalItemExternalId: opts[:postal_item_external_id],
14
+ Limit: opts[:limit],
15
+ Offset: opts[:offset]
16
+ }
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ module Evropochta
2
+ module Postal
3
+ module OfficesIn
4
+ module_function
5
+
6
+ def call(type_sender: 2)
7
+ Services::Shared.request("Postal.OfficesIn", { TypeSender: type_sender })
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Evropochta
2
+ module Postal
3
+ module OfficesOut
4
+ module_function
5
+
6
+ def call
7
+ Services::Shared.request("Postal.OfficesOut")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module Evropochta
2
+ module Postal
3
+ module OrderInfo
4
+ module_function
5
+
6
+ def call(track_number: "", postal_item_external_id: "")
7
+ Services::Shared.request(
8
+ "Postal.OrderInfo",
9
+ { Number: track_number, PostalItemExternalId: postal_item_external_id }
10
+ )
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,46 @@
1
+ module Evropochta
2
+ module Postal
3
+ module PutOrder
4
+ module_function
5
+
6
+ def call(opts: {})
7
+ Services::Shared.request(
8
+ "Postal.PutOrder",
9
+ {
10
+ GoodsId: opts[:goods_id],
11
+ PostDeliveryTypeId: opts[:post_delivery_type_id],
12
+ PostalWeightId: opts[:postal_weight_id],
13
+ IsFragile: opts[:is_fragile],
14
+ IsInventory: opts[:is_inventory],
15
+ IsCompletenessCheck: opts[:is_completeness_check],
16
+ CashOnDeliverySum: opts[:cash_on_delivery_sum],
17
+ CashOnDeliveryDeclareValueSum: opts[:cash_on_delivery_declare_value_sum],
18
+ WarehouseIdStart: opts[:warehouse_id_start],
19
+ WarehouseIdFinish: opts[:warehouse_id_finish],
20
+ Adress1IdReciever: opts[:adress1_id_reciever],
21
+ PhoneNumberReciever: opts[:phone_number_reciever],
22
+ EMailReciever: opts[:email_reciever],
23
+ Name1Reciever: opts[:name1_reciever],
24
+ Name2Reciever: opts[:name2_reciever],
25
+ Name3Reciever: opts[:name3_reciever],
26
+ CashOnDeliveryMoneyBackId: opts[:cash_on_delivery_money_back_id],
27
+ InfoSender: opts[:info_sender],
28
+ PostalItemExternalId: opts[:postal_item_external_id],
29
+ IsOversize: opts[:is_oversize],
30
+ PostalHeight: opts[:postal_height],
31
+ PostalWidth: opts[:postal_width],
32
+ PostalLength: opts[:postal_length],
33
+ IsAutoDeliveryFlag: opts[:is_auto_delivery_flag],
34
+ AutoDeliveryTimeFrom: opts[:auto_delivery_time_from],
35
+ AutoDeliveryTimeTo: opts[:auto_delivery_time_to],
36
+ IsRelabeling: opts[:is_relabeling],
37
+ IsRecieverShipping: opts[:is_reciever_shipping],
38
+ IsRecieverPackaging: opts[:is_reciever_packaging],
39
+ IsRecieverCashOnDelivery: opts[:is_reciever_cash_on_delivery],
40
+ AgreementTypeId: opts[:agreement_type_id]
41
+ }
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,14 @@
1
+ module Evropochta
2
+ module Postal
3
+ module Tracking
4
+ module_function
5
+
6
+ def call(track_number: "", postal_item_external_id: "")
7
+ Services::Shared.request(
8
+ "Postal.Tracking",
9
+ { Number: track_number, PostalItemExternalId: postal_item_external_id }
10
+ )
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Evropochta
2
+ module Postal
3
+ module TypesDir
4
+ module_function
5
+
6
+ def call
7
+ Services::Shared.request("Postal.TypesDir")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Evropochta
2
+ module Postal
3
+ module WeightTypeDir
4
+ module_function
5
+
6
+ def call(type: 2)
7
+ Services::Shared.request("Postal.WeightTypeDir", { IsEnable: type })
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ module Evropochta
6
+ module Services
7
+ module ApiService
8
+ include Config
9
+
10
+ module_function
11
+
12
+ def api_url
13
+ URI("#{ENV.fetch('API_URL', nil)}:#{ENV.fetch('API_PORT', 80)}/Json")
14
+ end
15
+
16
+ def do_request(opts)
17
+ uri = api_url
18
+ request = Net::HTTP::Post.new(uri)
19
+ request["Content-Type"] = "application/json"
20
+ request_body = opts[:post_body]
21
+
22
+ request.body = request_body.to_json
23
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
24
+ http.request(request)
25
+ end
26
+ end
27
+
28
+ def handle_response(response)
29
+ case response
30
+ when Net::HTTPSuccess
31
+ json_response = JSON.parse(response.body)
32
+ json_response["Table"]
33
+ else
34
+ raise "Error fetching: #{response.message}"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ module Evropochta
2
+ module Services
3
+ module Shared
4
+ include Config
5
+ extend ApiService
6
+ extend Auth::JWT
7
+
8
+ module_function
9
+
10
+ def request(method_name, data={})
11
+ token = jwt_token
12
+ request_options = {
13
+ token: token,
14
+ data: data,
15
+ method_name: method_name
16
+ }
17
+
18
+ handle_response(do_request(post_body: post_body(request_options)))
19
+ end
20
+
21
+ def post_body(opts)
22
+ {
23
+ CRC: "",
24
+ Packet: {
25
+ JWT: opts[:token],
26
+ MethodName: opts[:method_name],
27
+ ServiceNumber: SERVICE_NUMBER,
28
+ Data: opts[:data]
29
+ }
30
+ }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Evropochta
2
+ VERSION = "0.2.0".freeze
3
+ end
data/lib/evropochta.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "dotenv/load"
2
+ require_relative "evropochta/version"
3
+ require_relative "evropochta/config"
4
+ require_relative "evropochta/services/api_service"
5
+ require_relative "evropochta/auth/jwt"
6
+ require_relative "evropochta/services/shared"
7
+
8
+ require_relative "evropochta/addresses/search4"
9
+ require_relative "evropochta/addresses/get_address_id"
10
+
11
+ require_relative "evropochta/postal/delivery_type_dir"
12
+ require_relative "evropochta/postal/types_dir"
13
+ require_relative "evropochta/postal/weight_type_dir"
14
+ require_relative "evropochta/postal/offices_in"
15
+ require_relative "evropochta/postal/offices_out"
16
+ require_relative "evropochta/postal/calculation_tariff"
17
+ require_relative "evropochta/postal/put_order"
18
+ require_relative "evropochta/postal/change_order"
19
+ require_relative "evropochta/postal/order_info"
20
+ require_relative "evropochta/postal/tracking"
21
+ require_relative "evropochta/postal/history_orders"
22
+ require_relative "evropochta/postal/get_pdf_content"
23
+ require_relative "evropochta/postal/group_order"
24
+ require_relative "evropochta/postal/delivery_time"
25
+
26
+ module Evropochta
27
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evropochta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Denis Grahovskiy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-11-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - kuberlite@gmail.com
16
+ executables:
17
+ - evropochta
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - exe/evropochta
23
+ - lib/evropochta.rb
24
+ - lib/evropochta/addresses/get_address_id.rb
25
+ - lib/evropochta/addresses/search4.rb
26
+ - lib/evropochta/auth/jwt.rb
27
+ - lib/evropochta/config.rb
28
+ - lib/evropochta/postal/calculation_tariff.rb
29
+ - lib/evropochta/postal/change_order.rb
30
+ - lib/evropochta/postal/delivery_time.rb
31
+ - lib/evropochta/postal/delivery_type_dir.rb
32
+ - lib/evropochta/postal/get_pdf_content.rb
33
+ - lib/evropochta/postal/group_order.rb
34
+ - lib/evropochta/postal/history_orders.rb
35
+ - lib/evropochta/postal/offices_in.rb
36
+ - lib/evropochta/postal/offices_out.rb
37
+ - lib/evropochta/postal/order_info.rb
38
+ - lib/evropochta/postal/put_order.rb
39
+ - lib/evropochta/postal/tracking.rb
40
+ - lib/evropochta/postal/types_dir.rb
41
+ - lib/evropochta/postal/weight_type_dir.rb
42
+ - lib/evropochta/services/api_service.rb
43
+ - lib/evropochta/services/shared.rb
44
+ - lib/evropochta/version.rb
45
+ homepage: https://github.com/KuberLite/evropochta
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ bug_tracker_uri: https://github.com/KuberLite/evropochta/issues
50
+ changelog_uri: https://github.com/KuberLite/evropochta/releases
51
+ source_code_uri: https://github.com/KuberLite/evropochta
52
+ homepage_uri: https://github.com/KuberLite/evropochta
53
+ rubygems_mfa_required: 'true'
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.2.33
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Evropochta API wrapper
73
+ test_files: []