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.
- checksums.yaml +15 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +51 -0
- data/README.md +271 -0
- data/README.rdoc +6 -0
- data/Rakefile +44 -0
- data/bin/veye +390 -0
- data/lib/veye/api/base_resource.rb +29 -0
- data/lib/veye/api/json_response.rb +56 -0
- data/lib/veye/api/resource.rb +22 -0
- data/lib/veye/api.rb +3 -0
- data/lib/veye/package/follow.rb +50 -0
- data/lib/veye/package/info.rb +50 -0
- data/lib/veye/package/info_csv.rb +18 -0
- data/lib/veye/package/info_json.rb +14 -0
- data/lib/veye/package/info_pretty.rb +27 -0
- data/lib/veye/package/info_table.rb +29 -0
- data/lib/veye/package/search.rb +46 -0
- data/lib/veye/package/search_csv.rb +33 -0
- data/lib/veye/package/search_json.rb +19 -0
- data/lib/veye/package/search_pretty.rb +35 -0
- data/lib/veye/package/search_table.rb +40 -0
- data/lib/veye/package.rb +23 -0
- data/lib/veye/pagination/pagination_csv.rb +17 -0
- data/lib/veye/pagination/pagination_json.rb +12 -0
- data/lib/veye/pagination/pagination_pretty.rb +22 -0
- data/lib/veye/pagination/pagination_table.rb +22 -0
- data/lib/veye/pagination/show.rb +26 -0
- data/lib/veye/pagination.rb +7 -0
- data/lib/veye/project/check.rb +147 -0
- data/lib/veye/project/licence.rb +48 -0
- data/lib/veye/project/project_csv.rb +28 -0
- data/lib/veye/project/project_dependency_csv.rb +25 -0
- data/lib/veye/project/project_dependency_json.rb +12 -0
- data/lib/veye/project/project_dependency_pretty.rb +30 -0
- data/lib/veye/project/project_dependency_table.rb +27 -0
- data/lib/veye/project/project_json.rb +13 -0
- data/lib/veye/project/project_licence_csv.rb +19 -0
- data/lib/veye/project/project_licence_json.rb +12 -0
- data/lib/veye/project/project_licence_pretty.rb +23 -0
- data/lib/veye/project/project_licence_table.rb +29 -0
- data/lib/veye/project/project_pretty.rb +28 -0
- data/lib/veye/project/project_table.rb +30 -0
- data/lib/veye/project.rb +11 -0
- data/lib/veye/service.rb +14 -0
- data/lib/veye/user/favorite_csv.rb +28 -0
- data/lib/veye/user/favorite_json.rb +14 -0
- data/lib/veye/user/favorite_pretty.rb +25 -0
- data/lib/veye/user/favorite_table.rb +28 -0
- data/lib/veye/user/me.rb +75 -0
- data/lib/veye/user/profile_csv.rb +21 -0
- data/lib/veye/user/profile_json.rb +14 -0
- data/lib/veye/user/profile_pretty.rb +31 -0
- data/lib/veye/user/profile_table.rb +34 -0
- data/lib/veye/user.rb +7 -0
- data/lib/veye/version.rb +13 -0
- data/lib/veye.rb +82 -0
- data/test/default_test.rb +14 -0
- data/test/files/Gemfile +20 -0
- data/test/files/maven-1.0.1.pom +128 -0
- data/test/test_helper.rb +9 -0
- data/veye.rdoc +5 -0
- metadata +229 -0
    
        data/bin/veye
    ADDED
    
    | @@ -0,0 +1,390 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'gli'
         | 
| 4 | 
            +
            require 'rest_client'
         | 
| 5 | 
            +
            require 'json'
         | 
| 6 | 
            +
            require 'rainbow'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            require 'veye'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            include GLI::App
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            program_desc 'VersionEye commandline tool'
         | 
| 13 | 
            +
            program_long_desc Veye::BIGEYE.foreground(:green)
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            wrap_help_text :verbatim
         | 
| 16 | 
            +
            version Veye::VERSION
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            config_file '.veye.rc'
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            desc 'set api key'
         | 
| 21 | 
            +
            flag :api_key, :default_value => "<add your api key here>"
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            desc 'set server url'
         | 
| 24 | 
            +
            flag :server, :default_value => "www.versioneye.com"
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            desc 'set service port'
         | 
| 27 | 
            +
            flag :port, :default_value => "80"
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            desc 'set service path'
         | 
| 30 | 
            +
            flag :path, :default_value => "api/v2"
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            desc 'set connection protocol'
         | 
| 33 | 
            +
            flag :protocol, :default_value => "http"
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            desc "don't use colors"
         | 
| 36 | 
            +
            switch 'color', :default_value => true, :negetable => true
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            pre do |global_options, options, args|
         | 
| 39 | 
            +
              $global_options = init_environment #global_options
         | 
| 40 | 
            +
              $global_options.merge!(global_options)
         | 
| 41 | 
            +
              check_configs($global_options)
         | 
| 42 | 
            +
              $global_options[:url] = Veye::API::Resource.build_url($global_options)
         | 
| 43 | 
            +
            end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            desc 'check service status'
         | 
