Sha256: e0a6205ef80eabf6d97a6c57d8def6f46e36ade115e671f5b76425e59cda3b1f

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'rubygems'
require 'httpclient'
module WolframDatabin
  class Base
  attr_accessor :shortid, :uri, :debug_flag
  
  def set_shortid(atid)
    self.shortid=atid
  end
  def initialize
    self.debug_flag=false
  end
  def debug
    self.debug_flag=true
  end
  def datadrop_url
    "http://wolfr.am/#{self.shortid}"
  end
  def get_url
    url="https://datadrop.wolframcloud.com/api/v1.0/Add?"
    url
  end
  def post_data(query)
    raise "short id not set" if self.shortid==nil
      res=''
      qdata={bin: self.shortid}.merge(query)
      begin
        Timeout::timeout(40) do    
          puts "uri #{@uri}" if self.debug_flag
          @uri=URI.parse(self.get_url)
          clnt = HTTPClient.new
          res=clnt.get(@uri,qdata)
        end
       rescue  Exception => e
         puts "Exception: #{e.inspect}"
       ensure
          puts "result: #{res.inspect}   query #{qdata} bin: #{self.shortid}  url: #{@uri.inspect}" if self.debug_flag
       end
       if res.is_a?(HTTP::Message)
          return {success: res.body.include?('successfully added'), result: res} 
        else
          return {success: false, result: res}   
        end
    end

   end    # Class
end    #Module



 
 

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wolfram_databin-0.1.1 lib/wolfram_databin/base.rb