bitodeme 0.1.7 → 0.2.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: 47c1bccb6089399d31440eab810a1b4c6ac210e0
4
- data.tar.gz: '09d81264d360aa21da27fc71d5be93651365edbf'
3
+ metadata.gz: e01f9cf44ba50b812a552214b08f7565c6fe088a
4
+ data.tar.gz: 9d67498f12188ed64ccc4cfe020ca8948a7ef917
5
5
  SHA512:
6
- metadata.gz: 6ad50422db90dac7723b63a2f9ae6d334a37388b3b86aee943c2e62a0443055bd13dded7e644727f5826dc1fe6b65bc1374fbeb7af426bef59b99d61977afdc8
7
- data.tar.gz: 6bb4e53305ab0d79c98fd89d16ffc9f51b10fb1bd8b4767bcd691f7a1835c5454c178bfc07b9c59405a4509c3251f2e3ea20e123da4b616f0fb3c43b5bf67312
6
+ metadata.gz: dfca15c71c7f81fd0b357c5269cfd18603992a2f292f750c4244a2515680e8f171f4cec884d971506934e08a57bc98824e036441b3e069b7ff843bcda8c84bda
7
+ data.tar.gz: add1c998835287bac4ada1ad637d64f5802ef78e5aaefe0eb04c64a0243573f8db64de6673f91073f4356d4909b38d3959179dae9df7dff4c1620dac5ffae952
@@ -0,0 +1,3 @@
1
+ BITODEME_HOSTNAME=alpha.bitodeme.com
2
+ BITODEME_CLIENT_ID=key
3
+ BITODEME_CLIENT_SECRET=secret
@@ -0,0 +1,3 @@
1
+ BITODEME_HOSTNAME=alpha.bitodeme.com
2
+ BITODEME_CLIENT_ID=key
3
+ BITODEME_CLIENT_SECRET=secret
data/.gitignore CHANGED
@@ -12,4 +12,5 @@
12
12
 
13
13
  .env
14
14
  .byebug_history
15
- *.gem
15
+ *.gem
16
+ .DS_Store
@@ -3,3 +3,7 @@ language: ruby
3
3
  rvm:
4
4
  - 2.4.3
5
5
  before_install: gem install bundler -v 1.16.0
6
+ env:
7
+ - BITODEME_HOSTNAME=alpha.bitodeme.com
8
+ - BITODEME_CLIENT_ID=key
9
+ - BITODEME_CLIENT_SECRET=secret
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitodeme (0.1.6)
4
+ bitodeme (0.1.7)
5
5
  dotenv (~> 2.2, >= 2.2)
6
6
  faraday (~> 0.13)
7
7
  faraday_middleware (~> 0.12)
@@ -42,6 +42,7 @@ GEM
42
42
  json (>= 1.8, < 3)
43
43
  simplecov-html (~> 0.10.0)
44
44
  simplecov-html (0.10.2)
45
+ vcr (4.0.0)
45
46
 
46
47
  PLATFORMS
47
48
  ruby
@@ -53,6 +54,7 @@ DEPENDENCIES
53
54
  rake (~> 10.0)
54
55
  rspec (~> 3.0)
55
56
  simplecov (~> 0.15)
57
+ vcr (~> 4.0)
56
58
 
57
59
  BUNDLED WITH
58
60
  1.16.0
data/README.md CHANGED
@@ -118,8 +118,8 @@ Build & create a withdrawal (send money)
118
118
  fund_id = '12b241a7-941e-43a8-878e-a467809e988e'
119
119
  withdrawal =
120
120
  Bitodeme.build_withdrawal(
121
- amount: 16.7,
122
- address: 'USD',
121
+ amount: 0.0013,
122
+ address: 'morg4YKzAESEktS7H74dtaavFjuhNUi8zq',
123
123
  fund_id: fund_id,
124
124
  otp_value: 123456 # otp value from Google Authenticator
125
125
  )
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
25
  spec.add_development_dependency 'rspec', '~> 3.0'
26
26
  spec.add_development_dependency 'simplecov', '~> 0.15'
