Class: Xtb::Http::Command
- Inherits:
-
Object
- Object
- Xtb::Http::Command
- Defined in:
- lib/xtb/http/command.rb
Overview
Base class for all commands.
Direct Known Subclasses
AllSymbols, Calendar, ChartLastRequest, ChartRangeRequest, CommissionDef, CurrentUserData, Login, Logout, MarginLevel, MarginTrade, News, Ping, ProfitCalculation, ServerTime, StepRules, Symbol, TickPrices, TradeRecords, TradeTransaction, Trades, TradesHistory, TradingHours, Version
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(**args) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(**args) ⇒ Command
Returns a new instance of Command.
83 84 85 86 |
# File 'lib/xtb/http/command.rb', line 83 def initialize(**args) @args = args @request_data = Request.new(command:, arguments:).to_json end |
Class Method Details
.call(**args) ⇒ Object
88 89 90 |
# File 'lib/xtb/http/command.rb', line 88 def self.call(**args) new(**args).call end |
Instance Method Details
#call ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/xtb/http/command.rb', line 92 def call raw_response = if args[:connection] args.fetch(:connection).request(request_data) else Xtb::Http::Client.post do |connection| connection.request(request_data) end end response = Response.new(command:, raw_response:) raise ErrorFactory.create(response.error_code, response.error_description) unless response.success? response end |