-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adhere to the plugin file layout suggestions
- Loading branch information
Showing
10 changed files
with
125 additions
and
140 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
## Main | ||
|
||
Nothing so far | ||
#### Changes | ||
* Adhere to plugin file layout suggestions | ||
|
||
## 0.4.3 | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
lib/rodbot/plugins/word_of_the_day/adapters/merriam_webster.rb
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
lib/rodbot/plugins/word_of_the_day/adapters/transparent.rb
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'adapters/base' | ||
require_relative 'adapters/merriam_webster' | ||
require_relative 'adapters/transparent' | ||
|
||
module WordOfTheDay | ||
class Adapter | ||
extend Forwardable | ||
|
||
def_delegator :@adapter, :message, :message | ||
|
||
def initialize(language) | ||
@language = language | ||
@adapter = (language == 'English' ? MerriamWebster : Transparent).new(language) | ||
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'httpx' | ||
|
||
module WordOfTheDay | ||
class Adapter | ||
class Base | ||
attr_reader :language | ||
|
||
def initialize(language) | ||
@language = language.downcase | ||
end | ||
|
||
def message | ||
if word | ||
"[#{word}](#{url}) (#{language.capitalize})" | ||
else | ||
"~~#{language.capitalize}~~" | ||
end | ||
end | ||
end | ||
end | ||
end |
30 changes: 30 additions & 0 deletions
30
lib/rodbot/plugins/word_of_the_day/lib/adapters/merriam_webster.rb
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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module WordOfTheDay | ||
class Adapter | ||
class MerriamWebster < Base | ||
private | ||
|
||
def word | ||
html.match(/<h2 class="word-header-txt">(.+?)</)&.captures&.first | ||
end | ||
|
||
def url | ||
"https://www.merriam-webster.com/word-of-the-day/#{today}" | ||
end | ||
|
||
private | ||
|
||
def today | ||
Time.now.strftime('%F') | ||
end | ||
|
||
def html | ||
case (response = HTTPX.get(url)) | ||
in { status: 200 } then response.body.to_s | ||
else '' | ||
end | ||
end | ||
end | ||
end | ||
end |
50 changes: 50 additions & 0 deletions
50
lib/rodbot/plugins/word_of_the_day/lib/adapters/transparent.rb
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,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module WordOfTheDay | ||
class Adapter | ||
class Transparent < Base | ||
LANGUAGE_CODES = { | ||
'arabic' => 'ar', | ||
'chinese' => 'zh', | ||
'dutch' => 'nl', | ||
'esperanto' => 'esp', | ||
'french' => 'fr', | ||
'german' => 'de', | ||
'irish' => 'ga', | ||
'italian' => 'it', | ||
'japanese' => 'ja', | ||
'latin' => 'la', | ||
'polish' => 'pl', | ||
'portuguese' => 'pt', | ||
'russian' => 'ru', | ||
'spanish' => 'es' | ||
}.freeze | ||
|
||
def word | ||
xml.match(/<word>(.+?)</)&.captures&.first | ||
end | ||
|
||
def url | ||
"https://wotd.transparent.com/widget/?lang=#{language}&date=#{today}" | ||
end | ||
|
||
private | ||
|
||
def today | ||
Time.now.strftime('%m-%d-%Y') | ||
end | ||
|
||
def language_code | ||
LANGUAGE_CODES.fetch(language, language) | ||
end | ||
|
||
def xml | ||
xml_url = "https://wotd.transparent.com/rss/#{today}-#{language_code}-widget.xml" | ||
case (response = HTTPX.get(xml_url)) | ||
in { status: 200 } then response.body.to_s | ||
else '' | ||
end | ||
end | ||
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