bitopro 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/bitopro/config/validator.rb +35 -0
- data/lib/bitopro/config.rb +25 -0
- data/lib/bitopro/version.rb +3 -0
- data/lib/bitopro.rb +40 -0
- data/spec/bitopro/api_spec.rb +24 -0
- data/spec/spec_helper.rb +21 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 592f45307f73b0a481ac447c06b61154a1fa302b13522de77b0d2c7439fe9511
|
4
|
+
data.tar.gz: 7835a701ec02aa883e3a168c7db6690adef5d95d5d7a045180b6e4e9499cc2f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7eaa44e533d2788c03394d7aa725017e3b0396446072b1e30f4a7801a85b2d5bcb2c09056cc47baa90c5d290b5c87d84b3374e648b9618c2900d46a4023a94a5
|
7
|
+
data.tar.gz: b523c8cb40a295c8efa6d2f9b584206b56402b02cedd3a4d11b149e1fd73c9a7c2bc5e492ac2cba0c978525b34691c5a0a20960d85fcb96911716a9207784738
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Bitopro
|
2
|
+
class Config
|
3
|
+
class Validator
|
4
|
+
class << self
|
5
|
+
Error = Class.new(StandardError)
|
6
|
+
|
7
|
+
def validate(config)
|
8
|
+
errors = []
|
9
|
+
|
10
|
+
unless valid_key?(config)
|
11
|
+
errors << 'key is required'
|
12
|
+
end
|
13
|
+
unless valid_secret?(config)
|
14
|
+
errors << 'secret is required'
|
15
|
+
end
|
16
|
+
|
17
|
+
errors.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def valid_key?(config)
|
23
|
+
return true if config.key.to_i > 0
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def valid_secret?(config)
|
28
|
+
return false unless config.secret.is_a?(String)
|
29
|
+
return false if config.secret.empty?
|
30
|
+
true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Bitopro
|
2
|
+
class Config
|
3
|
+
class << self
|
4
|
+
# @param [Config] new_instance
|
5
|
+
attr_writer :instance
|
6
|
+
|
7
|
+
# @return [Config]
|
8
|
+
def instance
|
9
|
+
@instance ||= new
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_accessor :key
|
14
|
+
attr_accessor :secret
|
15
|
+
|
16
|
+
def initialize(user_config = {})
|
17
|
+
self.key = user_config[:key]
|
18
|
+
self.secret = user_config[:secret]
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid?
|
22
|
+
Validator.validate(self)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/bitopro.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "rest-client"
|
2
|
+
require "openssl"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
require "bitopro/version"
|
6
|
+
require "bitopro/config"
|
7
|
+
require "bitopro/config/validator"
|
8
|
+
|
9
|
+
module Bitopro
|
10
|
+
BASE_URL = "https://api.bitopro.com/v2".freeze
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# Configures the Bitopro API.
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# Bitopro.configure do |c|
|
17
|
+
# config.key = 113743
|
18
|
+
# config.secret = 'fd04e13d806a90f96614ad8e529b2822'
|
19
|
+
# end
|
20
|
+
def configure
|
21
|
+
yield config = Bitopro::Config.instance
|
22
|
+
end
|
23
|
+
|
24
|
+
def configured?
|
25
|
+
Bitopro::Config.instance.valid?
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.order_book(currency_pair)
|
32
|
+
JSON.parse(resource["order-book"][currency_pair].get)
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def self.resource
|
38
|
+
@resource ||= RestClient::Resource.new(BASE_URL)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Bitopro do
|
4
|
+
it "has a version number" do
|
5
|
+
expect(Bitopro::VERSION).not_to be nil
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ".configure" do
|
9
|
+
before do
|
10
|
+
Bitopro::Config.instance = Bitopro::Config.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it "makes Bitopro configured" do
|
14
|
+
expect(described_class).not_to be_configured
|
15
|
+
|
16
|
+
described_class.configure do |c|
|
17
|
+
c.key = 1
|
18
|
+
c.secret = '2'
|
19
|
+
end
|
20
|
+
|
21
|
+
expect(described_class).to be_configured
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "bundler/setup"
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'pry'
|
5
|
+
require 'bitopro'
|
6
|
+
|
7
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each { |file| require file }
|
8
|
+
|
9
|
+
WebMock.disable_net_connect!
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
# Enable flags like --only-failures and --next-failure
|
13
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
14
|
+
|
15
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
16
|
+
config.disable_monkey_patching!
|
17
|
+
|
18
|
+
config.expect_with :rspec do |c|
|
19
|
+
c.syntax = :expect
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bitopro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- niclin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.11.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.11.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Ruby wrapper for the Bitopro API.
|
84
|
+
email:
|
85
|
+
- bboyceo@hotmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- lib/bitopro.rb
|
91
|
+
- lib/bitopro/config.rb
|
92
|
+
- lib/bitopro/config/validator.rb
|
93
|
+
- lib/bitopro/version.rb
|
94
|
+
- spec/bitopro/api_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
homepage: https://github.com/niclin/bitopro
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata:
|
100
|
+
allowed_push_host: https://rubygems.org
|
101
|
+
homepage_uri: https://github.com/niclin/bitopro
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.7.8
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: bitopro-0.1.1
|
122
|
+
test_files:
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
- spec/bitopro/api_spec.rb
|