Class: Cloudfuji::Command
- Inherits:
-
Object
- Object
- Cloudfuji::Command
- Defined in:
- lib/cloudfuji/command.rb
Overview
:nodoc:
Constant Summary collapse
- @@last_request =
nil
- @@request_count =
0
- @@last_request_successful =
true
Class Method Summary collapse
- .get_command(url, params = {}) ⇒ Object
- .last_command_errored? ⇒ Boolean
- .last_command_successful? ⇒ Boolean
- .post_command(url, params) ⇒ Object
- .put_command(url, params, meta = {}) ⇒ Object
- .request_count ⇒ Object
- .show_errors(response) ⇒ Object
- .show_messages(response) ⇒ Object
- .show_response(response) ⇒ Object
Class Method Details
.get_command(url, params = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cloudfuji/command.rb', line 12 def get_command(url, params={}) @@request_count += 1 params.merge!({:auth_token => Cloudfuji::Platform.key}) if params[:auth_token].nil? unless Cloudfuji::Platform.key.nil? begin raw = RestClient.get(url, {:params => params, :accept => :json}) rescue # => e # puts e.inspect @@last_request_successful = false return nil end @@last_request_successful = true @@last_request = JSON(raw) end |
.last_command_errored? ⇒ Boolean
105 106 107 |
# File 'lib/cloudfuji/command.rb', line 105 def last_command_errored? not last_command_successful? end |
.last_command_successful? ⇒ Boolean
101 102 103 |
# File 'lib/cloudfuji/command.rb', line 101 def last_command_successful? @@last_request_successful end |
.post_command(url, params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cloudfuji/command.rb', line 28 def post_command(url, params) @@request_count += 1 unless Cloudfuji::Platform.key.nil? params["auth_token"] ||= Cloudfuji::Platform.key end begin puts "RestClient.post(#{url}, #{params.to_json}, :content_type => :json, :accept => :json)" raw = RestClient.post(url, params.to_json, :content_type => :json, :accept => :json) rescue => e puts e.inspect @@last_request_successful = false return nil end @@last_request_successful = true @@last_request = JSON(raw) end |
.put_command(url, params, meta = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cloudfuji/command.rb', line 48 def put_command(url, params, ={}) @@request_count += 1 if [:force] params.merge!({:auth_token => Cloudfuji::Platform.key}) if params[:auth_token].nil? unless Cloudfuji::Platform.key.nil? begin raw = RestClient.put(url, params.to_json, :content_type => :json) rescue # => e # puts e.inspect @@last_request_successful = false return nil end else params.merge!({:auth_token => Cloudfuji::Platform.key}) if params[:auth_token].nil? unless Cloudfuji::Platform.key.nil? begin raw = RestClient.put(url, params.to_json, :content_type => :json) rescue # => e #puts e.inspect @@last_request_successful = false return nil end end @@last_request_successful = true @@last_request = JSON.parse raw end |
.request_count ⇒ Object
8 9 10 |
# File 'lib/cloudfuji/command.rb', line 8 def request_count @@request_count end |
.show_errors(response) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/cloudfuji/command.rb', line 92 def show_errors(response) if response["errors"] puts "Errors:" response["errors"].each_with_index do |error, counter| puts "\t#{counter + 1}. #{error}" end end end |
.show_messages(response) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/cloudfuji/command.rb', line 83 def (response) if response["messages"] puts "Messages:" response["messages"].each_with_index do |error, counter| puts "\t#{counter + 1}. #{error}" end end end |
.show_response(response) ⇒ Object
78 79 80 81 |
# File 'lib/cloudfuji/command.rb', line 78 def show_response(response) response show_errors response end |