blockchain 1.0.2 → 1.1.1

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.
@@ -1,3 +1,3 @@
1
1
  module Blockchain
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -1,167 +1,167 @@
1
- require 'json'
2
- require_relative 'util'
3
-
4
- module Blockchain
5
-
6
- class Wallet
7
-
8
- def initialize(identifier, password, second_password = nil, api_code = nil)
9
- @identifier = identifier
10
- @password = password
11
- @second_password = second_password
12
- @api_code = api_code
13
- end
14
-
15
- def send(to, amount, from_address: nil, fee: nil, note: nil)
16
- recipient = { to => amount }
17
- return send_many(recipient, from_address: from_address, fee: fee, note: note)
18
- end
19
-
20
- def send_many(recipients, from_address: nil, fee: nil, note: nil)
21
- params = build_basic_request()
22
- method = ''
23
-
24
- if recipients.size == 1
25
- params['to'] = recipients.keys[0]
26
- params['amount'] = recipients.values[0]
27
- method = 'payment'
28
- else
29
- params['recipients'] = JSON.dump(recipients)
30
- method = 'sendmany'
31
- end
32
-
33
- if !from_address.nil?
34
- params['from'] = from_address
35
- end
36
- if !fee.nil?
37
- params['fee'] = fee
38
- end
39
- if !note.nil?
40
- params['note'] = note
41
- end
42
-
43
- response = Blockchain::call_api("merchant/#{@identifier}/#{method}", method: 'post', data: params)
44
- json_response = parse_json(response)
45
- return PaymentResponse.new(
46
- json_response['message'],
47
- json_response['tx_hash'],
48
- json_response['notice'])
49
- end
50
-
51
- def get_balance()
52
- response = resp = Blockchain::call_api("merchant/#{@identifier}/balance", method: 'get', data: build_basic_request())
53
- json_response = parse_json(response)
54
- return json_response['balance']
55
- end
56
-
57
- def list_addresses(confirmations = 0)
58
- params = build_basic_request()
59
- params['confirmations'] = confirmations
60
- response = Blockchain::call_api("merchant/#{@identifier}/list", method: 'get', data: params)
61
- json_response = parse_json(response)
62
-
63
- addresses = []
64
- json_response['addresses'].each do |a|
65
- addr = WalletAddress.new(a['balance'],
66
- a['address'],
67
- a['label'],
68
- a['total_received'])
69
- addresses.push(addr)
70
- end
71
- return addresses
72
- end
73
-
74
- def get_address(address, confirmations = 0)
75
- params = build_basic_request()
76
- params['address'] = address
77
- params['confirmations'] = confirmations
78
- response = Blockchain::call_api("merchant/#{@identifier}/address_balance", method: 'get', data: params)
79
- json_response = parse_json(response)
80
- return WalletAddress.new(json_response['balance'],
81
- json_response['address'],
82
- nil,
83
- json_response['total_received'])
84
- end
85
-
86
- def new_address(label = nil)
87
- params = build_basic_request()
88
- if !label.nil? then params['label'] = label end
89
- response = Blockchain::call_api("merchant/#{@identifier}/new_address", method: 'post', data: params)
90
- json_response = parse_json(response)
91
- return WalletAddress.new(0,
92
- json_response['address'],
93
- json_response['label'],
94
- 0)
95
- end
96
-
97
- def archive_address(address)
98
- params = build_basic_request()
99
- params['address'] = address
100
- response = Blockchain::call_api("merchant/#{@identifier}/archive_address", method: 'post', data: params)
101
- json_response = parse_json(response)
102
- return json_response['archived']
103
- end
104
-
105
- def unarchive_address(address)
106
- params = build_basic_request()
107
- params['address'] = address
108
- response = Blockchain::call_api("merchant/#{@identifier}/unarchive_address", method: 'post', data: params)
109
- json_response = parse_json(response)
110
- return json_response['active']
111
- end
112
-
113
- def consolidate(days)
114
- params = build_basic_request()
115
- params['days'] = days
116
- response = Blockchain::call_api("merchant/#{@identifier}/auto_consolidate", method: 'post', data: params)
117
- json_response = parse_json(response)
118
- return json_response['consolidated']
119
- end
120
-
121
- def build_basic_request()
122
- params = { 'password' => @password }
123
- if !@second_password.nil?
124
- params['second_password'] = @second_password
125
- end
126
- if !@api_code.nil?
127
- params['api_code'] = @api_code
128
- end
129
- return params
130
- end
131
-
132
- # convenience method that parses a response into json AND makes sure there are no errors
133
- def parse_json(response)
134
- json_response = JSON.parse(response)
135
- error = json_response['error']
136
- if !error.nil? then raise APIException.new(error) end
137
- return json_response
138
- end
139
- end
140
-
141
- class WalletAddress
142
- attr_reader :balance
143
- attr_reader :address
144
- attr_reader :label
145
- attr_reader :total_received
146
-
147
- def initialize(balance, address, label, total_received)
148
- @balance = balance
149
- @address = address
150
- @label = label
151
- @total_received = total_received
152
- end
153
- end
154
-
155
- class PaymentResponse
156
- attr_reader :message
157
- attr_reader :tx_hash
158
- attr_reader :notice
159
-
160
- def initialize(message, tx_hash, notice)
161
- @message = message
162
- @tx_hash = tx_hash
163
- @notice = notice
164
- end
165
- end
166
-
1
+ require 'json'
2
+ require_relative 'util'
3
+
4
+ module Blockchain
5
+
6
+ class Wallet
7
+
8
+ def initialize(identifier, password, second_password = nil, api_code = nil)
9
+ @identifier = identifier
10
+ @password = password
11
+ @second_password = second_password
12
+ @api_code = api_code
13
+ end
14
+
15
+ def send(to, amount, from_address: nil, fee: nil, note: nil)
16
+ recipient = { to => amount }
17
+ return send_many(recipient, from_address: from_address, fee: fee, note: note)
18
+ end
19
+
20
+ def send_many(recipients, from_address: nil, fee: nil, note: nil)
21
+ params = build_basic_request()
22
+ method = ''
23
+
24
+ if recipients.size == 1
25
+ params['to'] = recipients.keys[0]
26
+ params['amount'] = recipients.values[0]
27
+ method = 'payment'
28
+ else
29
+ params['recipients'] = JSON.dump(recipients)
30
+ method = 'sendmany'
31
+ end
32
+
33
+ if !from_address.nil?
34
+ params['from'] = from_address
35
+ end
36
+ if !fee.nil?
37
+ params['fee'] = fee
38
+ end
39
+ if !note.nil?
40
+ params['note'] = note
41
+ end
42
+
43
+ response = Blockchain::call_api("merchant/#{@identifier}/#{method}", method: 'post', data: params)
44
+ json_response = parse_json(response)
45
+ return PaymentResponse.new(
46
+ json_response['message'],
47
+ json_response['tx_hash'],
48
+ json_response['notice'])
49
+ end
50
+
51
+ def get_balance()
52
+ response = resp = Blockchain::call_api("merchant/#{@identifier}/balance", method: 'get', data: build_basic_request())
53
+ json_response = parse_json(response)
54
+ return json_response['balance']
55
+ end
56
+
57
+ def list_addresses(confirmations = 0)
58
+ params = build_basic_request()
59
+ params['confirmations'] = confirmations
60
+ response = Blockchain::call_api("merchant/#{@identifier}/list", method: 'get', data: params)
61
+ json_response = parse_json(response)
62
+
63
+ addresses = []
64
+ json_response['addresses'].each do |a|
65
+ addr = WalletAddress.new(a['balance'],
66
+ a['address'],
67
+ a['label'],
68
+ a['total_received'])
69
+ addresses.push(addr)
70
+ end
71
+ return addresses
72
+ end
73
+
74
+ def get_address(address, confirmations = 0)
75
+ params = build_basic_request()
76
+ params['address'] = address
77
+ params['confirmations'] = confirmations
78
+ response = Blockchain::call_api("merchant/#{@identifier}/address_balance", method: 'get', data: params)
79
+ json_response = parse_json(response)
80
+ return WalletAddress.new(json_response['balance'],
81
+ json_response['address'],
82
+ nil,
83
+ json_response['total_received'])
84
+ end
85
+
86
+ def new_address(label = nil)
87
+ params = build_basic_request()
88
+ if !label.nil? then params['label'] = label end
89
+ response = Blockchain::call_api("merchant/#{@identifier}/new_address", method: 'post', data: params)
90
+ json_response = parse_json(response)
91
+ return WalletAddress.new(0,
92
+ json_response['address'],
93
+ json_response['label'],
94
+ 0)
95
+ end
96
+
97
+ def archive_address(address)
98
+ params = build_basic_request()
99
+ params['address'] = address
100
+ response = Blockchain::call_api("merchant/#{@identifier}/archive_address", method: 'post', data: params)
101
+ json_response = parse_json(response)
102
+ return json_response['archived']
103
+ end
104
+
105
+ def unarchive_address(address)
106
+ params = build_basic_request()
107
+ params['address'] = address
108
+ response = Blockchain::call_api("merchant/#{@identifier}/unarchive_address", method: 'post', data: params)
109
+ json_response = parse_json(response)
110
+ return json_response['active']
111
+ end
112
+
113
+ def consolidate(days)
114
+ params = build_basic_request()
115
+ params['days'] = days
116
+ response = Blockchain::call_api("merchant/#{@identifier}/auto_consolidate", method: 'post', data: params)
117
+ json_response = parse_json(response)
118
+ return json_response['consolidated']
119
+ end
120
+
121
+ def build_basic_request()
122
+ params = { 'password' => @password }
123
+ if !@second_password.nil?
124
+ params['second_password'] = @second_password
125
+ end
126
+ if !@api_code.nil?
127
+ params['api_code'] = @api_code
128
+ end
129
+ return params
130
+ end
131
+
132
+ # convenience method that parses a response into json AND makes sure there are no errors
133
+ def parse_json(response)
134
+ json_response = JSON.parse(response)
135
+ error = json_response['error']
136
+ if !error.nil? then raise APIException.new(error) end
137
+ return json_response
138
+ end
139
+ end
140
+
141
+ class WalletAddress
142
+ attr_reader :balance
143
+ attr_reader :address
144
+ attr_reader :label
145
+ attr_reader :total_received
146
+
147
+ def initialize(balance, address, label, total_received)
148
+ @balance = balance
149
+ @address = address
150
+ @label = label
151
+ @total_received = total_received
152
+ end
153
+ end
154
+
155
+ class PaymentResponse
156
+ attr_reader :message
157
+ attr_reader :tx_hash
158
+ attr_reader :notice
159
+
160
+ def initialize(message, tx_hash, notice)
161
+ @message = message
162
+ @tx_hash = tx_hash
163
+ @notice = notice
164
+ end
165
+ end
166
+
167
167
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blockchain
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blockchain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-23 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  requirements: []
90
90
  rubyforge_project:
91
- rubygems_version: 2.2.2
91
+ rubygems_version: 2.4.5.1
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: Blockchain API library (Ruby, v1)