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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c77ff43cc141faaf34d664f16c0c7b10e8d42a00
4
- data.tar.gz: 4ab2dcd154b4f87a49e14370fd7434aca890bcd3
3
+ metadata.gz: 6ed5bd942765642e4bd3c2d5288cabc376fc63fd
4
+ data.tar.gz: a4b6662afce323e336b7b5e89837e13a148c3d76
5
5
  SHA512:
6
- metadata.gz: ad07486909d6881a3fa13c952a088be1264b201cae2fda691e98df9cda1404b3c4158cfc79a1f80d2476cc211063c8405dcf72a45d62e2ecd7255586c9cc738c
7
- data.tar.gz: d1dbd86b6ab786e8c393c59922f35689b8cced15f9268108806950fc1476f6cfb8f3b953f957b98a67c95c6eea7ca872bcf229842e64d73dac483fa4f443ae5c
6
+ metadata.gz: 911bf26795481cac044b2d68f572f197a6b96deffd9ac35862d3ee8897424f4cb67bce6800b69b6b32b90d69c0c10b945629f66d11334688791839c59ab2ade1
7
+ data.tar.gz: 6912913ce0388053688d9308748023bacb37b1e0ca42c18d110852ef6b7561a02bb4923de45613c070e11bd0d2afc2abcfd725cd73f8ec6d832d7f01e5702b69
@@ -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
@@ -0,0 +1,15 @@
1
+ module Ipfs
2
+ module Command
3
+ class Add
4
+ PATH = '/add'
5
+
6
+ def self.build_request(filepath)
7
+ Command.build_request(PATH, filepath: filepath)
8
+ end
9
+
10
+ def self.parse_response(response)
11
+ JSON.parse response
12
+ end
13
+ end
14
+ end
15
+ end
@@ -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(multi_hash)
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)
@@ -3,12 +3,8 @@ module Ipfs
3
3
  class Ls
4
4
  PATH = '/ls'
5
5
 
6
- def self.build_request(multi_hash)
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)
@@ -4,10 +4,7 @@ module Ipfs
4
4
  PATH = '/id'
5
5
 
6
6
  def self.build_request
7
- {
8
- verb: :post,
9
- path: PATH
10
- }
7
+ Command.build_request(PATH)
11
8
  end
12
9
 
13
10
  def self.parse_response(response)
@@ -4,10 +4,7 @@ module Ipfs
4
4
  PATH = '/version'
5
5
 
6
6
  def self.build_request
7
- {
8
- verb: :get,
9
- path: PATH
10
- }
7
+ Command.build_request(PATH)
11
8
  end
12
9
 
13
10
  def self.parse_response(response)
@@ -1,8 +1,5 @@
1
1
  require_relative './http_api'
2
- require_relative './api/generic/id'
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(multi_hash)
23
- execute Command::Cat, Multihash.new(multi_hash)
19
+ def cat(multihash)
20
+ execute Command::Cat, multihash
24
21
  end
25
22
 
26
- def ls(multi_hash)
27
- execute Command::Ls, Multihash.new(multi_hash)
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
@@ -17,9 +17,9 @@ module Ipfs
17
17
 
18
18
  def call(command)
19
19
  HTTP.request(
20
- command[:verb],
21
- url(command[:path]),
22
- command[:options] ? command[:options] : {}
20
+ command.verb,
21
+ url(command.path),
22
+ command.options
23
23
  )
24
24
  end
25
25
 
@@ -2,6 +2,6 @@ require_relative './client'
2
2
 
3
3
  module Ipfs
4
4
  class Client
5
- VERSION = '0.4.1'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -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
@@ -0,0 +1,14 @@
1
+ module Ipfs
2
+ class Request
3
+ attr_reader :path, :verb
4
+
5
+ def initialize(path, verb)
6
+ @path = path
7
+ @verb = verb
8
+ end
9
+
10
+ def options
11
+ {}
12
+ end
13
+ end
14
+ 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.1
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-11-27 00:00:00.000000000 Z
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