alfi 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0633e677fc670dbc88146eabc2cd5c89f3603bc
4
- data.tar.gz: af0b1c8a0d733edfa60c689b089da11bbf99ba98
3
+ metadata.gz: 1d07d7fb4c9aeba401ae4ef9b068de84c2eb8732
4
+ data.tar.gz: 41b540df33caf99a587eb15978f807d99a789b50
5
5
  SHA512:
6
- metadata.gz: f682c176e633ef529b6fd040a6d57e8d86e47c88b2bbe83464f7e02b22ace4d79e8da4070238a8b550eb3ccb489a7a3f17165c1b251bfb6fd39869d2aeaebc65
7
- data.tar.gz: 8812c640dec3f882b520a6d4f4112838495fc8ffea5bbe960290c423ff1ccc6de998bf6a81505057dbf144d5a123fae08f4ab2f2e52f653906f0fd760faa7cf2
6
+ metadata.gz: 777dde62f366a2f3336c5e718668c7fa57d0437264a83b47a1a5ea938c2d6ebe561cf079ecde1f331844aff9c5732bc3ad42a30bc955320bb4cef10a957afb35
7
+ data.tar.gz: 4eadc87f42ba066aff43a0eafa1cd27b73d8a6e1831a5ef2854a72336337c3059298d44dce1eb27f1985075a2ec25ecf0ebd4c6c6c210d7a3284b727744d6aef
data/.travis.yml CHANGED
@@ -1,4 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.2.0
data/README.md CHANGED
@@ -17,6 +17,21 @@ alfi picasso
17
17
  <img src="https://raw.github.com/cesarferreira/alfi/master/extras/images/terminal01.gif" />
18
18
  </p>
19
19
 
20
+
21
+ Search for `something` by repository
22
+
23
+ ```bash
24
+ alfi picasso --repository maven
25
+ ```
26
+
27
+ This will search picasso only on maven, you can also define multiple repositories like:
28
+
29
+ ```bash
30
+ alfi picasso -r mavenCentral -r jCenter
31
+ ```
32
+
33
+ This will search picasso on mavenCentral and jCenter
34
+
20
35
  **Final step:** Copy the library you want to your `build.gradle` and sync it
21
36
 
22
37
  ## Installation
data/lib/alfi/cli.rb CHANGED
@@ -10,6 +10,7 @@ class Alfi::Cli
10
10
  end
11
11
 
12
12
  def call(arguments)
13
+ @search_type = []
13
14
  create_options_parser
14
15
  search_param = @all_defined_arguments.include?(arguments.first) ? nil : arguments.shift
15
16
  @bintray_username = nil
@@ -20,7 +21,7 @@ class Alfi::Cli
20
21
 
21
22
  exit_with("Missing query parameter\n".red + @opt_parser.help) unless search_param
22
23
 
23
- Alfi::Search.new.call(search_param)
24
+ Alfi::Search.new.call(search_param, @search_type)
24
25
  end
25
26
 
26
27
  def create_options_parser
@@ -29,6 +30,8 @@ class Alfi::Cli
29
30
  '--user',
30
31
  '-k',
31
32
  '--key',
33
+ '-r',
34
+ '--repository',
32
35
  '-h',
33
36
  '--help',
34
37
  '-v',
@@ -53,6 +56,24 @@ class Alfi::Cli
53
56
  puts Alfi::VERSION
54
57
  exit
55
58
  end
59
+ opts.on('-r REPOSITORY_NAME', '--repository REPOSITORY_NAME', 'If should search on maven, jCenter or mavenCentral ') do |repository_name|
60
+ if repository_name != "maven" && repository_name != "jcenter" && repository_name != "mavencentral"
61
+ puts "Please choose one of the following maven, jcenter or mavencentral"
62
+ exit
63
+ end
64
+
65
+ if repository_name.downcase == "maven"
66
+ @search_type << "m"
67
+ end
68
+
69
+ if repository_name.downcase == "mavencentral"
70
+ @search_type << "maven"
71
+ end
72
+
73
+ if repository_name.downcase == "jcenter"
74
+ @search_type << "jcenter"
75
+ end
76
+ end
56
77
 
57
78
  opts.separator "\nNow you are using alfi credentials for Bintray".yellow
58
79
  opts.separator "But you also could enter your authentication data if you want. "\
@@ -1,9 +1,10 @@
1
1
  class Alfi::Providers::Base
2
- def initialize(query)
2
+ def initialize(query, search_type)
3
3
  @query = query
4
4
  @uri = URI.parse(query_url(query))
5
5
  @http = Net::HTTP.new(@uri.host, @uri.port)
6
6
  @request = Net::HTTP::Get.new(@uri.request_uri)
7
+ @search_type = search_type
7
8
  request_extensions if self.class.method_defined?(:request_extensions)
