lair 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7200fbe9e5d135374b48d2a2b2a4451ccacd41b2
4
+ data.tar.gz: c4cea286ae986eade844abd230f0a43cd272ab66
5
+ SHA512:
6
+ metadata.gz: 07ed10d866f70af79eef1e5551e1c905e551d3848b3ff129b4e6add798d2adb999c6dbfabdf0faab0255f0e8a17f5c4548fbb56d4c5f06482c616c15ab6ea9fd
7
+ data.tar.gz: 204abf26fbbb53631e651f47bfed14bee752272ebf903fb4d350f8be424cfd138949821bffa55699444a52ccf76a362a7090508f6e28e7d0aa29b02deaf48624
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'paint', '~> 0.8.5'
7
+ gem 'commander', '~> 4.1.2'
8
+ gem 'which_works', '~> 1.0.0'
9
+ gem 'httparty', '~> 0.12.0'
10
+ gem 'oj', '~> 2.5.4'
11
+ gem 'multi_json', '~> 1.8.4'
12
+
13
+ # Add dependencies to develop your gem here.
14
+ # Include everything needed to run rake, tests, features, etc.
15
+ group :development do
16
+ gem 'bundler'
17
+ gem 'rake'
18
+ gem 'rspec'
19
+ gem 'jeweler'
20
+ gem 'rake-version'
21
+ gem 'simplecov'
22
+ gem 'fakefs', require: 'fakefs/safe'
23
+ gem 'coveralls', require: false
24
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Simon Oulevay (Alpha Hydrae)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,11 @@
1
+ # lair-client
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/lair.png)](http://badge.fury.io/rb/lair)
4
+ [![Dependency Status](https://gemnasium.com/AlphaHydrae/lair.png)](https://gemnasium.com/AlphaHydrae/lair)
5
+ [![Build Status](https://secure.travis-ci.org/AlphaHydrae/lair-client.png)](http://travis-ci.org/AlphaHydrae/lair-client)
6
+ [![Coverage Status](https://coveralls.io/repos/AlphaHydrae/lair-client/badge.png?branch=master)](https://coveralls.io/r/AlphaHydrae/lair-client?branch=master)
7
+
8
+ ## Meta
9
+
10
+ * **Author:** Simon Oulevay (Alpha Hydrae)
11
+ * **License:** MIT (see [LICENSE.txt](https://raw.github.com/AlphaHydrae/lair-client/master/LICENSE.txt))
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'lair_client')
3
+ LairClient::Program.new.run!
@@ -0,0 +1,21 @@
1
+ require 'paint'
2
+
3
+ module LairClient
4
+ VERSION = '0.1.0'
5
+
6
+ class Error < StandardError
7
+ attr_reader :code
8
+
9
+ def self.default_code code = nil
10
+ @default_code = code if code
11
+ @default_code || 1
12
+ end
13
+
14
+ def initialize msg, code = nil
15
+ super msg
16
+ @code = code || self.class.default_code
17
+ end
18
+ end
19
+ end
20
+
21
+ Dir[File.join File.dirname(__FILE__), File.basename(__FILE__, '.*'), '*.rb'].each{ |lib| require lib }
@@ -0,0 +1,66 @@
1
+ require 'httparty'
2
+ require 'multi_json'
3
+ require 'oj'
4
+
5
+ module LairClient
6
+
7
+ class CLI
8
+ include HTTParty
9
+
10
+ def scan *sources
11
+
12
+ options = sources.last.is_a?(Hash) ? sources.pop : {}
13
+
14
+ config = YAML.load_file File.join(File.expand_path('~'), '.lair.yml')
15
+
16
+ sources << Dir.pwd if sources.empty?
17
+ check_sources *sources
18
+
19
+ puts
20
+ puts Paint["Scanning #{sources.length} directories...", :yellow]
21
+
22
+ print Paint["Looking for nfo files...", :yellow]
23
+ nfo_files = sources.inject([]){ |memo,source| memo + Dir.glob(File.join(source, '**', '*.nfo')) }
24
+
25
+ if nfo_files.length == 0
26
+ puts " found none"
27
+ exit 0
28
+ else
29
+ puts Paint[" found #{nfo_files.length}", :green]
30
+ end
31
+
32
+ nfo_files = nfo_files[0, 3]
33
+
34
+ nfo_files.each do |nfo_file|
35
+
36
+ url = File.read(nfo_file).strip
37
+ body = MultiJson.dump contents: { url: url }
38
+ headers = { 'Content-Type' => 'application/json', 'Authorization' => %/Token token="#{config['api']['key']}"/ }
39
+ res = self.class.post "#{config['api']['url']}/payloads/items", body: body, headers: headers
40
+
41
+ puts res.code
42
+ puts res.body if res.code != 200
43
+ end
44
+
45
+ puts
46
+ end
47
+
48
+ private
49
+
50
+ def check_sources *sources
51
+ sources.each do |source|
52
+ if !File.exists? source
53
+ raise SourceError, "No such directory #{source.inspect}"
54
+ elsif !File.directory? source
55
+ raise SourceError, "#{source.inspect} is not a directory"
56
+ elsif !File.readable? source
57
+ raise SourceError, "You do not have permission to read #{source.inspect}"
58
+ end
59
+ end
60
+ end
61
+
62
+ class SourceError < Error
63
+ default_code 2
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: UTF-8
2
+ require 'commander'
3
+
4
+ class LairClient::Program < Commander::Runner
5
+
6
+ GLOBAL_OPTIONS = [ :config, :verbose ]
7
+ BACKTRACE_NOTICE = ' (use --trace to view backtrace)'
8
+
9
+ include Commander::UI
10
+ include Commander::UI::AskForClass
11
+
12
+ def initialize argv = ARGV
13
+ super argv
14
+
15
+ program :name, 'lair'
16
+ program :version, LairClient::VERSION
17
+ program :description, 'Lair client.'
18
+
19
+ global_option '-c', '--config PATH', 'Use a custom configuration file (defaults to ~/.lair.yml)'
20
+ global_option '--verbose', 'Increase verbosity'
21
+
22
+ command :scan do |c|
23
+ c.syntax = 'lair scan'
24
+ c.description = 'Scan files'
25
+ c.action do |args,options|
26
+ to_trace_or_not_to_trace options.trace do
27
+ cli.scan *args, extract(options)
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def cli
36
+ LairClient::CLI.new
37
+ end
38
+
39
+ def to_trace_or_not_to_trace trace = false
40
+ if trace
41
+ yield
42
+ else
43
+ begin
44
+ yield
45
+ rescue ::LairClient::Error => e
46
+ warn Paint["#{e.message}#{BACKTRACE_NOTICE}", :red]
47
+ exit e.code
48
+ end
49
+ end
50
+ end
51
+
52
+ def extract *args
53
+ options = args.pop
54
+ (args | GLOBAL_OPTIONS).inject({}){ |memo,k| memo[k] = options.__send__(k); memo }.reject{ |k,v| v.nil? }
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,250 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lair
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Oulevay
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: commander
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 4.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 4.1.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: which_works
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.12.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.12.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: oj
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.5.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.5.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: multi_json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.4
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.4
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: jeweler
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rake-version
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: fakefs
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: coveralls
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ description: Lair ruby client.
210
+ email: simon.oulevay@gmail.com
211
+ executables:
212
+ - lair
213
+ extensions: []
214
+ extra_rdoc_files:
215
+ - LICENSE.txt
216
+ - README.md
217
+ files:
218
+ - Gemfile
219
+ - LICENSE.txt
220
+ - README.md
221
+ - VERSION
222
+ - bin/lair
223
+ - lib/lair_client.rb
224
+ - lib/lair_client/cli.rb
225
+ - lib/lair_client/program.rb
226
+ homepage: http://github.com/AlphaHydrae/lair-client
227
+ licenses:
228
+ - MIT
229
+ metadata: {}
230
+ post_install_message:
231
+ rdoc_options: []
232
+ require_paths:
233
+ - lib
234
+ required_ruby_version: !ruby/object:Gem::Requirement
235
+ requirements:
236
+ - - ">="
237
+ - !ruby/object:Gem::Version
238
+ version: '0'
239
+ required_rubygems_version: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ requirements: []
245
+ rubyforge_project:
246
+ rubygems_version: 2.2.1
247
+ signing_key:
248
+ specification_version: 4
249
+ summary: Lair client.
250
+ test_files: []