Class: DistributedPress
- Inherits:
-
Object
- Object
- DistributedPress
- Includes:
- HTTParty
- Defined in:
- lib/distributed_press.rb,
lib/distributed_press/v1.rb,
lib/distributed_press/version.rb,
lib/distributed_press/v1/token.rb,
lib/distributed_press/multipart.rb,
lib/distributed_press/v1/client.rb,
lib/distributed_press/v1/errors.rb,
lib/distributed_press/v1/social.rb,
lib/distributed_press/v1/schemas.rb,
lib/distributed_press/v1/client/auth.rb,
lib/distributed_press/v1/client/site.rb,
lib/distributed_press/v1/social/hook.rb,
lib/distributed_press/v1/client/admin.rb,
lib/distributed_press/v1/schemas/site.rb,
lib/distributed_press/v1/social/inbox.rb,
lib/distributed_press/v1/social/likes.rb,
lib/distributed_press/v1/schemas/admin.rb,
lib/distributed_press/v1/social/client.rb,
lib/distributed_press/v1/social/outbox.rb,
lib/distributed_press/v1/social/shares.rb,
lib/distributed_press/v1/social/replies.rb,
lib/distributed_press/v1/client/publisher.rb,
lib/distributed_press/v1/schemas/new_site.rb,
lib/distributed_press/v1/social/allowlist.rb,
lib/distributed_press/v1/social/blocklist.rb,
lib/distributed_press/v1/social/followers.rb,
lib/distributed_press/v1/social/reference.rb,
lib/distributed_press/v1/schemas/new_admin.rb,
lib/distributed_press/v1/schemas/publisher.rb,
lib/distributed_press/v1/social/collection.rb,
lib/distributed_press/v1/schemas/update_site.rb,
lib/distributed_press/v1/social/dereferencer.rb,
lib/distributed_press/v1/schemas/token_header.rb,
lib/distributed_press/v1/schemas/http_protocol.rb,
lib/distributed_press/v1/schemas/ipfs_protocol.rb,
lib/distributed_press/v1/schemas/new_publisher.rb,
lib/distributed_press/v1/schemas/token_payload.rb,
lib/distributed_press/v1/social/signed_headers.rb,
lib/distributed_press/v1/schemas/hyper_protocol.rb,
lib/distributed_press/v1/social/schemas/webhook.rb,
lib/distributed_press/v1/schemas/publishing_site.rb,
lib/distributed_press/v1/social/referenced_object.rb,
lib/distributed_press/v1/schemas/new_token_payload.rb,
lib/distributed_press/v1/schemas/bittorrent_protocol.rb
Overview
API client
Defined Under Namespace
Modules: V1 Classes: Multipart
Constant Summary collapse
- DEFAULT_URL =
Default URL
'https://api.distributed.press'
- VERSION =
Version
'0.5.1'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#configure_result ⇒ Object
readonly
Returns the value of attribute configure_result.
-
#project_domain ⇒ Object
readonly
Returns the value of attribute project_domain.
-
#publish_result ⇒ Object
readonly
Returns the value of attribute publish_result.
Instance Method Summary collapse
-
#configure ⇒ Boolean
Configure the domain.
-
#initialize(url: DEFAULT_URL, api_key: nil, project_domain: nil) ⇒ DistributedPress
constructor
A new instance of DistributedPress.
-
#publish(path) ⇒ Boolean
Publishes a directory by tarballing it on the fly.
Constructor Details
#initialize(url: DEFAULT_URL, api_key: nil, project_domain: nil) ⇒ DistributedPress
Returns a new instance of DistributedPress.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/distributed_press.rb', line 19 def initialize(url: DEFAULT_URL, api_key: nil, project_domain: nil) url ||= DEFAULT_URL @api_key = api_key || ENV['DISTRIBUTED_PRESS_API_KEY'] @project_domain = project_domain || ENV['DISTRIBUTED_PRESS_PROJECT_DOMAIN'] raise ArgumentError, 'API key is missing' unless @api_key raise ArgumentError, 'Project domain is missing' unless @project_domain self.class.[:base_uri] = HTTParty.normalize_base_uri(url) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
14 15 16 |
# File 'lib/distributed_press.rb', line 14 def api_key @api_key end |
#configure_result ⇒ Object (readonly)
Returns the value of attribute configure_result.
14 15 16 |
# File 'lib/distributed_press.rb', line 14 def configure_result @configure_result end |
#project_domain ⇒ Object (readonly)
Returns the value of attribute project_domain.
14 15 16 |
# File 'lib/distributed_press.rb', line 14 def project_domain @project_domain end |
#publish_result ⇒ Object (readonly)
Returns the value of attribute publish_result.
14 15 16 |
# File 'lib/distributed_press.rb', line 14 def publish_result @publish_result end |
Instance Method Details
#configure ⇒ Boolean
Configure the domain
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/distributed_press.rb', line 33 def configure stream, config = IO.pipe multipart = Multipart.new Thread.new do multipart.write_header config, 'config.json' IO.copy_stream StringIO.new({ 'domain' => project_domain }.to_json), config multipart. config config.close end @configure_result = upload_io('/v0/publication/configure', stream, multipart.boundary) configure_result['errorCode'].zero? end |
#publish(path) ⇒ Boolean
Publishes a directory by tarballing it on the fly.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/distributed_press.rb', line 54 def publish(path) raise ArgumentError, "#{path} is not a directory" unless File.directory? path filename = File.basename path Open3.popen2('tar', '--to-stdout', '--create', '--gzip', '--dereference', '--directory', path, '.') do |_stdin, stdout, thread| stream, body = IO.pipe multipart = Multipart.new # Generate a multipart body and copy contents to it. Thread.new do multipart.write_header body, "#{filename}.tar.gz" IO.copy_stream stdout, body multipart. body body.close end @publish_result = upload_io '/v0/publication/publish', stream, multipart.boundary # wait thread.value publish_result['errorCode'].zero? end end |