safe-t-rest 0.0.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e20d688d2f00aa0da8542721bcf48bea3569325
4
- data.tar.gz: ce79343210ed7631483f3aa85ba9f52a1ba18ef8
3
+ metadata.gz: 6d3bab011ff613248b16904f750edc1e4c40b4ea
4
+ data.tar.gz: 8b85042ef3c65e91bc7e2a6542f7a4fdf9f9b981
5
5
  SHA512:
6
- metadata.gz: cc68e6161be3c07ba250db4ab098fe1582adb1acaebd545ba60de34de70b9822f7cbb0f2805fe0d2747b9f2aeb4ad9bf0b60187ba3f432e717e5f91f18935aae
7
- data.tar.gz: 99ff0681e20047f58e2ce797c9958176f3f60da4dfe678676fea5bfd5941b4b852725706236cefd69c0c0523b83eb765a79e472076cc204d3fe83c3ce3f51ea4
6
+ metadata.gz: dc02c1a829cbb66340ba529da4334e831e211baf9589e8bbeaf5cfddf9e18a270aa7801259de9a43676872ac7e91bdd7a327f148b0e8598e1d46be61b2c5372d
7
+ data.tar.gz: 0b76657b613bb3f86494acc7fcfb505a822bfb4b35017e475074dff04560acd7bb644935171f26ba451bc237c36e2da81c2e466cb048248872f3a5f97f9cd053
data/README.md CHANGED
@@ -82,4 +82,9 @@ args = {
82
82
  file = client.iFileDownload(args) # Get back the file as a base64 string
83
83
  file = Base64.decode64(file) # decode the string
84
84
  File.write('file.txt', file) # write decoded file
85
- ```
85
+ ```
86
+
87
+ # RubyDoc
88
+ http://www.rubydoc.info/github/bararchy/safe-t-rest/SafeTRest
89
+
90
+ * Added example client under /bin
data/bin/safe-t-bin CHANGED
@@ -6,71 +6,69 @@ require 'nokogiri'
6
6
  require 'base64'
7
7
  require 'colorize'
8
8
 
9
-
10
9
  class ApiBin
11
-
12
- def self.main_loop
13
-
14
- puts "Safe-T API -- Using 'safe-t-rest' GEM".blue
15
- client = SafeTRest.new
16
- puts "Please enter servers url: ".bold
17
- client.url = gets.chomp
18
- puts "Please enter username: ".bold
19
- client.username = gets.chomp
20
- puts "Please enter password: ".bold
21
- client.password = gets.chomp
22
- puts "Please enter Role ID: ".bold
23
- client.role_id = gets.chomp
24
- puts "Please enter Extenstion ID: ".bold
25
- client.extenstion_id = gets.chomp
10
+
11
+ def self.main_loop
12
+
13
+ puts "Safe-T API -- Using 'safe-t-rest' GEM".blue
14
+ client = SafeTRest.new
15
+ puts "Please enter servers url: ".bold
16
+ client.url = gets.chomp
17
+ puts "Please enter username: ".bold
18
+ client.username = gets.chomp
19
+ puts "Please enter password: ".bold
20
+ client.password = gets.chomp
21
+ puts "Please enter Role ID: ".bold
22
+ client.role_id = gets.chomp
23
+ puts "Please enter Extenstion ID: ".bold
24
+ client.extenstion_id = gets.chomp
25
+ puts "Configuration Loaded".green
26
+
27
+ loop do
26
28
 
27
- puts "Configuration Loaded".green
28
- loop do
29
-
30
- puts '1. List Files'.bold
31
- puts '2. Upload Files'.bold
32
- puts '3. Download Files'.bold
29
+ puts '1. List Files'.bold
30
+ puts '2. Upload Files'.bold
31
+ puts '3. Download Files'.bold
32
+ answer = gets.chomp
33
33
 
34
- answer = gets.chomp
35
- case answer
36
- when '1'
37
- puts "Please enter the path on the server to list (empty for root folder): "
38
- path = gets.chomp
39
- puts Nokogiri::XML(client.iGetFolderList(path))
40
- when '2'
41
- puts "Please enter the path to the file you want to upload: "
42
- file = gets.chomp
43
- filename = File.basename(file)
44
- filepath = file.split('/')[-1]
45
- upload_string = Base64.encode64(File.read(file))
46
- args = {
47
- :file_base64 => upload_string, # the file as a base64 string Base64.encode64(File.read(file))
48
- :file_name => filename, # the name of the file
49
- :folder_path => '', # empty means root folder
50
- :root_folder_id => 417 # My Storage ID
51
- }
52
- answer = client.iFileUpload(args)
53
- if answer == 'OK'
54
- puts "File Uploaded".green
55
- else
56
- puts "Error Uploading File: #{answer}".red
57
- end
58
- when '3'
59
- puts "Please enter the name of the file you want to download: "
60
- filename = gets.chomp
61
- puts "Please enter the path to the directory the file is in (empty for root directory): "
62
- server_path = gets.chomp
63
- puts "Please enter the path to save it to (example: /tmp): "
64
- path = gets.chomp
65
- args = {
66
- :file_name => filename, # The name of the file to download
67
- :folder_path => server_path, # The path of the file
68
- :root_folder_id => 417 # My Storage ID
69
- }
70
- download_string = Base64.decode64(client.iFileDownload(args))
71
- File.write("#{path}/#{filename}", download_string)
72
- end
73
- end
74
- end
34
+ case answer
35
+ when '1'
36
+ puts "Please enter the path on the server to list (empty for root folder): "
37
+ path = gets.chomp
38
+ puts Nokogiri::XML(client.get_folder_list(path))
39
+ when '2'
40
+ puts "Please enter the path to the file you want to upload: "
41
+ file = gets.chomp
42
+ filename = File.basename(file)
43
+ upload_string = Base64.encode64(File.read(file))
44
+ args = {
45
+ file_base64: upload_string, # the file as a base64 string Base64.encode64(File.read(file))
46
+ file_name: filename, # the name of the file
47
+ folder_path: '', # empty means root folder
48
+ root_folder_id: 417 # My Storage ID
49
+ }
50
+ answer = client.file_upload(args)
51
+ if answer == 'OK'
52
+ puts "File Uploaded".green
53
+ else
54
+ puts "Error Uploading File: #{answer}".red
55
+ end
56
+ when '3'
57
+ puts "Please enter the name of the file you want to download: "
58
+ filename = gets.chomp
59
+ puts "Please enter the path to the directory the file is in (empty for root directory): "
60
+ server_path = gets.chomp
61
+ puts "Please enter the path to save it to (example: /tmp): "
62
+ path = gets.chomp
63
+ args = {
64
+ file_name: filename, # The name of the file to download
65
+ folder_path: server_path, # The path of the file
66
+ root_folder_id: 417 # My Storage ID
67
+ }
68
+ download_string = Base64.decode64(client.file_download(args))
69
+ File.write("#{path}/#{filename}", download_string)
70
+ end
71
+ end
72
+ end
75
73
  end
76
74
  ApiBin.main_loop
data/lib/safe-t-rest.rb CHANGED
@@ -1,105 +1,62 @@
1
1
  require 'rest-client'
2
-
3
- class SafeTRest
4
- attr_accessor(:extenstion_id, :username, :password, :url, :role_id, :guid)
5
-
6
- def getAppsProcessState
7
- RestClient::Request.execute(
8
- :method => :post,
9
- :url => @url,
10
- :headers => {
11
- :servletRequestID => 'MethodRequest',
12
- :BusinessLogic => "{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', GetAppsProcessState: ['#{@guid}', false]}"
13
- }
14
- )
15
- end
16
-
17
- def getPackageFileList
18
- RestClient::Request.execute(
19
- :method => :post,
20
- :url => @url,
21
- :headers => {
22
- :servletRequestID => 'MethodRequest',
23
- :BusinessLogic => "{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', GetPackageFileList: ['#{@guid}']}"
24
- }
25
- )
26
- end
27
-
28
- def iVerifyUserAccount
29
- RestClient::Request.execute(
30
- :method => :post,
31
- :url => @url,
32
- :headers => {
33
- :servletRequestID => 'MethodRequest',
34
- :BusinessLogic => "{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iVerifyUserAccount: ['#{@username}', '#{@password}', true]}"
35
- }
36
- )
37
- end
38
-
39
- def iGetHistory(days)
40
- RestClient::Request.execute(
41
- :method => :post,
42
- :url => @url,
43
- :headers => {
44
- :servletRequestID => 'MethodRequest',
45
- :BusinessLogic => "{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iGetHistory: ['#{@username}', '#{@password}', #{days}]}"
46
- }
47
- )
48
- end
49
-
50
- def iUserAccountAddressList
51
- RestClient::Request.execute(
52
- :method => :post,
53
- :url => @url,
54
- :headers => {
55
- :servletRequestID => 'MethodRequest',
56
- :BusinessLogic => "{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iUserAccountAddressList: ['#{@username}', '#{@password}']}"
57
- }
58
- )
59
- end
60
-
61
- def iGetFolderList(path)
62
- RestClient::Request.execute(
63
- :method => :post,
64
- :url => @url,
65
- :headers => {
66
- :servletRequestID => 'MethodRequest',
67
- :BusinessLogic => "{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iGetFolderList: ['#{@username}', '#{@password}', #{false}, #{true}, '#{path}', 417]}"
68
- }
69
- )
70
- end
71
-
72
- def iSafeShareFile(args)
73
- RestClient::Request.execute(
74
- :method => :post,
75
- :url => @url,
76
- :headers => {
77
- :servletRequestID => 'MethodRequest',
78
- :BusinessLogic => "{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iSafeShareFile: ['#{@username}', '#{@password}', '#{args[:files]}', '#{args[:recipients]}', '#{args[:sender_name]}', '#{args[:sender_address]}', '#{args[:subject]}', '#{args[:message]}', #{args[:message_encryption_level]}, #{args[:delivery_method]}, '#{args[:mobile_recipient]}', #{args[:return_receipt]}, #{args[:safe_reply]}, #{args[:max_downloads]}, #{args[:package_expiry]}, '#{args[:folder_path]}', #{args[:root_folder_id]}]}"
79
- }
80
- )
81
- end
82
-
83
- def iFileUpload(args)
84
- RestClient::Request.execute(
85
- :method => :post,
86
- :url => @url,
87
- :headers => {
88
- :servletRequestID => 'MethodRequest',
89
- :BusinessLogic => "{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iFileUpload: ['#{@username}', '#{@password}', '#{args[:file_base64]}', '#{args[:file_name]}', '#{args[:folder_path]}', #{args[:root_folder_id]}]}"
90
- }
91
- )
92
- end
93
-
94
- def iFileDownload(args)
95
- RestClient::Request.execute(
96
- :method => :post,
97
- :url => @url,
98
- :headers => {
99
- :servletRequestID => 'MethodRequest',
100
- :BusinessLogic => "{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iFileDownload: ['#{@username}', '#{@password}', '#{args[:file_name]}', '#{args[:folder_path]}', #{args[:root_folder_id]}]}"
101
- }
102
- )
103
- end
104
2
 
3
+ class SafeTRest
4
+ attr_accessor :extenstion_id, :user_name, :password, :url, :role_id
5
+
6
+ def initialize(config_hash={})
7
+ @extenstion_id = config_hash[:extenstion_id]
8
+ @user_name = config_hash[:user_name]
9
+ @password = config_hash[:password]
10
+ @url = config_hash[:url]
11
+ @role_id = config_hash[:role_id]
12
+ end
13
+
14
+ def get_apps_process_state(guid)
15
+ send_request("{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', GetAppsProcessState: ['#{guid}', false]}")
16
+ end
17
+
18
+ def get_package_file_list(guid)
19
+ send_request("{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', GetPackageFileList: ['#{guid}']}")
20
+ end
21
+
22
+ def verify_user_account
23
+ send_request("{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iVerifyUserAccount: ['#{@user_name}', '#{@password}', true]}")
24
+ end
25
+
26
+ def get_user_history(days)
27
+ send_request("{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iGetHistory: ['#{@user_name}', '#{@password}', #{days}]}")
28
+ end
29
+
30
+ def user_account_address_list
31
+ send_request("{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iUserAccountAddressList: ['#{@user_name}', '#{@password}']}")
32
+ end
33
+
34
+ def get_folder_list(path)
35
+ send_request("{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iGetFolderList: ['#{@user_name}', '#{@password}', false, true, '#{path}', 417]}")
36
+ end
37
+
38
+ def safe_share_file(args)
39
+ send_request("{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iSafeShareFile: ['#{@user_name}', '#{@password}', '#{args[:files]}', '#{args[:recipients]}', '#{args[:sender_name]}', '#{args[:sender_address]}', '#{args[:subject]}', '#{args[:message]}', #{args[:message_encryption_level]}, #{args[:delivery_method]}, '#{args[:mobile_recipient]}', #{args[:return_receipt]}, #{args[:safe_reply]}, #{args[:max_downloads]}, #{args[:package_expiry]}, '#{args[:folder_path]}', #{args[:root_folder_id]}]}")
40
+ end
41
+
42
+ def file_upload(args)
43
+ send_request("{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iFileUpload: ['#{@user_name}', '#{@password}', '#{args[:file_base64]}', '#{args[:file_name]}', '#{args[:folder_path]}', #{args[:root_folder_id]}]}")
44
+ end
45
+
46
+ def file_download(args)
47
+ send_request("{Username:'', Password:'', RoleID: '#{@role_id}', ExtensionID: '#{@extenstion_id}', iFileDownload: ['#{@user_name}', '#{@password}', '#{args[:file_name]}', '#{args[:folder_path]}', #{args[:root_folder_id]}]}")
48
+ end
49
+
50
+ private
51
+
52
+ def send_request(request_string)
53
+ RestClient::Request.execute(
54
+ method: :post,
55
+ url: @url,
56
+ headers: {
57
+ servletRequestID: 'MethodRequest',
58
+ BusinessLogic: request_string
59
+ }
60
+ )
61
+ end
105
62
  end
data/safe-t-rest.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'safe-t-rest'
3
- s.version = '0.0.8'
3
+ s.version = '0.1.0'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
  s.summary = 'A ruby gem to interact with Safe-T Box.'
6
6
  s.description = 'Ruby gem to interact with Safe-T Box rest API. '
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safe-t-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bar Hofesh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-01 00:00:00.000000000 Z
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  version: '0'
63
63
  requirements: []
64
64
  rubyforge_project:
65
- rubygems_version: 2.4.5
65
+ rubygems_version: 2.4.6
66
66
  signing_key:
67
67
  specification_version: 4
68
68
  summary: A ruby gem to interact with Safe-T Box.