veye 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +51 -0
  4. data/README.md +271 -0
  5. data/README.rdoc +6 -0
  6. data/Rakefile +44 -0
  7. data/bin/veye +390 -0
  8. data/lib/veye/api/base_resource.rb +29 -0
  9. data/lib/veye/api/json_response.rb +56 -0
  10. data/lib/veye/api/resource.rb +22 -0
  11. data/lib/veye/api.rb +3 -0
  12. data/lib/veye/package/follow.rb +50 -0
  13. data/lib/veye/package/info.rb +50 -0
  14. data/lib/veye/package/info_csv.rb +18 -0
  15. data/lib/veye/package/info_json.rb +14 -0
  16. data/lib/veye/package/info_pretty.rb +27 -0
  17. data/lib/veye/package/info_table.rb +29 -0
  18. data/lib/veye/package/search.rb +46 -0
  19. data/lib/veye/package/search_csv.rb +33 -0
  20. data/lib/veye/package/search_json.rb +19 -0
  21. data/lib/veye/package/search_pretty.rb +35 -0
  22. data/lib/veye/package/search_table.rb +40 -0
  23. data/lib/veye/package.rb +23 -0
  24. data/lib/veye/pagination/pagination_csv.rb +17 -0
  25. data/lib/veye/pagination/pagination_json.rb +12 -0
  26. data/lib/veye/pagination/pagination_pretty.rb +22 -0
  27. data/lib/veye/pagination/pagination_table.rb +22 -0
  28. data/lib/veye/pagination/show.rb +26 -0
  29. data/lib/veye/pagination.rb +7 -0
  30. data/lib/veye/project/check.rb +147 -0
  31. data/lib/veye/project/licence.rb +48 -0
  32. data/lib/veye/project/project_csv.rb +28 -0
  33. data/lib/veye/project/project_dependency_csv.rb +25 -0
  34. data/lib/veye/project/project_dependency_json.rb +12 -0
  35. data/lib/veye/project/project_dependency_pretty.rb +30 -0
  36. data/lib/veye/project/project_dependency_table.rb +27 -0
  37. data/lib/veye/project/project_json.rb +13 -0
  38. data/lib/veye/project/project_licence_csv.rb +19 -0
  39. data/lib/veye/project/project_licence_json.rb +12 -0
  40. data/lib/veye/project/project_licence_pretty.rb +23 -0
  41. data/lib/veye/project/project_licence_table.rb +29 -0
  42. data/lib/veye/project/project_pretty.rb +28 -0
  43. data/lib/veye/project/project_table.rb +30 -0
  44. data/lib/veye/project.rb +11 -0
  45. data/lib/veye/service.rb +14 -0
  46. data/lib/veye/user/favorite_csv.rb +28 -0
  47. data/lib/veye/user/favorite_json.rb +14 -0
  48. data/lib/veye/user/favorite_pretty.rb +25 -0
  49. data/lib/veye/user/favorite_table.rb +28 -0
  50. data/lib/veye/user/me.rb +75 -0
  51. data/lib/veye/user/profile_csv.rb +21 -0
  52. data/lib/veye/user/profile_json.rb +14 -0
  53. data/lib/veye/user/profile_pretty.rb +31 -0
  54. data/lib/veye/user/profile_table.rb +34 -0
  55. data/lib/veye/user.rb +7 -0
  56. data/lib/veye/version.rb +13 -0
  57. data/lib/veye.rb +82 -0
  58. data/test/default_test.rb +14 -0
  59. data/test/files/Gemfile +20 -0
  60. data/test/files/maven-1.0.1.pom +128 -0
  61. data/test/test_helper.rb +9 -0
  62. data/veye.rdoc +5 -0
  63. metadata +229 -0
