jekyll-indico 0.4.5 → 0.5.0

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
  SHA1:
3
- metadata.gz: 91bed0b6b864fa3f7a1b8dee140c9f9eb791823b
4
- data.tar.gz: 6519f4dd2b0681d3961ce636733701342eed4a7d
3
+ metadata.gz: 4e2a1ea8813f626061be2c5da553cafe9453aaac
4
+ data.tar.gz: '06758dd8b0908b58f065a13a5fc8f8990ff1ab0d'
5
5
  SHA512:
6
- metadata.gz: 1f5064ba79a8af25de947a654f5718e70b48a19533f05afa1cb6739ffd07a9c6c25d4296def57d50b00a5f34e57467629ad048b5d6ed6858d6fbb8811dca7d79
7
- data.tar.gz: 260ecb6e6b9b1801928d0f6eeb204e71217db6f3e6d5fd77128fe750128b976d5401725556054c939cad347f2aebb7071540b35ac4dd08931584d121f35831c1
6
+ metadata.gz: 7f909dd6bffbd0f595c03daa73d2da3fc234a3ff9f72ccca3e35e532a962dada79dc5be4f978b3aa4e4c92edbb6248807d03be92e08658fb7d45c679576a4dc1
7
+ data.tar.gz: 246baf00d16729890482b79743ef9c625e6976c52bf8c336c91b66bfd039c6a6c3f1333f6984e393e8de366b391ce6be2b499b1ddd257a7b50161b42550967ad
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # Version 0.5
2
+
3
+ Added a way to paginate. Use `paginate: N` to iterate over pages of results.
4
+
1
5
  # Version 0.4.5
2
6
 
3
7
  Fix timeout being incorrectly called again.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-indico (0.4.5)
4
+ jekyll-indico (0.5.0)
5
5
  jekyll (>= 3.8, < 5.0)
6
6
 
7
7
  GEM
@@ -54,12 +54,12 @@ GEM
54
54
  public_suffix (4.0.6)
55
55
  rainbow (3.1.1)
56
56
  rake (13.0.6)
57
- rb-fsevent (0.11.0)
57
+ rb-fsevent (0.11.1)
58
58
  rb-inotify (0.10.1)
59
59
  ffi (~> 1.0)
60
60
  regexp_parser (2.2.0)
61
61
  rexml (3.2.5)
62
- rouge (3.27.0)
62
+ rouge (3.28.0)
63
63
  rspec (3.10.0)
64
64
  rspec-core (~> 3.10.0)
65
65
  rspec-expectations (~> 3.10.0)
data/README.md CHANGED
@@ -14,6 +14,8 @@ indico:
14
14
  url: https://indico.cern.ch # Indico instance to use (REQUIRED)
15
15
  data: indico # Optional, folder name in _data to use
16
16
  cache-command: bundle exec rake cache # Optional, user msg if you support it
17
+ paginate: 20 # Optional integer number of results per page (auto-iterates over all pages)
18
+ timeout: 120 # Optional timeout in number of seconds (default: 60)
17
19
  ids:
18
20
  topical: 10570
19
21
  blueprint: 11329
@@ -23,10 +23,10 @@ module JekyllIndico
23
23
  attr_accessor :dict
24
24
 
25
25
  # ID for IRIS-HEP: 10570
26
- def initialize(base_url, indico_id, **kargs)
26
+ def initialize(base_url, indico_id, limit: nil, **kargs)
27
27
  @dict = {}
28
28
 
29
- download_and_iterate(base_url, indico_id, **kargs) do |i|
29
+ download_and_iterate(base_url, indico_id, limit: limit, **kargs) do |i|
30
30
  # Trim paragraph tags
31
31
  d = i['description']
32
32
  d = d[3..-1] if d.start_with? '<p>'
@@ -62,9 +62,10 @@ module JekyllIndico
62
62
 
63
63
  private
64
64
 
65
- # Run a block over each item in the downloaded results
66
- def download_and_iterate(base_url, indico_id, timeout: nil, **params, &block)
67
- params[:pretty] = 'no'
65
+ def get_parsed_results(base_url, indico_id, timeout: nil, **params)
66
+ opts = { use_ssl: true }
67
+ opts[:read_timeout] = timeout if timeout
68
+
68
69
  uri = URI.join(base_url, "/export/categ/#{indico_id}.json")
69
70
  uri.query = URI.encode_www_form(params)
70
71
 
@@ -75,15 +76,29 @@ module JekyllIndico
75
76
  raise Error, 'Use INDICO_TOKEN with a new-style token'
76
77
  end
77
78
 
78
- opts = { use_ssl: true }
79
- opts[:read_timeout] = timeout if timeout
80
-
81
79
  response = Net::HTTP.start(uri.hostname, uri.port, **opts) { |http| http.request(req) }
82
80
 
83
- string = response.body
84
- parsed = JSON.parse(string) # returns a hash
81
+ parsed = JSON.parse(response.body)
82
+ parsed['results']
83
+ end
84
+
85
+ # Run a block over each item in the downloaded results
86
+ def download_and_iterate(base_url, indico_id, limit: nil, **params, &block)
87
+ params[:limit] = limit if limit
88
+ params[:pretty] = 'no'
85
89
 
86
- parsed['results'].each(&block)
90
+ unless limit
91
+ results = get_parsed_results(base_url, indico_id, **params)
92
+ results.each(&block)
93
+ return
94
+ end
95
+
96
+ 0.step.each do |n|
97
+ results = get_parsed_results(base_url, indico_id, offset: n * limit, **params)
98
+ break if results.empty?
99
+
100
+ results.each(&block)
101
+ end
87
102
  end
88
103
  end
89
104
  end
@@ -35,6 +35,7 @@ module JekyllIndico
35
35
  @site.data[data_path] = {} unless @site.data.key? data_path
36
36
 
37
37
  timeout = @site.config.dig('indico', 'timeout')
38
+ limit = @site.config.dig('indico', 'paginate')
38
39
 
39
40
  # Do nothing if already downloaded
40
41
  return if @site.data[data_path].key? name
@@ -42,7 +43,7 @@ module JekyllIndico
42
43
  msg = @cache_msg ? " - run `#{@cache_msg}` to cache" : ''
43
44
  print "Accessing Indico meeting API for #{name}:#{number}#{msg}"
44
45
  time = Benchmark.realtime do
45
- iris_meeting = Meetings.new(base_url, number, timeout: timeout)
46
+ iris_meeting = Meetings.new(base_url, number, timeout: timeout, limit: limit)
46
47
  @site.data[data_path][name] = iris_meeting.dict
47
48
  end
48
49
  puts ", took #{time.round(1)} s"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllIndico
4
- VERSION = '0.4.5'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-indico
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Schreiner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-02 00:00:00.000000000 Z
11
+ date: 2022-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll