lib/cosgrove/utils.rb in cosgrove-0.0.1rc14 vs lib/cosgrove/utils.rb in cosgrove-0.0.1rc15
- old
+ new
@@ -17,31 +17,54 @@
reset_api unless result.keys.any?
true
end
+ def chain_options(chain)
+ case chain
+ when :steem
+ {
+ chain: :steem,
+ url: steem_api_url,
+ failover_urls: steem_api_failover_urls
+ }
+ when :golos
+ {
+ chain: :golos,
+ url: golos_api_url,
+ failover_urls: golos_api_failover_urls
+ }
+ when :test
+ {
+ chain: :test,
+ url: test_api_url,
+ failover_urls: test_api_failover_urls
+ }
+ end
+ end
+
def api(chain)
reset_api if @cycle_api_at.nil? || @cycle_api_at < 15.minutes.ago
@cycle_api_at ||= Time.now
case chain
- when :steem then @steem_api ||= Radiator::Api.new(chain: :steem, url: steem_api_url)
- when :golos then @golos_api ||= Radiator::Api.new(chain: :golos, url: golos_api_url)
- when :test then @test_api ||= Radiator::Api.new(chain: :test, url: test_api_url)
+ when :steem then @steem_api ||= Radiator::Api.new(chain_options(chain))
+ when :golos then @golos_api ||= Radiator::Api.new(chain_options(chain))
+ when :test then @test_api ||= Radiator::Api.new(chain_options(chain))
end
end
def follow_api(chain)
reset_api if @cycle_api_at.nil? || @cycle_api_at < 15.minutes.ago
@cycle_api_at ||= Time.now
case chain
- when :steem then @steem_follow_api ||= Radiator::FollowApi.new(chain: :steem, url: steem_api_url)
- when :golos then @golos_follow_api ||= Radiator::FollowApi.new(chain: :golos, url: golos_api_url)
- when :test then @test_follow_api ||= Radiator::FollowApi.new(chain: :test, url: test_api_url)
+ when :steem then @steem_follow_api ||= Radiator::FollowApi.new(chain_options(chain))
+ when :golos then @golos_follow_api ||= Radiator::FollowApi.new(chain_options(chain))
+ when :test then @test_follow_api ||= Radiator::FollowApi.new(chain_options(chain))
end
end
def reset_stream
@steem_stream = @golos_stream = @test_stream = nil
@@ -53,13 +76,13 @@
reset_stream if @cycle_stream_at.nil? || @cycle_stream_at < 15.minutes.ago
@cycle_stream_at ||= Time.now
case chain
- when :steem then @steem_stream ||= Radiator::Stream.new(url: steem_api_url)
- when :golos then @golos_stream ||= Radiator::Stream.new(url: golos_api_url)
- when :test then @test_stream ||= Radiator::Stream.new(url: test_api_url)
+ when :steem then @steem_stream ||= Radiator::Stream.new(chain_options(chain))
+ when :golos then @golos_stream ||= Radiator::Stream.new(chain_options(chain))
+ when :test then @test_stream ||= Radiator::Stream.new(chain_options(chain))
end
end
def steem_data_head_block_number
latest_settings_block = begin
@@ -98,12 +121,12 @@
properties(chain)['last_irreversible_block_num']
end
def new_tx(chain)
case chain
- when :steem then Radiator::Transaction.new(chain: :steem, wif: steem_posting_wif, url: steem_api_url)
- when :golos then Radiator::Transaction.new(chain: :golos, wif: golos_posting_wif, url: golos_api_url)
- when :test then Radiator::Transaction.new(chain: :test, wif: test_posting_wif, url: test_api_url)
+ when :steem then Radiator::Transaction.new(chain_options(chain).merge(wif: steem_posting_wif))
+ when :golos then Radiator::Transaction.new(chain_options(chain).merge(wif: golos_posting_wif))
+ when :test then Radiator::Transaction.new(chain_options(chain).merge(wif: test_posting_wif))
end
end
def to_rep(raw)
raw = raw.to_i