Class: LairClient::CLI
- Inherits:
-
Object
- Object
- LairClient::CLI
- Includes:
- HTTParty
- Defined in:
- lib/lair_client/cli.rb
Defined Under Namespace
Classes: SourceError
Instance Method Summary collapse
Instance Method Details
#scan(*sources) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lair_client/cli.rb', line 10 def scan *sources = sources.last.is_a?(Hash) ? sources.pop : {} config = YAML.load_file File.join(File.('~'), '.lair.yml') sources << Dir.pwd if sources.empty? check_sources *sources puts puts Paint["Scanning #{sources.length} directories...", :yellow] print Paint["Looking for nfo files...", :yellow] nfo_files = sources.inject([]){ |memo,source| memo + Dir.glob(File.join(source, '**', '*.nfo')) } if nfo_files.length == 0 puts " found none" exit 0 else puts Paint[" found #{nfo_files.length}", :green] end nfo_files = nfo_files[0, 3] nfo_files.each do |nfo_file| url = File.read(nfo_file).strip body = MultiJson.dump contents: { url: url } headers = { 'Content-Type' => 'application/json', 'Authorization' => %/Token token="#{config['api']['key']}"/ } res = self.class.post "#{config['api']['url']}/payloads/items", body: body, headers: headers puts res.code puts res.body if res.code != 200 end puts end |