distributed-press-api-client 0.1.3 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae448e05caf1d538ac277c028958db6d002f18d623940b34f107f9fffb9ceb69
4
- data.tar.gz: 52a18426f835670fd078cd73fd9aa65b0b3f18ec83d58f76dcf3dee0a79e7007
3
+ metadata.gz: 9629ab7d59c1d050b2bab1917411f46ca1d1e23eede72d0ea99341d0dd2aca01
4
+ data.tar.gz: 5d755057e6eb43e84ae65409bdd864635c8135307a4377290ecc384ce8fc97e4
5
5
  SHA512:
6
- metadata.gz: 4bd3a517a48151f9e50ad237f694c936e8942177ef886aa244534e45212532655d09858f5912d51a8f9f841dfa6bbf074af84c34e3f1e70a9ab781b8a001f22f
7
- data.tar.gz: 3d012f7c84984cbb94f291aab7ea10ca0ce717ad9328042de8e07a84a9b8873bbe3ab38009e2fbb42f65714305ad5008997f01df776ad22056cacd09d3fc9b66
6
+ metadata.gz: d6bbbae13ac80552f7b83a3967ac74530a916c29ed8896f577b93028e3e5eb9002f7a23554cc8c84b5bc7fb150802873f862bf541c5f06da639767d0867895e2
7
+ data.tar.gz: f796cb6a9f5ed258a55580a32e8ba8625adc50ae367ec6eb29c885ddbd7f589d4b8ea9565eb019550f2045ba18928a2d6c8def03a21b1f329b6185066e622c41
data/README.md CHANGED
@@ -62,6 +62,13 @@ Build and publish site:
62
62
  JEKYLL_ENV=production DISTRIBUTED_PRESS_API_KEY=the_api_key bundle exec jekyll build
63
63
  ```
64
64
 
65
+ Other env vars:
66
+
67
+ ```bash
68
+ DISTRIBUTED_PRESS_PROJECT_DOMAIN=your.domain.at.distributed.press
69
+ DISTRIBUTED_PRESS_API_URL=https://api.distributed.press
70
+ ```
71
+
65
72
  ## Contributing
66
73
 
67
74
  Bug reports and pull requests are welcome on 0xacab.org at
@@ -7,16 +7,18 @@ require 'open3'
7
7
  class DistributedPress
8
8
  include ::HTTParty
9
9
 
10
+ DEFAULT_URL = 'https://api.distributed.press'
10
11
  NEWLINE = "\r\n"
11
12
  BOUNDARY = '--'
12
13
 
13
- attr_reader :api_key, :project_domain
14
+ attr_reader :api_key, :project_domain, :configure_result, :publish_result
14
15
 
15
16
  # @param options [Hash]
16
17
  # @option options [String] :url API URL
17
18
  # @option options [String] :api_key API Key
18
19
  # @option options [String] :project_domain Domain name
19
- def initialize(url: 'https://api.distributed.press', api_key: nil, project_domain: nil)
20
+ def initialize(url: DEFAULT_URL, api_key: nil, project_domain: nil)
21
+ url ||= DEFAULT_URL
20
22
  @api_key = api_key || ENV['DISTRIBUTED_PRESS_API_KEY']
21
23
  @project_domain = project_domain || ENV['DISTRIBUTED_PRESS_PROJECT_DOMAIN']
22
24
 
@@ -40,9 +42,9 @@ class DistributedPress
40
42
  config.close
41
43
  end
42
44
 
43
- result = upload_io('/v0/publication/configure', stream)
45
+ @configure_result = upload_io('/v0/publication/configure', stream)
44
46
 
45
- result['errorCode'].zero?
47
+ configure_result['errorCode'].zero?
46
48
  end
47
49
 
48
50
  # Publishes a directory by tarballing it on the fly.
@@ -66,11 +68,11 @@ class DistributedPress
66
68
  body.close
67
69
  end
68
70
 
69
- result = upload_io '/v0/publication/publish', stream
71
+ @publish_result = upload_io '/v0/publication/publish', stream
70
72
 
71
73
  # wait
72
74
  thread.value
73
- result['errorCode'].zero?
75
+ publish_result['errorCode'].zero?
74
76
  end
75
77
  end
76
78
 
@@ -3,9 +3,40 @@
3
3
  require 'distributed_press'
4
4
 
5
5
  Jekyll::Hooks.register :site, :post_write, priority: :low do |site|
6
- next unless ENV['JEKYLL_ENV'] == 'production'
7
- if site.config['locales']
8
- next unless site.config['locale'] == site.config['locales'].last
6
+ def logger(message:, level: :info)
7
+ Jekyll.logger.public_send(level, 'Distributed Press:', message)
8
+ end
9
+
10
+ def warn(message)
11
+ logger level: :warn, message: message
12
+ end
13
+
14
+ def debug(message)
15
+ logger level: :debug, message: message
16
+ end
17
+
18
+ def info(message)
19
+ logger message: message
20
+ end
21
+
22
+ unless ENV['JEKYLL_ENV'] == 'production'
23
+ debug "Ignoring publication in #{ENV['JEKYLL_ENV']} mode"
24
+ next
25
+ end
26
+
27
+ # Compatibility with jekyll-locales, only publish on the last locale
28
+ dest = site.dest
29
+ locales_enabled = site.config['plugins'].include?('jekyll-locales')
30
+
31
+ if locales_enabled
32
+ if site.locales?
33
+ if site.locale != site.locales.last
34
+ info "Ignoring #{site.locale}"
35
+ next
36
+ else
37
+ dest = File.realpath(File.join(site.dest, '..'))
38
+ end
39
+ end
9
40
  end
10
41
 
11
42
  hostname = ENV['DISTRIBUTED_PRESS_PROJECT_DOMAIN']
@@ -14,12 +45,19 @@ Jekyll::Hooks.register :site, :post_write, priority: :low do |site|
14
45
 
15
46
  raise URI::Error unless hostname
16
47
 
17
- Jekyll.logger.info 'Distributed Press:', 'Publishing website'
48
+ info 'Publishing website'
18
49
 
19
- distributed_press = DistributedPress.new project_domain: hostname
20
- distributed_press.configure && distributed_press.publish(site.dest)
50
+ distributed_press = DistributedPress.new(url: ENV['DISTRIBUTED_PRESS_API_URL'], project_domain: hostname)
21
51
 
22
- Jekyll.logger.info 'Distributed Press:', 'Published!'
52
+ if distributed_press.configure
53
+ if distributed_press.publish(dest)
54
+ info 'Published!'
55
+ else
56
+ warn distributed_press.publish_result['error']
57
+ end
58
+ else
59
+ warn distributed_press.configure_result['error']
60
+ end
23
61
  rescue URI::Error
24
- Jekyll.logger.warn 'Distributed Press:', '`hostname` or `url` keys missing on _config.yml, skipping publication.'
62
+ warn '`hostname` or `url` keys missing on _config.yml, skipping publication.'
25
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: distributed-press-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-06 00:00:00.000000000 Z
11
+ date: 2022-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -59,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 2.6.0
62
+ version: '2.7'
63
63
  required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="