oca-epak 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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/oca-epak.rb +91 -0
  3. metadata +116 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e80708f0514549511c124d5b498c015c2421499
4
+ data.tar.gz: 896781b61e4c17bee020ba15676720ab1b684e0b
5
+ SHA512:
6
+ metadata.gz: 357ae0486a84f3e1227492bcb4de2b562e3a02b0fae8b83d6f4ec71715df4871b2f1ae98c217271fff7d36707223732c747eb8b36bb791bebaab6a52facd4a17
7
+ data.tar.gz: 0e8a2efc413f96e39df06493299b27d07d1289464eeba60ba6f52ed0ae522ea0798cb107d3fd7f36c184f61983abe6a98a880e70a4975e581c874c49039bfb0a
data/lib/oca-epak.rb ADDED
@@ -0,0 +1,91 @@
1
+ require 'savon'
2
+
3
+ class Oca
4
+ attr_reader :client
5
+
6
+ WSDL_BASE_URI = 'http://webservice.oca.com.ar/oep_tracking/Oep_Track.asmx?'\
7
+ 'WSDL'.freeze
8
+
9
+ def initialize
10
+ @client = Savon.client(wsdl: WSDL_BASE_URI)
11
+ end
12
+
13
+ # Checks if the user has input valid credentials
14
+ #
15
+ # @param [String] Username (Email)
16
+ # @param [String] Password
17
+ # @return [Boolean] Whether the credentials are valid or not
18
+ def check_credentials(username, password)
19
+ begin
20
+ opts = { "usr" => username, "psw" => password }
21
+ client.call(:generar_consolidacion_de_ordenes_de_retiro, message: opts)
22
+ false
23
+ rescue Savon::SOAPFault => e
24
+ true
25
+ end
26
+ end
27
+
28
+ # Get rates and delivery estimate for a shipment
29
+ #
30
+ # @param [String] Total Weight e.g: 20
31
+ # @param [String] Total Volume e.g: 0.0015 (0.1mts * 0.15mts * 0.1mts)
32
+ # @param [String] Origin ZIP Code
33
+ # @param [String] Destination ZIP Code
34
+ # @param [String] Quantity of Packages
35
+ # @param [String] Client's CUIT e.g: 30-99999999-7
36
+ # @param [String] Operation Type
37
+ # @return [Hash, nil] Contains Total Price, Delivery Estimate
38
+ def get_shipping_rates(wt, vol, origin, destination, qty, cuit, op)
39
+ method = :tarifar_envio_corporativo
40
+ opts = { "PesoTotal" => wt, "VolumenTotal" => vol,
41
+ "CodigoPostalOrigen" => origin,
42
+ "CodigoPostalDestino" => destination, "CantidadPaquetes" => qty,
43
+ "Cuit" => cuit, "Operativa" => op }
44
+ response = client.call(method, message: opts)
45
+ parse_results(method, response)
46
+ end
47
+
48
+ # Returns all existing "Centros de Imposición"
49
+ #
50
+ # @return [Array, nil] Information for all the Centros de Imposición
51
+ def centros_de_imposicion
52
+ method = :get_centros_imposicion
53
+ response = client.call(method)
54
+ parse_results(method, response)
55
+ end
56
+
57
+ # Given a client's CUIT with a range of dates, returns a list with
58
+ # all shipments made within the given period.
59
+ #
60
+ # @param [String] Client's CUIT
61
+ # @param [String] "From date" in DD-MM-YYYY format
62
+ # @param [String] "To date" in DD-MM-YYYY format
63
+ # @return [Array, nil] Contains an array of hashes with NroProducto and NumeroEnvio
64
+ def list_shipments(cuit, from_date, to_date)
65
+ method = :list_envios
66
+ opts = { "CUIT" => cuit, "FechaDesde" => from_date,
67
+ "FechaHasta" => to_date }
68
+ response = client.call(method, message: opts)
69
+ parse_results(method, response)
70
+ end
71
+
72
+ # Returns all provinces in Argentina
73
+ #
74
+ # @return [Array, nil] Provinces in Argentina with their ID and name as a Hash
75
+ def provinces
76
+ response = client.call(:get_provincias)
77
+ if body = response.body[:get_provincias_response]
78
+ body[:get_provincias_result][:provincias][:provincia]
79
+ end
80
+ end
81
+
82
+ private
83
+
84
+ def parse_results(method, response)
85
+ method_response = "#{method}_response".to_sym
86
+ method_result = "#{method}_result".to_sym
87
+ if body = response.body[method_response]
88
+ body[method_result][:diffgram][:new_data_set][:table]
89
+ end
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oca-epak
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mauro Otonelli
8
+ - Ernesto Tagwerker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-09-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: savon
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.11'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2.11'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.3'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.3'
42
+ - !ruby/object:Gem::Dependency
43
+ name: vcr
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.9'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.9'
56
+ - !ruby/object:Gem::Dependency
57
+ name: webmock
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.21'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.21'
70
+ - !ruby/object:Gem::Dependency
71
+ name: pry-byebug
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.2'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.2'
84
+ description: Ruby wrapper for the OCA E-Pak API
85
+ email:
86
+ - mauro@ombulabs.com
87
+ - ernesto@ombulabs.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - lib/oca-epak.rb
93
+ homepage: http://rubygems.org/gems/oca-epak
94
+ licenses: []
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: OCA E-Pak
116
+ test_files: []