27
+ spec.add_development_dependency 'vcr', '~> 4.0'
27
28
 
28
29
  spec.add_dependency 'dotenv', '~> 2.2', '>= 2.2'
29
30
  spec.add_dependency 'faraday', '~> 0.13'
@@ -16,23 +16,29 @@ module Bitodeme
16
16
  access_token
17
17
  end
18
18
 
19
+ def inspect
20
+ "#<#{self.class.name}:0x#{(object_id << 1).to_s(16)} " \
21
+ "hostname=\"#{hostname}\" client_id=\"#{client_id}\" " \
22
+ "client_secret=\"#{client_secret}\">"
23
+ end
24
+
19
25
  private
20
26
 
21
- USER_AGENT = "Ruby / Bitodeme::Auth v#{Bitodeme::VERSION}".freeze
22
- GRANT_TYPE = 'client_credentials'.freeze
23
- AUTH_ENDPOINT = '/api/v1/tokens'.freeze
27
+ USER_AGENT = "Ruby / Bitodeme::Auth v#{Bitodeme::VERSION}".freeze
24
28
 
25
29
  def_delegators :Bitodeme, :config
26
30
  def_delegators :config, :hostname, :client_id, :client_secret
27
31
 
28
- attr_reader :access_token, :expires_at
32
+ attr_reader :connection, :access_token, :expires_at
29
33
 
30
34
  def initialize
31
- @expires_at = 0
35
+ @connection = build_connection
36
+ @expires_at = 0
37
+ @access_token = ''
32
38
  end
33
39
 
34
40
  def expired?
35
- Time.now.to_i > expires_at
41
+ Time.now.to_i >= expires_at
36
42
  end
37
43
 
38
44
  def reset_token
@@ -42,14 +48,14 @@ module Bitodeme
42
48
  end
43
49
 
44
50
  def authenticate
45
- conn.post(AUTH_ENDPOINT, auth_body).body
51
+ connection.post('/api/v1/tokens', auth_body).body
46
52
  end
47
53
 
48
- def conn
49
- @conn ||= Faraday.new(faraday_opts) do |faraday|
50
- faraday.request :json
51
- faraday.response :json, content_type: /\bjson$/
52
- faraday.adapter Faraday.default_adapter
54
+ def build_connection
55
+ Faraday.new(faraday_opts) do |conn|
56
+ conn.request :json
57
+ conn.response :json, content_type: /\bjson$/
58
+ conn.adapter Faraday.default_adapter
53
59
  end
54
60
  end
55
61
 
@@ -68,7 +74,7 @@ module Bitodeme
68
74
  {
69
75
  client_id: client_id,
70
76
  client_secret: client_secret,
71
- grant_type: GRANT_TYPE
77
+ grant_type: 'client_credentials'
72
78
  }
73
79
  end
74
80
  end
@@ -9,30 +9,29 @@ module Bitodeme
9
9
  USER_AGENT = "Ruby / Bitodeme::Conn v#{Bitodeme::VERSION}".freeze
10
10
 
11
11
  def self.build
12
- $bitodeme_conn ||= instance.send(:conn)
12
+ $bitodeme_conn ||= instance.send(:connection)
13
13
  end
14
14
 
15
15
  private
16
16
 
17
- attr_reader :auth, :hostname
17
+ attr_reader :auth
18
18
 
19
19
  def initialize
20
- @auth = Bitodeme::Auth.build
21
- @hostname = Bitodeme.config.hostname
20
+ @auth = Bitodeme::Auth.build
22
21
  end
23
22
 
24
- def conn
25
- Faraday.new(faraday_opts) do |faraday|
26
- faraday.request :oauth2, auth.token, token_type: :bearer
27
- faraday.request :json
28
- faraday.response :json, content_type: /\bjson$/
29
- faraday.adapter Faraday.default_adapter
23
+ def connection
24
+ Faraday.new(faraday_opts) do |conn|
25
+ conn.request :oauth2, auth.token, token_type: :bearer
26
+ conn.request :json
27
+ conn.response :json, content_type: /\bjson$/
28
+ conn.adapter Faraday.default_adapter
30
29
  end
