ruby-skynet 1.3.1 → 1.3.5
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 +4 -4
- data/lib/skynet/download.rb +4 -5
- data/lib/skynet/helper.rb +27 -5
- data/lib/skynet/upload.rb +12 -40
- data/lib/skynet.rb +2 -17
- metadata +25 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69e91f4fb679501098bfe4f595eddcbd72b7a89d24e98618f10927ca1f3ded3e
|
4
|
+
data.tar.gz: 0113ba2ed43c53d7b9d4f6daeeca01d47acdab5cb80923b9095b3ddaaf6d42f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8268872ad64745251cdb33723eec0b613e30d0b45f89d57845d51a526ac37a208a6d3921a8663c5fb9d8ec67d89fb7f0810a2fa702ddf54b0e5fccb665e5ad75
|
7
|
+
data.tar.gz: 3b7a37c79e7c32077a73c4eca1314dffe6238ad03940255e5aa86efaaf7e23ee815fd9dc97819177bda2c7891f79009c9b2d3c8bbe0e48c437860ff66814124b
|
data/lib/skynet/download.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'helper
|
3
|
+
require_relative 'helper'
|
4
4
|
|
5
5
|
# Module for handling inbound requests
|
6
6
|
module Download
|
7
|
-
|
8
7
|
# Array with http redirect & http permanent code
|
9
8
|
# Used to determine if the GET request should start downloading or follow redirect
|
10
9
|
HTTP_REDIRECT_PERMANENT = [301, 302].freeze
|
@@ -12,12 +11,12 @@ module Download
|
|
12
11
|
|
13
12
|
# Download file from the skynet portal
|
14
13
|
# file_name & skylink is required, the rest is optional since they come with default values
|
15
|
-
def download_file(file_name, skylink,
|
14
|
+
def download_file(file_name, skylink, override_options = {}, stream: true)
|
16
15
|
options = Helper::Download.default_options
|
17
|
-
options = Helper::Download.default_options.merge(
|
16
|
+
options = Helper::Download.default_options.merge(override_options) unless override_options.empty?
|
18
17
|
|
19
18
|
portal = options[:portal_url]
|
20
|
-
skylink =
|
19
|
+
skylink = Helper::Download.strip_prefix(skylink)
|
21
20
|
url = "#{portal}#{skylink}?attachment=#{options[:download]}"
|
22
21
|
|
23
22
|
File.open(file_name, 'w') do |file|
|
data/lib/skynet/helper.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
3
|
+
# Module with helpful utilities and default settings
|
4
4
|
module Helper
|
5
|
-
|
6
5
|
# The default skynet portal
|
7
6
|
PORTAL_URL = 'https://siasky.net/'
|
8
7
|
|
8
|
+
# Prefix for the protocol
|
9
|
+
URI_SKYNET_PREFIX = 'sia://'
|
10
|
+
|
9
11
|
# Module for keeping download settings
|
10
12
|
module Download
|
11
|
-
|
12
13
|
# Default options for the download module
|
13
14
|
def self.default_options
|
14
15
|
{
|
@@ -16,11 +17,21 @@ module Helper
|
|
16
17
|
download: true
|
17
18
|
}
|
18
19
|
end
|
20
|
+
|
21
|
+
# Removes the Skynet::URI_SKYNET_PREFIX constant from string
|
22
|
+
def self.strip_prefix(str)
|
23
|
+
return nil if str.nil?
|
24
|
+
|
25
|
+
if str.index(URI_SKYNET_PREFIX).nil?
|
26
|
+
str
|
27
|
+
else
|
28
|
+
str.delete_prefix(URI_SKYNET_PREFIX)
|
29
|
+
end
|
30
|
+
end
|
19
31
|
end
|
20
32
|
|
21
33
|
# Module for keeping upload settings
|
22
34
|
module Upload
|
23
|
-
|
24
35
|
# Default options for the upload module
|
25
36
|
def self.default_options
|
26
37
|
{
|
@@ -28,8 +39,19 @@ module Helper
|
|
28
39
|
portal_upload_path: 'skynet/skyfile',
|
29
40
|
portal_file_fieldname: 'file',
|
30
41
|
portal_directory_fieldname: 'files[]',
|
31
|
-
custom_filename: nil
|
42
|
+
custom_filename: nil
|
32
43
|
}
|
33
44
|
end
|
45
|
+
|
46
|
+
# Removes "./" from a given filename if provided
|
47
|
+
def self.strip_dotslash_path(file_path)
|
48
|
+
return nil if file_path.nil?
|
49
|
+
|
50
|
+
if file_path.start_with?('./')
|
51
|
+
file_path.delete_prefix('./')
|
52
|
+
else
|
53
|
+
file_path
|
54
|
+
end
|
55
|
+
end
|
34
56
|
end
|
35
57
|
end
|
data/lib/skynet/upload.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'helper
|
3
|
+
require_relative 'helper'
|
4
4
|
|
5
5
|
# Module for handling outbound requests
|
6
6
|
module Upload
|
@@ -21,57 +21,29 @@ module Upload
|
|
21
21
|
end
|
22
22
|
|
23
23
|
# Uploads file to the skynet, file_path is required but options are optional since default values are provided
|
24
|
-
def upload_file(file_path,
|
24
|
+
def upload_file(file_path, override_options = {})
|
25
25
|
options = Helper::Upload.default_options
|
26
|
-
options = Helper::Upload.default_options.merge(
|
26
|
+
options = Helper::Upload.default_options.merge(override_options) unless override_options.empty?
|
27
27
|
return "File #{file_path} does not exist!" unless File.exist?(file_path)
|
28
28
|
|
29
29
|
host = options[:portal_url]
|
30
30
|
path = options[:portal_upload_path]
|
31
31
|
filename = options[:custom_filename] || file_path
|
32
|
+
filename = Helper::Upload.strip_dotslash_path(filename)
|
32
33
|
|
33
34
|
url = "#{host}#{path}?filename=#{filename}"
|
34
|
-
binary_content =
|
35
|
+
binary_content = File.readlines(file_path, mode: 'rb').join
|
35
36
|
|
36
37
|
header_data = http_post_header({
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
headers: {
|
39
|
+
'Content-Disposition' => "attachment; filename='#{filename}'"
|
40
|
+
},
|
41
|
+
body: binary_content,
|
42
|
+
options[:portal_file_fieldname] => filename
|
43
|
+
})
|
43
44
|
|
44
45
|
upload_request = HTTParty.post(url, header_data)
|
45
46
|
parsed_request = upload_request.to_hash
|
46
|
-
"Upload successful, skylink:
|
47
|
+
"Upload successful, skylink: #{parsed_request['skylink']}"
|
47
48
|
end
|
48
|
-
|
49
|
-
# Still work in progress
|
50
|
-
# Uploads a whole directory to the skynet
|
51
|
-
# def upload_directory(directory_path, options = {})
|
52
|
-
# options = Helper::Upload.default_options
|
53
|
-
# options = Helper::Upload.default_options.merge(options) unless options.empty?
|
54
|
-
# return "Given path is not a directory!" unless Dir.exist?(directory_path)
|
55
|
-
|
56
|
-
# directory_entries = Dir.glob("#{directory_path}/*")
|
57
|
-
|
58
|
-
# binary_content = IO.read(filename, mode: 'rb')
|
59
|
-
|
60
|
-
# header_data = http_post_header({
|
61
|
-
# headers: {
|
62
|
-
# 'Content-Disposition' => 'attachment; ' + filename
|
63
|
-
# },
|
64
|
-
# body: binary_content,
|
65
|
-
# options[:portal_directory_fieldname] => filename
|
66
|
-
# })
|
67
|
-
|
68
|
-
# host = options[:portal_url]
|
69
|
-
# path = options[:portal_upload_path]
|
70
|
-
# dir_name = options[:custom_filename] || directory_path
|
71
|
-
# url = "#{host}#{path}?filename=#{dir_name}"
|
72
|
-
|
73
|
-
# upload_request = HTTParty.post(url, header_data)
|
74
|
-
# parsed_request = upload_request.to_hash
|
75
|
-
# "Upload successful, skylink: " + parsed_request['skylink']
|
76
|
-
# end
|
77
49
|
end
|
data/lib/skynet.rb
CHANGED
@@ -1,26 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'httparty'
|
4
|
-
require_relative 'skynet/download
|
5
|
-
require_relative 'skynet/upload
|
4
|
+
require_relative 'skynet/download'
|
5
|
+
require_relative 'skynet/upload'
|
6
6
|
|
7
7
|
# The entrypoint for the SDK
|
8
8
|
class Skynet
|
9
|
-
|
10
|
-
# Prefix for the protocol
|
11
|
-
URI_SKYNET_PREFIX = 'sia://'
|
12
|
-
|
13
9
|
extend Download
|
14
10
|
extend Upload
|
15
|
-
|
16
|
-
# Removes the Skynet::URI_SKYNET_PREFIX constant from string
|
17
|
-
def self.strip_prefix(str)
|
18
|
-
return nil if str.nil?
|
19
|
-
|
20
|
-
if str.index(URI_SKYNET_PREFIX).nil?
|
21
|
-
str
|
22
|
-
else
|
23
|
-
str.delete_prefix(URI_SKYNET_PREFIX)
|
24
|
-
end
|
25
|
-
end
|
26
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-skynet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- beyarz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -94,8 +94,28 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.2.5
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.2'
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 2.2.21
|
107
|
+
type: :development
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - "~>"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '2.2'
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 2.2.21
|
97
117
|
description: Ruby gem for integrating Sia Skynet into Ruby apps
|
98
|
-
email:
|
118
|
+
email: beyar-123@live.com
|
99
119
|
executables: []
|
100
120
|
extensions: []
|
101
121
|
extra_rdoc_files: []
|
@@ -117,14 +137,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
137
|
requirements:
|
118
138
|
- - ">="
|
119
139
|
- !ruby/object:Gem::Version
|
120
|
-
version:
|
140
|
+
version: 2.7.0
|
121
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
142
|
requirements:
|
123
143
|
- - ">="
|
124
144
|
- !ruby/object:Gem::Version
|
125
145
|
version: '0'
|
126
146
|
requirements: []
|
127
|
-
rubygems_version: 3.1.
|
147
|
+
rubygems_version: 3.1.6
|
128
148
|
signing_key:
|
129
149
|
specification_version: 4
|
130
150
|
summary: Sia skynet gem
|