Module: WikiPluginAdapter
- Includes:
- PluginAdapter
- Defined in:
- lib/lyrics/cli/wikipluginadapter.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(including) ⇒ Object
Hack to make module methods become class methods when the module gets included.
Instance Method Summary collapse
- #check_submit_conditions ⇒ Object
- #set_submit_settings(username, password, review, prompt_autogen, prompt_no_lyrics) ⇒ Object
- #submit? ⇒ Boolean
-
#wiki_process_response(response, response_plugin, wiki_searched) ⇒ Object
returns true if the review contents page is shown to the user (which can only happen when there was something to submit).
Methods included from PluginAdapter
Class Method Details
.included(including) ⇒ Object
Hack to make module methods become class methods when the module gets included
30 31 32 33 34 35 36 |
# File 'lib/lyrics/cli/wikipluginadapter.rb', line 30 def WikiPluginAdapter.included( including ) if including.is_a?( Class ) including.extend( ClassMethods ) # adds class methods else # including.is_a?( Module ) including::ClassMethods.append_class_methods( self ) end end |
Instance Method Details
#check_submit_conditions ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/lyrics/cli/wikipluginadapter.rb', line 52 def check_submit_conditions() if @wpa_submit login( @wpa_username, @wpa_password, false ) else logout() end if ! logged_in? @wpa_submit = false end if ! @wpa_submit || ! @wpa_review @wpa_prompt_no_lyrics = false @wpa_prompt_autogen = false end end |
#set_submit_settings(username, password, review, prompt_autogen, prompt_no_lyrics) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/lyrics/cli/wikipluginadapter.rb', line 69 def set_submit_settings( username, password, review, prompt_autogen, prompt_no_lyrics ) @wpa_submit = true @wpa_review = review @wpa_prompt_autogen = prompt_autogen @wpa_prompt_no_lyrics = prompt_no_lyrics @wpa_username = username @wpa_password = password if ! @wpa_submit || ! @wpa_review @wpa_prompt_no_lyrics = false @wpa_prompt_autogen = false end end |
#submit? ⇒ Boolean
48 49 50 |
# File 'lib/lyrics/cli/wikipluginadapter.rb', line 48 def submit?() return @wpa_submit end |
#wiki_process_response(response, response_plugin, wiki_searched) ⇒ Object
returns true if the review contents page is shown to the user (which can only happen when there was something to submit)
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/lyrics/cli/wikipluginadapter.rb', line 83 def wiki_process_response( response, response_plugin, wiki_searched ) return false if ! submit?() || ! lyrics_found_on_site = response.lyrics && response_plugin == self lyrics_autogenerated = lyrics_found_on_site && ! response.custom_data["reviewed"] return false if lyrics_found_on_site && ! lyrics_autogenerated # we have nothing to do return false if (! @wpa_prompt_autogen && lyrics_autogenerated) || (! @wpa_prompt_no_lyrics && ! response.lyrics) begin check_submit_conditions() song_data = MediaWikiLyrics::SongData.new( response.artist ? response.artist : response.request.artist, response.title ? response.title : response.request.title, response.lyrics, response.album ? response.album : response.request.album, response.year ? response.year : response.request.year, response.custom_data["credits"], response.custom_data["lyricist"] ) submitted_url, submitted_data = submit_song_page( song_data, lyrics_autogenerated ? response.url : nil, # are we editing an existing page or creating a new one? song_data.artist == response.request.artist && song_data.title == response.request.title && wiki_searched && ! lyrics_found_on_site, # do we KNOW FOR SURE the page doesn't exists? @wpa_review || lyrics_autogenerated, # should we show the review contents dialog? lyrics_autogenerated # should user be forced to review contents? (true causes the operation to abort otherwise) ) # transfer summited data to response if submitted_data response.artist = submitted_data["artist"] if ! Strings.empty?( submitted_data["artist"] ) response.title = submitted_data["title"] if ! Strings.empty?( submitted_data["title"] ) response.album = submitted_data["album"] if ! Strings.empty?( submitted_data["album"] ) response.year = submitted_data["year"] if ! Strings.empty?( submitted_data["year"] ) response.lyrics = submitted_data["lyrics"] if ! Strings.empty?( submitted_data["lyrics"] ) custom_data = {} custom_data.merge( response.custom_data ) custom_data["credits"] = submitted_data["credits"] if ! Strings.empty?( submitted_data["credits"] ) custom_data["lyricst"] = submitted_data["lyricst"] if ! Strings.empty?( submitted_data["lyricst"] ) response.custom_data = custom_data end return (@wpa_review || lyrics_autogenerated) && submitted_data rescue TimeoutError notify( I18n.get( "cli.application.plugintimeout", plugin_name(), site_host() ) ) return false end end |