31
30
  end
32
31
 
33
32
  def faraday_opts
34
33
  @faraday_opts ||= {
35
- url: "https://#{hostname}",
34
+ url: "https://#{Bitodeme.config.hostname}",
36
35
  headers: { 'User-Agent' => USER_AGENT }
37
36
  }
38
37
  end
@@ -1,4 +1,5 @@
1
1
  require 'forwardable'
2
+ require 'ostruct'
2
3
 
3
4
  module Bitodeme
4
5
  module Resource
@@ -6,7 +7,7 @@ module Bitodeme
6
7
  class Base
7
8
  extend SingleForwardable
8
9
 
9
- def_delegators :conn, :post, :get, :put, :delete
10
+ def_delegators :conn, :post, :get
10
11
 
11
12
  class << self
12
13
  private
@@ -16,44 +17,38 @@ module Bitodeme
16
17
  end
17
18
 
18
19
  def _find(collection, resource, id)
19
- get("/api/v1/#{collection}/#{id}").body.fetch(resource, {}) || {}
20
+ item = get("/api/v1/#{collection}/#{id}").body.fetch(resource, {})
21
+ new(item || {})
20
22
  end
21
23
 
22
- def _all(collection, page: 1, per_page: 50, since: 0)
23
- query_params = { page: page, per_page: per_page, since: since }
24
- get("/api/v1/#{collection}", query_params).body.fetch(collection, [])
25
- end
26
-
27
- def _update(collection, resource, id, data)
28
- put("/api/v1/#{collection}/#{id}", data).body.fetch(resource, data)
24
+ def _all(collection, options)
25
+ items = get("/api/v1/#{collection}", _query_params(options)).body
26
+ items.fetch(collection, []).map { |item| new(item) }
29
27
  end
30
28
 
31
29
  def _create(collection, resource, data)
32
- post("/api/v1/#{collection}", data).body.fetch(resource, data)
30
+ item = post("/api/v1/#{collection}", data).body.fetch(resource, data)
31
+ new(item || {})
33
32
  end
34
33
 
35
- def _delete(collection, id)
36
- delete("/api/v1/#{collection}/#{id}").body
34
+ def _query_params(page: 1, per_page: 50, since: 0)
35
+ { page: page, per_page: per_page, since: since }
37
36
  end
38
37
  end
39
38
 
40
39
  def to_h
41
- hash = {}
42
- attrs.each do |attr|
43
- val = instance_variable_get(:"@#{attr}")
44
- hash[attr.to_sym] = val unless val.nil?
40
+ attrs.each_with_object({}) do |attr, hash|
41
+ val = instance_variable_get(:"@#{attr}")
42
+ hash[attr] = val unless val.nil?
45
43
  end
46
- hash
47
44
  end
48
45
 
49
46
  private
50
47
 
51
48
  def initialize(attrs:, params:)
52
49
  attrs.each do |attr|
53
- instance_variable_set(
54
- "@#{attr}",
55
- params.fetch(attr.to_s, params.fetch(attr.to_sym, nil))
56
- )
50
+ val = params.fetch(attr.to_s, params.fetch(attr, nil))
51
+ instance_variable_set("@#{attr}", val)
57
52
  end
58
53
  end
59
54
 
@@ -62,7 +57,7 @@ module Bitodeme
62
57
  end
63
58
 
64
59
  def klass_methods
65
- self.class.methods - [:name]
60
+ self.class.methods - %i[name]
66
61
  end
67
62
 
68
63
  def excluded_attrs
@@ -46,8 +46,7 @@ module Bitodeme
46
46
  # Arguments:
47
47
  # options: (Hash)
48
48
  def all(options = {})
49
- items = _all('currencies', options)
50
- items.map { |item| new(item) }
49
+ _all('currencies', options)
51
50
  end
52
51
  end
53
52
 
@@ -8,16 +8,12 @@ module Bitodeme
8
8
  attr_reader :id
9
9
 
10
10
  class << self
