Module: Culqi

Defined in:
lib/culqi-ruby.rb,
lib/culqi/card.rb,
lib/culqi/iins.rb,
lib/culqi/plan.rb,
lib/culqi/event.rb,
lib/culqi/token.rb,
lib/culqi/charge.rb,
lib/culqi/refund.rb,
lib/util/connect.rb,
lib/culqi/version.rb,
lib/culqi/customer.rb,
lib/culqi/transfer.rb,
lib/culqi/subscription.rb

Defined Under Namespace

Modules: Delete, Get, List, Post, Update Classes: Card, Charge, Customer, Event, Iins, Plan, Refund, Subscription, Token, Transfer

Constant Summary collapse

API_BASE =
'https://api.culqi.com/v2'
API_BASE_SECURE =
'https://secure.culqi.com/v2'
READ_TIMEOUT =
120
LIST_TIMEOUT =
360
VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.public_keyObject

Returns the value of attribute public_key.



27
28
29
# File 'lib/culqi-ruby.rb', line 27

def public_key
  @public_key
end

.secret_keyObject

Returns the value of attribute secret_key.



27
28
29
# File 'lib/culqi-ruby.rb', line 27

def secret_key
  @secret_key
end

Class Method Details

.connect(url, api_key, data, type, time_out, secure_url = false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/util/connect.rb', line 9

def self.connect(url, api_key, data, type, time_out, secure_url = false)    

  if secure_url == true 
    url = URI("#{Culqi::API_BASE_SECURE}#{url}")
  else 
    url = URI("#{Culqi::API_BASE}#{url}")  
  end      

  http = Net::HTTP.new(url.host, url.port)
  http.read_timeout = time_out
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  request = ''
  if type.upcase == 'POST'
    request = Net::HTTP::Post.new(url)
    if !data.nil?
      request.body = data.to_json
    end
  end

  if type.upcase == 'GET'
    if !data.nil?
      url.query = URI.encode_www_form(data)
      request = Net::HTTP::Get.new(url)
    else
      request = Net::HTTP::Get.new(url)
    end
  end

  if type.upcase == 'DELETE'
    request = Net::HTTP::Delete.new(url)
  end

  if type.upcase == 'PATCH'
    request = Net::HTTP::Patch.new(url)
    request.body = data.to_json
  end

  request["Authorization"] = "Bearer #{api_key}"
  request["Content-Type"] = 'application/json'
  request["cache-control"] = 'no-cache'

  return http.request(request)

end