ruby-ipfs-api 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api/command.rb +26 -0
- data/lib/api/files/add.rb +15 -0
- data/lib/api/files/cat.rb +2 -7
- data/lib/api/files/ls.rb +2 -6
- data/lib/api/generic/id.rb +1 -4
- data/lib/api/generic/version.rb +1 -4
- data/lib/client.rb +10 -9
- data/lib/http_api.rb +3 -3
- data/lib/ipfs_api.rb +1 -1
- data/lib/request/basic_request.rb +17 -0
- data/lib/request/file_upload_request.rb +19 -0
- data/lib/request/request.rb +14 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ed5bd942765642e4bd3c2d5288cabc376fc63fd
|
4
|
+
data.tar.gz: a4b6662afce323e336b7b5e89837e13a148c3d76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 911bf26795481cac044b2d68f572f197a6b96deffd9ac35862d3ee8897424f4cb67bce6800b69b6b32b90d69c0c10b945629f66d11334688791839c59ab2ade1
|
7
|
+
data.tar.gz: 6912913ce0388053688d9308748023bacb37b1e0ca42c18d110852ef6b7561a02bb4923de45613c070e11bd0d2afc2abcfd725cd73f8ec6d832d7f01e5702b69
|
data/lib/api/command.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative '../multihash'
|
2
|
+
|
3
|
+
require_relative '../request/basic_request'
|
4
|
+
require_relative '../request/file_upload_request'
|
5
|
+
|
6
|
+
require_relative './generic/id'
|
7
|
+
require_relative './generic/version'
|
8
|
+
require_relative './files/cat'
|
9
|
+
require_relative './files/ls'
|
10
|
+
require_relative './files/add'
|
11
|
+
|
12
|
+
module Ipfs
|
13
|
+
module Command
|
14
|
+
def self.build_request(path, **arguments)
|
15
|
+
keys = arguments.keys
|
16
|
+
|
17
|
+
if keys.include?(:multihash)
|
18
|
+
BasicRequest.new(path, multihash: arguments[:multihash])
|
19
|
+
elsif keys.include?(:filepath)
|
20
|
+
FileUploadRequest.new(path, arguments[:filepath])
|
21
|
+
else
|
22
|
+
BasicRequest.new(path)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/api/files/cat.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
require_relative '../../dagstream'
|
2
|
-
require_relative '../../errors'
|
3
2
|
|
4
3
|
module Ipfs
|
5
4
|
module Command
|
6
5
|
class Cat
|
7
6
|
PATH = '/cat'
|
8
7
|
|
9
|
-
def self.build_request(
|
10
|
-
|
11
|
-
verb: :get,
|
12
|
-
path: PATH,
|
13
|
-
options: { params: { arg: multi_hash.raw } }
|
14
|
-
}
|
8
|
+
def self.build_request(multihash)
|
9
|
+
Command.build_request(PATH, multihash: Ipfs::Multihash.new(multihash))
|
15
10
|
end
|
16
11
|
|
17
12
|
def self.parse_response(response)
|
data/lib/api/files/ls.rb
CHANGED
@@ -3,12 +3,8 @@ module Ipfs
|
|
3
3
|
class Ls
|
4
4
|
PATH = '/ls'
|
5
5
|
|
6
|
-
def self.build_request(
|
7
|
-
|
8
|
-
verb: :get,
|
9
|
-
path: PATH,
|
10
|
-
options: { params: { arg: multi_hash.raw } }
|
11
|
-
}
|
6
|
+
def self.build_request(multihash)
|
7
|
+
Command.build_request(PATH, multihash: Ipfs::Multihash.new(multihash))
|
12
8
|
end
|
13
9
|
|
14
10
|
def self.parse_response(response)
|
data/lib/api/generic/id.rb
CHANGED
data/lib/api/generic/version.rb
CHANGED
data/lib/client.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
require_relative './http_api'
|
2
|
-
require_relative './api/
|
3
|
-
require_relative './api/generic/version'
|
4
|
-
require_relative './api/files/cat'
|
5
|
-
require_relative './api/files/ls'
|
2
|
+
require_relative './api/command'
|
6
3
|
require_relative './multihash'
|
7
4
|
|
8
5
|
module Ipfs
|
@@ -19,12 +16,16 @@ module Ipfs
|
|
19
16
|
execute Command::Version
|
20
17
|
end
|
21
18
|
|
22
|
-
def cat(
|
23
|
-
execute Command::Cat,
|
19
|
+
def cat(multihash)
|
20
|
+
execute Command::Cat, multihash
|
24
21
|
end
|
25
22
|
|
26
|
-
def ls(
|
27
|
-
execute Command::Ls,
|
23
|
+
def ls(multihash)
|
24
|
+
execute Command::Ls, multihash
|
25
|
+
end
|
26
|
+
|
27
|
+
def add(filepath)
|
28
|
+
execute Command::Add, filepath
|
28
29
|
end
|
29
30
|
|
30
31
|
private
|
@@ -33,4 +34,4 @@ module Ipfs
|
|
33
34
|
command.parse_response @http_api.call command.build_request *args
|
34
35
|
end
|
35
36
|
end
|
36
|
-
end
|
37
|
+
end
|
data/lib/http_api.rb
CHANGED
data/lib/ipfs_api.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative './request'
|
2
|
+
|
3
|
+
module Ipfs
|
4
|
+
class BasicRequest < Request
|
5
|
+
def initialize(path, **arguments)
|
6
|
+
super(path, :get)
|
7
|
+
|
8
|
+
@multihash = arguments[:multihash]
|
9
|
+
end
|
10
|
+
|
11
|
+
def options
|
12
|
+
@multihash \
|
13
|
+
? { params: { arg: @multihash.raw } }
|
14
|
+
: {}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative './request'
|
2
|
+
|
3
|
+
module Ipfs
|
4
|
+
class FileUploadRequest < Request
|
5
|
+
def initialize(path, filepath)
|
6
|
+
super(path, :post)
|
7
|
+
|
8
|
+
@filepath = filepath
|
9
|
+
end
|
10
|
+
|
11
|
+
def options
|
12
|
+
{
|
13
|
+
form: {
|
14
|
+
arg: HTTP::FormData::File.new(@filepath)
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-ipfs-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Benett
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: http
|
@@ -31,6 +31,8 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- lib/api/command.rb
|
35
|
+
- lib/api/files/add.rb
|
34
36
|
- lib/api/files/cat.rb
|
35
37
|
- lib/api/files/ls.rb
|
36
38
|
- lib/api/generic/id.rb
|
@@ -42,6 +44,9 @@ files:
|
|
42
44
|
- lib/http_api.rb
|
43
45
|
- lib/ipfs_api.rb
|
44
46
|
- lib/multihash.rb
|
47
|
+
- lib/request/basic_request.rb
|
48
|
+
- lib/request/file_upload_request.rb
|
49
|
+
- lib/request/request.rb
|
45
50
|
homepage: https://github.com/mahloun/ruby-ipfs-api
|
46
51
|
licenses:
|
47
52
|
- MIT
|