| 46 | 
            +
            command :ping do |c|
         | 
| 47 | 
            +
             c.action do |global_options, options, args|
         | 
| 48 | 
            +
               respond = Veye::Service.ping()
         | 
| 49 | 
            +
               if respond.success
         | 
| 50 | 
            +
                 puts "#{respond.data['message']}".foreground(:green)
         | 
| 51 | 
            +
               else
         | 
| 52 | 
            +
                 printf(
         | 
| 53 | 
            +
                   "VersionEye didnt recognized secret word.Answered %s, %s\n",
         | 
| 54 | 
            +
                   respond.code.to_s.foreground(:red),
         | 
| 55 | 
            +
                   "#{respond.message}".foreground(:yellow)
         | 
| 56 | 
            +
                 )
         | 
| 57 | 
            +
               end
         | 
| 58 | 
            +
             end
         | 
| 59 | 
            +
            end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            desc 'Search packages on VersionEye.'
         | 
| 62 | 
            +
            arg_name 'search_term'
         | 
| 63 | 
            +
            command :search do |c|
         | 
| 64 | 
            +
              c.desc 'filter results by language'
         | 
| 65 | 
            +
              c.flag [:l, :language, 'language-name']
         | 
| 66 | 
            +
             | 
| 67 | 
            +
              c.desc 'filter result by Manven specific GroupId'
         | 
| 68 | 
            +
              c.flag "group-id"
         | 
| 69 | 
            +
             | 
| 70 | 
            +
              c.desc "get next N results, by default it only return 30 results."
         | 
| 71 | 
            +
              c.flag [:page, 'page-number']
         | 
| 72 | 
            +
             | 
| 73 | 
            +
              c.desc "change output format"
         | 
| 74 | 
            +
              c.flag [:format,'format-name'], :default_value => "pretty"
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              c.desc "show paging information"
         | 
| 77 | 
            +
              c.switch [:pagination, 'show-pagination'], :default_value => true,
         | 
| 78 | 
            +
                                                         :negatable => true
         | 
| 79 | 
            +
             | 
| 80 | 
            +
              c.action do |global_options, options, args|
         | 
| 81 | 
            +
                help_now!("the search term is mandatory.".foreground(:red)) if args.empty?
         | 
| 82 | 
            +
                search_term = args.shift
         | 
| 83 | 
            +
                response = Veye::Package::Search.search(search_term, 
         | 
| 84 | 
            +
                                                     options[:language], 
         | 
| 85 | 
            +
                                                     options["group-id"], 
         | 
| 86 | 
            +
                                                     options[:page])
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                if response.success == false or response.data["results"].empty?
         | 
| 89 | 
            +
                    error_msg = sprintf(
         | 
| 90 | 
            +
                      "No results for `%s` %s",
         | 
| 91 | 
            +
                      "#{search_term}".foreground(:yellow),
         | 
| 92 | 
            +
                      (options[:language].nil?)? "" : " for language: #{options[:language]}"
         | 
| 93 | 
            +
                    )
         | 
| 94 | 
            +
                    exit_now!(error_msg)
         | 
| 95 | 
            +
                end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                Veye::Package::Search.format(response.data["results"], options[:format])
         | 
| 98 | 
            +
                if options[:pagination]
         | 
| 99 | 
            +
                  printf("\n#-- pagination data ------------------\n")
         | 
| 100 | 
            +
                  Veye::Pagination::Show.format response.data['paging'], options[:format]
         | 
| 101 | 
            +
                end
         | 
| 102 | 
            +
              
         | 
| 103 | 
            +
              end
         | 
| 104 | 
            +
            end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
            desc 'returns package information'
         | 
| 107 | 
            +
            arg_name 'product_key'
         | 
| 108 | 
            +
            command :info do |c|
         | 
| 109 | 
            +
              c.desc "change output format"
         | 
| 110 | 
            +
              c.flag [:format, 'format-name'], :default_value => 'pretty'
         | 
| 111 | 
            +
             | 
| 112 | 
            +
              c.action do |global_options, options, args|
         | 
| 113 | 
            +
                help_now!("package_key is missing".foreground(:red)) if args.empty?
         | 
| 114 | 
            +
                package_key = args.shift
         | 
| 115 | 
            +
                response = Veye::Package::Info.search(package_key)
         | 
| 116 | 
            +
                
         | 
| 117 | 
            +
                unless response.success
         | 
| 118 | 
            +
                    error_msg = sprintf(
         | 
| 119 | 
            +
                      "Didnt find any package with product_key: `%s`",
         | 
| 120 | 
            +
                      "#{package_key}".foreground(:yellow)
         | 
| 121 | 
            +
                    )
         | 
| 122 | 
            +
                    exit_now!(error_msg)
         | 
| 123 | 
            +
                end
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                Veye::Package::Info.format(response.data, options[:format])
         | 
| 126 | 
            +
              end
         | 
| 127 | 
            +
            end
         | 
| 128 | 
            +
             | 
| 129 | 
            +
            desc 'analyzes given project file and returns version info'
         | 
| 130 | 
            +
            arg_name 'product_file'
         | 
