Class: WolframDatabin::Base
- Inherits:
-
Object
- Object
- WolframDatabin::Base
- Defined in:
- lib/wolfram_databin/base.rb
Instance Attribute Summary collapse
-
#debug_flag ⇒ Object
Returns the value of attribute debug_flag.
-
#shortid ⇒ Object
Returns the value of attribute shortid.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #datadrop_url ⇒ Object
- #debug ⇒ Object
- #fix_query(query) ⇒ Object
- #get_url ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #post_data(query) ⇒ Object
- #set_shortid(atid) ⇒ Object
- #submit_data(tshortid, aquery) ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
10 11 12 |
# File 'lib/wolfram_databin/base.rb', line 10 def initialize self.debug_flag=false end |
Instance Attribute Details
#debug_flag ⇒ Object
Returns the value of attribute debug_flag.
5 6 7 |
# File 'lib/wolfram_databin/base.rb', line 5 def debug_flag @debug_flag end |
#shortid ⇒ Object
Returns the value of attribute shortid.
5 6 7 |
# File 'lib/wolfram_databin/base.rb', line 5 def shortid @shortid end |
#uri ⇒ Object
Returns the value of attribute uri.
5 6 7 |
# File 'lib/wolfram_databin/base.rb', line 5 def uri @uri end |
Class Method Details
.submit_data(tshortid, aquery) ⇒ Object
23 24 25 26 |
# File 'lib/wolfram_databin/base.rb', line 23 def self.submit_data(tshortid,aquery) dbin=WolframDatabin::Base.new dbin.submit_data(tshortid,aquery) end |
Instance Method Details
#datadrop_url ⇒ Object
16 17 18 |
# File 'lib/wolfram_databin/base.rb', line 16 def datadrop_url "http://wolfr.am/#{self.shortid}" end |
#debug ⇒ Object
13 14 15 |
# File 'lib/wolfram_databin/base.rb', line 13 def debug self.debug_flag=true end |
#fix_query(query) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/wolfram_databin/base.rb', line 27 def fix_query(query) #need to remove underscores fixed={} query.each {|k,v| fixed[k.to_s.gsub('_',"U")]=v} # puts "fixed is #{fixed} query is #{query}" fixed end |
#get_url ⇒ Object
19 20 21 22 |
# File 'lib/wolfram_databin/base.rb', line 19 def get_url url="https://datadrop.wolframcloud.com/api/v1.0/Add?" url end |
#post_data(query) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/wolfram_databin/base.rb', line 42 def post_data(query) raise "short id not set" if self.shortid==nil res='' qdata={bin: self.shortid}.merge(self.fix_query(query)) begin Timeout::timeout(40) do # @uri=URI.parse(self.get_url) q=self.get_url + Hurley::Query::Flat.new(qdata).to_s puts "url #{q} query #{qdata}" if self.debug_flag res=Hurley.get(q) 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) if res.is_a?(Hurley::Response) return {success: res.body.include?('successfully added'), result: res} else return {success: false, result: res} end end |
#set_shortid(atid) ⇒ Object
7 8 9 |
# File 'lib/wolfram_databin/base.rb', line 7 def set_shortid(atid) self.shortid=atid end |
#submit_data(tshortid, aquery) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/wolfram_databin/base.rb', line 35 def submit_data(tshortid,aquery) self.set_shortid(tshortid) # puts "INSPECT POST #{self.shortid} query: #{aquery}" # self.debug res=self.post_data(aquery) res end |