Class: Dscli::API

Inherits:
Object
  • Object
show all
Defined in:
lib/dscli/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAPI

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

#hashObject (readonly)

Returns the value of attribute hash.



6
7
8
# File 'lib/dscli/api.rb', line 6

def hash
  @hash
end

Instance Method Details

#balanceObject



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



125
126
127
# File 'lib/dscli/api.rb', line 125

def historics_delete(id)
  return @datasift.historics.delete(id)
end

#historics_get(id) ⇒ Object



117
118
119
# File 'lib/dscli/api.rb', line 117

def historics_get(id)
  return @datasift.historics.get_by_id(id)
end

#historics_list(page) ⇒ Object

HISTORICS



112
113
114
115
# File 'lib/dscli/api.rb', line 112

def historics_list(page)
  response = @datasift.historics.get(20,page)
  response[:data]
end

#historics_pause(id) ⇒ Object



129
130
131
# File 'lib/dscli/api.rb', line 129

def historics_pause(id)
  return @datasift.historics.pause(id)
end

#historics_resume(id) ⇒ Object



133
134
135
# File 'lib/dscli/api.rb', line 133

def historics_resume(id)
  return @datasift.historics.resume(id)
end

#historics_stop(id) ⇒ Object



121
122
123
# File 'lib/dscli/api.rb', line 121

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
# 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_pause(id) ⇒ Object



98
99
100
101
# File 'lib/dscli/api.rb', line 98

def push_pause(id)
  response = @datasift.push.pause(id)
  return response
end

#push_resume(id) ⇒ Object



103
104
105
106
# File 'lib/dscli/api.rb', line 103

def push_resume(id)
  response = @datasift.push.resume(id)
  return response
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



158
159
160
# File 'lib/dscli/api.rb', line 158

def source_delete(id)
  return @datasift.managed_source.delete(id)
end

#source_get(id) ⇒ Object



146
147
148
# File 'lib/dscli/api.rb', line 146

def source_get(id)
  return @datasift.managed_source.get(id)
end

#source_list(page) ⇒ Object

MANAGED SOURCES



141
142
143
144
# File 'lib/dscli/api.rb', line 141

def source_list(page)
  response = @datasift.managed_source.get(nil,nil,page,20)
  response[:data]
end

#source_log(id) ⇒ Object



162
163
164
165
# File 'lib/dscli/api.rb', line 162

def source_log(id)
  response = @datasift.managed_source.log(id,1,20)
  response[:data]
end

#source_start(id) ⇒ Object



150
151
152
# File 'lib/dscli/api.rb', line 150

def source_start(id)
  return @datasift.managed_source.start(id)
end

#source_stop(id) ⇒ Object



154
155
156
# File 'lib/dscli/api.rb', line 154

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.message.to_s }
  on_message = lambda { |message, stream, hash| puts Yajl::Encoder.encode(message) }
  on_connect = lambda { |stream| stream.subscribe(hash, on_message) }
  on_close   = lambda { |stream, message| puts "Closed #{stream}: #{message}" }

  on_datasift_message = lambda do |stream, message, hash|
    puts "DataSift Message #{hash} ==> #{message}"
  end

  conn = DataSift::new_stream(@config, on_delete, on_error, on_connect, on_close)
  conn.on_datasift_message = on_datasift_message
  conn.stream.read_thread.join

  rescue DataSiftError => dse
    puts "Error #{dse.message}"
    case dse
      when ConnectionError
      when AuthError
      when BadRequestError
        puts "Error #{dse.message}"
    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