Class: Papercall::RestFetcher
Overview
Fetches submissions from Papercall REST API Params:
Constant Summary
collapse
- SUBMISSIONS_URL =
'https://www.papercall.io/api/v1/submissions'.freeze
Instance Attribute Summary
Attributes inherited from Fetcher
#accepted, #declined, #rejected, #submitted, #waitlist
Instance Method Summary
collapse
Methods inherited from Fetcher
#all, #analysis
Constructor Details
Returns a new instance of RestFetcher.
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/papercall/rest_fetcher.rb', line 15
def initialize()
@output = Papercall.configuration.output
api_key = Papercall.configuration.API_KEY
raise ArgumentError, 'Missing API_KEY for access to Papercall. Please refer to documentation for instructions on setting this value.' unless api_key
@auth_hash = { Authorization: api_key }
@submitted = []
@accepted = []
@rejected = []
@waitlist = []
@declined = []
end
|
Instance Method Details
#fetch(*states) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/papercall/rest_fetcher.rb', line 43
def fetch(*states)
states = [i[submitted accepted rejected waitlist declined]] if states == [[:all]]
states.flatten.each do |state|
next unless state
start_time = Time.now
print "Fetching #{state} submissions from PaperCall API..." if @output
submissions = papercall(submission_url(state.to_s))
instance_variable_set("@#{state}_raw", submissions)
instance_variable_set("@#{state}", submissions.map {|s| Submission.new(s)})
puts "finished in #{Time.now - start_time} seconds." if @output
end
fetch_ratings
fetch_feedback
end
|
#fetch_feedback ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/papercall/rest_fetcher.rb', line 73
def fetch_feedback
start_time = Time.now
print 'Fetching feedback for all submissions from Papercall API...' if @output
Parallel.each(analysis, in_threads: 128) do |submission|
if submission.feedback.empty?
feedback_url = "#{SUBMISSIONS_URL}/#{submission.id}/feedback"
submission.feedback = papercall(feedback_url).map {|f| Feedback.new(f)}
end
end
puts "finished in #{Time.now - start_time} seconds." if @output
end
|
#fetch_ratings ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/papercall/rest_fetcher.rb', line 58
def fetch_ratings
start_time = Time.now
print 'Fetching ratings for all submissions from Papercall API...' if @output
Parallel.each(analysis, in_threads: 128) do |submission|
if submission.ratings.empty?
ratings_url = "#{SUBMISSIONS_URL}/#{submission.id}/ratings"
ratings = papercall(ratings_url).map {|r| Rating.new(r)}
submission.ratings = ratings
end
end
puts "finished in #{Time.now - start_time} seconds." if @output
end
|
#papercall(papercall_url) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/papercall/rest_fetcher.rb', line 31
def papercall(papercall_url)
raw_results =
RestClient::Request.execute(method: :get,
url: papercall_url,
headers: @auth_hash)
if raw_results
JSON.parse(raw_results).map {|r| r.with_indifferent_access}
else
[]
end
end
|
#submission_url(state, per_page: 150) ⇒ Object
27
28
29
|
# File 'lib/papercall/rest_fetcher.rb', line 27
def submission_url(state, per_page: 150)
"#{SUBMISSIONS_URL}?state=#{state}&per_page=#{per_page}"
end
|