Class: Bushido::Command
- Inherits:
-
Object
- Object
- Bushido::Command
- Defined in:
- lib/bushido/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/bushido/command.rb', line 12 def get_command(url, params={}) @@request_count += 1 params.merge!({:auth_token => Bushido::Platform.key}) if params[:auth_token].nil? unless Bushido::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.parse raw end |
.last_command_errored? ⇒ Boolean
103 104 105 |
# File 'lib/bushido/command.rb', line 103 def last_command_errored? not last_command_successful? end |
.last_command_successful? ⇒ Boolean
99 100 101 |
# File 'lib/bushido/command.rb', line 99 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 |
# File 'lib/bushido/command.rb', line 28 def post_command(url, params) @@request_count += 1 params.merge!({:auth_token => Bushido::Platform.key}) if params[:auth_token].nil? unless Bushido::Platform.key.nil? begin 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.parse raw end |
.put_command(url, params, meta = {}) ⇒ Object
44 45 46 47 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 |
# File 'lib/bushido/command.rb', line 44 def put_command(url, params, ={}) @@request_count += 1 if [:force] params.merge!({:auth_token => Bushido::Platform.key}) if params[:auth_token].nil? unless Bushido::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 @@last_request_successful = true @@last_request = JSON.parse raw else params.merge!({:auth_token => Bushido::Platform.key}) if params[:auth_token].nil? unless Bushido::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 @@last_request_successful = true @@last_request = JSON.parse raw end end |
.request_count ⇒ Object
8 9 10 |
# File 'lib/bushido/command.rb', line 8 def request_count @@request_count end |
.show_errors(response) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/bushido/command.rb', line 90 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
81 82 83 84 85 86 87 88 |
# File 'lib/bushido/command.rb', line 81 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
76 77 78 79 |
# File 'lib/bushido/command.rb', line 76 def show_response(response) response show_errors response end |