Module: Vindicia

Defined in:
lib/vindicia.rb

Defined Under Namespace

Modules: SoapClient, XMLBuilder Classes: Account, Activity, ActivityCancellation, ActivityEmailContact, ActivityFulfillment, ActivityLogin, ActivityLogout, ActivityNamedValue, ActivityNote, ActivityPhoneContact, ActivityTypeArg, ActivityURIView, ActivityUsage, Address, Authentication, AutoBill, BillingPlan, BillingPlanPeriod, BillingPlanPrice, Boleto, CancelResult, CaptureResult, Chargeback, CreditCard, DirectDebit, ECP, ElectronicSignature, EmailTemplate, Entitlement, MerchantEntitlementId, MetricStatistics, NameValuePair, PayPal, PaymentMethod, PaymentProvider, Product, Refund, Return, SalesTax, ScoreCode, SoapObject, TaxExemption, Token, TokenAmount, TokenTransaction, Transaction, TransactionItem, TransactionStatus, TransactionStatusBoleto, TransactionStatusCreditCard, TransactionStatusDirectDebit, TransactionStatusECP, TransactionStatusPayPal, WebSession

Constant Summary collapse

NAMESPACE =
"http://soap.vindicia.com/Vindicia"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.environmentObject (readonly)

Returns the value of attribute environment.



13
14
15
# File 'lib/vindicia.rb', line 13

def environment
  @environment
end

.loginObject (readonly)

Returns the value of attribute login.



13
14
15
# File 'lib/vindicia.rb', line 13

def 
  @login
end

.passwordObject (readonly)

Returns the value of attribute password.



13
14
15
# File 'lib/vindicia.rb', line 13

def password
  @password
end

Class Method Details

.authObject



24
25
26
# File 'lib/vindicia.rb', line 24

def auth
  {'version' => version, 'login' => , 'password' => password}
end

.authenticate(login, pass, env = :prodtest) ⇒ Object



14
15
16
17
18
# File 'lib/vindicia.rb', line 14

def authenticate(, pass, env=:prodtest)
  @login       = 
  @password    = pass
  @environment = env.to_s
end

.class(type) ⇒ Object



64
65
66
67
68
# File 'lib/vindicia.rb', line 64

def class(type)
  klass = type.split(':').last
  klass = singularize($1) if klass =~ /^ArrayOf(.*)$/
  Vindicia.const_get(klass) rescue nil
end

.coerce(name, type, value) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/vindicia.rb', line 91

def coerce(name, type, value)
  return value if value.kind_of? SoapObject

  case type
  when /ArrayOf/
    return [] if value.nil?
    if value.kind_of? Hash
      return [] if value[:array_type] =~ /\[0\]$/
      if value[name.to_sym]
        return coerce(name, type, [value[name.to_sym]].flatten)
      else
        value = [value]
      end
    end
    value.map do |val|
      coerce(name, singularize(type), val)
    end
  when /^namesp/, /^vin/, /^tns/
    type = value[:type] if value.kind_of? Hash
    if klass = Vindicia.class(type)
      klass.new(value)
    else
      value
    end
  when "xsd:string"
    if value == {:type=>"xsd:string", :xmlns=>""}
      nil
    else
      value
    end
  when "xsd:int"
    value.to_i
  else
    value
  end
end

.domainObject



28
29
30
31
32
33
34
# File 'lib/vindicia.rb', line 28

def domain
  case @environment
  when 'production'; "soap.vindicia.com"
  when 'staging'   ; "soap.staging.sj.vindicia.com"
  else             ; "soap.prodtest.sj.vindicia.com"
  end
end

.endpointObject



36
37
38
# File 'lib/vindicia.rb', line 36

def endpoint
  "https://#{domain}/v#{version}/soap.pl"
end

.silence_debug_output!Object



57
58
59
60
61
62
# File 'lib/vindicia.rb', line 57

def silence_debug_output!
  Savon.configure do |config|
    config.log = false
  end
  def HTTPI.log(*args); end
end

.type_of(arg) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/vindicia.rb', line 70

def type_of(arg)
  case arg
    when TrueClass, FalseClass
      'xsd:boolean'
    when String
      'xsd:string'
    when Fixnum
      'xsd:int'
    when Float #, Decimal
      'xsd:decimal'
    # TODO: 'xsd:long'
    when Date, DateTime, Time
      'xsd:dateTime'
    #TODO: 'xsd:anyURI'
    when SoapObject
      "wsdl:#{arg.classname}"
    else
      raise "Unknown type for #{arg.class}~#{arg.inspect}"
  end
end

.versionObject



20
21
22
# File 'lib/vindicia.rb', line 20

def version
  '3.4'
end

.wsdl(object) ⇒ Object



53
54
55
# File 'lib/vindicia.rb', line 53

def wsdl(object)
  "https://#{domain}/#{version}/#{object}.wsdl"
end

.xsd(klass) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vindicia.rb', line 40

def xsd(klass)
  require 'open-uri'
  url = "https://#{domain}/#{version}/Vindicia.xsd"
  @xsd_data ||= begin
    doc = REXML::Document.new(open(url).read)
    doc.root.get_elements("//xsd:complexType").inject({}){|memo, node|
      memo[node.attributes["name"]] = node.get_elements("xsd:sequence/xsd:element").map{|e|e.attributes}
      memo
    }
  end
  @xsd_data[klass]
end