alfi 0.3.8 → 0.4.1
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 +4 -4
- data/README.md +1 -1
- data/alfi.gemspec +1 -2
- data/bin/alfi +1 -1
- data/lib/alfi.rb +5 -131
- data/lib/alfi/cli.rb +75 -0
- data/lib/alfi/providers.rb +6 -0
- data/lib/alfi/providers/base.rb +29 -0
- data/lib/alfi/providers/bintray.rb +58 -0
- data/lib/alfi/providers/maven.rb +32 -0
- data/lib/alfi/providers/offline.rb +27 -0
- data/lib/alfi/search.rb +32 -0
- data/lib/alfi/version.rb +1 -1
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2238e66c04bcf94075bdb3e52d5baf5fe43e9ca0
|
4
|
+
data.tar.gz: f3cf2058e9bdd64d92a218da57846e56eaf93c2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa308295578ad68226007c0fa24c8ab2cf12d9daa8425aa198924fb3ba70072ce5f0a719d96fb60adbb6d478388b26228422bc811b3e2f98049f98e516472be6
|
7
|
+
data.tar.gz: a5bd08adf5efb90c0d9ec36713affe3833089aeb2acfa11c71112a3ace8f28c7f758a43a6044b28a596c549947659cb3893bbea6b11cefc61b9bf28b4fff22fc
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# alfi
|
2
2
|
|
3
|
-
](https://travis-ci.org/cesarferreira/alfi) [](http://badge.fury.io/rb/alfi) [](https://gemnasium.com/cesarferreira/alfi)
|
4
4
|
|
5
5
|
|
6
6
|
**A**ndroid **L**ibrary **Fi**nder
|
data/alfi.gemspec
CHANGED
@@ -27,9 +27,8 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency 'webmock', '~> 1.21'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
29
29
|
spec.add_development_dependency 'vcr', '~> 2.9'
|
30
|
-
|
30
|
+
spec.add_development_dependency 'pry', '~> 0.10.1'
|
31
31
|
spec.add_dependency 'bundler', '~> 1.7'
|
32
32
|
spec.add_dependency 'json', '~> 1.8'
|
33
33
|
spec.add_dependency 'colorize', '~> 0.7'
|
34
|
-
|
35
34
|
end
|
data/bin/alfi
CHANGED
data/lib/alfi.rb
CHANGED
@@ -1,136 +1,10 @@
|
|
1
|
+
module Alfi
|
2
|
+
end
|
3
|
+
|
1
4
|
require 'json'
|
2
5
|
require 'net/http'
|
3
6
|
require 'uri'
|
4
7
|
require 'colorize'
|
8
|
+
require 'alfi/providers'
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
class SearchModel
|
9
|
-
|
10
|
-
def self.query_url (query)
|
11
|
-
"http://search.maven.org/solrsearch/select?q=#{query}&rows=350&wt=json"
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.fetch_results(query)
|
15
|
-
uri = URI.parse(query_url(query))
|
16
|
-
|
17
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
18
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
19
|
-
|
20
|
-
begin
|
21
|
-
response = http.request(request)
|
22
|
-
rescue SocketError
|
23
|
-
puts "Internet Connection not available".red
|
24
|
-
exit 1
|
25
|
-
end
|
26
|
-
|
27
|
-
if response.code == '200'
|
28
|
-
result = JSON.parse(response.body)
|
29
|
-
|
30
|
-
# Amount of results
|
31
|
-
num_results = result['response']['numFound']
|
32
|
-
|
33
|
-
suggestions = nil
|
34
|
-
|
35
|
-
# Possible suggestions
|
36
|
-
if num_results==0
|
37
|
-
suggestions = (result['spellcheck']['suggestions'].last || {})['suggestion']
|
38
|
-
end
|
39
|
-
|
40
|
-
# Init the result list
|
41
|
-
result_list = Array.new
|
42
|
-
|
43
|
-
# query google reps
|
44
|
-
result_list = query_offline_reps(query)
|
45
|
-
|
46
|
-
# Iterate the libraries
|
47
|
-
result['response']['docs'].each do |doc|
|
48
|
-
output = " compile '#{doc['id']}:#{doc['latestVersion']}'"
|
49
|
-
result_list << output
|
50
|
-
end
|
51
|
-
|
52
|
-
return num_results, result_list, suggestions
|
53
|
-
else
|
54
|
-
puts "Error: #{response.code}\n#{response}".red
|
55
|
-
exit 1
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# QUERY OFFLINE REPOSITORIES (google)
|
60
|
-
def self.query_offline_reps(query)
|
61
|
-
|
62
|
-
google_libs = Array.new
|
63
|
-
google_libs << 'com.android.support:appcompat-v7'
|
64
|
-
google_libs << 'com.android.support:cardview-v7'
|
65
|
-
google_libs << 'com.android.support:gridlayout-v7'
|
66
|
-
google_libs << 'com.android.support:leanback-v17'
|
67
|
-
google_libs << 'com.android.support:mediarouter-v7'
|
68
|
-
google_libs << 'com.android.support:palette-v7'
|
69
|
-
google_libs << 'com.android.support:support-annotations'
|
70
|
-
google_libs << 'com.android.support:support-v4'
|
71
|
-
google_libs << 'com.android.support:support-v13'
|
72
|
-
google_libs << 'com.google.android.gms:play-services-wearable'
|
73
|
-
google_libs << 'com.google.android.gms:play-services'
|
74
|
-
google_libs << 'com.android.support:recyclerview-v7'
|
75
|
-
|
76
|
-
found_libs = Array.new
|
77
|
-
|
78
|
-
# is there anything?
|
79
|
-
google_libs.each do |lib|
|
80
|
-
|
81
|
-
if lib.include?(query)
|
82
|
-
found_libs << " compile '#{lib}:+'"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
return found_libs
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
# INIT
|
91
|
-
def self.initialize (param)
|
92
|
-
|
93
|
-
if param == nil
|
94
|
-
puts "Missing query parameter".red
|
95
|
-
puts "\tusage: alfi SEARCH_QUERY".yellow
|
96
|
-
else
|
97
|
-
if param.size>=3
|
98
|
-
|
99
|
-
puts "Searching...\n"
|
100
|
-
|
101
|
-
num_results, result_list, suggestions = fetch_results(param)
|
102
|
-
|
103
|
-
if !result_list
|
104
|
-
puts 'Something went wrong with your search'.red
|
105
|
-
exit 1
|
106
|
-
end
|
107
|
-
|
108
|
-
puts "\ndependencies {\n" if num_results>0
|
109
|
-
# Iterate to print results
|
110
|
-
result_list.each do |result|
|
111
|
-
puts result.green
|
112
|
-
end
|
113
|
-
puts "}\n" if num_results>0
|
114
|
-
|
115
|
-
puts "\nFound: #{num_results} result#{num_results>1?'s':''} for '#{param}'"
|
116
|
-
|
117
|
-
|
118
|
-
# handle the suggestions
|
119
|
-
if suggestions!=nil
|
120
|
-
|
121
|
-
output = ''
|
122
|
-
|
123
|
-
# iterate the suggestions
|
124
|
-
suggestions.each do |suggestion|
|
125
|
-
output += "#{suggestion} ".yellow
|
126
|
-
end
|
127
|
-
puts "Did you mean: #{output}"
|
128
|
-
end
|
129
|
-
else
|
130
|
-
puts 'The search needs 3+ characters'.red
|
131
|
-
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
10
|
+
Dir["#{File.dirname(__FILE__)}/alfi/**/*.rb"].each { |file| require file }
|
data/lib/alfi/cli.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
class Alfi::Cli
|
2
|
+
BINTRAY_OPTIONS_FILE_NAME = File.expand_path('~/.alfi_bintray.json')
|
3
|
+
|
4
|
+
def exit_with(message)
|
5
|
+
puts message
|
6
|
+
exit 1
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(arguments)
|
10
|
+
create_options_parser
|
11
|
+
search_param = @all_defined_arguments.include?(arguments.first) ? nil : arguments.shift
|
12
|
+
@bintray_username = nil
|
13
|
+
@bintray_key = nil
|
14
|
+
@opt_parser.parse!(arguments)
|
15
|
+
|
16
|
+
parse_bintray_auth
|
17
|
+
|
18
|
+
exit_with("Missing query parameter\n".red + @opt_parser.help) unless search_param
|
19
|
+
|
20
|
+
Alfi::Search.new.call(search_param)
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_options_parser
|
24
|
+
@all_defined_arguments = [
|
25
|
+
'-u',
|
26
|
+
'--user',
|
27
|
+
'-k',
|
28
|
+
'--key',
|
29
|
+
'-h',
|
30
|
+
'--help',
|
31
|
+
'-v',
|
32
|
+
'--version'
|
33
|
+
]
|
34
|
+
@opt_parser = OptionParser.new do |opts|
|
35
|
+
opts.banner = "Usage: alfi SEARCH_QUERY [OPTIONS]"
|
36
|
+
opts.separator ''
|
37
|
+
opts.separator 'Options'
|
38
|
+
|
39
|
+
opts.on('-u BINTRAY_USER_NAME', '--user BINTRAY_USER_NAME', 'your binray user name') do |bintray_username|
|
40
|
+
@bintray_username = bintray_username
|
41
|
+
end
|
42
|
+
opts.on('-k BINTRAY_KEY', '--key BINTRAY_KEY', 'your binray api key') do |bintray_key|
|
43
|
+
@bintray_key = bintray_key
|
44
|
+
end
|
45
|
+
opts.on('-h', '--help', 'Displays help') do
|
46
|
+
puts opts.help
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
opts.on('-v', '--version', 'Displays version') do
|
50
|
+
puts Alfi::VERSION
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
|
54
|
+
opts.separator "\nNow you are using alfi credentials for Bintray".yellow
|
55
|
+
opts.separator "But you also could enter your authentication data if you want. "\
|
56
|
+
"It will be saved once you provided it\n".green unless @bintray_username
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse_bintray_auth
|
61
|
+
$bintray_auth = if @bintray_username && @bintray_key
|
62
|
+
# write new auth data
|
63
|
+
new_data = { user_name: @bintray_username, api_key: @bintray_key }
|
64
|
+
File.open(BINTRAY_OPTIONS_FILE_NAME, 'w+') do |f|
|
65
|
+
f.puts new_data.to_json
|
66
|
+
end
|
67
|
+
new_data
|
68
|
+
else
|
69
|
+
# read old auth data
|
70
|
+
return unless File.exist?(BINTRAY_OPTIONS_FILE_NAME)
|
71
|
+
auth_data = JSON.parse(File.read(BINTRAY_OPTIONS_FILE_NAME) || '{}', symbolize_names: true)
|
72
|
+
auth_data if auth_data[:user_name] && auth_data[:api_key]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Alfi::Providers::Base
|
2
|
+
def initialize(query)
|
3
|
+
@query = query
|
4
|
+
@uri = URI.parse(query_url(query))
|
5
|
+
@http = Net::HTTP.new(@uri.host, @uri.port)
|
6
|
+
@request = Net::HTTP::Get.new(@uri.request_uri)
|
7
|
+
request_extensions if self.class.method_defined?(:request_extensions)
|
8
|
+
end
|
9
|
+
|
10
|
+
def query_url
|
11
|
+
fail NotImplementedError
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
fail NotImplementedError
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_to_list(helper_string)
|
19
|
+
$result_list << helper_string
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_suggestions(suggestions)
|
23
|
+
$suggestions += Array(suggestions)
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_repo_to_list(package)
|
27
|
+
$result_list << " compile '#{package}'".green
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class Alfi::Providers::Bintray < Alfi::Providers::Base
|
2
|
+
PROVIDERS_TEXTS = {
|
3
|
+
'maven' => 'mavenCentral()',
|
4
|
+
'jcenter' => 'jcenter()'
|
5
|
+
}
|
6
|
+
ALFI_BINTRAY_CREDS = [
|
7
|
+
{
|
8
|
+
user_name: 'alfi',
|
9
|
+
api_key: '5bfa2bedc8d2f5abb8a3fdff49a8599d6ebe7bef'
|
10
|
+
},
|
11
|
+
{
|
12
|
+
user_name: 'alfi2',
|
13
|
+
api_key: '98ebb0e5c0fb45c03a1d747da5532b294e01f77e'
|
14
|
+
},
|
15
|
+
{
|
16
|
+
user_name: 'alfi3',
|
17
|
+
api_key: 'd506539a493ede165e6497269bea4b0f822fdb6a'
|
18
|
+
},
|
19
|
+
{
|
20
|
+
user_name: 'alfi4',
|
21
|
+
api_key: '3da11d361aa52d5d46ee5fd320838f7a5592d9e1'
|
22
|
+
}
|
23
|
+
]
|
24
|
+
|
25
|
+
def query_url(query)
|
26
|
+
"https://api.bintray.com/search/packages?name=#{query}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def request_extensions
|
30
|
+
unless $bintray_auth
|
31
|
+
puts " # Bintray using random credentials".yellow
|
32
|
+
$bintray_auth = ALFI_BINTRAY_CREDS.sample
|
33
|
+
end
|
34
|
+
@http.use_ssl = true
|
35
|
+
@request.basic_auth $bintray_auth[:user_name], $bintray_auth[:api_key]
|
36
|
+
end
|
37
|
+
|
38
|
+
def call
|
39
|
+
begin
|
40
|
+
response = @http.request(@request)
|
41
|
+
rescue SocketError
|
42
|
+
puts "Internet Connection not available".red
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
|
46
|
+
return if response.code != '200'
|
47
|
+
response_json = JSON.parse(response.body || '{}')
|
48
|
+
|
49
|
+
add_to_list " # #{'-'*20}Bintray#{'-'*20}" if response_json.size > 0
|
50
|
+
|
51
|
+
response_json.group_by { |package| package['repo'] }.each do |provider, repositories|
|
52
|
+
add_to_list " # #{PROVIDERS_TEXTS[provider]}"
|
53
|
+
repositories.each do |repo|
|
54
|
+
add_repo_to_list "#{repo['system_ids'][0]}:#{repo['latest_version']}" if repo['system_ids'].size > 0
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Alfi::Providers::Maven < Alfi::Providers::Base
|
2
|
+
def query_url(query)
|
3
|
+
"http://search.maven.org/solrsearch/select?q=#{query}&rows=350&wt=json"
|
4
|
+
end
|
5
|
+
|
6
|
+
def call
|
7
|
+
begin
|
8
|
+
response = @http.request(@request)
|
9
|
+
rescue SocketError
|
10
|
+
puts "Internet Connection not available".red
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
|
14
|
+
if response.code == '200'
|
15
|
+
result = JSON.parse(response.body)
|
16
|
+
|
17
|
+
num_results = result['response']['numFound']
|
18
|
+
|
19
|
+
if num_results == 0
|
20
|
+
suggestions = (result['spellcheck']['suggestions'].last || {})['suggestion']
|
21
|
+
add_suggestions(suggestions) if suggestions
|
22
|
+
else
|
23
|
+
add_to_list " # #{'-'*20}Maven.org#{'-'*20}"
|
24
|
+
add_to_list ' # mavenCentral()'
|
25
|
+
end
|
26
|
+
result['response']['docs'].each { |doc| add_repo_to_list "#{doc['id']}:#{doc['latestVersion']}" }
|
27
|
+
else
|
28
|
+
puts "Error: #{response.code}\n#{response}".red
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# require 'alfi/providers/base'
|
2
|
+
class Alfi::Providers::Offline < Alfi::Providers::Base
|
3
|
+
def initialize(query)
|
4
|
+
@query = query
|
5
|
+
end
|
6
|
+
|
7
|
+
def call
|
8
|
+
google_libs = [
|
9
|
+
'com.android.support:appcompat-v7',
|
10
|
+
'com.android.support:cardview-v7',
|
11
|
+
'com.android.support:gridlayout-v7',
|
12
|
+
'com.android.support:leanback-v17',
|
13
|
+
'com.android.support:mediarouter-v7',
|
14
|
+
'com.android.support:palette-v7',
|
15
|
+
'com.android.support:support-annotations',
|
16
|
+
'com.android.support:support-v4',
|
17
|
+
'com.android.support:support-v13',
|
18
|
+
'com.google.android.gms:play-services-wearable',
|
19
|
+
'com.google.android.gms:play-services',
|
20
|
+
'com.android.support:recyclerview-v7'
|
21
|
+
]
|
22
|
+
results = google_libs.map { |lib| "#{lib}:+" if lib.include?(@query) }.compact
|
23
|
+
return unless results.size > 0
|
24
|
+
add_to_list ' # Google'
|
25
|
+
results.each { |library| add_repo_to_list(library) }
|
26
|
+
end
|
27
|
+
end
|
data/lib/alfi/search.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
class Alfi::Search
|
2
|
+
def initialize
|
3
|
+
$result_list = []
|
4
|
+
$suggestions = []
|
5
|
+
end
|
6
|
+
|
7
|
+
def exit_with(message)
|
8
|
+
puts message
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(search_param)
|
13
|
+
return puts 'The search needs 3+ characters'.red if search_param.size < 3
|
14
|
+
puts "Searching...\n"
|
15
|
+
|
16
|
+
Alfi::Providers.all.each { |cc| cc.new(search_param).call }
|
17
|
+
|
18
|
+
exit_with('No results'.red) if $result_list.empty? && $suggestions.empty?
|
19
|
+
num_results = $result_list.count { |r| r.strip[0] != '#' }
|
20
|
+
|
21
|
+
if num_results > 0
|
22
|
+
puts "\ndependencies {\n"
|
23
|
+
$result_list.each { |result| puts result }
|
24
|
+
puts "}\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
puts "\nFound: #{num_results} result#{num_results > 1?'s':''} for '#{search_param.yellow}'"
|
28
|
+
|
29
|
+
return if $suggestions.empty?
|
30
|
+
puts "Did you mean: #{$suggestions.join(', ').yellow}"
|
31
|
+
end
|
32
|
+
end
|
data/lib/alfi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alfi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cesar ferreira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.10.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.10.1
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: bundler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,6 +145,13 @@ files:
|
|
131
145
|
- extras/images/terminal01.gif
|
132
146
|
- extras/images/wide-logo.png
|
133
147
|
- lib/alfi.rb
|
148
|
+
- lib/alfi/cli.rb
|
149
|
+
- lib/alfi/providers.rb
|
150
|
+
- lib/alfi/providers/base.rb
|
151
|
+
- lib/alfi/providers/bintray.rb
|
152
|
+
- lib/alfi/providers/maven.rb
|
153
|
+
- lib/alfi/providers/offline.rb
|
154
|
+
- lib/alfi/search.rb
|
134
155
|
- lib/alfi/version.rb
|
135
156
|
homepage: https://github.com/cesarferreira/alfi
|
136
157
|
licenses:
|
@@ -152,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
173
|
version: '0'
|
153
174
|
requirements: []
|
154
175
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.4.
|
176
|
+
rubygems_version: 2.4.8
|
156
177
|
signing_key:
|
157
178
|
specification_version: 4
|
158
179
|
summary: Android Library Finder
|