| 131 | 
            +
             | 
| 132 | 
            +
            command :check do |c|
         | 
| 133 | 
            +
              c.desc "change output format"
         | 
| 134 | 
            +
              c.flag [:format, 'format-name'], :default_value => 'pretty'
         | 
| 135 | 
            +
              
         | 
| 136 | 
            +
              c.action do |global_options, options, args|
         | 
| 137 | 
            +
                help_now!("File of project is unspecified.".foreground(:red)) if args.empty?
         | 
| 138 | 
            +
                file_name = args.shift
         | 
| 139 | 
            +
                response = Veye::Project::Check.upload(file_name, global_options[:api_key])
         | 
| 140 | 
            +
                if response.success == false
         | 
| 141 | 
            +
                  exit_now!("File upload failed.\n #{response.message}\n".foreground(:red))
         | 
| 142 | 
            +
                end
         | 
| 143 | 
            +
             
         | 
| 144 | 
            +
                if response.success
         | 
| 145 | 
            +
                  Veye::Project::Check.format_dependencies(
         | 
| 146 | 
            +
                    response.data['dependencies'], 
         | 
| 147 | 
            +
                    options[:format]
         | 
| 148 | 
            +
                  )
         | 
| 149 | 
            +
                else
         | 
| 150 | 
            +
                  exit_now!("Didnt get dependency info from API: #{response.message}")
         | 
| 151 | 
            +
                end
         | 
| 152 | 
            +
              end
         | 
| 153 | 
            +
            end
         | 
| 154 | 
            +
             | 
| 155 | 
            +
             | 
| 156 | 
            +
            desc 'manage your projects'
         | 
| 157 | 
            +
            arg_name 'subcommand'
         | 
| 158 | 
            +
            command :projects do |c|
         | 
| 159 | 
            +
              c.desc "change output format"
         | 
| 160 | 
            +
              c.flag [:format, 'format-name'], :default_value => 'pretty'
         | 
| 161 | 
            +
               
         | 
| 162 | 
            +
              c.desc "show all projects"
         | 
| 163 | 
            +
              c.command :list do |list|
         | 
| 164 | 
            +
                list.action do |global_options, options, args|
         | 
| 165 | 
            +
                  api_key = global_options[:api_key]
         | 
| 166 | 
            +
                  response = Veye::Project::Check.get_list(api_key)
         | 
| 167 | 
            +
                  
         | 
| 168 | 
            +
                  if response.success == false
         | 
| 169 | 
            +
                    error_msg = "Didnt get list of projects: \n #{response.message.foreground(:red)}"
         | 
| 170 | 
            +
                    exit_now!(error_msg)
         | 
| 171 | 
            +
                  end
         | 
| 172 | 
            +
             | 
| 173 | 
            +
                  Veye::Project::Check.format(response.data, options[:format])
         | 
| 174 | 
            +
                end
         | 
| 175 | 
            +
              end
         | 
| 176 | 
            +
             | 
| 177 | 
            +
              c.desc "upload new project file"
         | 
| 178 | 
            +
              c.arg_name "filepath"
         | 
| 179 | 
            +
              c.command :upload do |upload|
         | 
| 180 | 
            +
                upload.action do |global_options, options, args|
         | 
| 181 | 
            +
                  help_now!("The filepath is missing.".foreground(:red)) if args.empty?
         | 
| 182 | 
            +
                  filename = args.shift
         | 
| 183 | 
            +
                  api_key = global_options[:api_key]
         | 
| 184 | 
            +
                  response = Veye::Project::Check.upload(filename, api_key)
         | 
| 185 | 
            +
                  unless response.success
         | 
| 186 | 
            +
                    error_msg = "Uploading failed - #{response.message.foreground(:red)}"
         | 
| 187 | 
            +
                    exit_now! error_msg
         | 
| 188 | 
            +
                  end
         | 
| 189 | 
            +
                  
         | 
| 190 | 
            +
                  Veye::Project::Check.format(response.data, options[:format])
         | 
| 191 | 
            +
                  Veye::Project::Check.format_dependencies(response.data['dependencies'], options[:format])
         | 
| 192 | 
            +
               end
         | 
| 193 | 
            +
              end
         | 
| 194 | 
            +
             
         | 
| 195 | 
            +
              c.desc "update existing project file"
         | 
| 196 | 
            +
              c.arg_name "project_key_and_filepath", multiple: true
         | 
| 197 | 
            +
              c.command :update do |update|
         | 
| 198 | 
            +
                update.action do |global_options, options, args|
         | 
| 199 | 
            +
                  help_now!("The project key and the filepath are missing".foreground(:red)) if args.empty?
         | 
| 200 | 
            +
                  help_now!("One argument is missing: a project key or filepath".foreground(:red)) if args.count == 1
         | 
| 201 | 
            +
                  
         | 
| 202 | 
            +
                  project_key, filename = args
         | 
| 203 | 
            +
                  api_key = global_options[:api_key]
         | 
| 204 | 
            +
             | 
| 205 | 
            +
                  response = Veye::Project::Check.update(project_key, filename, api_key)
         | 
