bitpagos 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bitpagos.rb +1 -0
- data/lib/bitpagos/client.rb +33 -8
- data/lib/bitpagos/errors/invalid_transaction_type.rb +6 -0
- data/lib/bitpagos/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa49867b69c6e13d1750496c1af02ad65dde63f1
|
4
|
+
data.tar.gz: 3bbd0397d50b3535f91b25ae44f21557310b2932
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 088e6664f5d6d967416e4571c630fe171c6e829953fd623e481cf8a753e14487ec1a31cdc27c663b7a55facaff55df72e8e93dd93aa6b6737e1a250c4ea1108a
|
7
|
+
data.tar.gz: 6a4439d7ab343de09b0a90d9215c166410acf87e2b23cae55182df167c29469c5f389fc258f69e85f1b76f3c84a495e99884408149e56ee73908cbf9ac0a8c04
|
data/lib/bitpagos.rb
CHANGED
data/lib/bitpagos/client.rb
CHANGED
@@ -22,42 +22,67 @@ module Bitpagos
|
|
22
22
|
retrieve_transactions(nil, transaction_id)
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
# Retrieve all transactions, or specify them with parameters, to retrieve
|
26
|
+
# allow retrieving paginated transactions.
|
27
|
+
#
|
28
|
+
# @param [Hash] Allows to specify transaction type, limit or offset
|
29
|
+
# @option [Symbol] status (:pending, :waiting, :completed, :partially_paid)
|
30
|
+
# @option [Integer] offset
|
31
|
+
# @option [Integer] limit
|
32
|
+
# @return [Hash]
|
33
|
+
def transactions(params = {})
|
34
|
+
if status = params[:status]
|
35
|
+
params[:status] = get_transaction_type_from_symbol(status)
|
36
|
+
end
|
37
|
+
retrieve_transactions(params)
|
27
38
|
end
|
28
39
|
|
29
40
|
def completed_transactions
|
30
|
-
retrieve_transactions(COMPLETED)
|
41
|
+
retrieve_transactions(status: COMPLETED)
|
31
42
|
end
|
32
43
|
|
33
44
|
def waiting_transactions
|
34
|
-
retrieve_transactions(WAITING)
|
45
|
+
retrieve_transactions(status: WAITING)
|
35
46
|
end
|
36
47
|
|
37
48
|
def pending_transactions
|
38
|
-
retrieve_transactions(PENDING)
|
49
|
+
retrieve_transactions(status: PENDING)
|
39
50
|
end
|
40
51
|
|
41
52
|
def partially_paid_transactions
|
42
|
-
retrieve_transactions(PARTIALLY_PAID)
|
53
|
+
retrieve_transactions(status: PARTIALLY_PAID)
|
43
54
|
end
|
44
55
|
|
45
56
|
# Returns the total count of transactions in all states.
|
46
57
|
#
|
47
58
|
# @return [Integer] Total transaction count
|
48
59
|
def transaction_count
|
49
|
-
|
60
|
+
transactions["meta"]["total_count"]
|
50
61
|
end
|
51
62
|
|
52
63
|
private
|
53
64
|
|
65
|
+
# Takes a symbol and returns the proper transaction type.
|
66
|
+
#
|
67
|
+
# @param [Symbol] Can be :pending, :waiting, :completed or :partially_paid
|
68
|
+
# @return [String,nil] Returns the corresponding "PE", "WA", "CO" or "PP"
|
69
|
+
def get_transaction_type_from_symbol(transaction_type)
|
70
|
+
begin
|
71
|
+
target_type = transaction_type.to_s.upcase
|
72
|
+
return if target_type.empty?
|
73
|
+
self.class.const_get(target_type)
|
74
|
+
rescue NameError => error
|
75
|
+
raise Bitpagos::Errors::InvalidTransactionType.new(error.message)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
54
79
|
# Hits the Bitpagos transaction API, returns a hash with results
|
55
80
|
#
|
56
81
|
# @param [String] State (Pending, Waiting, Completed, Partially Paid)
|
57
82
|
# @param [String] Transaction ID
|
58
83
|
# @return [Hash]
|
59
84
|
def retrieve_transactions(query = nil, transaction_id = nil)
|
60
|
-
headers.merge!(params:
|
85
|
+
headers.merge!(params: query) if query
|
61
86
|
url = "#{API_BASE}/transaction/#{transaction_id}"
|
62
87
|
begin
|
63
88
|
response = RestClient.get(url, headers)
|
data/lib/bitpagos/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitpagos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mauro Otonelli
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/bitpagos/client.rb
|
106
106
|
- lib/bitpagos/errors/generic_error.rb
|
107
107
|
- lib/bitpagos/errors/invalid_api_key.rb
|
108
|
+
- lib/bitpagos/errors/invalid_transaction_type.rb
|
108
109
|
- lib/bitpagos/errors/unauthorized.rb
|
109
110
|
- lib/bitpagos/version.rb
|
110
111
|
homepage: http://github.com/ombulabs/bitpagos
|