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.



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

def environment
  @environment
end

.loginObject (readonly)

Returns the value of attribute login.



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

def 
  @login
end

.passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

Class Method Details

.authObject



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

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

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



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

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

.class(type) ⇒ Object



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

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



83
84
85
86
87
88
89
90
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
# File 'lib/vindicia.rb', line 83

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



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

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



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

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

.type_of(arg) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vindicia.rb', line 62

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



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

def version
  '3.4'
end

.wsdl(object) ⇒ Object



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

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

.xsd(klass) ⇒ Object



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

def xsd(klass)
  require 'open-uri'
  url = "http://#{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