Class: FastshopCatalog::BaseService

Inherits:
Object
  • Object
show all
Defined in:
lib/fastshop_catalog/base_service.rb

Constant Summary collapse

AUX_LOG =
Logger.new(STDOUT)

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ BaseService

Returns a new instance of BaseService.



34
35
36
37
38
39
40
41
42
# File 'lib/fastshop_catalog/base_service.rb', line 34

def initialize(params={})
  @@log_level ||= :info
  default_params = {:wsdl => "#{service_url}?wsdl", :soap_version => 2, :namespaces =>
    {"xmlns:x" => "http://www.w3.org/2005/08/addressing"}, :soap_header =>
    {"x:To" => service_url, "x:Action" => "http://tempuri.org/#{action}"}, :log_level =>
    @log_level}
  @client = Savon.client(recursive_merge(default_params, params))
  HTTPI.log = false
end

Class Attribute Details

.base_urlObject

Returns the value of attribute base_url.



9
10
11
# File 'lib/fastshop_catalog/base_service.rb', line 9

def base_url
  @base_url
end

.crypto_keyObject

Returns the value of attribute crypto_key.



10
11
12
# File 'lib/fastshop_catalog/base_service.rb', line 10

def crypto_key
  @crypto_key
end

.log_levelObject

Returns the value of attribute log_level.



8
9
10
# File 'lib/fastshop_catalog/base_service.rb', line 8

def log_level
  @log_level
end

Class Method Details

.camelize(val) ⇒ Object



25
26
27
# File 'lib/fastshop_catalog/base_service.rb', line 25

def self.camelize(val)
  val.to_s.split('_').map {|w| w.capitalize}.join
end

Instance Method Details

#actionObject



21
22
23
# File 'lib/fastshop_catalog/base_service.rb', line 21

def action
  @action ||= "#{@interface}/#{BaseService.camelize(@soap_method)}"
end

#encrypt(payload) ⇒ Object



29
30
31
32
# File 'lib/fastshop_catalog/base_service.rb', line 29

def encrypt(payload)
  require_relative 'crypto'
  Crypto.new.encrypt(payload.to_s)
end

#service_urlObject



13
14
15
16
17
18
19
# File 'lib/fastshop_catalog/base_service.rb', line 13

def service_url
  env = "development"

  env = Rails.env if defined?(Rails)
  url_service = FastshopCatalog::ServiceUrls.new(env)
  @service_url ||= url_service.url_for(@service)
end