| 206 | 
            +
                  unless response.success
         | 
| 207 | 
            +
                    error_msg = "Uploading failed - #{response.message.foreground(:red)}"
         | 
| 208 | 
            +
                    exit_now! error_msg
         | 
| 209 | 
            +
                  end
         | 
| 210 | 
            +
                  
         | 
| 211 | 
            +
                  Veye::Project::Check.format(response.data, options[:format])
         | 
| 212 | 
            +
                  Veye::Project::Check.format_dependencies(response.data['dependencies'], options[:format])
         | 
| 213 | 
            +
                end
         | 
| 214 | 
            +
              end
         | 
| 215 | 
            +
             | 
| 216 | 
            +
              c.desc "show project info"
         | 
| 217 | 
            +
              c.arg_name "project_key"
         | 
| 218 | 
            +
              c.command :show do |show|
         | 
| 219 | 
            +
                show.action do |global_options, options, args|
         | 
| 220 | 
            +
                  help_now!("Project_key is unspecified".foreground(:red)) if args.empty?
         | 
| 221 | 
            +
                  proj_key = args.shift
         | 
| 222 | 
            +
                  api_key = global_options[:api_key]
         | 
| 223 | 
            +
             | 
| 224 | 
            +
                  response = Veye::Project::Check.get_project(proj_key, api_key)
         | 
| 225 | 
            +
                  unless response.success
         | 
| 226 | 
            +
                    error_msg = "Cant read information about project: `#{proj_key}`"
         | 
| 227 | 
            +
                    error_msg +=  "- #{response.message}".foreground(:red)
         | 
| 228 | 
            +
                    exit_now! error_msg
         | 
| 229 | 
            +
                  end
         | 
| 230 | 
            +
             | 
| 231 | 
            +
                  Veye::Project::Check.format(response.data, options[:format])
         | 
| 232 | 
            +
                  Veye::Project::Check.format_dependencies(response.data['dependencies'], options[:format])
         | 
| 233 | 
            +
                end
         | 
| 234 | 
            +
              end
         | 
| 235 | 
            +
             | 
| 236 | 
            +
              c.desc "show licences of subdependencies"
         | 
| 237 | 
            +
              c.arg_name "project_key"
         | 
| 238 | 
            +
              c.command :licences do |licences|
         | 
| 239 | 
            +
                licences.action do |global_options, options, args|
         | 
| 240 | 
            +
                  help_now!("Project's key is unspecified".foreground(:red)) if args.empty?
         | 
| 241 | 
            +
                  proj_key = args.shift
         | 
| 242 | 
            +
                  api_key = global_options[:api_key]
         | 
| 243 | 
            +
             | 
| 244 | 
            +
                  response = Veye::Project::Licence.get_project(proj_key, api_key)
         | 
| 245 | 
            +
                  unless response.success
         | 
| 246 | 
            +
                    error_msg = sprintf("%s \n %s",
         | 
| 247 | 
            +
                                        "Cant access a information for project `#{proj_key}`".foreground(:red),
         | 
| 248 | 
            +
                                        "#{response.message}")
         | 
| 249 | 
            +
                    exit_now! error_msg
         | 
| 250 | 
            +
                  end
         | 
| 251 | 
            +
                  
         | 
| 252 | 
            +
                  Veye::Project::Licence.format(response.data, options[:format])
         | 
| 253 | 
            +
                end
         | 
| 254 | 
            +
              end
         | 
| 255 | 
            +
             | 
| 256 | 
            +
              c.desc "delete project"
         | 
| 257 | 
            +
              c.arg_name "project_key"
         | 
| 258 | 
            +
              c.command :delete do |delete|
         | 
| 259 | 
            +
                delete.action do |global_options, options, args|
         | 
| 260 | 
            +
                  help_now!("Project is missing".foreground(:red)) if args.empty?
         | 
| 261 | 
            +
                  proj_key = args.shift
         | 
| 262 | 
            +
                  api_key = global_options[:api_key]
         | 
| 263 | 
            +
             | 
| 264 | 
            +
                  response = Veye::Project::Check.delete_project(proj_key, api_key)
         | 
| 265 | 
            +
                  unless response.success
         | 
| 266 | 
            +
                    printf("Cant delete - %s\n%s\n", response.message.foreground(:red),
         | 
| 267 | 
            +
                                                     response.data['error'])
         | 
| 268 | 
            +
                  else
         | 
| 269 | 
            +
                    printf "Deleted\n".foreground(:green)
         | 
| 270 | 
            +
                  end
         | 
| 271 | 
            +
                end
         | 
| 272 | 
            +
              end
         | 
| 273 | 
            +
            end
         | 
| 274 | 
            +
             | 
| 275 | 
            +
            desc "package related methods"
         | 
| 276 | 
            +
            command :products do |c|
         | 
| 277 | 
            +
              c.desc "change output format"
         | 
| 278 | 
            +
              c.flag [:format, 'format-name'], :default_value => 'pretty'
         | 
| 279 | 
            +
             | 
| 280 | 
            +
              c.desc "check your following status"
         | 
| 281 | 
            +
              c.arg_name "prod_key"
         | 