11
- PLURAL = 'deposits'.freeze
12
- SINGULAR = 'deposit'.freeze
13
-
14
11
  # List all deposits
15
12
  #
16
13
  # Arguments:
17
14
  # options: (Hash)
18
15
  def all(options = {})
19
- items = _all(PLURAL, options)
20
- items.map { |item| new(item) }
16
+ _all('deposits', options)
21
17
  end
22
18
  end
23
19
 
@@ -26,16 +26,12 @@ module Bitodeme
26
26
  attr_reader :updated_at
27
27
 
28
28
  class << self
29
- PLURAL = 'funds'.freeze
30
- SINGULAR = 'fund'.freeze
31
-
32
29
  # Find a fund
33
30
  #
34
31
  # Arguments:
35
32
  # id: (UUID)
36
33
  def find(id)
37
- item = _find(PLURAL, SINGULAR, id)
38
- new(item)
34
+ _find('funds', 'fund', id)
39
35
  end
40
36
 
41
37
  # List all funds
@@ -43,8 +39,7 @@ module Bitodeme
43
39
  # Arguments:
44
40
  # options: (Hash)
45
41
  def all(options = {})
46
- items = _all(PLURAL, options)
47
- items.map { |item| new(item) }
42
+ _all('funds', options)
48
43
  end
49
44
  end
50
45
 
@@ -32,16 +32,12 @@ module Bitodeme
32
32
  attr_reader :updated_at
33
33
 
34
34
  class << self
35
- PLURAL = 'fund_addresses'.freeze
36
- SINGULAR = 'fund_address'.freeze
37
-
38
35
  # Find a fund address
39
36
  #
40
37
  # Arguments:
41
38
  # id: (UUID)
42
39
  def find(id)
43
- item = _find(PLURAL, SINGULAR, id)
44
- new(item)
40
+ _find('fund_addresses', 'fund_address', id)
45
41
  end
46
42
 
47
43
  # List all fund addresses
@@ -49,8 +45,7 @@ module Bitodeme
49
45
  # Arguments:
50
46
  # options: (Hash)
51
47
  def all(options = {})
52
- items = _all(PLURAL, options)
53
- items.map { |item| new(item) }
48
+ _all('fund_addresses', options)
54
49
  end
55
50
  end
56
51
 
@@ -50,14 +50,11 @@ module Bitodeme
50
50
  attr_reader :updated_at
51
51
 
52
52
  class << self
53
- PLURAL = 'invoices'.freeze
54
- SINGULAR = 'invoice'.freeze
55
-
56
53
  # Build an invoice
57
54
  #
58
55
  # Example:
59
56
  # >> invoice =
60
- # >> Bitodeme.build_invoice(
57
+ # >> Bitodeme::Resource::Invoice.build(
61
58
  # >> name: 'Virtual game gold',
62
59
  # >> description: 'Buy a game gold',
63
60
  # >> original_amount: 16.7,
@@ -77,8 +74,7 @@ module Bitodeme
77
74
  # Arguments:
78
75
  # id: (UUID)
79
76
  def find(id)
80
- item = _find(PLURAL, SINGULAR, id)
81
- new(item)
77
+ _find('invoices', 'invoice', id)
82
78
  end
83
79
 
84
80
  # Craete a new invoice
@@ -100,8 +96,7 @@ module Bitodeme
100
96
  # invoice: (Bitodeme::Resource::Invoice)
101
97
  def create(invoice)
102
98
  raise_for('invoice', invoice) unless invoice.is_a?(Invoice)
103
- item = _create(PLURAL, SINGULAR, invoice: invoice.to_h)
104
- new(item)
99
+ _create('invoices', 'invoice', invoice: invoice.to_h)
105
100
  end
106
101
 
107
102
  private
@@ -41,16 +41,12 @@ module Bitodeme
41
41
  attr_reader :updated_at
42
42
 
43
43
  class << self
44
- PLURAL = 'transaction_logs'.freeze
45
- SINGULAR = 'transaction_log'.freeze
46
-
47
44
  # Find a transaction log
48
45
  #
