Class: Meer::Datameer
- Inherits:
-
Object
- Object
- Meer::Datameer
- Defined in:
- lib/meer/datameer.rb
Defined Under Namespace
Modules: Session
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize(url, user = nil, password = nil) ⇒ Datameer
constructor
A new instance of Datameer.
- #login ⇒ Object
- #post(url) ⇒ Object
- #request(req) ⇒ Object
- #run_workbook(wb_id) ⇒ Object
- #running_jobs ⇒ Object
- #workbook(wb_id) ⇒ Object
- #workbook_data(wb_id, sheet) ⇒ Object
- #workbooks ⇒ Object
Constructor Details
#initialize(url, user = nil, password = nil) ⇒ Datameer
Returns a new instance of Datameer.
6 7 8 9 10 11 |
# File 'lib/meer/datameer.rb', line 6 def initialize url, user=nil, password=nil @uri, @user, @password = URI(url), user, password @http = Net::HTTP.new uri.host, uri.port @http.use_ssl = true if uri.port == 443 end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
5 6 7 |
# File 'lib/meer/datameer.rb', line 5 def password @password end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
5 6 7 |
# File 'lib/meer/datameer.rb', line 5 def uri @uri end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
5 6 7 |
# File 'lib/meer/datameer.rb', line 5 def user @user end |
Instance Method Details
#get(url) ⇒ Object
31 32 33 34 |
# File 'lib/meer/datameer.rb', line 31 def get url req = Net::HTTP::Get.new(URI(uri.to_s + url)) request(req) end |
#login ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/meer/datameer.rb', line 42 def login resp = get('/browser') if resp.code.to_i == 200 Session.set(resp['set-cookie']) puts "Logged In" else puts "Failed to log in" end end |
#post(url) ⇒ Object
36 37 38 39 |
# File 'lib/meer/datameer.rb', line 36 def post url req = Net::HTTP::Post.new(URI(uri.to_s + url)) request(req) end |
#request(req) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/meer/datameer.rb', line 14 def request req if [user, password].compact.size == 2 req.basic_auth self.user, self.password else req['Cookie'] = Session.load end res = @http.request(req) if res.code == '200' res else puts "error fetching #{req.uri}" puts res.code puts res.to_hash end end |
#run_workbook(wb_id) ⇒ Object
67 68 69 |
# File 'lib/meer/datameer.rb', line 67 def run_workbook wb_id JSON.parse post("/rest/job-execution?configuration=#{wb_id}").body end |
#running_jobs ⇒ Object
71 72 73 |
# File 'lib/meer/datameer.rb', line 71 def running_jobs JSON.parse get("/rest/jobs/list-running").body end |
#workbook(wb_id) ⇒ Object
59 60 61 |
# File 'lib/meer/datameer.rb', line 59 def workbook wb_id JSON.parse(get("/rest/workbook/#{wb_id}").body) end |
#workbook_data(wb_id, sheet) ⇒ Object
54 55 56 57 |
# File 'lib/meer/datameer.rb', line 54 def workbook_data wb_id, sheet res = get "/rest/data/workbook/#{wb_id}/#{sheet}/download" res.body end |
#workbooks ⇒ Object
63 64 65 |
# File 'lib/meer/datameer.rb', line 63 def workbooks JSON.parse(get("/rest/workbook").body) end |