| 282 | 
            +
              c.command :following do |following|
         | 
| 283 | 
            +
                following.action do |global_options, options, args|
         | 
| 284 | 
            +
                  help_now!("Product's key is missing".foreground(:red)) if args.empty?
         | 
| 285 | 
            +
                  prod_key = args.shift
         | 
| 286 | 
            +
                  api_key = global_options[:api_key]
         | 
| 287 | 
            +
                  
         | 
| 288 | 
            +
                  response = Veye::Package::Follow.get_follow_status(prod_key, api_key)
         | 
| 289 | 
            +
                  unless response.success
         | 
| 290 | 
            +
                    error_msg = sprintf("Checking state of following failed: %s \n %s",
         | 
| 291 | 
            +
                                       "#{response.message}".foreground(:red),
         | 
| 292 | 
            +
                                       "#{response.data}")
         | 
| 293 | 
            +
                    exit_now! error_msg
         | 
| 294 | 
            +
                  end
         | 
| 295 | 
            +
                  
         | 
| 296 | 
            +
                  printf "#{response.data}\n".foreground(:green)
         | 
| 297 | 
            +
                end
         | 
| 298 | 
            +
              end
         | 
| 299 | 
            +
             | 
| 300 | 
            +
              c.desc "start following specific software package"
         | 
| 301 | 
            +
              c.arg_name "prod_key"
         | 
| 302 | 
            +
              c.command :follow do |follow|
         | 
| 303 | 
            +
                follow.action do |global_options, options, args|
         | 
| 304 | 
            +
                  help_now!("Product's key is missing".foreground(:red)) if args.empty?
         | 
| 305 | 
            +
                  prod_key = args.shift
         | 
| 306 | 
            +
                  api_key = global_options[:api_key]
         | 
| 307 | 
            +
                  
         | 
| 308 | 
            +
                  response = Veye::Package::Follow.follow(prod_key, api_key)
         | 
| 309 | 
            +
                  unless response.success
         | 
| 310 | 
            +
                    error_msg = sprintf("Following failed: %s \n %s",
         | 
| 311 | 
            +
                                       "#{response.message}".foreground(:red),
         | 
| 312 | 
            +
                                       "#{response.data}")
         | 
| 313 | 
            +
                    exit_now! error_msg
         | 
| 314 | 
            +
                  end
         | 
| 315 | 
            +
                  printf "#{response.data}\n".foreground(:green)
         | 
| 316 | 
            +
                end
         | 
| 317 | 
            +
              end
         | 
| 318 | 
            +
             | 
| 319 | 
            +
              c.desc "stop following given software package"
         | 
| 320 | 
            +
              c.arg_name "prod_key"
         | 
| 321 | 
            +
              c.command :unfollow do |unfollow|
         | 
| 322 | 
            +
                unfollow.action do |global_options, options, args|
         | 
| 323 | 
            +
                  help_now!("Product's key is missing".foreground(:red)) if args.empty?
         | 
| 324 | 
            +
                  prod_key = args.shift
         | 
| 325 | 
            +
                  api_key = global_options[:api_key]
         | 
| 326 | 
            +
             | 
| 327 | 
            +
                  response =  Veye::Package::Follow.unfollow(prod_key, api_key)
         | 
| 328 | 
            +
                  unless response.success
         | 
| 329 | 
            +
                    error_msg =  sprintf("Unfollowing failed: %s \n %s",
         | 
| 330 | 
            +
                                        "#{response.message}".foreground(:red),
         | 
| 331 | 
            +
                                        "#{response.data}")
         | 
| 332 | 
            +
                    exit_now! error_msg
         | 
| 333 | 
            +
                  end
         | 
| 334 | 
            +
             | 
| 335 | 
            +
                  printf "#{response.data}\n".foreground(:green)
         | 
| 336 | 
            +
                end
         | 
| 337 | 
            +
              end
         | 
| 338 | 
            +
            end
         | 
| 339 | 
            +
             | 
| 340 | 
            +
             | 
| 341 | 
            +
            desc "handle your personal data"
         | 
| 342 | 
            +
            command :me do |c|
         | 
| 343 | 
            +
              c.desc "change output format"
         | 
| 344 | 
            +
              c.flag [:format, 'format-name'], :default_value => 'pretty'
         | 
| 345 | 
            +
             | 
| 346 | 
            +
              c.desc "get profile information"
         | 
| 347 | 
            +
              c.action do |global_options, options, args|
         | 
| 348 | 
            +
                api_key = global_options[:api_key]
         | 
| 349 | 
            +
                response = Veye::User::Me.get_profile(api_key)
         | 
| 350 | 
            +
                unless response.success
         | 
| 351 | 
            +
                  error_msg = sprintf("Failed to read your profile data: %s\n%s\n",
         | 
| 352 | 
            +
                                     "#{response.message}".foreground(:red),
         | 
| 353 | 
            +
                                     "#{response.data}")
         | 
| 354 | 
            +
                  exit_now! error_msg
         | 
| 355 | 
            +
                end
         | 
| 356 | 
            +
             | 
