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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28b6e63d61b1c9c5a7ee4ae0af71787cc04c5233
4
- data.tar.gz: 65a45c1268f73237ef29bcc3c87e517aa754a26c
3
+ metadata.gz: aa49867b69c6e13d1750496c1af02ad65dde63f1
4
+ data.tar.gz: 3bbd0397d50b3535f91b25ae44f21557310b2932
5
5
  SHA512:
6
- metadata.gz: adbb05cff2ec909756785fb9c64751c15d8d6b9e830d23ac4504fe75db31fcb465e8cb3bf50045dcdd3d244e4e991af8dcd0af12e59dc2ed2f55a3701d7c7171
7
- data.tar.gz: 44e277d6710cef072251ce4836cc94c073967a83b07fa6aa5aa272edfbdb2c3552aaa63f31c458db76570a37d7f7b7542ee2f40f03152a7224bc26d4b19059b3
6
+ metadata.gz: 088e6664f5d6d967416e4571c630fe171c6e829953fd623e481cf8a753e14487ec1a31cdc27c663b7a55facaff55df72e8e93dd93aa6b6737e1a250c4ea1108a
7
+ data.tar.gz: 6a4439d7ab343de09b0a90d9215c166410acf87e2b23cae55182df167c29469c5f389fc258f69e85f1b76f3c84a495e99884408149e56ee73908cbf9ac0a8c04
@@ -2,4 +2,5 @@ require 'rest-client'
2
2
  require 'bitpagos/client'
3
3
  require 'bitpagos/errors/generic_error'
4
4
  require 'bitpagos/errors/invalid_api_key'
5
+ require 'bitpagos/errors/invalid_transaction_type'
5
6
  require 'bitpagos/errors/unauthorized'
@@ -22,42 +22,67 @@ module Bitpagos
22
22
  retrieve_transactions(nil, transaction_id)
23
23
  end
24
24
 
25
- def all_transactions
26
- retrieve_transactions
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
- all_transactions["meta"]["total_count"]
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: { status: query }) if query
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)
@@ -0,0 +1,6 @@
1
+ module Bitpagos
2
+ module Errors
3
+ class InvalidTransactionType < GenericError
4
+ end
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Bitpagos
2
- VERSION = '0.3.1'
2
+ VERSION = '1.0.0'
3
3
  end
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.3.1
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