@@ -0,0 +1,12 @@
1
+ module Veye
2
+ module Project
3
+ class ProjectLicenceJSON
4
+ def before; end
5
+ def after; end
6
+
7
+ def format(results)
8
+ printf("%s\n", {"licences" => results["licenses"]}.to_json)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ require 'rainbow'
2
+
3
+ module Veye
4
+ module Project
5
+ class ProjectLicencePretty
6
+ def before; end
7
+ def after; end
8
+
9
+ def format(results)
10
+
11
+ n = 1
12
+ results["licenses"].each_pair do |licence, products|
13
+ product_keys = products.map {|prod| prod["prod_key"]}
14
+ licence_name = "#{licence}".foreground(:green).bright
15
+ printf("%3d - %s\n", n, licence_name)
16
+ printf("\t%-15s : %s\n", "Products", product_keys.join(", "))
17
+
18
+ n += 1
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ require 'terminal-table'
2
+
3
+ module Veye
4
+ module Project
5
+ class ProjectLicenceTable
6
+ def before
7
+ @@table = Terminal::Table.new :title => "Licences",
8
+ :headings => %w(index licence product_keys)
9
+
10
+ @@table.align_column(0, :right)
11
+ end
12
+
13
+ def after
14
+ puts @@table.to_s
15
+ end
16
+
17
+ def format(results)
18
+ n = 1
19
+ results["licenses"].each_pair do |licence, products|
20
+ products.each do |prod|
21
+ row = [n, licence, prod["prod_key"]]
22
+ @@table << row
23
+ end
24
+ n += 1
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ require 'rainbow'
2
+
3
+ module Veye
4
+ module Project
5
+ class ProjectPretty
6
+ def before; end
7
+ def after; end
8
+
9
+ def format(results)
10
+ results = [results] if results.is_a? Hash
11
+
12
+ results.each_with_index do |result, index|
13
+ project_name = "#{result['name']}".foreground(:green).bright
14
+ printf("%3d - %s\n", index + 1, project_name)
15
+ printf("\t%-15s: %s\n", "Project key", "#{result['project_key']}".bright)
16
+ printf("\t%-15s: %s\n", "Project type", result['project_type'])
17
+ printf("\t%-15s: %s\n", "Private", result['private'])
18
+ printf("\t%-15s: %s\n", "Period", result['period'])
19
+ printf("\t%-15s: %s\n", "Source", result['source'])
20
+ printf("\t%-15s: %s\n", "Dependencies", result['dep_number'])
21
+ printf("\t%-15s: %s\n", "Outdated", result['out_number'])
22
+ printf("\t%-15s: %s\n", "Created", result['created_at'])
23
+
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ require 'terminal-table'
2
+
3
+ module Veye
4
+ module Project
5
+ class ProjectTable
6
+ def before
7
+ @@table = Terminal::Table.new :title => "Projects",
8
+ :headings => %w(index name project_key private period source dependencies outdated created_at)
9
+
10
+ @@table.align_column(0, :right)
11
+ end
12
+
13
+ def after
14
+ puts @@table.to_s
15
+ end
16
+
17
+ def format(results)
18
+ results = [results] if results.is_a? Hash
19
+
20
+ results.each_with_index do |result, index|
21
+ row = [index + 1, result['name'], result['project_key'], result['private'],
22
+ result['period'], result['source'], result['dep_number'],
23
+ result['out_number'], result['created_at']]
24
+ @@table << row
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,11 @@
1
+ require_relative 'project/check.rb'
2
+ require_relative 'project/licence.rb'
3
+
4
+ module Veye
5
+ module Project
6
+ RESOURCE_PATH = "/projects"
7
+ MAX_FILE_SIZE = 500000 # ~ 500kB
8
+ end
9
+ end
10
+
11
+
@@ -0,0 +1,14 @@
1
+ module Veye
2
+ class Service
3
+ RESOURCE_PATH = "/services"
4
+ def self.ping(n = 1)
5
+ public_api = API::Resource.new RESOURCE_PATH
6
+ api_respond = "no idea"
7
+ public_api.resource['/ping'].get do |response, request, result, &block|
8
+ api_respond = API::JSONResponse.new(request, result, response)
9
+ end
10
+
11
+ return api_respond
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ module Veye
2
+ module User
3
+ class FavoriteCSV
4
+ def before
5
+ printf("index,name,prod_key,prod_type,version,language\n")
6
+ end
7
+ def after; end
8
+
9
+ def make_row(result, index = 1)
10
+ row = sprintf("%d,%s,%s,%s,%s,%s",
11
+ index + 1,
12
+ result['name'],
13
+ result['prod_key'],
14
+ result['prod_type'],
15
+ result['version'],
16
+ result['language']
17
+ )
18
+ row
19
+ end
20
+
21
+ def format(results)
22
+ results = [results] if results.is_a? Hash
23
+ results.each_with_index {|result, index| printf("%s\n", make_row(result, index))}
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,14 @@
1
+ module Veye
2
+ module User
3
+ class FavoriteJSON
4
+ def before; end
5
+ def after; end
6
+
7
+ def format(results)
8
+ results = [results] if results.is_a? Hash
9
+ printf("%s\n", {"favorites" => results}.to_json)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,25 @@
1
+ require 'rainbow'
2
+
3
+ module Veye
4
+ module User
5
+ class FavoritePretty
6
+ def before; end
7
+ def after; end
8
+
9
+ def show_favorite(fav, index)
10
+ printf("\t%15s - %s\n",
11
+ "#{fav['name']}".foreground(:green).bright,
12
+ "#{fav['prod_key'].bright}")
13
+ puts "\t-------------------------"
14
+ printf("\t%-15s: %s\n", "Product type", fav['prod_type'])
15
+ printf("\t%-15s: %s\n", "Version", "#{fav['prod_type']}".bright)
16
+ printf("\t%-15s: %s\n", "Language", fav['language'])
17
+ end
18
+
19
+ def format(results)
20
+ results = [results] if results.is_a? Hash
21
+ results.each_with_index {|fav, index| show_favorite(fav, index)}
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ require 'terminal-table'
2
+
3
+ module Veye
4
+ module User
5
+ class FavoriteTable
6
+ def before
7
+ @@table = Terminal::Table.new :title => "Favorite packages",
8
+ :headings => %w(nr name product_key version language)
9
+ @@table.align_column(0, :right)
10
+ end
11
+
12
+ def after
13
+ puts @@table.to_s
14
+ end
15
+
16
+ def make_row(fav, index)
17
+ row = [index + 1, fav['name'], fav['prod_key'], fav['version'], fav['language']]
18
+ row
19
+ end
20
+
21
+ def format(results)
22
+ results = [results] if results.is_a? Hash
23
+ results.each_with_index {|fav, index| @@table << make_row(fav, index)}
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,75 @@
1
+ require_relative 'profile_csv.rb'
2
+ require_relative 'profile_json.rb'
3
+ require_relative 'profile_pretty.rb'
4
+ require_relative 'profile_table.rb'
5
+
6
+ require_relative 'favorite_csv.rb'
7
+ require_relative 'favorite_json.rb'
8
+ require_relative 'favorite_pretty.rb'
9
+ require_relative 'favorite_table.rb'
10
+
11
+ module Veye
12
+ module User
13
+ class Me
14
+ @@profile_formats = {
15
+ 'csv' => ProfileCSV.new,
16
+ 'json' => ProfileJSON.new,
17
+ 'pretty' => ProfilePretty.new,
18
+ 'table' => ProfileTable.new
19
+ }
20
+
21
+ @@favorite_formats = {
22
+ 'csv' => FavoriteCSV.new,
23
+ 'json' => FavoriteJSON.new,
24
+ 'pretty' => FavoritePretty.new,
25
+ 'table' => FavoriteTable.new
26
+ }
27
+
28
+ def self.get_profile(api_key)
29
+ user_api = API::Resource.new(RESOURCE_PATH)
30
+ response_data = nil
31
+ qparams = {:params => {:api_key => api_key}}
32
+
33
+ user_api.resource.get(qparams) do |response, request, result|
34
+ response_data = API::JSONResponse.new(request, result, response)
35
+ end
36
+
37
+ return response_data
38
+ end
39
+
40
+ def self.get_favorites(api_key, page = 1)
41
+ user_api = API::Resource.new(RESOURCE_PATH)
42
+ response_data = nil
43
+ qparams = {
44
+ :params => {
45
+ :api_key => api_key,
46
+ :page => page || 1
47
+ }
48
+ }
49
+
50
+ user_api.resource['/favorites'].get(qparams) do |response, request, result|
51
+ response_data = API::JSONResponse.new(request, result, response)
52
+ end
53
+
54
+ return response_data
55
+ end
56
+
57
+ def self.format_profile(results, format = 'pretty')
58
+ formatter = @@profile_formats[format]
59
+ formatter.before
60
+ formatter.format(results)
61
+ formatter.after
62
+ end
63
+
64
+ def self.format_favorites(results, format = 'pretty')
65
+ formatter = @@favorite_formats[format]
66
+
67
+ formatter.before
68
+ formatter.format results
69
+ formatter.after
70
+ end
71
+
72
+ end
73
+ end
74
+ end
75
+
@@ -0,0 +1,21 @@
1
+ module Veye
2
+ module User
3
+ class ProfileCSV
4
+ def before
5
+ printf("index,username,fullname,email,plan_name_id,admin,new_notifications,total_notifications\n")
6
+ end
7
+ def after; end
8
+
9
+ def format(results)
10
+ results = [results] if results.is_a? Hash
11
+
12
+ results.each_with_index do |result, index|
13
+ printf("%d,%s,%s,%s,%s,%s,%s,%s\n",
14
+ index + 1, result['username'], result['fullname'], result['email'],
15
+ result['plan_name_id'], result['admin'],
16
+ result['notifications']['new'],result['notifications']['total'])
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ module Veye
2
+ module User
3
+ class ProfileJSON
4
+ def before; end
5
+ def after; end
6
+
7
+ def format(results)
8
+ results = [results] if results.is_a? Hash
9
+ printf("%s\n", {"profiles" => results}.to_json)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,31 @@
1
+ require 'rainbow'
2
+
3
+ module Veye
4
+ module User
5
+ class ProfilePretty
6
+ def before; end
7
+ def after; end
8
+
9
+ def show_profile(profile, index)
10
+ printf("\t%15s - %s\n",
11
+ "#{profile['username']}".foreground(:green).bright,
12
+ "#{profile['fullname'].bright}")
13
+ puts "\t-------------------------"
14
+ printf("\t%-15s: %s\n", "Email", profile['email'])
15
+ printf("\t%-15s: %s\n", "Plan name", profile['plan_name_id'])
16
+ printf("\t%-15s: %s\n", "Admin", profile['admin'])
17
+ printf("\t%-15s: %s\n", "Deleted", profile['deleted'])
18
+ printf("\t%-15s: %s\n", "New notif.s",
19
+ "#{profile['notifications']['new']}".bright)
20
+ printf("\t%-15s: %s\n", "Total notif.s",
21
+ profile['notifications']['total'])
22
+ end
23
+
24
+ def format(results)
25
+ results = [results] if results.is_a? Hash
26
+ results.each_with_index {|profile, index| show_profile(profile, index)}
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,34 @@
1
+ require 'terminal-table'
2
+
3
+ module Veye
4
+ module User
5
+ class ProfileTable
6
+ def before
7
+ @@table = Terminal::Table.new :title => "User's profile",
8
+ :headings => %w(nr username fullname email plan_name, admin, deleted, new_notifications, total_notifications)
9
+
10
+ @@table.align_column(0, :right)
11
+ end
12
+
13
+ def after
14
+ puts @@table.to_s
15
+ end
16
+
17
+ def make_row(profile, index)
18
+ row = [index + 1, profile['username'], profile['fullname'], profile['email']]
19
+ row << profile['plan_name_id']
20
+ row << profile['admin']
21
+ row << profile['deleted']
22
+ row << profile['notifications']['new']
23
+ row << profile['notifications']['total']
24
+ return row
25
+ end
26
+
27
+ def format(results)
28
+ results = [results] if results.is_a? Hash
29
+ results.each_with_index {|profile, index| @@table << make_row(profile, index)}
30
+ end
31
+ end
32
+ end
33
+ end
34
+
data/lib/veye/user.rb ADDED
@@ -0,0 +1,7 @@
1
+ require_relative 'user/me.rb'
2
+
3
+ module Veye
4
+ module User
5
+ RESOURCE_PATH = "/me"
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ module Veye
2
+ VERSION = '0.0.2'
3
+ BIGEYE = %q{
4
+
5
+ _ __ _ ______
6
+ | | / /___ _____ _____ (_)____ ____ / ____/__ __ ___
7
+ | | / // _ \ / ___// ___// // __ \ / __ \ / __/ / / / // _ \
8
+ | |/ // __// / (__ )/ // /_/ // / / // /___ / /_/ // __/
9
+ |___/ \___//_/ /____//_/ \____//_/ /_//_____/ \__, / \___/
10
+ /____/
11
+ }
12
+
13
+ end
data/lib/veye.rb ADDED
@@ -0,0 +1,82 @@
1
+ # Add requires for other files you add to your project here, so
2
+ # you just need to require this one file in your bin file
3
+ require 'veye/version.rb'
4
+ require 'veye/service.rb'
5
+ require 'veye/api.rb'
6
+ require 'veye/package.rb'
7
+ require 'veye/project.rb'
8
+ require 'veye/user.rb'
9
+ require 'veye/pagination.rb'
10
+
11
+ $global_options ||= nil
12
+ DEFAULT_CONFIG_FILE = ".veye.rc"
13
+ DEFAULT_CONFIG_PATH = "~"
14
+
15
+ def get_config_fullpath
16
+ File.expand_path("#{DEFAULT_CONFIG_PATH}/#{DEFAULT_CONFIG_FILE}")
17
+ end
18
+
19
+ def config_exists?
20
+ filepath = get_config_fullpath
21
+ File.exists?(filepath)
22
+ end
23
+
24
+ def self.check_configs(global_opts)
25
+ unless config_exists?
26
+ msg = sprintf("%s: %s\n",
27
+ "config file doesnt exist. ".foreground(:red),
28
+ "Use `veye initconfig` to initialize settings file.")
29
+ exit_now!(msg)
30
+ end
31
+ check_api_key(global_opts)
32
+
33
+ true
34
+ end
35
+
36
+ def init_environment
37
+ #sets up required variables and modules to work on IRB or unittest
38
+ config_file = get_config_fullpath
39
+ $global_options = YAML.load_file(config_file)
40
+ $global_options[:config_file] = config_file
41
+ $global_options[:url] = Veye::API::Resource.build_url($global_options)
42
+
43
+ $global_options
44
+ end
45
+
46
+ def check_api_key(global_opts)
47
+ result = false
48
+ if global_opts[:api_key].nil? or global_opts[:api_key].match("add your api key")
49
+ msg = sprintf("%s: %s\n",
50
+ "Warning: API key is missing.".foreground(:yellow),
51
+ "You cant access private data.")
52
+ print msg
53
+ else
54
+ result = true
55
+ end
56
+
57
+ result
58
+ end
59
+
60
+ def update_api_key
61
+ user_key = gets.chomp.to_s.strip
62
+ if user_key =~ /No/i
63
+ msg = sprintf("%s: %s",
64
+ "Warning:".foreground(:yellow),
65
+ " missing, you cant access private data.")
66
+ print msg
67
+ else
68
+ $global_options[:api_key] = user_key
69
+ save_configs
70
+ end
71
+ end
72
+
73
+ def save_configs
74
+ filepath = get_config_fullpath
75
+ File.open(filepath, 'w') do |f|
76
+ f.puts $global_options.to_yaml
77
+ end
78
+ msg = sprintf("%s: %s",
79
+ "Success".foreground(:green),
80
+ "new settings are saved into file: `#{filepath}`")
81
+ print msg
82
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class DefaultTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_the_truth
12
+ assert true
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rails', '3.2.9'
3
+ group :assets do
4
+ gem 'sass-rails', '~> 3.2.3'
5
+ gem 'coffee-rails', '~> 3.2.1'
6
+ gem 'uglifier', '>= 1.0.3'
7
+ end
8
+ gem 'jquery-rails'
9
+ gem "mongoid", ">= 3.0.14"
10
+ gem "rspec-rails", ">= 2.11.4", :group => [:development, :test]
11
+ gem "database_cleaner", ">= 0.9.1", :group => :test
12
+ gem "mongoid-rspec", ">= 1.5.5", :group => :test
13
+ gem "email_spec", ">= 1.4.0", :group => :test
14
+ gem "cucumber-rails", ">= 1.3.0", :group => :test, :require => false
15
+ gem "launchy", ">= 2.1.2", :group => :test
16
+ gem "capybara", ">= 1.1.4", :group => :test
17
+ gem "factory_girl_rails", ">= 4.1.0", :group => [:development, :test]
18
+ gem "omniauth", ">= 1.1.1"
19
+ gem "omniauth-twitter"
20
+ gem "quiet_assets", ">= 1.0.1", :group => :development