bitreserve 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -3
- data/bitreserve.gemspec +1 -0
- data/lib/bitreserve.rb +2 -0
- data/lib/bitreserve/api/endpoints.rb +0 -1
- data/lib/bitreserve/api/public_transaction.rb +1 -1
- data/lib/bitreserve/entities/asset.rb +3 -1
- data/lib/bitreserve/entities/auth_token.rb +3 -1
- data/lib/bitreserve/entities/base_entity.rb +3 -14
- data/lib/bitreserve/entities/card.rb +9 -2
- data/lib/bitreserve/entities/contact.rb +7 -1
- data/lib/bitreserve/entities/error.rb +9 -0
- data/lib/bitreserve/entities/phone.rb +6 -1
- data/lib/bitreserve/entities/ticker.rb +4 -1
- data/lib/bitreserve/entities/transaction.rb +11 -1
- data/lib/bitreserve/entities/user.rb +12 -13
- data/lib/bitreserve/request.rb +8 -2
- data/lib/bitreserve/request_data.rb +1 -1
- data/lib/bitreserve/version.rb +1 -1
- data/spec/unit/entities/base_entity_spec.rb +11 -7
- data/spec/unit/request_spec.rb +11 -0
- metadata +18 -5
- data/spec/unit/entities/user_spec.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8d1c7b27348dfa25433e60edf1be84f5cc89b49
|
4
|
+
data.tar.gz: f294a82c9d166b9f56df06c668f578fa6410a0c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d1ecd9e4f0c707ebff9f0be545b1a9ce58476f9f459b4f3f5abab0daedf58b16714bec53f21ae6f8227e8efe4a1e549d63d84c0f035f0ba51bcfbd38361a3c1
|
7
|
+
data.tar.gz: 40a9eca15c48940afe36e845f73d6f65e8e24e1f8589aa0dcb4797367d991b0e27971c5178e7fe090277d7fbc89218dd2af162b3c4ace265a1f31b76cb214fe7
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/bitreserve.gemspec
CHANGED
data/lib/bitreserve.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'httparty'
|
3
3
|
require 'dotenv'
|
4
|
+
require 'virtus'
|
4
5
|
Dotenv.load
|
5
6
|
|
6
7
|
require 'bitreserve/version'
|
@@ -31,3 +32,4 @@ require 'bitreserve/entities/phone'
|
|
31
32
|
require 'bitreserve/entities/ticker'
|
32
33
|
require 'bitreserve/entities/transaction'
|
33
34
|
require 'bitreserve/entities/user'
|
35
|
+
require 'bitreserve/entities/error'
|
@@ -10,7 +10,7 @@ module Bitreserve
|
|
10
10
|
Request.perform_with_objects(:get, request_data)
|
11
11
|
end
|
12
12
|
|
13
|
-
def find_public_transaction(id:
|
13
|
+
def find_public_transaction(id: '')
|
14
14
|
request_data = RequestData.new(
|
15
15
|
Endpoints::PUBLIC_TRANSACTIONS + "/#{id}",
|
16
16
|
Entities::Transaction,
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Bitreserve
|
2
2
|
module Entities
|
3
3
|
class BaseEntity
|
4
|
+
include Virtus.model
|
5
|
+
|
4
6
|
def self.from_collection(entities)
|
5
7
|
entities.map do |entity|
|
6
8
|
new(entity)
|
@@ -8,20 +10,7 @@ module Bitreserve
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def initialize(attributes = {})
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def instantiate_variables(attributes)
|
17
|
-
attributes.each_pair do |key, value|
|
18
|
-
instance_variable_set(instance_variable_name(key), value)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def instance_variable_name(key)
|
23
|
-
underscored_key = Bitreserve::Helpers.underscored_key(key)
|
24
|
-
"@#{underscored_key}"
|
13
|
+
super(Bitreserve::Helpers.underscored_hash(attributes))
|
25
14
|
end
|
26
15
|
end
|
27
16
|
end
|
@@ -1,8 +1,15 @@
|
|
1
1
|
module Bitreserve
|
2
2
|
module Entities
|
3
3
|
class Card < BaseEntity
|
4
|
-
|
5
|
-
|
4
|
+
attribute :id
|
5
|
+
attribute :address
|
6
|
+
attribute :addresses
|
7
|
+
attribute :label
|
8
|
+
attribute :currency
|
9
|
+
attribute :balance
|
10
|
+
attribute :available
|
11
|
+
attribute :lastTransactionAt, DateTime
|
12
|
+
attribute :settings
|
6
13
|
end
|
7
14
|
end
|
8
15
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
module Bitreserve
|
2
2
|
module Entities
|
3
3
|
class Contact < BaseEntity
|
4
|
-
|
4
|
+
attribute :id
|
5
|
+
attribute :first_name
|
6
|
+
attribute :last_name
|
7
|
+
attribute :company
|
8
|
+
attribute :emails
|
9
|
+
attribute :addresses
|
10
|
+
attribute :name
|
5
11
|
end
|
6
12
|
end
|
7
13
|
end
|
@@ -1,7 +1,12 @@
|
|
1
1
|
module Bitreserve
|
2
2
|
module Entities
|
3
3
|
class Phone < BaseEntity
|
4
|
-
|
4
|
+
attribute :id
|
5
|
+
attribute :verified, Boolean
|
6
|
+
attribute :primary, Boolean
|
7
|
+
attribute :e164_masked
|
8
|
+
attribute :national_masked
|
9
|
+
attribute :international_masked
|
5
10
|
end
|
6
11
|
end
|
7
12
|
end
|
@@ -1,7 +1,17 @@
|
|
1
1
|
module Bitreserve
|
2
2
|
module Entities
|
3
3
|
class Transaction < BaseEntity
|
4
|
-
|
4
|
+
attribute :id
|
5
|
+
attribute :message
|
6
|
+
attribute :status
|
7
|
+
attribute :type
|
8
|
+
attribute :refunded_by_id
|
9
|
+
attribute :created_at, DateTime
|
10
|
+
attribute :quoted_at, DateTime
|
11
|
+
attribute :denomination
|
12
|
+
attribute :origin
|
13
|
+
attribute :destination
|
14
|
+
attribute :params
|
5
15
|
end
|
6
16
|
end
|
7
17
|
end
|
@@ -1,19 +1,18 @@
|
|
1
1
|
module Bitreserve
|
2
2
|
module Entities
|
3
3
|
class User < BaseEntity
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
4
|
+
attribute :username, String
|
5
|
+
attribute :email, String
|
6
|
+
attribute :first_name, String
|
7
|
+
attribute :last_name, String
|
8
|
+
attribute :country, String
|
9
|
+
attribute :state, String
|
10
|
+
attribute :currencies
|
11
|
+
attribute :settings
|
12
|
+
attribute :status
|
13
|
+
attribute :balances
|
14
|
+
attribute :phones, Array[Entities::Phone]
|
15
|
+
attribute :cards, Array[Entities::Card]
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
data/lib/bitreserve/request.rb
CHANGED
@@ -5,12 +5,18 @@ module Bitreserve
|
|
5
5
|
|
6
6
|
def self.perform_with_objects(http_method, request_data)
|
7
7
|
response = new(request_data).public_send(http_method)
|
8
|
-
request_data.entity.from_collection(response)
|
8
|
+
check_error(response) || request_data.entity.from_collection(response)
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.perform_with_object(http_method, request_data)
|
12
12
|
response = new(request_data).public_send(http_method)
|
13
|
-
request_data.entity.new(response)
|
13
|
+
check_error(response) || request_data.entity.new(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.check_error(response)
|
17
|
+
return unless response.is_a?(Hash) && response['error']
|
18
|
+
|
19
|
+
Entities::Error.new(response)
|
14
20
|
end
|
15
21
|
|
16
22
|
def initialize(request_data)
|
data/lib/bitreserve/version.rb
CHANGED
@@ -3,28 +3,32 @@ require 'spec_helper'
|
|
3
3
|
module Bitreserve
|
4
4
|
module Entities
|
5
5
|
describe BaseEntity do
|
6
|
+
class MockEntity < BaseEntity
|
7
|
+
attribute :a_key
|
8
|
+
end
|
9
|
+
|
6
10
|
context '#initialize' do
|
7
11
|
it 'instantiates instance variables from arguments' do
|
8
|
-
entity =
|
12
|
+
entity = MockEntity.new(a_key: 'value')
|
9
13
|
|
10
|
-
expect(entity.
|
14
|
+
expect(entity.a_key).to eq 'value'
|
11
15
|
end
|
12
16
|
|
13
17
|
it 'converts camelCase to snake_case' do
|
14
|
-
entity =
|
18
|
+
entity = MockEntity.new(a_key: 'value')
|
15
19
|
|
16
|
-
expect(entity.
|
20
|
+
expect(entity.a_key).to eq 'value'
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
24
|
context '.from_collection' do
|
21
25
|
it 'instantiates each of the entities passed in' do
|
22
26
|
entity = double('Entity')
|
23
|
-
allow(
|
27
|
+
allow(MockEntity).to receive(:new)
|
24
28
|
|
25
|
-
|
29
|
+
MockEntity.from_collection([entity])
|
26
30
|
|
27
|
-
expect(
|
31
|
+
expect(MockEntity).to have_received(:new).with(entity)
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
data/spec/unit/request_spec.rb
CHANGED
@@ -56,6 +56,17 @@ module Bitreserve
|
|
56
56
|
|
57
57
|
expect(Request).to have_received(:get).with(url, headers: headers, body: body)
|
58
58
|
end
|
59
|
+
|
60
|
+
it 'handles an error response' do
|
61
|
+
fake_error = { code: '401', error: 'message' }
|
62
|
+
request_data = RequestData.new('/some-url', object_class)
|
63
|
+
WebMockHelpers.bitreserve_stub_request(:get, '/some-url', fake_error)
|
64
|
+
|
65
|
+
result = Request.public_send(method_name, :get, request_data)
|
66
|
+
|
67
|
+
expect(result).to be_a(Entities::Error)
|
68
|
+
expect(result.code).to eq '401'
|
69
|
+
end
|
59
70
|
end
|
60
71
|
|
61
72
|
def request_data(url = anything, client = nil, payload = nil)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitreserve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Group Buddies
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.13.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: virtus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.4
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: dotenv
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,6 +169,7 @@ files:
|
|
155
169
|
- lib/bitreserve/entities/base_entity.rb
|
156
170
|
- lib/bitreserve/entities/card.rb
|
157
171
|
- lib/bitreserve/entities/contact.rb
|
172
|
+
- lib/bitreserve/entities/error.rb
|
158
173
|
- lib/bitreserve/entities/phone.rb
|
159
174
|
- lib/bitreserve/entities/ticker.rb
|
160
175
|
- lib/bitreserve/entities/transaction.rb
|
@@ -203,7 +218,6 @@ files:
|
|
203
218
|
- spec/unit/api/user_spec.rb
|
204
219
|
- spec/unit/client_spec.rb
|
205
220
|
- spec/unit/entities/base_entity_spec.rb
|
206
|
-
- spec/unit/entities/user_spec.rb
|
207
221
|
- spec/unit/helper_spec.rb
|
208
222
|
- spec/unit/request_spec.rb
|
209
223
|
homepage: https://github.com/groupbuddies/bitreserve
|
@@ -226,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
240
|
version: '0'
|
227
241
|
requirements: []
|
228
242
|
rubyforge_project:
|
229
|
-
rubygems_version: 2.
|
243
|
+
rubygems_version: 2.4.6
|
230
244
|
signing_key:
|
231
245
|
specification_version: 4
|
232
246
|
summary: A wrapper for the bitreserve API
|
@@ -271,7 +285,6 @@ test_files:
|
|
271
285
|
- spec/unit/api/user_spec.rb
|
272
286
|
- spec/unit/client_spec.rb
|
273
287
|
- spec/unit/entities/base_entity_spec.rb
|
274
|
-
- spec/unit/entities/user_spec.rb
|
275
288
|
- spec/unit/helper_spec.rb
|
276
289
|
- spec/unit/request_spec.rb
|
277
290
|
has_rdoc:
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Bitreserve
|
4
|
-
module Entities
|
5
|
-
describe User do
|
6
|
-
shared_examples 'a collectionable attribute' do |klass|
|
7
|
-
attribute_name = klass.to_s.split('::').last.downcase
|
8
|
-
attribute_name_plural = attribute_name + 's'
|
9
|
-
|
10
|
-
it "gets all #{attribute_name} entities from a collection" do
|
11
|
-
attribute = double(attribute_name_plural)
|
12
|
-
user = User.new attribute_name_plural => attribute
|
13
|
-
allow(klass).to receive(:from_collection)
|
14
|
-
|
15
|
-
user.public_send(attribute_name_plural)
|
16
|
-
|
17
|
-
expect(klass).to have_received(:from_collection).with(attribute)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it_behaves_like 'a collectionable attribute', Phone
|
22
|
-
it_behaves_like 'a collectionable attribute', Card
|
23
|
-
it_behaves_like 'a collectionable attribute', Transaction
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|