-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/retry-requests
- Loading branch information
Showing
18 changed files
with
279 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Unipept | ||
class OutputWriter | ||
attr_reader :output | ||
|
||
def initialize(file) | ||
@output = file ? File.open(file, 'a') : $stdout | ||
end | ||
|
||
def write_line(line) | ||
@output.write line | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'typhoeus' | ||
|
||
require_relative 'configuration' | ||
|
||
module Unipept | ||
class ServerMessage | ||
attr_reader :message_url | ||
|
||
attr_reader :configuration | ||
|
||
def initialize(host) | ||
@message_url = "#{host}/api/v1/messages.json" | ||
@configuration = Unipept::Configuration.new | ||
end | ||
|
||
# Checks if the server has a message and prints it if not empty. | ||
# We will only check this once a day and won't print anything if the quiet | ||
# option is set or if we output to a file. | ||
def print | ||
return unless $stdout.tty? | ||
return if recently_fetched? | ||
resp = fetch_server_message | ||
update_fetched | ||
puts resp unless resp.empty? | ||
end | ||
|
||
# Fetches a message from the server and returns it | ||
def fetch_server_message | ||
Typhoeus.get(@message_url, params: { version: Unipept::VERSION }).body.chomp | ||
end | ||
|
||
# Returns true if the last check for a server message was less than a day | ||
# ago. | ||
def recently_fetched? | ||
last_fetched = @configuration['last_fetch_date'] | ||
!last_fetched.nil? && (last_fetched + 60 * 60 * 24) > Time.now | ||
end | ||
|
||
# Updates the last checked timestamp | ||
def update_fetched | ||
@configuration['last_fetch_date'] = Time.now | ||
@configuration.save | ||
end | ||
end | ||
end |
Oops, something went wrong.