Class: Wikian
- Inherits:
-
Object
- Object
- Wikian
- Defined in:
- lib/wikian.rb,
lib/wikian/get.rb,
lib/wikian/post.rb,
lib/wikian/search.rb,
lib/wikian/version.rb,
lib/wikian/subcommand.rb,
lib/wikian/contributions.rb
Defined Under Namespace
Classes: ArgumentRequiredError, BadUrlError, Contributions, ExtractWikiError, Get, MissingConfigFileError, Post, Search, Subcommand, UnknownSubcommandError, WikiFileError, WikianError, WikianGetError, WikianPostError, WikianSubcommandError
Constant Summary collapse
- CONFIG_FILE =
'wiki.yml'- RESPONSE_FORMAT =
'json'- VERSION =
"0.1.7"
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#subcommand ⇒ Object
Returns the value of attribute subcommand.
Instance Method Summary collapse
- #help ⇒ Object
-
#initialize(*args) ⇒ Wikian
constructor
A new instance of Wikian.
- #run ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(*args) ⇒ Wikian
Returns a new instance of Wikian.
27 28 29 |
# File 'lib/wikian.rb', line 27 def initialize(*args) @args = args end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
22 23 24 |
# File 'lib/wikian.rb', line 22 def args @args end |
#subcommand ⇒ Object
Returns the value of attribute subcommand.
22 23 24 |
# File 'lib/wikian.rb', line 22 def subcommand @subcommand end |
Instance Method Details
#help ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 |
# File 'lib/wikian.rb', line 61 def help puts <<~eos Usage: wiki [options] <subcommand> [url|file] Options: -a, --append append the input file -c, --captcha ID:MESSAGE captcha info -d, --debug debug -m, --message MESSAGE add a commit message (HIGHLY recommended) -p, --prepend prepend the input file -r, --remove-cookie remove API cookie -s, --section NUMBER section to edit -t, --template create template configuration file -v, --version Subcommands: c, contributions [N] get user last N contributions. N defaults to 20 g, get get wikitext file from a wikipedia article p, post post wikitext file to a wikipedia article s, search search wikitext file to a wikipedia article Examples: # create wiki.yml template wiki -t # download article and create response and wikitext files wiki get https://en.wikipedia.org/wiki/Spider-Man # upload file to English Wikipedia wiki post Spider-Man.en.wikipedia.org.wiki # upload file to Spanish Wikipedia wiki post Spider-Man.es.wikipedia.org.wiki # upload file to English Wiktionary wiki file to Spider-Man.es.wiktionary.org.wiki # append new section to article wiki post -a Spider-Man-new-section.wiki # heavy use of the API may require cache validation wiki post -c 1234:someMessage spider-Man.wiki Comments: Posted files must follow the convention: <article_name>.<host>.wiki where <host> is a wikimedia site. More info at: https://meta.wikimedia.org/wiki/Our_projects eos exit end |
#run ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/wikian.rb', line 31 def run if args.have?(%w(-h --help)) help elsif args.have?(%w(-v --version)) version end @subcommand = args.shift raise(UnknownSubcommandError, "Unkown Subcommand") unless %w(c g p s contributions get post search).include?(subcommand) if subcommand[0] == 'g' api = Wikian::Get.new(args) api.doit api.extract_wikitext elsif subcommand[0] == 's' api = Wikian::Search.new(args) api.doit elsif subcommand[0] == 'c' api = Wikian::Contributions.new(args) api.doit else api = Wikian::Post.new(args) api.post end rescue UnknownSubcommandError => e puts "#{e.class} #{e.} in #{__FILE__}" end |
#version ⇒ Object
114 115 116 117 |
# File 'lib/wikian.rb', line 114 def version puts "wikian #{VERSION}" exit end |