orionx-sdk-ruby 1.0.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.
data/lib/orionx.rb ADDED
@@ -0,0 +1,20 @@
1
+ require_relative "orionx/version"
2
+
3
+ module OrionX
4
+ class Error < StandardError; end
5
+ class APIError < Error; end
6
+ class AuthenticationError < APIError; end
7
+ class RateLimitError < APIError; end
8
+ class ValidationError < Error; end
9
+ class NetworkError < Error; end
10
+ end
11
+
12
+ require_relative "orionx/configuration"
13
+ require_relative "orionx/logger"
14
+ require_relative "orionx/client"
15
+ require_relative "orionx/api"
16
+ require_relative "orionx/endpoints/user"
17
+ require_relative "orionx/endpoints/orders"
18
+ require_relative "orionx/endpoints/accounts"
19
+ require_relative "orionx/endpoints/markets"
20
+ require_relative "orionx/endpoints/transactions"
@@ -0,0 +1,89 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe OrionX::Client do
4
+ before do
5
+ configure_orionx
6
+ end
7
+
8
+ describe "#initialize" do
9
+ it "creates a client with default configuration" do
10
+ client = OrionX::Client.new
11
+ expect(client).to be_a(OrionX::Client)
12
+ expect(client.user).to be_a(OrionX::Endpoints::User)
13
+ expect(client.orders).to be_a(OrionX::Endpoints::Orders)
14
+ expect(client.accounts).to be_a(OrionX::Endpoints::Accounts)
15
+ expect(client.markets).to be_a(OrionX::Endpoints::Markets)
16
+ expect(client.transactions).to be_a(OrionX::Endpoints::Transactions)
17
+ end
18
+
19
+ it "accepts configuration parameters" do
20
+ client = OrionX::Client.new(
21
+ api_key: "custom_key",
22
+ api_secret: "custom_secret",
23
+ debug: true
24
+ )
25
+
26
+ expect(OrionX.configuration.api_key).to eq("custom_key")
27
+ expect(OrionX.configuration.api_secret).to eq("custom_secret")
28
+ expect(OrionX.configuration.debug).to be_truthy
29
+ end
30
+ end
31
+
32
+ describe "#me" do
33
+ it "delegates to user endpoint" do
34
+ client = OrionX::Client.new
35
+
36
+ stub_graphql_request(/getMe/, {
37
+ me: {
38
+ _id: "user123",
39
+ email: "test@example.com",
40
+ name: "Test User"
41
+ }
42
+ })
43
+
44
+ result = client.me
45
+ expect(result["_id"]).to eq("user123")
46
+ end
47
+ end
48
+
49
+ describe "#ping" do
50
+ context "when connection is successful" do
51
+ it "returns success status" do
52
+ client = OrionX::Client.new
53
+
54
+ stub_graphql_request(/getMe/, {
55
+ me: { _id: "user123" }
56
+ })
57
+
58
+ result = client.ping
59
+ expect(result[:status]).to eq("ok")
60
+ expect(result[:message]).to eq("Connection successful")
61
+ end
62
+ end
63
+
64
+ context "when connection fails" do
65
+ it "returns error status" do
66
+ client = OrionX::Client.new
67
+
68
+ stub_request(:post, "https://api.test.orionx.com/graphql")
69
+ .to_return(status: 401)
70
+
71
+ result = client.ping
72
+ expect(result[:status]).to eq("error")
73
+ expect(result[:message]).to include("Authentication failed")
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "#debug=" do
79
+ it "updates debug configuration" do
80
+ client = OrionX::Client.new
81
+
82
+ expect(client.debug?).to be_falsey
83
+
84
+ client.debug = true
85
+ expect(client.debug?).to be_truthy
86
+ expect(OrionX.configuration.debug).to be_truthy
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,71 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe OrionX::Configuration do
4
+ describe "#initialize" do
5
+ it "sets default values" do
6
+ config = OrionX::Configuration.new
7
+
8
+ expect(config.api_key).to be_nil
9
+ expect(config.api_secret).to be_nil
10
+ expect(config.api_endpoint).to eq("https://api.orionx.com/graphql")
11
+ expect(config.debug).to be_falsey
12
+ expect(config.timeout).to eq(30)
13
+ expect(config.retries).to eq(3)
14
+ end
15
+ end
16
+
17
+ describe "#valid?" do
18
+ it "returns false when credentials are missing" do
19
+ config = OrionX::Configuration.new
20
+ expect(config.valid?).to be_falsey
21
+ end
22
+
23
+ it "returns true when all required credentials are present" do
24
+ config = OrionX::Configuration.new
25
+ config.api_key = "test_key"
26
+ config.api_secret = "test_secret"
27
+
28
+ expect(config.valid?).to be_truthy
29
+ end
30
+ end
31
+
32
+ describe "#debug?" do
33
+ it "returns false by default" do
34
+ config = OrionX::Configuration.new
35
+ expect(config.debug?).to be_falsey
36
+ end
37
+
38
+ it "returns true when debug is enabled" do
39
+ config = OrionX::Configuration.new
40
+ config.debug = true
41
+ expect(config.debug?).to be_truthy
42
+ end
43
+ end
44
+ end
45
+
46
+ RSpec.describe OrionX do
47
+ describe ".configure" do
48
+ it "yields configuration object" do
49
+ expect { |b| OrionX.configure(&b) }.to yield_with_args(OrionX::Configuration)
50
+ end
51
+
52
+ it "sets configuration values" do
53
+ OrionX.configure do |config|
54
+ config.api_key = "test_key"
55
+ config.debug = true
56
+ end
57
+
58
+ expect(OrionX.configuration.api_key).to eq("test_key")
59
+ expect(OrionX.configuration.debug).to be_truthy
60
+ end
61
+ end
62
+
63
+ describe ".configuration" do
64
+ it "returns the same instance" do
65
+ config1 = OrionX.configuration
66
+ config2 = OrionX.configuration
67
+
68
+ expect(config1).to be(config2)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,59 @@
1
+ require "rspec"
2
+ require "webmock/rspec"
3
+ require "simplecov"
4
+
5
+ SimpleCov.start do
6
+ add_filter "/spec/"
7
+ add_filter "/vendor/"
8
+ end
9
+
10
+ require_relative "../lib/orionx"
11
+
12
+ WebMock.disable_net_connect!(allow_localhost: true)
13
+
14
+ RSpec.configure do |config|
15
+ config.expect_with :rspec do |c|
16
+ c.syntax = :expect
17
+ end
18
+
19
+ config.mock_with :rspec do |c|
20
+ c.verify_partial_doubles = true
21
+ end
22
+
23
+ config.filter_run_when_matching :focus
24
+ config.disable_monkey_patching!
25
+ config.warnings = true
26
+
27
+ config.before(:each) do
28
+ # Reset configuration before each test
29
+ OrionX.instance_variable_set(:@configuration, nil)
30
+ end
31
+ end
32
+
33
+ # Test helpers
34
+ def configure_orionx(debug: false)
35
+ OrionX.configure do |config|
36
+ config.api_key = "test_api_key"
37
+ config.api_secret = "test_api_secret"
38
+ config.api_endpoint = "https://api.test.orionx.com/graphql"
39
+ config.debug = debug
40
+ end
41
+ end
42
+
43
+ def stub_graphql_request(query_match, response_body = {}, status: 200)
44
+ stub_request(:post, "https://api.test.orionx.com/graphql")
45
+ .with(
46
+ body: hash_including("query" => a_string_matching(query_match)),
47
+ headers: {
48
+ "Content-Type" => "application/json",
49
+ "X-ORIONX-APIKEY" => "test_api_key",
50
+ "X-ORIONX-TIMESTAMP" => /.+/,
51
+ "X-ORIONX-SIGNATURE" => /.+/
52
+ }
53
+ )
54
+ .to_return(
55
+ status: status,
56
+ body: { data: response_body }.to_json,
57
+ headers: { "Content-Type" => "application/json" }
58
+ )
59
+ end
metadata ADDED
@@ -0,0 +1,218 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orionx-sdk-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - PabloB07
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: faraday-net_http
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: logger
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.5'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.5'
54
+ - !ruby/object:Gem::Dependency
55
+ name: bundler
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rake
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '13.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '13.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: rubocop
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.21'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.21'
110
+ - !ruby/object:Gem::Dependency
111
+ name: yard
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.9'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '0.9'
124
+ - !ruby/object:Gem::Dependency
125
+ name: pry
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '0.14'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '0.14'
138
+ - !ruby/object:Gem::Dependency
139
+ name: simplecov
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '0.21'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '0.21'
152
+ - !ruby/object:Gem::Dependency
153
+ name: webmock
154
+ requirement: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '3.18'
159
+ type: :development
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '3.18'
166
+ description: A comprehensive Ruby SDK for the OrionX cryptocurrency exchange API with
167
+ debug capabilities, error handling, and comprehensive examples.
168
+ email:
169
+ - pablob0798@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - CHANGELOG.md
175
+ - CONTRIBUTING.md
176
+ - Gemfile
177
+ - README.md
178
+ - Rakefile
179
+ - lib/orionx.rb
180
+ - lib/orionx/api.rb
181
+ - lib/orionx/client.rb
182
+ - lib/orionx/configuration.rb
183
+ - lib/orionx/endpoints/accounts.rb
184
+ - lib/orionx/endpoints/markets.rb
185
+ - lib/orionx/endpoints/orders.rb
186
+ - lib/orionx/endpoints/transactions.rb
187
+ - lib/orionx/endpoints/user.rb
188
+ - lib/orionx/logger.rb
189
+ - lib/orionx/version.rb
190
+ - spec/client_spec.rb
191
+ - spec/configuration_spec.rb
192
+ - spec/spec_helper.rb
193
+ homepage: https://github.com/PabloB07/orionx-sdk-ruby
194
+ licenses:
195
+ - MIT
196
+ metadata:
197
+ allowed_push_host: https://rubygems.org
198
+ homepage_uri: https://github.com/PabloB07/orionx-sdk-ruby
199
+ source_code_uri: https://github.com/PabloB07/orionx-sdk-ruby
200
+ changelog_uri: https://github.com/PabloB07/orionx-sdk-ruby/blob/main/CHANGELOG.md
201
+ rdoc_options: []
202
+ require_paths:
203
+ - lib
204
+ required_ruby_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: 2.7.0
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ requirements: []
215
+ rubygems_version: 3.7.2
216
+ specification_version: 4
217
+ summary: Unofficial OrionX SDK for Ruby
218
+ test_files: []