Class: Dscli::API
- Inherits:
-
Object
- Object
- Dscli::API
- Defined in:
- lib/dscli/api.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
-
#compile(csdl) ⇒ Object
Core API endpoints [ Missing /validate /balance ].
- #dpu(hash) ⇒ Object
-
#initialize ⇒ API
constructor
A new instance of API.
- #stream(hash) ⇒ Object
- #usage(period) ⇒ Object
Constructor Details
#initialize ⇒ API
Returns a new instance of API.
8 9 10 11 12 13 |
# File 'lib/dscli/api.rb', line 8 def initialize storage = Dscli::Storage.new config = storage.get_auth @config = {:username => config[:auth][:username], :api_key => config[:auth][:api_key], :enable_ssl => false} @datasift = DataSift::Client.new(@config) end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
6 7 8 |
# File 'lib/dscli/api.rb', line 6 def hash @hash end |
Instance Method Details
#compile(csdl) ⇒ Object
Core API endpoints
- Missing /validate /balance
19 20 21 22 23 |
# File 'lib/dscli/api.rb', line 19 def compile(csdl) response = @datasift.compile csdl definition = response[:data] definition[:hash] end |
#dpu(hash) ⇒ Object
30 31 32 33 |
# File 'lib/dscli/api.rb', line 30 def dpu(hash) response = @datasift.dpu hash dpu = response[:data] end |
#stream(hash) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dscli/api.rb', line 35 def stream(hash) on_delete = lambda { |stream, m| puts m } on_error = lambda { |stream, e| puts 'A serious error has occurred: ' + e..to_s } = lambda { |, stream, hash| puts Yajl::Encoder.encode() } on_connect = lambda { |stream| stream.subscribe(hash, ) } on_close = lambda { |stream| puts 'closed' } = lambda do |stream, , hash| puts "DataSift Message #{hash} ==> #{}" end conn = DataSift::new_stream(@config, on_delete, on_error, on_connect, on_close) conn. = conn.stream.read_thread.join rescue DataSiftError => dse puts "Error #{dse.}" case dse when ConnectionError when AuthError when BadRequestError puts "Error #{dse.}" end end |
#usage(period) ⇒ Object
25 26 27 28 |
# File 'lib/dscli/api.rb', line 25 def usage(period) response = @datasift.usage period usage = response[:data] end |