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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f186b06c781c63fe87bc6e16c2528b51fe2f9c6a
4
- data.tar.gz: bd8d53c2aa34b64500f6a2bebe7d616510452d84
3
+ metadata.gz: f8d1c7b27348dfa25433e60edf1be84f5cc89b49
4
+ data.tar.gz: f294a82c9d166b9f56df06c668f578fa6410a0c5
5
5
  SHA512:
6
- metadata.gz: b6ae05f969c7e315f6c6f1723c9269b7c8962678b93f5971d75bca765110223fe0e978995e026ad445729c342e72388e0d4c7b56e235f8a576247f8979dec98f
7
- data.tar.gz: 94e73c2fb2aa3d2c6c17854f4d5277c71eab2fa138ece11256aff22c10482652b153fe7833eb8b15beab284176ae45b5c9f63dc1e16a8d748e66ee5f328d5315
6
+ metadata.gz: 1d1ecd9e4f0c707ebff9f0be545b1a9ce58476f9f459b4f3f5abab0daedf58b16714bec53f21ae6f8227e8efe4a1e549d63d84c0f035f0ba51bcfbd38361a3c1
7
+ data.tar.gz: 40a9eca15c48940afe36e845f73d6f65e8e24e1f8589aa0dcb4797367d991b0e27971c5178e7fe090277d7fbc89218dd2af162b3c4ace265a1f31b76cb214fe7
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ mkmf.log
15
15
  .env
16
16
  tags
17
17
  .tags
18
+ path
19
+ .ruby-version
data/.rubocop.yml CHANGED
@@ -3,9 +3,7 @@ AllCops:
3
3
  - '**/Rakefile'
4
4
  - '**/config.ru'
5
5
  Exclude:
6
- - 'db/**/*'
7
- - 'config/**/*'
8
- - 'script/**/*'
6
+ - 'path/**/*'
9
7
  - 'bin/**/*'
10
8
  - 'vendor/**/*'
11
9
 
data/bitreserve.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ['lib']
19
19
 
20
20
  spec.add_dependency 'httparty', '>= 0.13.3'
21
+ spec.add_dependency 'virtus', '>= 1.0.4'
21
22
  spec.add_dependency 'dotenv'
22
23
 
23
24
  spec.add_development_dependency 'bundler', '~> 1.7'
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,6 @@ module Bitreserve
10
10
  PUBLIC_TRANSACTIONS = '/reserve/transactions'
11
11
  STATS = '/reserve/statistics'
12
12
  TICKER = '/ticker'
13
- TRANSACTIONS = '/reserve/transactions'
14
13
  USER = '/me'
15
14
  USER_CONTACTS = '/me/contacts'
16
15
  USER_PHONES = '/me/phones'
@@ -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: id)
13
+ def find_public_transaction(id: '')
14
14
  request_data = RequestData.new(
15
15
  Endpoints::PUBLIC_TRANSACTIONS + "/#{id}",
16
16
  Entities::Transaction,
@@ -1,7 +1,9 @@
1
1
  module Bitreserve
2
2
  module Entities
3
3
  class Asset < BaseEntity
4
- attr_reader :currency, :values, :totals
4
+ attribute :currency
5
+ attribute :values
6
+ attribute :totals
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  module Bitreserve
2
2
  module Entities
3
3
  class AuthToken < BaseEntity
4
- attr_reader :access_token, :description, :expires
4
+ attribute :access_token
5
+ attribute :description
6
+ attribute :expires, DateTime
5
7
  end
6
8
  end
7
9
  end
@@ -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
- instantiate_variables(attributes)
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
- attr_reader :id, :address, :addresses, :label, :currency, :balance,
5
- :available, :lastTransactionAt, :position
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
- attr_reader :id, :first_name, :last_name, :company, :emails, :addresses, :name
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
@@ -0,0 +1,9 @@
1
+ module Bitreserve
2
+ module Entities
3
+ class Error < BaseEntity
4
+ attribute :code
5
+ attribute :error
6
+ attribute :error_description
7
+ end
8
+ end
9
+ end
@@ -1,7 +1,12 @@
1
1
  module Bitreserve
2
2
  module Entities
3
3
  class Phone < BaseEntity
4
- attr_reader :id, :verified, :primary, :e164_masked, :national_masked, :international_masked
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,10 @@
1
1
  module Bitreserve
2
2
  module Entities
3
3
  class Ticker < BaseEntity
4
- attr_reader :ask, :bid, :currency, :pair
4
+ attribute :ask
5
+ attribute :bid
6
+ attribute :currency
7
+ attribute :pair
5
8
  end
6
9
  end
7
10
  end
@@ -1,7 +1,17 @@
1
1
  module Bitreserve
2
2
  module Entities
3
3
  class Transaction < BaseEntity
4
- attr_reader :id, :message, :status, :type, :refunded_by_id, :created_at, :denomination, :origin, :destination, :params, :quoted_at
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
- attr_reader :username, :email, :first_name, :last_name, :country, :state, :currencies, :settings, :status, :balances
5
-
6
- def phones
7
- @_phones ||= Entities::Phone.from_collection(@phones)
8
- end
9
-
10
- def cards
11
- @_cards ||= Entities::Card.from_collection(@cards)
12
- end
13
-
14
- def transactions
15
- @_transactions ||= Entities::Transaction.from_collection(@transactions)
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
@@ -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)
@@ -1,5 +1,5 @@
1
1
  module Bitreserve
2
- class RequestData < Struct.new(:endpoint, :entity, :headers, :payload)
2
+ RequestData = Struct.new(:endpoint, :entity, :headers, :payload) do
3
3
  def initialize(endpoint, entity, headers = {}, payload = nil)
4
4
  super
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module Bitreserve
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -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 = BaseEntity.new(key: 'value')
12
+ entity = MockEntity.new(a_key: 'value')
9
13
 
10
- expect(entity.instance_variable_get(:@key)).to eq 'value'
14
+ expect(entity.a_key).to eq 'value'
11
15
  end
12
16
 
13
17
  it 'converts camelCase to snake_case' do
14
- entity = BaseEntity.new(someKey: 'value')
18
+ entity = MockEntity.new(a_key: 'value')
15
19
 
16
- expect(entity.instance_variable_get(:@some_key)).to eq 'value'
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(BaseEntity).to receive(:new)
27
+ allow(MockEntity).to receive(:new)
24
28
 
25
- BaseEntity.from_collection([entity])
29
+ MockEntity.from_collection([entity])
26
30
 
27
- expect(BaseEntity).to have_received(:new).with(entity)
31
+ expect(MockEntity).to have_received(:new).with(entity)
28
32
  end
29
33
  end
30
34
  end
@@ -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.0.0
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-01-30 00:00:00.000000000 Z
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.2.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