Class: SecurenetUtil
- Inherits:
-
Object
- Object
- SecurenetUtil
- Defined in:
- lib/securenet/util.rb
Instance Method Summary collapse
- #delete(path, content) ⇒ Object
- #error(message) ⇒ Object
- #get(path, content) ⇒ Object
-
#initialize(id, key, url = "https://gwapi.demo.securenet.com/api") ⇒ SecurenetUtil
constructor
A new instance of SecurenetUtil.
- #post(path, content) ⇒ Object
- #put(path, content) ⇒ Object
Constructor Details
#initialize(id, key, url = "https://gwapi.demo.securenet.com/api") ⇒ SecurenetUtil
Returns a new instance of SecurenetUtil.
3 4 5 6 7 |
# File 'lib/securenet/util.rb', line 3 def initialize(id, key, url = "https://gwapi.demo.securenet.com/api") @id = id @key = key @url = url end |
Instance Method Details
#delete(path, content) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/securenet/util.rb', line 50 def delete(path, content) url = "#{@url}#{path}" response = RestClient::Request.new( :method => :delete, :url => url, :payload => content.to_json, :user => @id, :password => @key, :headers => { :accept => :json, :content_type => :json } ).execute results = JSON.parse(response.to_str) return results end |
#error(message) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/securenet/util.rb', line 64 def error() return { :message => , :success => false, :result => "COMMUNICATION_ERROR" } end |
#get(path, content) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/securenet/util.rb', line 9 def get(path, content) url = "#{@url}#{path}" response = RestClient::Request.new( :method => :get, :url => url, :user => @id, :password => @key, :headers => { :accept => :json, :content_type => :json } ).execute results = JSON.parse(response.to_str) return results end |
#post(path, content) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/securenet/util.rb', line 22 def post(path, content) url = "#{@url}#{path}" response = RestClient::Request.new( :method => :post, :url => url, :payload => content.to_json, :user => @id, :password => @key, :headers => { :accept => :json, :content_type => :json } ).execute results = JSON.parse(response.to_str) return results end |
#put(path, content) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/securenet/util.rb', line 36 def put(path, content) url = "#{@url}#{path}" response = RestClient::Request.new( :method => :put, :url => url, :payload => content.to_json, :user => @id, :password => @key, :headers => { :accept => :json, :content_type => :json } ).execute results = JSON.parse(response.to_str) return results end |