oca-epak 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b770b600437c06428ca3857ee228823915a249b5
4
- data.tar.gz: 9cca002c4d209ad4824026486fa959730e9181ae
3
+ metadata.gz: 28d1b13cc67bd420e4bc7838c2bf4c122a8bf01d
4
+ data.tar.gz: a92563151e81a485126934f34d86dd85fe827900
5
5
  SHA512:
6
- metadata.gz: 2b707fa3733af3a184bce13abbb4802c3147c8b95d4a0f2bceba5faadacab82dc2484864b142f36b0c2022c817aa811308575bd8560242cc28d84e4710d58768
7
- data.tar.gz: 897ee612dcb938f5adf5e97374647b855afbe9b669820da0252fd85135a2e27074baff33cf409811cb7bfb53ad7df87aa659a3a64fab3fef62d06cbba9aa966d
6
+ metadata.gz: d7bd05bde365ba9cef7ab983ed152e8c318add7f5e54e947a4541acbfca8b1fb8ea3cf6a26703db5ccbb4f7544f9573f3d3e75233d12d410606606a9ca5b53ef
7
+ data.tar.gz: 2b6f084a2e742a46bc853f2bea23c89491f6d9aa78038f239dd57bdb149835b2d6c76553a75f5d45ae4df4470638ec8afa8c76b7f14cc0fc5bd5ab996294244f
@@ -2,6 +2,7 @@ require 'savon'
2
2
  require 'erb'
3
3
  require 'ostruct'
4
4
  require 'oca-epak/base_client'
5
+ require 'oca-epak/logger'
5
6
  require 'oca-epak/epak/client'
6
7
  require 'oca-epak/oep/client'
7
8
  require 'oca-epak/pickup_data'
@@ -3,7 +3,8 @@ module Oca
3
3
  attr_reader :client
4
4
  attr_accessor :username, :password
5
5
 
6
- BASE_WSDL_URL = 'http://webservice.oca.com.ar'.freeze
6
+ BASE_WSDL_URL = "http://webservice.oca.com.ar".freeze
7
+ FALSE_STRING = "false".freeze
7
8
 
8
9
  def initialize(username, password)
9
10
  @username = username
@@ -1,10 +1,15 @@
1
1
  module Oca
2
2
  module Epak
3
3
  class Client < BaseClient
4
+ ONE_STRING = "1".freeze
5
+ USER_STRING = "usr".freeze
6
+ PASSWORD_STRING = "psw".freeze
7
+ WSDL_URL = "#{BASE_WSDL_URL}/epak_tracking/Oep_TrackEPak.asmx?wsdl".freeze
8
+
4
9
  def initialize(username, password)
5
10
  super
6
- wsdl_url = "#{BASE_WSDL_URL}/epak_tracking/Oep_TrackEPak.asmx?wsdl"
7
- @client = Savon.client(wsdl: wsdl_url)
11
+ @opts = { wsdl: WSDL_URL }.merge(Oca::Logger.options)
12
+ @client = Savon.client(@opts)
8
13
  end
9
14
 
10
15
  # Checks if the user has input valid credentials
@@ -12,9 +17,9 @@ module Oca
12
17
  # @return [Boolean] Whether the credentials entered are valid or not
13
18
  def check_credentials
14
19
  method = :get_epack_user
15
- opts = { "usr" => username, "psw" => password }
20
+ opts = { USER_STRING => username, PASSWORD_STRING => password }
16
21
  response = client.call(method, message: opts)
17
- parse_results_table(response, method).first[:existe] == "1"
22
+ parse_results_table(response, method).first[:existe] == ONE_STRING
18
23
  end
19
24
 
20
25
  # Creates a Pickup Order, which lets OCA know you want to make a delivery.
@@ -28,12 +33,12 @@ module Oca
28
33
  # @option opts [Integer] :pickup_range Range to be used when picking it up, default: 1
29
34
  # @return [Hash, nil]
30
35
  def create_pickup_order(opts = {})
31
- confirm_pickup = opts.fetch(:confirm_pickup, false)
32
- days_to_pickup = opts.fetch(:days_to_pickup, "1")
33
- pickup_range = opts.fetch(:pickup_range, "1")
36
+ confirm_pickup = opts.fetch(:confirm_pickup, FALSE_STRING)
37
+ days_to_pickup = opts.fetch(:days_to_pickup, ONE_STRING)
38
+ pickup_range = opts.fetch(:pickup_range, ONE_STRING)
34
39
  rendered_xml = opts[:pickup_data].to_xml
35
40
 
