ruby-ipfs-api 0.0.0 → 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 +4 -4
- data/lib/api/files/cat.rb +22 -0
- data/lib/api/generic/id.rb +18 -0
- data/lib/api/generic/version.rb +18 -0
- data/lib/dagnode.rb +15 -0
- data/lib/errors.rb +6 -0
- data/lib/ipfs-api.rb +30 -1
- data/lib/request.rb +35 -0
- metadata +13 -7
- data/lib/ipfs.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6be77b3c8b110052ee64c9dae0041ca4a01da400
|
4
|
+
data.tar.gz: d667d4ceb0722a86261c88218f5c6444803659b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2998fe01ce08f03066de75ee6d1da7b00e10214b7da5bbbf0a7b37dcf4d5af51336366b86821d0b51fa3b2560dc46af890f317eca2bb3d3e7168bade698f1baf
|
7
|
+
data.tar.gz: 7325c99bfbddad37937694b9496f51c06b18b9f22b2addac51d89034e83b1bce1babb0f3b027ac9db0048780d97ca29e2c43a7c4512febea64e6025c7c3647e2
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../../dagnode'
|
2
|
+
require_relative '../../errors'
|
3
|
+
|
4
|
+
module Ipfs
|
5
|
+
module Command
|
6
|
+
class Cat
|
7
|
+
PATH = '/cat'
|
8
|
+
|
9
|
+
def self.make_request multi_hash
|
10
|
+
{
|
11
|
+
method: :get,
|
12
|
+
path: PATH,
|
13
|
+
params: { :arg => multi_hash }
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.parse_response response
|
18
|
+
DagNode.new response
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/dagnode.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative './errors'
|
2
|
+
|
3
|
+
module Ipfs
|
4
|
+
class DagNode
|
5
|
+
attr_reader :content
|
6
|
+
|
7
|
+
def initialize http_response
|
8
|
+
if http_response.status.code == 200
|
9
|
+
@content = http_response.body
|
10
|
+
else
|
11
|
+
raise Error::InvalidDagNode.new JSON.parse(http_response.body)["Message"]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/errors.rb
ADDED
data/lib/ipfs-api.rb
CHANGED
@@ -1 +1,30 @@
|
|
1
|
-
require_relative './
|
1
|
+
require_relative './request'
|
2
|
+
require_relative './api/generic/id'
|
3
|
+
require_relative './api/generic/version'
|
4
|
+
require_relative './api/files/cat'
|
5
|
+
|
6
|
+
module Ipfs
|
7
|
+
class Client
|
8
|
+
def initialize server = {}
|
9
|
+
@request = Request.new server
|
10
|
+
end
|
11
|
+
|
12
|
+
def id
|
13
|
+
execute Command::Id
|
14
|
+
end
|
15
|
+
|
16
|
+
def version
|
17
|
+
execute Command::Version
|
18
|
+
end
|
19
|
+
|
20
|
+
def cat multi_hash
|
21
|
+
execute Command::Cat, multi_hash
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def execute command, *args
|
27
|
+
command.parse_response @request.call_api command.make_request *args
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/request.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Ipfs
|
5
|
+
class Request
|
6
|
+
attr_reader :host, :port, :base_path
|
7
|
+
|
8
|
+
DEFAULT_HOST = 'localhost'
|
9
|
+
DEFAULT_PORT = 5001
|
10
|
+
DEFAULT_BASE_PATH = '/api/v0'
|
11
|
+
|
12
|
+
def initialize **api_server
|
13
|
+
@host = api_server[:host] || DEFAULT_HOST
|
14
|
+
@port = api_server[:port] || DEFAULT_PORT
|
15
|
+
@base_path = api_server[:base_path] || DEFAULT_BASE_PATH
|
16
|
+
end
|
17
|
+
|
18
|
+
def call_api command
|
19
|
+
HTTP.request(
|
20
|
+
command[:method],
|
21
|
+
url(command[:path]),
|
22
|
+
params: command[:params]
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def url command_path
|
29
|
+
URI::HTTP.build \
|
30
|
+
host: @host,
|
31
|
+
port: @port,
|
32
|
+
path: @base_path + command_path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,24 +1,30 @@
|
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Nieto
|
8
|
+
- Neil Nilou
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2017-
|
12
|
+
date: 2017-08-12 00:00:00.000000000 Z
|
12
13
|
dependencies: []
|
13
|
-
description:
|
14
|
+
description: A client library for the IPFS HTTP API, immplemented in Ruby
|
14
15
|
email: thms.no@gmail.com
|
15
16
|
executables: []
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
20
|
+
- lib/api/files/cat.rb
|
21
|
+
- lib/api/generic/id.rb
|
22
|
+
- lib/api/generic/version.rb
|
23
|
+
- lib/dagnode.rb
|
24
|
+
- lib/errors.rb
|
19
25
|
- lib/ipfs-api.rb
|
20
|
-
- lib/
|
21
|
-
homepage:
|
26
|
+
- lib/request.rb
|
27
|
+
homepage: https://github.com/mahloun/ruby-ipfs-api
|
22
28
|
licenses:
|
23
29
|
- MIT
|
24
30
|
metadata: {}
|
@@ -38,8 +44,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
44
|
version: '0'
|
39
45
|
requirements: []
|
40
46
|
rubyforge_project:
|
41
|
-
rubygems_version: 2.6.
|
47
|
+
rubygems_version: 2.6.8
|
42
48
|
signing_key:
|
43
49
|
specification_version: 4
|
44
|
-
summary:
|
50
|
+
summary: ipfs client
|
45
51
|
test_files: []
|