social_wallet 1.0.3 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fdf12140aa01114e5b4910a8985732936f945e91
4
- data.tar.gz: 5133eca30991f157a9459c64452f2fb423dacaa9
3
+ metadata.gz: efcf1377f95d5c41b20f36ecd8944a19c3429f08
4
+ data.tar.gz: 897540772baadda63332f1c9ee802c40fdab005f
5
5
  SHA512:
6
- metadata.gz: 3daad05172f5d38bc0fee1e398cf43178e25954b5654bb66123271da5c03d7c0bc8743b84ff1542dba75958eb3cb5be23f9fb9887d310c26090a8a4e4e9620c8
7
- data.tar.gz: 227fa5b9ea0637535d215297ff68eb6d7a8c951d09f1a082fdd4893734ab2e61966bd2179016429eae45a21259e4c342fe18a031183f030e280b24d9929d5cae
6
+ metadata.gz: c3e7b14d90113b7f0ada0edebf16cb24a78cfb562eae0eed59d0ec391bf7350ece2c70a6d37484a4bec0628d9e345461e8aea61ef1c4d97247f070aae8f974fe
7
+ data.tar.gz: 6c73550c70671e4b4efb7fa2a33cc72bfe1418e08c92e3b26c6522cbe2b1e2c5a792c2aa4019368d7d71ee0da24c628450ed5fbd2e5d2be5d9dbad2acd8e9693
data/README.md CHANGED
@@ -20,6 +20,10 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
+ ### ⚠️ Version compatibility ⚠️
24
+
25
+ If you use [Social Wallet API](https://github.com/Commonfare-net/social-wallet-api) version ≤ 0.10.x you must use [v1.0.3 of this gem](https://github.com/Commonfare-net/social_wallet_ruby/tree/5fe6ee36f3055de165540f49eb03e54ea9fc268d).
26
+
23
27
  ### Create the client
24
28
 
25
29
  The default client uses the *database* `mongo` as backend.
@@ -28,10 +32,11 @@ The default client uses the *database* `mongo` as backend.
28
32
  client = SocialWallet::Client.new(api_endpoint: 'http://example.com/wallet/v1')
29
33
  ```
30
34
 
31
- If you want to use the API on a *blockchain* just specify it like this:
35
+ This constructor defaults to a client that uses `connection: 'mongo'` and `type: 'db-only'`.
36
+ If you want to use the API on a different backend just specify it like this:
32
37
 
33
38
  ```ruby
34
- client = SocialWallet::Client.new(api_endpoint: 'http://example.com/wallet/v1', blockchain: 'faircoin')
39
+ client = SocialWallet::Client.new(api_endpoint: 'http://example.com/wallet/v1', connection: 'faircoin', type: 'blockchain-and-db')
35
40
  ```
36
41
 
37
42
  ### List of tags
@@ -62,7 +67,7 @@ client.transactions.new(from_id: 'paolo', to_id: 'aaron', amount: 10, tags: ['ta
62
67
  Retrieve the list of the transactions of a specific account.
63
68
 
64
69
  ```ruby
65
- client.transactions(account_id: 'pietro', count: 0, from: 0, page: 0, per_page: 0, currency: 'MONGO').list
70
+ client.transactions(account_id: 'pietro', count: 0, from: 0, page: 0, per_page: 0, currency: 'Commoncoin').list(from_datetime: Time.now - 3600, to_datetime: Time.now)
66
71
  ```
67
72
 
68
73
  To retrieve the list of the transactions of the default account use `account_id: ''`
@@ -73,9 +78,11 @@ To retrieve the list of the transactions of the default account use `account_id:
73
78
 
74
79
  * **Filter by currency**: another optional parameter for *database* transactions is `:currency`, to filter transactions only by one currency.
75
80
 
81
+ * **Filter by dates**: use `from_datetime` and `to_datetime`.
82
+
76
83
  **Response**
77
84
 
78
- The list of transaction is always paginated to avoid overload on the server.
85
+ The list of transactions is always paginated to avoid overload on the server.
79
86
 
80
87
  ```ruby
81
88
  {
@@ -89,7 +96,8 @@ The list of transaction is always paginated to avoid overload on the server.
89
96
  'amount'=>10,
90
97
  'amount-text'=>'10.0',
91
98
  'transaction-id'=>'xqc4cvhr...pCPfju5inCO',
92
- 'currency'=>'MONGO'
99
+ 'currency'=>'Commoncoin'
100
+ 'description'=>'...'
93
101
  },
94
102
  {
95
103
  ...
@@ -126,7 +134,7 @@ client.transactions.get transaction_id: 'xqc4cvhr...pCPfju5inCO'
126
134
  'amount'=>10,
127
135
  'amount-text'=>'10.0',
128
136
  'transaction-id'=>'xqc4cvhr...pCPfju5inCO',
129
- 'currency'=>'MONGO'
137
+ 'currency'=>'Commoncoin'
130
138
  }
131
139
  ```
132
140
 
@@ -188,7 +196,7 @@ Retrieve the label of the currency for the client's backend
188
196
 
189
197
  ```ruby
190
198
  client.label
191
- #=> { 'currency' => 'MONGO' }
199
+ #=> { 'currency' => 'Commoncoin' }
192
200
  ```
193
201
 
194
202
  ### Address
@@ -1,13 +1,20 @@
1
1
  module SocialWallet
2
2
  class Client
3
- attr_accessor :api_endpoint, :blockchain, :request_data
3
+ attr_accessor :api_endpoint, :blockchain, :request_data, :connection, :type
4
4
 
5
5
  SW_ERROR_STATUSES = [404, 503].freeze
6
6
 
7
- def initialize(api_endpoint: nil, blockchain: 'mongo')
7
+ def initialize(
8
+ api_endpoint: nil,
9
+ blockchain: 'mongo',
10
+ connection: 'mongo',
11
+ type: 'db-only'
12
+ )
8
13
  @api_endpoint = api_endpoint
9
- @blockchain = blockchain
10
- @request_data = { blockchain: blockchain }
14
+ @blockchain = blockchain # NOTE: here for backward compatibility
15
+ @connection = connection
16
+ @type = type
17
+ @request_data = { connection: connection, type: type }
11
18
  @path_parts = []
12
19
  end
13
20
 
@@ -55,9 +62,9 @@ module SocialWallet
55
62
  end
56
63
 
57
64
  def ___balance(account_id: nil)
58
- conn = Faraday.new(url: api_endpoint + '/' + path, ssl: { version: 'TLSv1_2' })
65
+ conn = Faraday.new(connection_params)
59
66
  response = conn.post do |req|
60
- req.headers['Content-Type'] = 'application/json'
67
+ req.headers.merge!(headers)
61
68
  request_data['account-id'] = account_id if account_id
62
69
  req.body = MultiJson.dump(request_data)
63
70
  end
@@ -67,9 +74,9 @@ module SocialWallet
67
74
  end
68
75
 
69
76
  def ___label
70
- conn = Faraday.new(url: api_endpoint + '/' + path, ssl: { version: 'TLSv1_2' })
77
+ conn = Faraday.new(connection_params)
71
78
  response = conn.post do |req|
72
- req.headers['Content-Type'] = 'application/json'
79
+ req.headers.merge!(headers)
73
80
  req.body = MultiJson.dump(request_data)
74
81
  end
75
82
  format_response(response)
@@ -78,9 +85,9 @@ module SocialWallet
78
85
  end
79
86
 
80
87
  def ___address(account_id: '')
81
- conn = Faraday.new(url: api_endpoint + '/' + path, ssl: { version: 'TLSv1_2' })
88
+ conn = Faraday.new(connection_params)
82
89
  response = conn.post do |req|
83
- req.headers['Content-Type'] = 'application/json'
90
+ req.headers.merge!(headers)
84
91
  request_data['account-id'] = account_id
85
92
  req.body = MultiJson.dump(request_data)
86
93
  end
@@ -89,22 +96,6 @@ module SocialWallet
89
96
  reset
90
97
  end
91
98
 
92
- # def move(from_id: nil, to_id: nil, amount: 0, tags: [])
93
- # @path_parts << 'move'
94
- # conn = Faraday.new(url: api_endpoint + '/' + path, ssl: { version: 'TLSv1_2' })
95
- # response = conn.post do |req|
96
- # req.headers['Content-Type'] = 'application/json'
97
- # request_data['from-id'] = (from_id ||= @account_id)
98
- # request_data['to-id'] = to_id
99
- # request_data[:amount] = amount
100
- # request_data[:tags] = tags
101
- # req.body = MultiJson.dump(request_data)
102
- # end
103
- # format_response(response)
104
- # ensure
105
- # reset
106
- # end
107
-
108
99
  def ___new(
109
100
  from_id: nil,
110
101
  to_id: nil,
@@ -114,11 +105,12 @@ module SocialWallet
114
105
  to_address: '',
115
106
  comment: '',
116
107
  comment_to: '',
108
+ description: '',
117
109
  tags: []
118
110
  )
119
- conn = Faraday.new(url: api_endpoint + '/' + path, ssl: { version: 'TLSv1_2' })
111
+ conn = Faraday.new(connection_params)
120
112
  response = conn.post do |req|
121
- req.headers['Content-Type'] = 'application/json'
113
+ req.headers.merge!(headers)
122
114
  # From SWAPI v0.9.3 amount is a String
123
115
  request_data[:amount] = BigDecimal.new(amount, 16).to_s('F')
124
116
  request_data[:tags] = tags
@@ -135,6 +127,7 @@ module SocialWallet
135
127
  elsif @path_parts.include? 'transactions'
136
128
  request_data['from-id'] = from_id
137
129
  request_data['to-id'] = to_id
130
+ request_data['description'] = description
138
131
  end
139
132
  req.body = MultiJson.dump(request_data)
140
133
  end
@@ -143,10 +136,15 @@ module SocialWallet
143
136
  reset
144
137
  end
145
138
 
146
- def ___list
147
- conn = Faraday.new(url: api_endpoint + '/' + path, ssl: { version: 'TLSv1_2' })
139
+ def ___list(
140
+ from_datetime: nil,
141
+ to_datetime: nil,
142
+ description: nil,
143
+ tags: nil
144
+ )
145
+ conn = Faraday.new(connection_params)
148
146
  response = conn.post do |req|
149
- req.headers['Content-Type'] = 'application/json'
147
+ req.headers.merge!(headers)
150
148
  if @path_parts.include?('transactions')
151
149
  request_data['account-id'] = @account_id
152
150
  request_data['count'] = @count unless @count.nil?
@@ -154,6 +152,10 @@ module SocialWallet
154
152
  request_data['page'] = @page unless @page.nil?
155
153
  request_data['per-page'] = @per_page unless @per_page.nil?
156
154
  request_data['currency'] = @currency unless @currency.nil?
155
+ request_data['from-datetime'] = from_datetime.iso8601 if from_datetime.is_a? Time
156
+ request_data['to-datetime'] = to_datetime.iso8601 if to_datetime.is_a? Time
157
+ request_data['description'] = description unless description.nil?
158
+ request_data['tags'] = tags unless tags.nil?
157
159
  end
158
160
  req.body = MultiJson.dump(request_data)
159
161
  end
@@ -163,9 +165,9 @@ module SocialWallet
163
165
  end
164
166
 
165
167
  def ___get(transaction_id: nil)
166
- conn = Faraday.new(url: api_endpoint + '/' + path, ssl: { version: 'TLSv1_2' })
168
+ conn = Faraday.new(connection_params)
167
169
  response = conn.post do |req|
168
- req.headers['Content-Type'] = 'application/json'
170
+ req.headers.merge!(headers)
169
171
  request_data[:txid] = transaction_id
170
172
  req.body = MultiJson.dump(request_data)
171
173
  end
@@ -175,9 +177,9 @@ module SocialWallet
175
177
  end
176
178
 
177
179
  def ___check(address: '')
178
- conn = Faraday.new(url: api_endpoint + '/' + path, ssl: { version: 'TLSv1_2' })
180
+ conn = Faraday.new(connection_params)
179
181
  response = conn.post do |req|
180
- req.headers['Content-Type'] = 'application/json'
182
+ req.headers.merge!(headers)
181
183
  request_data[:address] = address
182
184
  req.body = MultiJson.dump(request_data)
183
185
  end
@@ -206,7 +208,7 @@ module SocialWallet
206
208
 
207
209
  def reset
208
210
  @path_parts = []
209
- @request_data = { blockchain: blockchain }
211
+ @request_data = { connection: connection, type: type }
210
212
  end
211
213
 
212
214
  def format_response(response)
@@ -219,5 +221,19 @@ module SocialWallet
219
221
  raise SocialWallet::Error.new("API Error: #{response.body}")
220
222
  end
221
223
  end
224
+
225
+ def connection_params
226
+ {
227
+ url: api_endpoint + '/' + path,
228
+ ssl: { version: 'TLSv1_2' }
229
+ }
230
+ end
231
+
232
+ def headers
233
+ {
234
+ 'Content-Type' => 'application/json',
235
+ # 'x-api-key' => ENV['SOCIAL_WALLET_API_KEY']
236
+ }
237
+ end
222
238
  end
223
239
  end
@@ -1,3 +1,3 @@
1
1
  module SocialWallet
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/social_wallet.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'faraday'
2
2
  require 'multi_json'
3
3
  require 'bigdecimal'
4
+ require 'time'
4
5
 
5
6
  require 'social_wallet/version'
6
7
  require 'social_wallet/error'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_wallet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pbmolini
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-06 00:00:00.000000000 Z
11
+ date: 2019-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday