class JekyllIndico::Meetings
Look for topical meetings
Attributes
dict[RW]
Public Class Methods
base_url(config = {})
click to toggle source
Get base URL from a config
# File lib/jekyll-indico/core.rb, line 66 def self.base_url(config = {}) url = config.dig('indico', 'url') raise MissingURL('indico: url: MISSING from your config!') unless url url end
meeting_ids(config = {})
click to toggle source
Get meeting ids from a config
# File lib/jekyll-indico/core.rb, line 61 def self.meeting_ids(config = {}) config.dig('indico', 'ids') end
new(base_url, indico_id, **kargs)
click to toggle source
ID for IRIS-HEP: 10570
# File lib/jekyll-indico/core.rb, line 23 def initialize(base_url, indico_id, **kargs) @dict = {} download_and_iterate(base_url, indico_id, **kargs) do |i| # Trim paragraph tags d = i['description'] d = d[3..-1] if d.start_with? '<p>' d = d[0..-5] if d.end_with? '</p>' start_date = Date.parse i['startDate']['date'] fname = start_date.strftime('%Y%m%d').to_s youtube = '' urllist = URI.extract(d) urllist.each do |url| youtube = url if url.include?('youtube') || url.include?('youtu.be') end @dict[fname] = { 'name' => i['title'], 'startdate' => start_date, 'meetingurl' => i['url'], 'location' => i['location'], 'youtube' => youtube, 'description' => d } end end
Public Instance Methods
to_files(folder) { |key| ... }
click to toggle source
Write out files (Folder given, by key name)
# File lib/jekyll-indico/core.rb, line 53 def to_files(folder) @dict.each do |key, dict| yield key if block_given? File.write(folder / "#{key}.yml", dict.to_yaml) end end
Private Instance Methods
build_url(base_url, indico_id, **kargs)
click to toggle source
Automatically signs request if environment has INDICO_API/SECRET_KEY
# File lib/jekyll-indico/core.rb, line 94 def build_url(base_url, indico_id, **kargs) kargs[:pretty] = 'no' if ENV['INDICO_API_KEY'] kargs[:ak] = ENV['INDICO_API_KEY'] if ENV['INDICO_SECRET_KEY'] kargs[:timestamp] = Time.new.to_i.to_s requeststr = join_url(indico_id, kargs) kargs[:signature] = OpenSSL::HMAC.hexdigest('SHA1', ENV['INDICO_SECRET_KEY'], requeststr) end end "#{base_url}#{join_url(indico_id, kargs)}" end
download_and_iterate(base_url, indico_id, **kargs, &block)
click to toggle source
Run a block over each item in the downloaded results
# File lib/jekyll-indico/core.rb, line 76 def download_and_iterate(base_url, indico_id, **kargs, &block) url = build_url(base_url, indico_id, **kargs) uri = URI.parse(url) response = Net::HTTP.get_response(uri) string = response.body parsed = JSON.parse(string) # returns a hash parsed['results'].each(&block) end
join_url(indico_id, options)
click to toggle source
Put together a dict and an indico ID
# File lib/jekyll-indico/core.rb, line 88 def join_url(indico_id, options) apicall = options.sort.to_h.map { |k, v| "#{k}=#{v}" }.join('&') "/export/categ/#{indico_id}.json?#{apicall}" end