Class: Tembin::Redash::Query
- Inherits:
-
Object
- Object
- Tembin::Redash::Query
- Defined in:
- lib/tembin/redash/query.rb
Constant Summary collapse
- INITIAL_DATA_SOURCE_ID =
1
Class Method Summary collapse
Instance Method Summary collapse
- #author_email ⇒ Object
- #changed?(query) ⇒ Boolean
- #delete! ⇒ Object
- #filename ⇒ Object
- #id ⇒ Object
-
#initialize(attributes) ⇒ Query
constructor
A new instance of Query.
- #name ⇒ Object
- #sql ⇒ Object
- #update!(query) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Query
Returns a new instance of Query.
21 22 23 |
# File 'lib/tembin/redash/query.rb', line 21 def initialize(attributes) @attributes = attributes end |
Class Method Details
.all ⇒ Object
6 7 8 9 10 |
# File 'lib/tembin/redash/query.rb', line 6 def self.all response = Tembin::Redash::Client.current.get('/api/queries') raise RequestNotSucceedError, response.body if !response.success? JSON.parse(response.body)['results'].map { |j| self.new(j) } end |
.create(name, sql) ⇒ Object
17 18 19 |
# File 'lib/tembin/redash/query.rb', line 17 def self.create(name, sql) Tembin::Redash::Client.current.post("/api/queries", body: { name: name, query: sql, data_source_id: INITIAL_DATA_SOURCE_ID }) end |
Instance Method Details
#author_email ⇒ Object
33 34 35 |
# File 'lib/tembin/redash/query.rb', line 33 def @attributes['user'] && @attributes['user']['email'] end |
#changed?(query) ⇒ Boolean
45 46 47 |
# File 'lib/tembin/redash/query.rb', line 45 def changed?(query) Diffy::Diff.new(sql, query).to_s.length != 0 end |
#delete! ⇒ Object
53 54 55 |
# File 'lib/tembin/redash/query.rb', line 53 def delete! Tembin::Redash::Client.current.delete("/api/queries/#{id}") end |
#filename ⇒ Object
41 42 43 |
# File 'lib/tembin/redash/query.rb', line 41 def filename "#{@attributes['id']}_#{@attributes['name'].gsub(/(\/|-|\s)/, '_')}" end |
#id ⇒ Object
25 26 27 |
# File 'lib/tembin/redash/query.rb', line 25 def id @attributes['id'] end |
#name ⇒ Object
29 30 31 |
# File 'lib/tembin/redash/query.rb', line 29 def name @attributes['name'] end |
#sql ⇒ Object
37 38 39 |
# File 'lib/tembin/redash/query.rb', line 37 def sql @attributes['query'] end |