diff --git a/plugins/dogecoin.rb b/plugins/dogecoin.rb index 4989a6e0bc08beef1d0796a74e8af371885e5135..ac609f687b8744ea1a1d7dfc2b3b8838b3883351 100644 --- a/plugins/dogecoin.rb +++ b/plugins/dogecoin.rb @@ -14,37 +14,31 @@ class Dogecoin @irc = irc @timer = timer - @api_host = 'pubapi.cryptsy.com' - @api_path = '/api.php?method=singlemarketdata&marketid=132' - - @last = BigDecimal.new( "0.0" ) + @api_uri = 'https://api.cryptonator.com/api/ticker/doge-btc' + @last = BigDecimal( "0.0" ) end # Alias for last def main( _nick, _user, _host, from, _msg, _arguments, con ) - uri = URI.parse( "http://#{@api_host}#{@api_path}" ) - - http = Net::HTTP.new( uri.host, uri.port ) - - request = Net::HTTP::Get.new( uri.request_uri ) - response = http.request( request ) - - result = JSON.parse( response.body ) - + uri = URI(@api_uri) + response = Net::HTTP.get( uri ) +puts response + result = JSON.parse( response ) - # Calculate delta from last !btc - ldiff = BigDecimal.new( result[ 'return' ][ 'markets' ][ 'DOGE' ][ 'lasttradeprice' ] ) - @last + puts result.inspect + # Calculate delta from last !doge + ldiff = BigDecimal( result[ 'ticker' ][ 'price' ] ) - @last if( ldiff > 0 ) ldiff = "+#{ldiff}" else ldiff = "#{ldiff}" end - @last = BigDecimal.new( result[ 'return' ][ 'markets' ][ 'DOGE' ][ 'lasttradeprice' ] ) + @last = BigDecimal( result[ 'ticker' ][ 'price' ] ) - rounded = "#{( BigDecimal.new( result[ 'return' ][ 'markets' ][ 'DOGE' ][ 'lasttradeprice' ] ) * 100 ).round / 100.0}" + rounded = "#{( BigDecimal( result[ 'ticker' ][ 'price' ] ) * 100 ).round / 100.0}" - line = "Cryptsy DOGE/BTC rate: #{rounded} (#{result[ 'return' ][ 'markets' ][ 'DOGE' ][ 'lasttradeprice' ]}) (#{ldiff} since last !doge)" + line = "Cryptonator DOGE/BTC rate: #{rounded} (#{result[ 'ticker' ][ 'price' ]}) (#{ldiff} since last !doge)" if( con ) @output.c( line + "\n" ) @@ -56,10 +50,10 @@ class Dogecoin # Function to send help about this plugin (Can also be called by the help plugin.) def help( nick, _user, _host, _from, _msg, _arguments, con ) help = [ - "Gets current litecoin values from Btc-e", + "Gets current litecoin values from cryptonator", " dogecoin - Get DOGE/BTC exchange rate" ] - + # Print out help help.each do |line| if( con )