49
46
  # Arguments:
50
47
  # id: (UUID)
51
48
  def find(id)
52
- item = _find(PLURAL, SINGULAR, id)
53
- new(item)
49
+ _find('transaction_logs', 'transaction_log', id)
54
50
  end
55
51
 
56
52
  # List all transaction logs
@@ -58,8 +54,7 @@ module Bitodeme
58
54
  # Arguments:
59
55
  # options: (Hash)
60
56
  def all(options = {})
61
- items = _all(PLURAL, options)
62
- items.map { |item| new(item) }
57
+ _all('transaction_logs', options)
63
58
  end
64
59
  end
65
60
 
@@ -13,21 +13,21 @@ module Bitodeme
13
13
  # Fund identifier
14
14
  attr_reader :fund_id
15
15
 
16
+ # Unique identifier
17
+ attr_reader :id
18
+
16
19
  # One time password value gathered from Google Authenticator
17
20
  attr_reader :otp_value
18
21
 
19
22
  class << self
20
- PLURAL = 'withdrawals'.freeze
21
- SINGULAR = 'withdrawal'.freeze
22
-
23
23
  # Build a withdrawal object
24
24
  #
25
25
  # Example:
26
26
  # >> fund_id = '12b241a7-941e-43a8-878e-a467809e988e'
27
27
  # >> withdrawal =
28
- # >> Bitodeme.build_withdrawal(
29
- # >> amount: 16.7,
30
- # >> address: 'USD',
28
+ # >> Bitodeme::Resource::Withdrawal.build(
29
+ # >> amount: 0.0013,
30
+ # >> address: 'morg4YKzAESEktS7H74dtaavFjuhNUi8zq',
31
31
  # >> fund_id: fund_id,
32
32
  # >> otp_value: 123456 # otp value from Google Authenticator
33
33
  # >> )
@@ -43,21 +43,20 @@ module Bitodeme
43
43
  # Example:
44
44
  # >> fund_id = '12b241a7-941e-43a8-878e-a467809e988e'
45
45
  # >> withdrawal =
46
- # >> Bitodeme.build_withdrawal(
47
- # >> amount: 16.7,
48
- # >> address: 'USD',
46
+ # >> Bitodeme::Resource::Withdrawal.build(
47
+ # >> amount: 0.0013,
48
+ # >> address: 'morg4YKzAESEktS7H74dtaavFjuhNUi8zq',
49
49
  # >> fund_id: fund_id,
50
50
  # >> otp_value: 123456 # otp value from Google Authenticator
51
51
  # >> )
52
52
  #
53
- # >> withdrawal = Bitodeme.create_withdrawal(withdrawal)
53
+ # >> withdrawal = Bitodeme::Resource::Withdrawal.create(withdrawal)
54
54
  #
55
55
  # Arguments:
56
56
  # withdrawal: (Bitodeme::Resource::Withdrawal)
57
57
  def create(withdrawal)
58
58
  raise_for('withdrawal') unless withdrawal.is_a?(Withdrawal)
59
- item = _create(PLURAL, SINGULAR, withdrawal: withdrawal.to_h)
60
- new(item)
59
+ _create('withdrawals', 'withdrawal', withdrawal: withdrawal.to_h)
61
60
  end
62
61
 
63
62
  private
@@ -1,6 +1,6 @@
1
1
  module Bitodeme
2
2
  # Validation Error
3
- class ValidationError < ::StandardError
3
+ class ValidationError < StandardError
4
4
  def initialize(attr, val)
5
5
  super("Unacceptable value('#{val}') for '#{attr}'!")
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module Bitodeme
2
- VERSION = '0.1.7'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitodeme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bitodeme Integrations Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-18 00:00:00.000000000 Z
11
+ date: 2017-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.15'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: dotenv
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -135,6 +149,8 @@ executables: []
135
149
  extensions: []
136
150
  extra_rdoc_files: []
137
151
  files:
152
+ - ".env.example"
153
+ - ".env.test"
138
154
  - ".gitignore"
139
155
  - ".rspec"
140
156
  - ".travis.yml"