8
9
  end
9
10
 
@@ -36,22 +36,26 @@ class Alfi::Providers::Bintray < Alfi::Providers::Base
36
36
  end
37
37
 
38
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
39
+ if @search_type.empty? || @search_type.include?('jcenter') || @search_type.include?('maven')
40
+ begin
41
+ response = @http.request(@request)
42
+ rescue SocketError
43
+ puts "Internet Connection not available".red
44
+ exit 1
45
+ end
45
46
 
46
- return if response.code != '200'
47
- response_json = JSON.parse(response.body || '{}')
47
+ return if response.code != '200'
48
+ response_json = JSON.parse(response.body || '{}')
48
49
 
49
- add_to_list " # #{'-'*20}Bintray#{'-'*20}" if response_json.size > 0
50
+ add_to_list " # #{'-'*20}Bintray#{'-'*20}" if response_json.size > 0
50
51
 
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
52
+ response_json.group_by { |package| package['repo'] }.each do |provider, repositories|
53
+ if @search_type.empty? || @search_type.include?(provider)
54
+ add_to_list " # #{PROVIDERS_TEXTS[provider]}"
55
+ repositories.each do |repo|
56
+ add_repo_to_list "#{repo['system_ids'][0]}:#{repo['latest_version']}" if repo['system_ids'].size > 0
57
+ end
58
+ end
55
59
  end
56
60
  end
57
61
  end
@@ -4,29 +4,31 @@ class Alfi::Providers::Maven < Alfi::Providers::Base
4
4
  end
5
5
 
6
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
7
+ if @search_type.empty? || @search_type.include?('m')
8
+ begin
9
+ response = @http.request(@request)
10
+ rescue SocketError
11
+ puts "Internet Connection not available".red
12
+ exit 1
13
+ end
13
14
 
14
- if response.code == '200'
15
- result = JSON.parse(response.body)
15
+ if response.code == '200'
16
+ result = JSON.parse(response.body)
16
17
 
17
- num_results = result['response']['numFound']
18
+ num_results = result['response']['numFound']
18
19
 
19
- if num_results == 0
20
- suggestions = (result['spellcheck']['suggestions'].last || {})['suggestion']
21
- add_suggestions(suggestions) if suggestions
20
+ if num_results == 0
21
+ suggestions = (result['spellcheck']['suggestions'].last || {})['suggestion']
22
+ add_suggestions(suggestions) if suggestions
23
+ else
24
+ add_to_list " # #{'-'*20}Maven.org#{'-'*20}"
25
+ add_to_list ' # mavenCentral()'
26
+ end
27
+ result['response']['docs'].each { |doc| add_repo_to_list "#{doc['id']}:#{doc['latestVersion']}" }
22
28
  else
23
- add_to_list " # #{'-'*20}Maven.org#{'-'*20}"
24
- add_to_list ' # mavenCentral()'
29
+ puts "Error: #{response.code}\n#{response}".red
30
+ exit 1
25
31
  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
32
  end
31
33
  end
32
34
  end
@@ -1,6 +1,6 @@
1
1
  # require 'alfi/providers/base'
2
2
  class Alfi::Providers::Offline < Alfi::Providers::Base
3
- def initialize(query)
3
+ def initialize(query, search_type)
4
4
  @query = query
5
5
  end
6
6
 
data/lib/alfi/search.rb CHANGED
@@ -9,14 +9,14 @@ class Alfi::Search
9
9
  exit 1
10
10
  end
11
11
 
12
- def call(search_param)
12
+ def call(search_param, search_type)
13
13
  return puts 'The search needs 3+ characters'.red if search_param.size < 3
14
14
  puts "Searching...\n"
15
15
 
16
- Alfi::Providers.all.each { |cc| cc.new(search_param).call }
16
+ Alfi::Providers.all.each { |cc| cc.new(search_param, search_type).call }
17
17
 
18
18
  exit_with('No results'.red) if $result_list.empty? && $suggestions.empty?
19
- num_results = $result_list.count { |r| r.strip[0] != '#' }
19
+ num_results = total_results_count
20
20
 
21
21
  if num_results > 0
22
22
  puts "\ndependencies {\n"
@@ -29,4 +29,8 @@ class Alfi::Search
29
29
  return if $suggestions.empty?
30
30
  puts "Did you mean: #{$suggestions.join(', ').yellow}"
31
31
  end
32
+
33
+ def total_results_count
34
+ return $result_list.count { |r| r.strip[0] != '#' }
35
+ end
32
36
  end
data/lib/alfi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Alfi
2
- VERSION = '0.4.4'
2
+ VERSION = '0.4.5'
3
3
  end
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.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - cesar ferreira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-21 00:00:00.000000000 Z
11
+ date: 2016-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake