Class: Zillabyte::API
- Inherits:
-
Object
show all
- Defined in:
- lib/zillabyte/api/settings.rb,
lib/zillabyte/api.rb
Defined Under Namespace
Classes: Base, Data, Flows, Logs, Metrics, Queries, SemanticTags, Sources, Zillalogs
Constant Summary
collapse
- CASPERJS_BIN =
PY_VIRTUAL_ENV_DIR = "/tmp/vEnv"
"/usr/local/bin/casperjs"
- API_CLIENT_JS =
File.join(ENV['HOME'], "zb1/api.client.js/api.coffee")
- NODEJS_BIN =
"/usr/local/bin/node"
{
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'User-Agent' => "zillabyte/#{Zillabyte::CLI::VERSION}",
'X-Ruby-Version' => RUBY_VERSION,
'X-Ruby-Platform' => RUBY_PLATFORM
}
- OPTIONS =
{
:headers => {},
:host => ENV['ZILLABYTE_API_HOST'] || 'api.zillabyte.com',
:port => (ENV['ZILLABYTE_API_PORT'] || '80').to_i,
:nonblock => false,
:scheme => 'http'
}
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ API
Returns a new instance of API.
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/zillabyte/api.rb', line 40
def initialize(options={})
options = OPTIONS.merge(options)
@progress = options.delete(:progress)
@api_key = options.delete(:api_key) || ENV['ZILLABYTE_API_KEY']
options[:headers] = HEADERS.merge({
'Authorization' => "auth_token #{@api_key}",
}).merge(options[:headers])
@options = options.clone
@options[:bubble_exceptions] = ENV['BUBBLE_EXCEPTIONS'] || false
@connection = Excon.new("#{options[:scheme]}://#{options[:host]}", options)
end
|
Class Method Details
.load ⇒ Object
155
156
157
158
159
160
161
162
163
|
# File 'lib/zillabyte/api.rb', line 155
def self.load
Dir[File.join(File.dirname(__FILE__), "api", "*.rb")].sort.each do |file|
require file
end
Dir[File.join(File.dirname(__FILE__), "api", "helpers", "*.rb")].sort.each do |file|
require file
end
end
|
Instance Method Details
#collectors ⇒ Object
Also known as:
collector
141
142
143
|
# File 'lib/zillabyte/api.rb', line 141
def collectors
@_collectors ||= ::Zillabyte::API::Collectors.new(self)
end
|
#data ⇒ Object
106
107
108
|
# File 'lib/zillabyte/api.rb', line 106
def data
@_data ||= ::Zillabyte::API::Data.new(self)
end
|
#flows ⇒ Object
Also known as:
flow
120
121
122
|
# File 'lib/zillabyte/api.rb', line 120
def flows
@_flows ||= ::Zillabyte::API::Flows.new(self)
end
|
#host ⇒ Object
58
59
60
|
# File 'lib/zillabyte/api.rb', line 58
def host
@options[:host]
end
|
#logs ⇒ Object
110
111
112
|
# File 'lib/zillabyte/api.rb', line 110
def logs
@_logs ||= ::Zillabyte::API::Logs.new(self)
end
|
#metrics ⇒ Object
Also known as:
metric
125
126
127
|
# File 'lib/zillabyte/api.rb', line 125
def metrics
@_metrics ||= ::Zillabyte::API::Metrics.new(self)
end
|
#queries ⇒ Object
Also known as:
query
115
116
117
|
# File 'lib/zillabyte/api.rb', line 115
def queries
@_queries ||= ::Zillabyte::API::Queries.new(self)
end
|
#request(params, &block) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/zillabyte/api.rb', line 63
def request(params, &block)
begin
response = @connection.request(params, &block)
rescue Excon::Errors::HTTPStatusError => error
@progress.error "internal server error" if @progress
raise error
end
if response.body && !response.body.empty?
begin
response.body = JSON.parse(response.body)
rescue Exception => e
raise e if @options[:bubble_exceptions]
@progress.error "unknown server response: \n #{response.body}" if @progress
end
end
if response.body.is_a?(Hash)
if response.body["status"] == "error"
if @progress
if response.body["error"] == "authentication_error"
@progress.error "authentication error. run 'zillabyte login'"
else
@progress.error response.body["error_message"]
end
end
end
end
@connection.reset
response
end
|
#sources ⇒ Object
Also known as:
source
135
136
137
|
# File 'lib/zillabyte/api.rb', line 135
def sources
@_sources ||= ::Zillabyte::API::Sources.new(self)
end
|
#zillalogs ⇒ Object
Also known as:
zillalog