Class: Wikian

Inherits:
Object
  • Object
show all
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, InitializeError, MissingSearchTermError, Post, Search, Subcommand, UnknownSubcommandError, WikiFileError, WikiFileNameError, WikiMergeError, WikianError, WikianGetError, WikianPostError, WikianSubcommandError

Constant Summary collapse

CONFIG_FILE =
'wiki.yml'
RESPONSE_FORMAT =
'json'
VERSION =
"0.2.4"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Wikian

Returns a new instance of Wikian.



28
29
30
# File 'lib/wikian.rb', line 28

def initialize(*args)
  @args = args
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



23
24
25
# File 'lib/wikian.rb', line 23

def args
  @args
end

#subcommandObject

Returns the value of attribute subcommand.



23
24
25
# File 'lib/wikian.rb', line 23

def subcommand
  @subcommand
end

Class Method Details

.meta_dirObject



63
64
65
# File 'lib/wikian.rb', line 63

def self.meta_dir
  '.wikian'
end

.meta_fileObject

file to store metadata of fetched articles



68
69
70
# File 'lib/wikian.rb', line 68

def self.meta_file
  File.join(meta_dir, 'meta.yml')
end

Instance Method Details

#helpObject



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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/wikian.rb', line 72

def help
  puts "    Usage:\n      wiki [options] <subcommand>  [url|file]\n\n    Options:\n      -a, --append               append the input file\n      -c, --captcha ID:MESSAGE   captcha info\n      -d, --debug                print debugging messages\n      -f, --force                force post (this ignores edit conflicts)\n      -h, --help                 print this help message\n      -m, --message MESSAGE      add a commit message (HIGHLY recommended)\n      -p, --prepend              prepend the input file\n      -r, --remove-cookie        remove API cookie\n      -s, --section NUMBER       section to edit\n      -t, --template             create template configuration file\n      -v, --version              print version number\n\n    Subcommands:\n      c, contributions [N]    get user last N contributions (defaults to \#{Contributions::DEFAULT_MAX_CONTRIBUTIONS})\n      g, get                  get wikitext from a Wikipedia article\n      p, post                 post wikitext to a Wikipedia article\n      s, search               search wikitext in Wikipedia\n\n    Examples:\n      # create wiki.yml template\n      wi g -t\n\n      # download article\n      wi get -t\n      wi get https://en.wikipedia.org/wiki/Wikipedia:Sandbox\n\n      # upload file\n      wi post Wikipedia:Sandbox.en.wikipedia.org.wiki\n\n      # upload file to Spanish Wikipedia\n      wi post Wikipedia:Sandbox.es.wikipedia.org.wiki\n\n      # upload file to English Wiktionary\n      wi post Wikipedia:Sandbox.en.wiktionary.org.wiki\n\n      # append wikitext to section 2 of the article\n      wi post -a -s 2 Wikipedia:Sandbox.en.wikipedia.org.wiki\n\n      # search for multiple terms in Wikipedia\n      wi search term 1:term 2:term 3\n\n      # heavy use of the API may require cache validation\n      wi post -c 1234:someMessage spider-Man.wiki\n\n    Comments:\n      Posted files must follow the convention:\n        <article_name>.<site>.wiki\n      where <site> is a wikimedia site.\n      More info at: https://meta.wikimedia.org/wiki/Our_projects\n  eos\n  exit\nend\n"

#runObject



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
60
61
# File 'lib/wikian.rb', line 32

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
    api.
  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.message} in #{__FILE__}"
end

#versionObject



131
132
133
134
# File 'lib/wikian.rb', line 131

def version
  puts "wikian #{VERSION}"
  exit
end