| 357 | 
            +
                Veye::User::Me.format_profile response.data, options[:format]
         | 
| 358 | 
            +
              end
         | 
| 359 | 
            +
             | 
| 360 | 
            +
              c.desc "get your favorite packages"
         | 
| 361 | 
            +
              c.command :favorites do |favorites|
         | 
| 362 | 
            +
                favorites.desc "pagination number"
         | 
| 363 | 
            +
                favorites.flag [:page, 'page-number']
         | 
| 364 | 
            +
             | 
| 365 | 
            +
                favorites.desc "show paging information"
         | 
| 366 | 
            +
                favorites.switch [:pagination, 'show-pagination'], :default_value => true,
         | 
| 367 | 
            +
                                                           :negatable => true
         | 
| 368 | 
            +
             | 
| 369 | 
            +
                favorites.action do |global_options, options, args|
         | 
| 370 | 
            +
                  api_key = global_options[:api_key]
         | 
| 371 | 
            +
                  response = Veye::User::Me.get_favorites(api_key, options[:page])
         | 
| 372 | 
            +
             | 
| 373 | 
            +
                  unless response.success
         | 
| 374 | 
            +
                    error_msg = sprintf("Failed to read your profile data: %s\n%s\n",
         | 
| 375 | 
            +
                                       "#{response.message}".foreground(:red),
         | 
| 376 | 
            +
                                       "#{response.data}")
         | 
| 377 | 
            +
                    exit_now! error_msg
         | 
| 378 | 
            +
                  end
         | 
| 379 | 
            +
             | 
| 380 | 
            +
                  Veye::User::Me.format_favorites response.data['favorites'], options[:format]
         | 
| 381 | 
            +
                  if options[:pagination]
         | 
| 382 | 
            +
                    printf("\n#-- pagination data ------------------\n")
         | 
| 383 | 
            +
                    Veye::Pagination::Show.format response.data['paging'], options[:format]
         | 
| 384 | 
            +
                  end
         | 
| 385 | 
            +
                end
         | 
| 386 | 
            +
             | 
| 387 | 
            +
              end
         | 
| 388 | 
            +
            end
         | 
| 389 | 
            +
             | 
| 390 | 
            +
            exit run(ARGV)
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            module Veye
         | 
| 2 | 
            +
              module API
         | 
| 3 | 
            +
                class  BaseResource
         | 
| 4 | 
            +
                  attr_reader :resource, :full_path 
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def initialize(path = nil)
         | 
| 7 | 
            +
                    @full_path = $global_options[:url]
         | 
| 8 | 
            +
                    @full_path = "#{@full_path}#{path}" unless path.nil?
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  def self.build_url(global_options)
         | 
| 12 | 
            +
                    resource_url = nil
         | 
| 13 | 
            +
                    protocol = global_options[:protocol]
         | 
| 14 | 
            +
                    server = global_options[:server]
         | 
| 15 | 
            +
                    port = global_options.fetch(:port, "")
         | 
| 16 | 
            +
                    path = global_options[:path]
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    unless port.to_s.empty?
         | 
| 19 | 
            +
                        resource_url = "#{protocol}://#{server}:#{port}/#{path}"
         | 
| 20 | 
            +
                    else
         | 
| 21 | 
            +
                        resource_url = "#{protocol}://#{server}/#{path}"
         | 
| 22 | 
            +
                    end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    return resource_url
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
            end
         | 
| @@ -0,0 +1,56 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Veye
         | 
| 4 | 
            +
              module API
         | 
| 5 | 
            +
                class JSONResponse
         | 
| 6 | 
            +
                  attr_reader :code, :success, :message, :data, :url, :headers
         | 
| 7 | 
            +
                  def initialize(request, result, response)
         | 
| 8 | 
            +
                     @url = request.url
         | 
| 9 | 
            +
                     @headers = request.headers
         | 
| 10 | 
            +
                     @code = result.code.to_i
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                     response_data = JSON.parse(response)
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                     @success, @message = success?(result, response_data)
         | 
| 15 | 
            +
                     @data = response_data
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  def success?(result, response_data)
         | 
| 19 | 
            +
                    @code = result.code.to_i
         | 
| 20 | 
            +
                    success = false
         | 
| 21 | 
            +
                     
         | 
| 22 | 
            +
                    case @code 
         | 
| 23 | 
            +
                    when 200
         | 
| 24 | 
            +
                      success = true
         | 
| 25 | 
            +
                      message = "fetched successfully"
         | 
| 26 | 
            +
                    when 201
         | 
| 27 | 
            +
                      success = true
         | 
| 28 | 
            +
                      message = "created successfully"
         | 
| 29 | 
            +
                    when 400
         | 
| 30 | 
            +
                      message = "bad request - wrong parameters, data"
         | 
| 31 | 
            +
                    when 401
         | 
| 32 | 
            +
                      message = "not authorized - add apikey or update settings file ~/.veye.rc"
         | 
| 33 | 
            +
                    when 403
         | 
| 34 | 
            +
                      message = "forbidden - server refused execute query"
         | 
| 35 | 
            +
                    when 413
         | 
