ruby-culqi 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a50f07e4c824046a04e48ff3045df7389ff4e0ae31e68293854b4e7d99b21fdc
4
- data.tar.gz: 39b18b9941dac0426e7e776e31174754db169905162fd93f5b18c9f897b37058
3
+ metadata.gz: 3ac525931f7cc5ec8e5aded7335bec54784379ae631b280ddc1adcb7dff1a35c
4
+ data.tar.gz: 3388c5f6ebb01dc8793dfd7b3d687cab2c0bf113fb52d37cca76fcc9e3afb740
5
5
  SHA512:
6
- metadata.gz: d212ef408e73a608417999ed44ee29ead9134da7e87a58c727e070bc29d8fe4c6c3d4673a8ef1518689587d870a11f7fe28d8cfa895928712b6318d034a267a1
7
- data.tar.gz: 01c1b269bc803109ff8ad8ca40a6624b77122124f7977e9b449f827509526eebef035f7d37a17162b81178d8fb6dc6cbf5b73ed0f778b90dc1a0e0864d09e192
6
+ metadata.gz: f09d3e6770651e93d732213429f32c8c0fcefdfbf2f4cd0eb03a01dc0f7cd5f017a76d0f93093ea1d215864e2e1a58bfa4171002260ef8fb2502905b74dc379c
7
+ data.tar.gz: f3768a3aecf710d388d0aec20b0b785528b56b8d718b41f7289e8addfb86b4a5b856a0f2d411058cc581613ee7eebbd293c0016b7403f83a13a9fbed6e395c58
data/lib/culqi/charge.rb CHANGED
@@ -11,8 +11,8 @@ module Culqi
11
11
  @url = URL
12
12
 
13
13
  def self.capture(id)
14
- response = Culqi.connect("#{@url}#{id}/capture/", Culqi.secret_key, nil, "post", Culqi::READ_TIMEOUT)
15
- return response.read_body
14
+ response, statuscode = Culqi.connect("#{@url}#{id}/capture/", Culqi.secret_key, nil, "post", Culqi::READ_TIMEOUT)
15
+ return response.read_body, statuscode
16
16
  end
17
17
 
18
18
  end
data/lib/culqi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Culqi
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -14,12 +14,12 @@ module Culqi::Post
14
14
  params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
15
15
  end
16
16
  key = Culqi.public_key
17
- response = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, true, rsa_id)
18
- return response
17
+ response, statuscode = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, true, rsa_id)
18
+ return response, statuscode
19
19
  else
20
20
  key = Culqi.secret_key
21
- response = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, false, '')
22
- return response
21
+ response, statuscode = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, false, '')
22
+ return response, statuscode
23
23
  end
24
24
 
25
25
  end
@@ -10,8 +10,8 @@ module Culqi::Update
10
10
  if(rsa_key != '')
11
11
  params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
12
12
  end
13
- response = Culqi.connect("#{@url}#{id}/", Culqi.secret_key, params, 'patch', Culqi::READ_TIMEOUT, rsa_id)
14
- return response
13
+ response, statusCode = Culqi.connect("#{@url}#{id}/", Culqi.secret_key, params, 'patch', Culqi::READ_TIMEOUT, rsa_id)
14
+ return response, statusCode
15
15
  end
16
16
 
17
17
  end
data/lib/util/connect.rb CHANGED
@@ -1,72 +1,41 @@
1
- require 'uri'
2
1
  require 'net/http'
3
- require 'openssl'
4
2
  require 'json'
5
3
  require 'culqi-ruby'
6
- require 'open3'
7
-
8
4
 
9
5
  module Culqi
10
-
11
6
  def self.connect(url, api_key, data, type, time_out, secure_url = false, rsa_id='')
12
-
13
- if secure_url == true
14
- url = URI("#{Culqi::API_BASE_SECURE}#{url}")
15
- else
16
- url = URI("#{Culqi::API_BASE}#{url}")
17
- end
18
-
19
- http = Net::HTTP.new(url.host, url.port)
20
- http.read_timeout = time_out
21
- http.use_ssl = true
22
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
23
-
24
- request = ''
25
- if type.upcase == 'POST'
26
-
27
- url = url.to_s
28
- auth_header = "Authorization: Bearer #{api_key}"
29
- content_type_header = "Content-Type: application/json"
30
- rsa_id_header = "x-culqi-rsa-id: #{rsa_id}"
31
- cache_control_header = "cache-control: no-cache"
32
- data = data.to_json
33
-
34
- stdout, stderr, status = Open3.capture3(
35
- "curl",
36
- "-X", "POST",
37
- url,
38
- "-H", auth_header,
39
- "-H", content_type_header,
40
- "-H", rsa_id_header,
41
- "-H", cache_control_header,
42
- "-d", data
43
- )
44
-
7
+ base_url = secure_url ? Culqi::API_BASE_SECURE : Culqi::API_BASE
8
+ full_url = "#{base_url}#{url}"
9
+ uri = URI(full_url)
10
+ http = Net::HTTP.new(uri.host, uri.port)
11
+ http.use_ssl = uri.scheme == 'https'
12
+
13
+ headers = {
14
+ "Authorization" => "Bearer #{api_key}",
15
+ "Content-Type" => "application/json",
16
+ "cache-control" => "no-cache"
17
+ }
18
+ headers["x-culqi-rsa-id"] = rsa_id if rsa_id && !rsa_id.empty?
19
+
20
+ case type.upcase
21
+ when 'GET'
22
+ request = Net::HTTP::Get.new(uri.request_uri, headers)
23
+ when 'POST'
24
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
25
+ request.body = data.to_json if data
26
+ when 'DELETE'
27
+ request = Net::HTTP::Delete.new(uri.request_uri, headers)
28
+ when 'PATCH'
29
+ request = Net::HTTP::Patch.new(uri.request_uri, headers)
30
+ request.body = data.to_json if data
31
+ else
32
+ raise ArgumentError, "Unsupported request type: #{type}"
45
33
  end
46
34
 
47
- if type.upcase == 'GET'
48
- if !data.nil?
49
- url.query = URI.encode_www_form(data)
50
- command = "curl '#{url}' -G -d '#{URI.encode_www_form(data)}'"
51
- else
52
- command = "curl '#{url}'"
53
- end
54
-
55
- stdout, stderr, status = Open3.capture3("#{command} -H 'Authorization: Bearer #{api_key}' -H 'Content-Type: application/json' -H 'cache-control: no-cache'")
56
-
57
- end
58
-
59
- if type.upcase == 'DELETE'
60
- command = "curl -X DELETE '#{url}' -H 'Authorization: Bearer #{api_key}' -H 'Content-Type: application/json' -H 'cache-control: no-cache'"
61
- stdout, stderr, status = Open3.capture3(command)
62
- end
63
-
64
- if type.upcase == 'PATCH'
65
- command = "curl -X PATCH '#{url}' -H 'Authorization: Bearer #{api_key}' -H 'Content-Type: application/json' -H 'x-culqi-rsa-id: #{rsa_id}' -H 'cache-control: no-cache' -d '#{data.to_json}'"
66
- stdout, stderr, status = Open3.capture3(command)
67
- end
68
-
69
- return stdout
35
+ http.read_timeout = time_out
36
+ response = http.request(request)
37
+ puts response.body
70
38
 
39
+ return response.body, response.code.to_i
71
40
  end
72
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-culqi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Diaz Diaz