datapagos 0.1.0
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 +7 -0
- data/lib/datapagos/charge.rb +19 -0
- data/lib/datapagos/subscription.rb +15 -0
- data/lib/datapagos/token.rb +11 -0
- data/lib/datapagos.rb +62 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d91d6700eefbced5dca3471423963e6d64e9e631
|
4
|
+
data.tar.gz: 52dab33db6479f89e2d1fa8a6769d85835c7db35
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 968071d5118aec6992497d693f2191c75275687d48178f9056d47a6f15cf1c9c888ffd93e8d151d8ff981f916a9fa4f5d7289916f91521b173733189995dd615
|
7
|
+
data.tar.gz: 7a172cb804b03380a409cd5e78b2f40f5de3631b4bbd0e1814678c367fea25cdeb348d62b458fcf1d1472f44fac974dd444d1c680422e4b4b75babf5bfd19da6
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module DataPagos
|
6
|
+
class Charge
|
7
|
+
def self.create(options={})
|
8
|
+
DataPagos.post "/charges", options
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.show(uid)
|
12
|
+
DataPagos.get "/charges/#{uid}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.refund(uid)
|
16
|
+
DataPagos.post "/charges/#{uid}/refund"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module DataPagos
|
6
|
+
class Subscription
|
7
|
+
def self.create(options={})
|
8
|
+
DataPagos.post "/subscriptions", options
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.show(uid)
|
12
|
+
DataPagos.get "/subscriptions/#{uid}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/datapagos.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.expand_path('datapagos/token.rb', File.dirname(__FILE__))
|
2
|
+
require File.expand_path('datapagos/charge.rb', File.dirname(__FILE__))
|
3
|
+
require File.expand_path('datapagos/subscription.rb', File.dirname(__FILE__))
|
4
|
+
|
5
|
+
# Ruby client of the DataPagos API
|
6
|
+
module DataPagos
|
7
|
+
@base_url = 'http://datapagos.herokuapp.com/api/v1'
|
8
|
+
class << self
|
9
|
+
attr_accessor :base_url, :public_key, :secret_key
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def self.get(resource)
|
14
|
+
uri = URI.parse("#{base_url}#{resource}")
|
15
|
+
http = get_http(uri)
|
16
|
+
|
17
|
+
request = Net::HTTP::Get.new(uri.path)
|
18
|
+
request.basic_auth public_key, secret_key
|
19
|
+
request['Accept'] = 'application/json'
|
20
|
+
|
21
|
+
response = http.request(request)
|
22
|
+
parse_json_response(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.post(resource, body = {})
|
26
|
+
uri = URI.parse("#{base_url}#{resource}")
|
27
|
+
http = get_http(uri)
|
28
|
+
|
29
|
+
request = Net::HTTP::Post.new(uri.path)
|
30
|
+
request.basic_auth public_key, secret_key
|
31
|
+
request['Content-Type'] = 'application/json'
|
32
|
+
request['Accept'] = 'application/json'
|
33
|
+
request.body = body.to_json
|
34
|
+
|
35
|
+
response = http.request(request)
|
36
|
+
parse_json_response(response)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.get_http(uri)
|
40
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
41
|
+
if uri.scheme == 'https'
|
42
|
+
http.use_ssl = true
|
43
|
+
end
|
44
|
+
|
45
|
+
return http
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.parse_json_response(response)
|
49
|
+
case response
|
50
|
+
when Net::HTTPSuccess
|
51
|
+
if response.body && !response.body.strip.empty? then
|
52
|
+
JSON.parse(response.body)
|
53
|
+
else
|
54
|
+
#TODO Make this more readable
|
55
|
+
true
|
56
|
+
end
|
57
|
+
else
|
58
|
+
response.error!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: datapagos
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- German Escobar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A client of the DataPagos API
|
28
|
+
email: german.escobar@elibom.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/datapagos.rb
|
34
|
+
- lib/datapagos/charge.rb
|
35
|
+
- lib/datapagos/subscription.rb
|
36
|
+
- lib/datapagos/token.rb
|
37
|
+
homepage: http://rubygems.org/gems/datapagos
|
38
|
+
licenses: []
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.4.5
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: DataPagos API client
|
60
|
+
test_files: []
|