Module: Epayco

Defined in:
lib/epayco.rb,
lib/epayco/resources.rb,
lib/epayco/operations.rb

Defined Under Namespace

Modules: Operations Classes: Bank, Cash, Charge, Customers, Error, Plan, Resource, Subscriptions, Token

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.apiKeyObject

Returns the value of attribute apiKey.



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

def apiKey
  @apiKey
end

.langObject

Returns the value of attribute lang.



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

def lang
  @lang
end

.privateKeyObject

Returns the value of attribute privateKey.



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

def privateKey
  @privateKey
end

.testObject

Returns the value of attribute test.



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

def test
  @test
end

Class Method Details

.request(method, url, extra = nil, params = {}, headers = {}, switch) ⇒ Object

Eject request and show response or error



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/epayco.rb', line 39

def self.request(method, url, extra=nil, params={}, headers={}, switch)
  method = method.to_sym

  if !apiKey || !privateKey || !lang
    raise Error.new('100', lang)
  end

  payload = JSON.generate(params) if method == :post || method == :patch
  params = nil unless method == :get

  # Switch secure or api
  if switch
    if method == :post || method == :patch
      enc = encrypt_aes(payload)
      payload = enc.to_json
    end
    url = @api_base_secure + url
  else
    if method == :post || method == :patch
      rb_hash = JSON.parse(payload)
      rb_hash["test"] = test ? "TRUE" : "FALSE"
      rb_hash["ip"] = local_ip
      payload = rb_hash.to_json
    end
    url = @api_base + url
  end

  headers = {
    :params => params,
    :content_type => 'application/json',
    :type => 'sdk'
  }.merge(headers)

  options = {
    :headers => headers,
    :user => apiKey,
    :method => method,
    :url => url,
    :payload => payload
  }

  # Open library rest client
  begin
    response = execute_request(options)
    return {} if response.code == 204 and method == :delete
    JSON.parse(response.body, :symbolize_names => true)
  rescue RestClient::Exception => e
    handle_errors e
  end
end