| 36 | 
            +
                      message = "request entity too big - use smaller data object"
         | 
| 37 | 
            +
                    when 500
         | 
| 38 | 
            +
                      message = "internal server error - write to us"
         | 
| 39 | 
            +
                    when 501
         | 
| 40 | 
            +
                      message = "not implemented - write to us"
         | 
| 41 | 
            +
                    when 503
         | 
| 42 | 
            +
                      message = "service unavailable - temporary overloaded - write to us."
         | 
| 43 | 
            +
                    when 531
         | 
| 44 | 
            +
                      message = "not authorized - add apikey or update settings file ~/.veye.rc"
         | 
| 45 | 
            +
                    else
         | 
| 46 | 
            +
                      success = false
         | 
| 47 | 
            +
                      message = ""
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                     return success, message
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
             | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
            end
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            require 'rest_client'
         | 
| 2 | 
            +
            require_relative 'base_resource.rb'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
             | 
| 5 | 
            +
            #for ssl keys:
         | 
| 6 | 
            +
            #openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -nodes
         | 
| 7 | 
            +
            module Veye
         | 
| 8 | 
            +
              module API
         | 
| 9 | 
            +
                class Resource < BaseResource
         | 
| 10 | 
            +
                  def initialize(path = nil)
         | 
| 11 | 
            +
                    super(path)
         | 
| 12 | 
            +
                    @resource = RestClient::Resource.new(
         | 
| 13 | 
            +
                      @full_path,
         | 
| 14 | 
            +
                      :ssl_client_cert  =>  OpenSSL::X509::Certificate.new(File.read("cert.pem")),
         | 
| 15 | 
            +
                      :ssl_client_key   =>  OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
         | 
| 16 | 
            +
                      :ssl_ca_file      =>  "ca_certificate.pem",
         | 
| 17 | 
            +
                      :verify_ssl       =>  OpenSSL::SSL::VERIFY_PEER
         | 
| 18 | 
            +
                    )
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
    
        data/lib/veye/api.rb
    ADDED
    
    
| @@ -0,0 +1,50 @@ | |
| 1 | 
            +
            module Veye
         | 
| 2 | 
            +
              module Package
         | 
| 3 | 
            +
                class Follow
         | 
| 4 | 
            +
               
         | 
| 5 | 
            +
                  def self.get_follow_status(prod_key, api_key)
         | 
| 6 | 
            +
                    product_api = API::Resource.new(RESOURCE_PATH)
         | 
| 7 | 
            +
                    response_data = nil
         | 
| 8 | 
            +
                    qparams = {:params => {:api_key => api_key}}
         | 
| 9 | 
            +
                    safe_prod_key = Package.encode_prod_key(prod_key)
         | 
| 10 | 
            +
                    product_api.resource[
         | 
| 11 | 
            +
                      "/#{safe_prod_key}/follow.json"].get(qparams) do |response, request, result|
         | 
| 12 | 
            +
                      
         | 
| 13 | 
            +
                      response_data = API::JSONResponse.new(request, result, response)
         | 
| 14 | 
            +
                    end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    return response_data
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  def self.follow(prod_key, api_key)
         | 
| 20 | 
            +
                    product_api = API::Resource.new(RESOURCE_PATH)
         | 
| 21 | 
            +
                    response_data = nil
         | 
| 22 | 
            +
                    qparams = {:api_key => api_key}
         | 
| 23 | 
            +
                    safe_prod_key = Package.encode_prod_key(prod_key)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    product_api.resource[
         | 
| 26 | 
            +
                      "/#{safe_prod_key}/follow.json"].post(qparams) do |response, request, result|
         | 
| 27 | 
            +
                      
         | 
| 28 | 
            +
                      response_data = API::JSONResponse.new(request, result, response)
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    return response_data
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  def self.unfollow(prod_key, api_key)
         | 
| 35 | 
            +
                    product_api = API::Resource.new(RESOURCE_PATH)
         | 
| 36 | 
            +
                    response_data = nil
         | 
| 37 | 
            +
                    qparams = {:params => {:api_key => api_key}}
         | 
| 38 | 
            +
                    safe_prod_key = Package.encode_prod_key(prod_key)
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    product_api.resource[
         | 
| 41 | 
            +
                      "/#{safe_prod_key}/follow.json"].delete(qparams) do |response, request, result|
         | 
| 42 | 
            +
                      
         | 
| 43 | 
            +
                      response_data = API::JSONResponse.new(request, result, response)
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    return response_data
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
            end
         | 
| @@ -0,0 +1,50 @@ | |
| 1 | 
            +
            require_relative 'info_csv.rb'
         | 
| 2 | 
            +
            require_relative 'info_json.rb'
         | 
| 3 | 
            +
            require_relative 'info_pretty.rb'
         | 
| 4 | 
            +
            require_relative 'info_table.rb'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module Veye
         | 
| 7 | 
            +
              module Package
         | 
| 8 | 
            +
                
         | 
| 9 | 
            +
                class Info
         | 
