Class: Cloudwalk::Ruby::RubyApplication
- Inherits:
-
Object
- Object
- Cloudwalk::Ruby::RubyApplication
- Includes:
- ManagerHelper
- Defined in:
- lib/cloudwalk/ruby/ruby_application.rb
Class Method Summary collapse
- .all ⇒ Object
-
.find(name) ⇒ Object
NEW.
-
.get(id) ⇒ Object
BASE.
- .get_name(id) ⇒ Object
- .update(app_id, bytecode, app_parameters = nil) ⇒ Object
Methods included from ManagerHelper
#host, included, #posxml2xml, #token, #xml2posxml, #xml2rb
Class Method Details
.all ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cloudwalk/ruby/ruby_application.rb', line 13 def self.all if @apps @apps else response = JSON.parse(Net::HTTP.get(URI("#{self.host}/v1/apps/ruby?access_token=#{self.token}&per_page=100"))) raise ManagerException.new(response["message"]) if response["message"] total_pages = response["pagination"]["total_pages"].to_i @apps = response["rubyapps"].collect {|r| r["ruby_app"] } (total_pages - 1).times do |page| url = "#{self.host}/v1/apps/ruby?access_token=#{self.token}&per_page=100&page=#{page+2}" response = JSON.parse(Net::HTTP.get(URI(url))) raise ManagerException.new(response["message"]) if response["message"] @apps.concat(response["ruby_app"]) end @apps end end |
.find(name) ⇒ Object
NEW
7 8 9 10 11 |
# File 'lib/cloudwalk/ruby/ruby_application.rb', line 7 def self.find(name) self.all.find do |app| app["name"] == name end end |
.get(id) ⇒ Object
BASE
35 36 37 38 39 40 41 |
# File 'lib/cloudwalk/ruby/ruby_application.rb', line 35 def self.get(id) url = "#{self.host}/v1/apps/ruby/#{id}?access_token=#{self.token}" response = JSON.parse(Net::HTTP.get(URI(url))) raise ManagerException.new(response["message"]) if response["message"] response["ruby_app"] end |
.get_name(id) ⇒ Object
43 44 45 |
# File 'lib/cloudwalk/ruby/ruby_application.rb', line 43 def self.get_name(id) get(id)["name"] end |
.update(app_id, bytecode, app_parameters = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cloudwalk/ruby/ruby_application.rb', line 47 def self.update(app_id, bytecode, app_parameters = nil) url = "#{self.host}/v1/apps/ruby/#{app_id}?access_token=#{self.token}" uri = URI(url) form = {"bytecode" => Base64.strict_encode64(bytecode)} response = nil if app_parameters form["authorizer_url"] = app_parameters["authorizer_url"] form["description"] = app_parameters["description"] form["pos_display_label"] = app_parameters["pos_display_label"] form["displayable"] = app_parameters["pos_display_label"] != "X" end Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http| request = Net::HTTP::Put.new(uri) request.set_form_data(form) response = http.request(request) end [response.code.to_i == 200, response] end |