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
- #balance ⇒ Object
-
#compile(csdl) ⇒ Object
Core API endpoints [ Missing /validate /balance ].
- #dpu(hash) ⇒ Object
- #historics_delete(id) ⇒ Object
- #historics_get(id) ⇒ Object
-
#historics_list(page) ⇒ Object
HISTORICS.
- #historics_stop(id) ⇒ Object
-
#initialize ⇒ API
constructor
A new instance of API.
- #push_delete(id) ⇒ Object
- #push_get(id) ⇒ Object
-
#push_list(page) ⇒ Object
PUSH.
- #push_log(id) ⇒ Object
- #push_stop(id) ⇒ Object
- #source_delete(id) ⇒ Object
- #source_get(id) ⇒ Object
-
#source_list(page) ⇒ Object
MANAGED SOURCES.
- #source_log(id) ⇒ Object
- #source_start(id) ⇒ Object
- #source_stop(id) ⇒ Object
- #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 => true} @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
#balance ⇒ Object
35 36 37 38 |
# File 'lib/dscli/api.rb', line 35 def balance response = @datasift.balance return response[:data] end |
#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 |
#historics_delete(id) ⇒ Object
118 119 120 |
# File 'lib/dscli/api.rb', line 118 def historics_delete(id) return @datasift.historics.delete(id) end |
#historics_get(id) ⇒ Object
110 111 112 |
# File 'lib/dscli/api.rb', line 110 def historics_get(id) return @datasift.historics.get_by_id(id) end |
#historics_list(page) ⇒ Object
HISTORICS
105 106 107 108 |
# File 'lib/dscli/api.rb', line 105 def historics_list(page) response = @datasift.historics.get(20,page) response[:data] end |
#historics_stop(id) ⇒ Object
114 115 116 |
# File 'lib/dscli/api.rb', line 114 def historics_stop(id) return @datasift.historics.stop(id) end |
#push_delete(id) ⇒ Object
84 85 86 87 |
# File 'lib/dscli/api.rb', line 84 def push_delete(id) response = @datasift.push.delete(id) return response end |
#push_get(id) ⇒ Object
74 75 76 77 |
# File 'lib/dscli/api.rb', line 74 def push_get(id) response = @datasift.push.get_by_subscription(id) return response end |
#push_list(page) ⇒ Object
PUSH
69 70 71 72 |
# File 'lib/dscli/api.rb', line 69 def push_list(page) response = @datasift.push.get(page) response[:data] end |
#push_log(id) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/dscli/api.rb', line 89 def push_log(id) if id.nil? response = @datasift.push.log else response = @datasift.push.log_for(id) end return response[:data] end |
#push_stop(id) ⇒ Object
79 80 81 82 |
# File 'lib/dscli/api.rb', line 79 def push_stop(id) response = @datasift.push.stop(id) puts response end |
#source_delete(id) ⇒ Object
143 144 145 |
# File 'lib/dscli/api.rb', line 143 def source_delete(id) return @datasift.managed_source.delete(id) end |
#source_get(id) ⇒ Object
131 132 133 |
# File 'lib/dscli/api.rb', line 131 def source_get(id) return @datasift.managed_source.get(id) end |
#source_list(page) ⇒ Object
MANAGED SOURCES
126 127 128 129 |
# File 'lib/dscli/api.rb', line 126 def source_list(page) response = @datasift.managed_source.get(nil,nil,page,20) response[:data] end |
#source_log(id) ⇒ Object
147 148 149 150 |
# File 'lib/dscli/api.rb', line 147 def source_log(id) response = @datasift.managed_source.log(id,1,20) response[:data] end |
#source_start(id) ⇒ Object
135 136 137 |
# File 'lib/dscli/api.rb', line 135 def source_start(id) return @datasift.managed_source.start(id) end |
#source_stop(id) ⇒ Object
139 140 141 |
# File 'lib/dscli/api.rb', line 139 def source_stop(id) return @datasift.managed_source.stop(id) end |
#stream(hash) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dscli/api.rb', line 40 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 #{stream}: #{}" } = 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 |