36
- message = { "usr" => username, "psw" => password,
41
+ message = { USER_STRING => username, PASSWORD_STRING => password,
37
42
  "xml_Datos" => rendered_xml,
38
43
  "ConfirmarRetiro" => confirm_pickup.to_s,
39
44
  "DiasHastaRetiro" => days_to_pickup,
@@ -83,7 +88,7 @@ module Oca
83
88
  # @return [Array, nil] Returns all operation codes available for the user
84
89
  def get_operation_codes
85
90
  method = :get_operativas_by_usuario
86
- opts = { "usr" => username, "psw" => password }
91
+ opts = { USER_STRING => username, PASSWORD_STRING => password }
87
92
  response = client.call(method, message: opts)
88
93
  parse_results_table(response, method)
89
94
  end
@@ -0,0 +1,34 @@
1
+ module Oca
2
+ class Logger
3
+ attr_accessor :log, :pretty_print_xml, :log_level
4
+
5
+ # Receives a hash with keys `log`, `pretty_print_xml` and `log_level`.
6
+ # `log_level` can be :info, :debug, :warn, :error or :fatal
7
+ #
8
+ # @param opts [Hash]
9
+ # @option opts [Boolean] :log
10
+ # @option opts [Boolean] :pretty_print_xml
11
+ # @option opts [Symbol] :log_level
12
+ def initialize(opts = {})
13
+ @log = opts[:log] || false
14
+ @pretty_print_xml = opts[:pretty_print_xml] || false
15
+ @log_level = opts[:log_level] || :info
16
+ end
17
+
18
+ # Returns a hash with the logging options for Savon.
19
+ #
20
+ # @return [Hash]
21
+ def logger_options
22
+ { log: log, pretty_print_xml: pretty_print_xml, log_level: log_level }
23
+ end
24
+
25
+ def self.options=(opts = {})
26
+ @logger = Oca::Logger.new(opts)
27
+ end
28
+
29
+ def self.options
30
+ @logger ||= Oca::Logger.new
31
+ @logger.logger_options
32
+ end
33
+ end
34
+ end
@@ -1,10 +1,12 @@
1
1
  module Oca
2
2
  module Oep
3
3
  class Client < BaseClient
4
+ WSDL_URL = "#{BASE_WSDL_URL}/oep_tracking/Oep_Track.asmx?wsdl".freeze
5
+
4
6
  def initialize(username, password)
5
7
  super
6
- wsdl_url = "#{BASE_WSDL_URL}/oep_tracking/Oep_Track.asmx?wsdl"
7
- @client = Savon.client(wsdl: wsdl_url)
8
+ @opts = { wsdl: WSDL_URL }.merge(Oca::Logger.options)
9
+ @client = Savon.client(@opts)
8
10
  end
9
11
 
10
12
  # Returns the HTML for a label
@@ -20,6 +22,27 @@ module Oca
20
22
  response = client.call(method, message: opts)
21
23
  parse_result(response, method)
22
24
  end
25
+
26
+ # Returns the PDF (Base64 encoded) String for a label
27
+ #
28
+ # @param [Hash] opts
29
+ # @option opts [Integer] :id_orden_retiro
30
+ # @option opts [String] :nro_envio
31
+ # @option opts [Boolean] :logistica_inversa
32
+ # @return [String] PDF data Base64 encoded
33
+ def get_pdf_de_etiquetas_por_orden_or_numero_envio(opts = {})
34
+ method = :get_pdf_de_etiquetas_por_orden_or_numero_envio
35
+ opts = {
36
+ "idOrdenRetiro" => opts[:id_orden_retiro],
37
+ "nroEnvio" => opts[:nro_envio],
38
+ "logisticaInversa" => opts.fetch(:logistica_inversa, FALSE_STRING).to_s
39
+ }
40
+ response = client.call(method, message: opts)
41
+ parse_result(response, method)
42
+ rescue Savon::SOAPFault => error
43
+ msg = "Oca WS responded with:\n#{error.http.code}\n#{error}"
44
+ raise Oca::Errors::BadRequest.new(msg)
45
+ end
23
46
  end
24
47
  end
25
48
  end
@@ -1,6 +1,8 @@
1
1
  module Oca
2
2
  module Epak
3
3
  class PickupData
4
+ PATH_TO_XML = File.expand_path("../retiro.xml.erb", __FILE__).freeze
5
+
4
6
  attr_accessor :account_number, :pickup, :shipments
5
7
 
6
8
  # Creates a Pickup Data object for creating a pickup order in OCA.
@@ -22,8 +24,7 @@ module Oca
22
24
  private
23
25
 
24
26
  def or_template
25
- path_to_xml = File.expand_path("../retiro.xml.erb", __FILE__)
26
- ERB.new(File.read(path_to_xml), nil, "-")
27
+ ERB.new(File.read(PATH_TO_XML), nil, "-")
27
28
  end
28
29
  end
29
30
  end
@@ -1,5 +1,5 @@
1
1
  module Oca
2
2
  module Epak
3
- VERSION = '1.5.0'
3
+ VERSION = '1.6.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oca-epak
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauro Otonelli
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-05 00:00:00.000000000 Z
12
+ date: 2016-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '3.2'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rubocop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 0.39.0
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 0.39.0
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: rake
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,7 @@ files:
108
122
  - lib/oca-epak/epak/client.rb
109
123
  - lib/oca-epak/errors/bad_request.rb
110
124
  - lib/oca-epak/errors/generic_error.rb
125
+ - lib/oca-epak/logger.rb
111
126
  - lib/oca-epak/oep/client.rb
112
127
  - lib/oca-epak/pickup_data.rb
113
128
  - lib/oca-epak/retiro.xml.erb
@@ -132,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
147
  version: '0'
133
148
  requirements: []
134
149
  rubyforge_project:
135
- rubygems_version: 2.2.2
150
+ rubygems_version: 2.4.6
136
151
  signing_key:
137
152
  specification_version: 4
138
153
  summary: OCA E-Pak