ipfs 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +68 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/ipfs.gemspec +30 -0
- data/lib/ipfs.rb +1 -0
- data/lib/ipfs/client.rb +27 -0
- data/lib/ipfs/commands/ls.rb +24 -0
- data/lib/ipfs/content/link.rb +17 -0
- data/lib/ipfs/content/node.rb +20 -0
- data/lib/ipfs/version.rb +3 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e3bff5c28eaec19587d278aaf451629dd80dc5d7
|
4
|
+
data.tar.gz: 1a3b6cdfb9d4120f328e47133b1fd02b519b8c93
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c7592748c4105d12b8fc18dbbc3d6f99b3c172bd649cf5bb8122253803f732d2a507a9b6886ee24b8701b63686e70a4d2f2719273b14d1f2cd0aa3ef4ed714c
|
7
|
+
data.tar.gz: 94ad3dfd9354c1bc960925ce5a951c78b340798ac9ec5e13d579e96b076ef73a5d48b14e79c77d4419f9f86171749cad39f09effe38e94c10ceeeecab5f860c2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Pierpaolo Frasa
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# IPFS API Bindings for Ruby
|
2
|
+
This gem provides IPFS API bindings for Ruby, see [https://ipfs.io](https://ipfs.io).
|
3
|
+
|
4
|
+
Work in progress.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
Requires Ruby >= 2.1, since it uses the new required keyword arguments syntax.
|
8
|
+
|
9
|
+
(The following doesn't work yet, the gem is not yet released on Rubygems. In the meantime, run ```rake install``` from the project root.)
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'ipfs'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install ipfs
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
### Initialize client
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'ipfs/client'
|
30
|
+
client = IPFS::Client.new host: 'yourhost', port: 5001
|
31
|
+
```
|
32
|
+
|
33
|
+
or:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'ipfs/client'
|
37
|
+
client = IPFS::Client.default # => uses localhost and port 5001
|
38
|
+
```
|
39
|
+
|
40
|
+
### ls
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
nodes = client.ls 'QmXqJAkSdP8e7TSXEeSRKoDY27G11ZwaFJGiKuNFWxpUZo'
|
44
|
+
|
45
|
+
nodes.each do |node|
|
46
|
+
# node is an instance of IPFS::Content::Node
|
47
|
+
|
48
|
+
puts node.hashcode
|
49
|
+
|
50
|
+
node.links.each do |link|
|
51
|
+
# link is an instance of IPFS::Content::Link
|
52
|
+
|
53
|
+
puts link.name
|
54
|
+
puts link.hashcode
|
55
|
+
puts link.size
|
56
|
+
end
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
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.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/Fryie/ipfs-ruby).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ipfs"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/ipfs.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ipfs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ipfs"
|
8
|
+
spec.version = IPFS::VERSION
|
9
|
+
spec.authors = ["Pierpaolo Frasa"]
|
10
|
+
spec.email = ["pfrasa@gmail.com"]
|
11
|
+
spec.license = 'MIT'
|
12
|
+
|
13
|
+
spec.summary = %q{IPFS API bindings}
|
14
|
+
spec.description = %q{API bindings for the Interplanetary File System}
|
15
|
+
spec.homepage = "https://ipfs.io"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "http", "~> 0.9.6"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "byebug"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "webmock"
|
29
|
+
spec.add_development_dependency "sinatra"
|
30
|
+
end
|
data/lib/ipfs.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "ipfs/version"
|
data/lib/ipfs/client.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'ipfs/commands/ls'
|
2
|
+
|
3
|
+
module IPFS
|
4
|
+
class Client
|
5
|
+
DEFAULT_HOST = 'http://localhost'
|
6
|
+
DEFAULT_PORT = 5001
|
7
|
+
API_VERSION = 'v0'
|
8
|
+
|
9
|
+
attr_reader :host, :port
|
10
|
+
|
11
|
+
def self.default
|
12
|
+
new(host: DEFAULT_HOST, port: DEFAULT_PORT)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(host:, port:)
|
16
|
+
@host, @port = host, port
|
17
|
+
end
|
18
|
+
|
19
|
+
def api_url
|
20
|
+
"#{host}:#{port}/api/#{API_VERSION}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def ls(node)
|
24
|
+
Commands::LS.call self, node
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'http'
|
2
|
+
require 'json'
|
3
|
+
require 'ipfs/content/node'
|
4
|
+
|
5
|
+
module IPFS
|
6
|
+
module Commands
|
7
|
+
class LS
|
8
|
+
|
9
|
+
def self.call(client, node)
|
10
|
+
parse query(client, node)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def self.query(client, node)
|
15
|
+
HTTP.get("#{client.api_url}/ls?arg=#{node}&stream-channels=true").to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.parse(response)
|
19
|
+
Content::Node.parse_array JSON.parse(response)['Objects']
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module IPFS
|
2
|
+
module Content
|
3
|
+
class Link
|
4
|
+
attr_reader :name, :hashcode, :size
|
5
|
+
|
6
|
+
def initialize(name:, hashcode:, size:)
|
7
|
+
@name, @hashcode, @size = name, hashcode, size
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.parse_array(array)
|
11
|
+
array.map do |item|
|
12
|
+
new name: item['Name'], hashcode: item['Hash'], size: item['Size']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'ipfs/content/link'
|
2
|
+
|
3
|
+
module IPFS
|
4
|
+
module Content
|
5
|
+
class Node
|
6
|
+
attr_reader :hashcode, :links
|
7
|
+
|
8
|
+
def initialize(hashcode:, links:)
|
9
|
+
@hashcode, @links = hashcode, links
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.parse_array(array)
|
13
|
+
array.map do |item|
|
14
|
+
new(hashcode: item['Hash'], links: Link.parse_array(item['Links']))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/ipfs/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ipfs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pierpaolo Frasa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sinatra
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: API bindings for the Interplanetary File System
|
112
|
+
email:
|
113
|
+
- pfrasa@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
127
|
+
- ipfs.gemspec
|
128
|
+
- lib/ipfs.rb
|
129
|
+
- lib/ipfs/client.rb
|
130
|
+
- lib/ipfs/commands/ls.rb
|
131
|
+
- lib/ipfs/content/link.rb
|
132
|
+
- lib/ipfs/content/node.rb
|
133
|
+
- lib/ipfs/version.rb
|
134
|
+
homepage: https://ipfs.io
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.4.8
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: IPFS API bindings
|
158
|
+
test_files: []
|