ipfs-http-client 0.3.1 → 0.3.2

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
  SHA256:
3
- metadata.gz: 7733656e3efdbcaa136286db2103be845bab263355386f4494e33f1adc050882
4
- data.tar.gz: 363de38533d5874896703dbec4029420b0762f09bd24ec93862de06cb8ce77ff
3
+ metadata.gz: 97ed4c9f300ffd5bb88d81b7513bc935e7f8c71853abb3a2b0fe8bdceea8f231
4
+ data.tar.gz: 24efd4f57ced393ee7697613abd6028030dea104230cca081aca9cd1ea2a1bf1
5
5
  SHA512:
6
- metadata.gz: ae68078066d3fe895f95faa3d8702ba7dc0ab52699b12361c6293a8ca23344910a8ea9bd5c67aa5902dbd54b0d1eaef2eada2c3067f54b31212eb9c5bda5c89a
7
- data.tar.gz: 8d50b80eb34c694aa776e26cd781656cdcaec4d21a19126bcd785101c847788470d56e30634f2aa05336db8ec074801a929789f5651c93cd330d29596b25c945
6
+ metadata.gz: 22765703adbd70b6a305125254715ff572f0e3850d323bd172d396240410fc43e43de10ecf92054af0ffce2f9b4b8391682a48b86571e13b74914c4774917f95
7
+ data.tar.gz: 4224a928a062d2fc76bae4dbd77bb3d5989a55cd289dd9d9a36b12427ef1c4301e81621456018ac51daca914d0f3310c45024f315ce2c73b2f36f03098844d90
data/README.md CHANGED
@@ -75,6 +75,12 @@ pry(main)> client.pin_rm "Qmbvkmk9LFsGneteXk3G7YLqtLVME566ho6ibaQZZVHaC9"
75
75
  => {"Pins"=>["Qmbvkmk9LFsGneteXk3G7YLqtLVME566ho6ibaQZZVHaC9"]}
76
76
  ```
77
77
 
78
+ ### pin add
79
+ ```
80
+ pry(main)> client.pin_add "Qmbvkmk9LFsGneteXk3G7YLqtLVME566ho6ibaQZZVHaC9"
81
+ => {"Pins"=>["Qmbvkmk9LFsGneteXk3G7YLqtLVME566ho6ibaQZZVHaC9"]}
82
+ ```
83
+
78
84
  ## Development
79
85
 
80
86
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -44,5 +44,9 @@ module Ipfs
44
44
  def pin_rm(node, recursive: true)
45
45
  Commands::PinRm.call self, node, recursive: recursive
46
46
  end
47
+
48
+ def pin_add(node, recursive: true)
49
+ Commands::PinAdd.call self, node, recursive: recursive
50
+ end
47
51
  end
48
52
  end
@@ -5,3 +5,4 @@ require 'ipfs-http-client/commands/cat_to_file'
5
5
  require 'ipfs-http-client/commands/add'
6
6
  require 'ipfs-http-client/commands/add_dir'
7
7
  require 'ipfs-http-client/commands/pin_rm'
8
+ require 'ipfs-http-client/commands/pin_add'
@@ -4,7 +4,7 @@ module Ipfs
4
4
  module Commands
5
5
  class Add < Ipfs::Commands::Base
6
6
  def self.call(client, file)
7
- response = http_get(client, "/add", {form: {file: HTTP::FormData::File.new(file)}})
7
+ response = request(client, "/add", {form: {file: HTTP::FormData::File.new(file)}})
8
8
  parse(response.body)
9
9
  end
10
10
  end
@@ -27,7 +27,7 @@ module Ipfs
27
27
  end
28
28
  end
29
29
 
30
- response = http_get(client, "/add?recursive=true",
30
+ response = request(client, "/add?recursive=true",
31
31
  {form: {file: form_files }})
32
32
 
33
33
  response.body.to_s.split("\n").map { |s| JSON.parse s }
@@ -6,12 +6,17 @@ require 'http/form_data'
6
6
 
7
7
  module Ipfs
8
8
  module Commands
9
+ class Error < StandardError; end
10
+
9
11
  class Base
10
- def self.http_get(client, path_with_query, args = nil)
12
+ def self.request(client, path_with_query, args = nil)
11
13
  url = "#{client.base_url}#{path_with_query}"
12
14
  response = HTTP.get(*[url, args].compact)
13
- yield response if block_given?
14
- response
15
+ if response.code >= 200 && response.code <= 299
16
+ response
17
+ else
18
+ raise Error, response.body
19
+ end
15
20
  end
16
21
 
17
22
  def self.parse(str)
@@ -4,7 +4,7 @@ module Ipfs
4
4
  module Commands
5
5
  class Cat < Ipfs::Commands::Base
6
6
  def self.call(client, node)
7
- http_get(client, "/cat?arg=#{node}").to_s
7
+ request(client, "/cat?arg=#{node}").to_s
8
8
  end
9
9
  end
10
10
  end
@@ -4,15 +4,15 @@ module Ipfs
4
4
  module Commands
5
5
  class CatToFile < Ipfs::Commands::Base
6
6
  def self.call(client, node, path)
7
- http_get(client, "/cat?arg=#{node}") do |response|
8
- begin
9
- file = File.open(path, 'wb')
10
- while (chunk = response.body.readpartial)
11
- file.write chunk
12
- end
13
- ensure
14
- file.close if file
7
+ response = request(client, "/cat?arg=#{node}")
8
+
9
+ begin
10
+ file = File.open(path, 'wb')
11
+ while (chunk = response.body.readpartial)
12
+ file.write chunk
15
13
  end
14
+ ensure
15
+ file.close if file
16
16
  end
17
17
 
18
18
  true
@@ -4,7 +4,7 @@ module Ipfs
4
4
  module Commands
5
5
  class Ls < Ipfs::Commands::Base
6
6
  def self.call(client, node)
7
- response = http_get(client, "/ls?arg=#{node}")
7
+ response = request(client, "/ls?arg=#{node}")
8
8
  parse(response.body)
9
9
  end
10
10
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ipfs
4
+ module Commands
5
+ class PinAdd < Ipfs::Commands::Base
6
+ def self.call(client, node, recursive: false)
7
+ response = request(client, "/pin/add?arg=#{node}&recursive=#{recursive}")
8
+ parse(response.body)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -4,7 +4,7 @@ module Ipfs
4
4
  module Commands
5
5
  class PinRm < Ipfs::Commands::Base
6
6
  def self.call(client, node, recursive: false)
7
- response = http_get client, "/pin/rm?arg=#{node}&recursive=#{recursive}"
7
+ response = request(client, "/pin/rm?arg=#{node}&recursive=#{recursive}")
8
8
  parse(response.body)
9
9
  end
10
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ipfs
4
- VERSION = '0.3.1'
4
+ VERSION = '0.3.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipfs-http-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jingyang Liang
@@ -127,6 +127,7 @@ files:
127
127
  - lib/ipfs-http-client/commands/cat.rb
128
128
  - lib/ipfs-http-client/commands/cat_to_file.rb
129
129
  - lib/ipfs-http-client/commands/ls.rb
130
+ - lib/ipfs-http-client/commands/pin_add.rb
130
131
  - lib/ipfs-http-client/commands/pin_rm.rb
131
132
  - lib/ipfs-http-client/version.rb
132
133
  homepage: https://gitlab.com/persper/gitlab/ipfs-http-client