| 10 | 
            +
                  @@output_formats = {
         | 
| 11 | 
            +
                    'csv'       => InfoCSV.new,
         | 
| 12 | 
            +
                    'json'      => InfoJSON.new,
         | 
| 13 | 
            +
                    'pretty'    => InfoPretty.new,
         | 
| 14 | 
            +
                    'table'     => InfoTable.new
         | 
| 15 | 
            +
                  }
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def self.search(package_key)
         | 
| 18 | 
            +
                    product_api = API::Resource.new(RESOURCE_PATH)
         | 
| 19 | 
            +
                    tokens = package_key.to_s.split('/')
         | 
| 20 | 
            +
                    lang = Package.encode_language(tokens.first)
         | 
| 21 | 
            +
                    safe_prod_key = Package.encode_prod_key(tokens.drop(1).join("/"))
         | 
| 22 | 
            +
                    
         | 
| 23 | 
            +
                    if lang.nil? or safe_prod_key.nil?
         | 
| 24 | 
            +
                      msg =  %Q[
         | 
| 25 | 
            +
                        You missed language or product key. 
         | 
| 26 | 
            +
                        Example: clojure/ztellman/aleph, which as required structure <prog lang>/<product_code>
         | 
| 27 | 
            +
                      ]
         | 
| 28 | 
            +
                      error_msg = sprrintf("%s. \n%s", 
         | 
| 29 | 
            +
                                           "Error: Malformed key.".foreground(:red),
         | 
| 30 | 
            +
                                          msg)
         | 
| 31 | 
            +
                      exit_now!(error_msg)
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    request_response = nil 
         | 
| 35 | 
            +
                    product_api.resource["/#{lang}/#{safe_prod_key}"].get do |response, request, result, &block|
         | 
| 36 | 
            +
                      request_response = API::JSONResponse.new(request, result, response)
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
                    return request_response
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  def self.format(results, format = 'pretty')
         | 
| 42 | 
            +
                    formatter = @@output_formats[format]
         | 
| 43 | 
            +
                    formatter.before
         | 
| 44 | 
            +
                    formatter.format(results)
         | 
| 45 | 
            +
                    formatter.after
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
            end
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            module Veye
         | 
| 2 | 
            +
              module Package
         | 
| 3 | 
            +
                class InfoCSV
         | 
| 4 | 
            +
                  def before
         | 
| 5 | 
            +
                    printf("name,version,language,prod_key,licence,prod_type,description,link\n")
         | 
| 6 | 
            +
                  end
         | 
| 7 | 
            +
                  def after; end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def format(result, index = 0)
         | 
| 10 | 
            +
                    printf("%s,%s,%s,%s,%s,%s,%s,%s\n",
         | 
| 11 | 
            +
                          result["name"], result["version"], result["language"],
         | 
| 12 | 
            +
                          result["prod_key"], result["license"], result["prod_type"],
         | 
| 13 | 
            +
                          result["link"], result["description"])
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
| 18 | 
            +
             | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require 'rainbow'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Veye
         | 
| 4 | 
            +
              module Package
         | 
| 5 | 
            +
                class InfoPretty
         | 
| 6 | 
            +
                  def before; end
         | 
| 7 | 
            +
                  def after; end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def format(result, index = 0)
         | 
| 10 | 
            +
                    printf("\t%15s - %s\n", "#{result['name']}".foreground(:green).bright,
         | 
| 11 | 
            +
                                            "#{result['version'].bright}")
         | 
| 12 | 
            +
                    puts "\t-------------------------"
         | 
| 13 | 
            +
                    printf("\t%-15s: %s\n", "Language", result["language"])
         | 
| 14 | 
            +
                    printf("\t%-15s: %s\n", "Licence", result["licence"])
         | 
| 15 | 
            +
                    
         | 
| 16 | 
            +
                    printf("\t%-15s: %s\n", "Product type", result["prod_type"])
         | 
| 17 | 
            +
                    printf("\t%-15s: %s\n", "Product key", 
         | 
| 18 | 
            +
                                            "#{result["prod_key"]}".bright)
         | 
| 19 | 
            +
                    printf("\t%-15s:\n\t %s\n", "Description", result["description"])
         | 
| 20 | 
            +
                    printf("\t%-15s: %s\n", "Group id", result["group_id"])
         | 
| 21 | 
            +
                    printf("\t%-15s: %s\n", "Link", result["link"])
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            require 'terminal-table'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Veye
         | 
| 4 | 
            +
              module Package
         | 
| 5 | 
            +
                class InfoTable
         | 
| 6 | 
            +
                  def before
         | 
| 7 | 
            +
                    @@table = Terminal::Table.new :title => "Package information",
         | 
| 8 | 
            +
                                                  :headings => %w(name version product_key language description)
         | 
| 9 | 
            +
                    @@table.align_column(0, :right)
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def after
         | 
| 13 | 
            +
                    puts @@table.to_s
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  def format(result)
         | 
| 17 | 
            +
                    row = [result["name"], result["version"], result["prod_key"]]
         | 
| 18 | 
            +
                    row << result["language"]
         | 
| 19 | 
            +
                    row << result["description"]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    @@table << row
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                    @@table << ["", "", "", "link:", result["link"]]
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| 29 | 
            +
             |