itamae-sonar 1.0.0 → 1.0.1

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: 7bc4c6d62ea536ac994831d60c796dc7d84d788b
4
- data.tar.gz: cc5c5557064b26eb063fa9c1d06d2d594de8b6a1
3
+ metadata.gz: 59aff8db71919acfc136b81081bca783d403c1f1
4
+ data.tar.gz: 6e86a67a5dc9d05aab1114b5cedff8dfbda0302c
5
5
  SHA512:
6
- metadata.gz: b61ab93155c1bf54a8f2233afb11c623d8f810dfa1f701d895469c81bf2149d26496851b2262f5b348223875a3cce5727ff04576c26ebf04a1c4bbeeaace10b6
7
- data.tar.gz: c2071784bba7ca336ce57bcde1bbad6caa5af2eea2d427fdb9d316ba923e1eac786118cd23733e5f1637257a9a2c4b731c9be2c0fb6025edf528f13b64b33e1b
6
+ metadata.gz: b397beb461970333ab8b54a9fe5289ad4aff3cc2a2eec902c48a50cd0c33d4e490f71e7bb68de71f4ff8fecd92424bedb1aaed1ef5e87a8e9bedda8a26906380
7
+ data.tar.gz: 250f5a69dfd75ba385b198d5d549160570eda8e67e4875809e84caccfbf5ac315ff523850fad1d7cb65a416c74d084b9c559f9c668113805b15a34a2cb1b168d
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,10 @@
1
+ ## v.1.0.1
2
+ 2015/01/07
3
+
4
+ ### Update Feature
5
+ * Fix search (Enable Paging)
6
+
7
+ ## v.1.0.0
8
+ 2014/12/04
9
+
10
+ * first release
data/README.md CHANGED
@@ -4,7 +4,9 @@ ItamaeSonar search itamae plugin gems.
4
4
 
5
5
  [Itamae](https://github.com/ryotarai/itamae) is Simple and lightweight configuration management tool inspired by Chef.
6
6
 
7
+ [![Gem Version](https://badge.fury.io/rb/itamae-sonar.svg)](http://badge.fury.io/rb/itamae-sonar)
7
8
  [![Build Status](https://travis-ci.org/tbpgr/itamae-sonar.png?branch=master)](https://travis-ci.org/tbpgr/itamae-sonar)
9
+ [![Coverage Status](https://coveralls.io/repos/tbpgr/itamae-sonar/badge.png)](https://coveralls.io/r/tbpgr/itamae-sonar)
8
10
 
9
11
  ## Installation
10
12
 
@@ -1,55 +1,82 @@
1
- # encoding: utf-8
2
- require 'gems'
3
-
4
- module ItamaeSonar
5
- module_function
6
-
7
- RUBOTY_SEARCH_CONDITION = 'itamae-'
8
-
9
- def self.info(gem_name)
10
- gem_info = Gems.info(gem_name)
11
- {
12
- name: gem_info['name'],
13
- desc: gem_info['info'],
14
- downloads: gem_info['downloads'],
15
- rubygems_uri: gem_info['project_uri'],
16
- homepage_uri: gem_info['homepage_uri']
17
- }
18
- end
19
-
20
- def self.random
21
- gem_info = Gems.search(RUBOTY_SEARCH_CONDITION).sample
22
- {
23
- name: gem_info['name'],
24
- desc: gem_info['info'],
25
- downloads: gem_info['downloads'],
26
- rubygems_uri: gem_info['project_uri'],
27
- homepage_uri: gem_info['homepage_uri']
28
- }
29
- end
30
-
31
- def self.ranking(limit = 5)
32
- Gems.search(RUBOTY_SEARCH_CONDITION)
33
- .map { |e|
34
- {
35
- name: e['name'],
36
- downloads: e['downloads'].to_i,
37
- authors: e['authors']
38
- }
39
- }.sort_by { |e|-e[:downloads] }
40
- .take(limit)
41
- end
42
-
43
- def self.author_ranking(limit = 5)
44
- Gems.search(RUBOTY_SEARCH_CONDITION)
45
- .map { |e|{ authors: e['authors'], downloads: e['downloads'] } }
46
- .group_by { |e| e[:authors] }
47
- .map { |key, values|
48
- {
49
- authors: key,
50
- downloads: values.reduce(0) { |a, e|a + e[:downloads] }
51
- }
52
- }.sort_by { |e| -e[:downloads] }
53
- .take(limit)
54
- end
55
- end
1
+ # encoding: utf-8
2
+ require 'gems'
3
+ require 'date'
4
+ require 'gems/configuration'
5
+ require 'gems/request'
6
+ require 'json'
7
+
8
+ # open class for paging
9
+ module Gems
10
+ class Client
11
+ include Gems::Request
12
+ def search_with_page(query, page)
13
+ response = get('/api/v1/search.json', :query => query, :page => page.to_s)
14
+ JSON.parse(response)
15
+ end
16
+ end
17
+ end
18
+
19
+ module ItamaeSonar
20
+ module_function
21
+
22
+ RUBOTY_SEARCH_CONDITION = 'itamae-'
23
+
24
+ def self.info(gem_name)
25
+ gem_info = Gems.info(gem_name)
26
+ {
27
+ name: gem_info['name'],
28
+ desc: gem_info['info'],
29
+ downloads: gem_info['downloads'],
30
+ rubygems_uri: gem_info['project_uri'],
31
+ homepage_uri: gem_info['homepage_uri']
32
+ }
33
+ end
34
+
35
+ def self.search(query)
36
+ results = []
37
+ page = 1
38
+ loop {
39
+ ret = Gems.search_with_page(query, page)
40
+ break if ret.empty?
41
+ results += ret
42
+ page += 1
43
+ }
44
+ results
45
+ end
46
+
47
+ def self.random
48
+ gem_info = search(RUBOTY_SEARCH_CONDITION).sample
49
+ {
50
+ name: gem_info['name'],
51
+ desc: gem_info['info'],
52
+ downloads: gem_info['downloads'],
53
+ rubygems_uri: gem_info['project_uri'],
54
+ homepage_uri: gem_info['homepage_uri']
55
+ }
56
+ end
57
+
58
+ def self.ranking(limit = 5)
59
+ search(RUBOTY_SEARCH_CONDITION)
60
+ .map { |e|
61
+ {
62
+ name: e['name'],
63
+ downloads: e['downloads'].to_i,
64
+ authors: e['authors']
65
+ }
66
+ }.sort_by { |e|-e[:downloads] }
67
+ .take(limit)
68
+ end
69
+
70
+ def self.author_ranking(limit = 5)
71
+ search(RUBOTY_SEARCH_CONDITION)
72
+ .map { |e|{ authors: e['authors'], downloads: e['downloads'] } }
73
+ .group_by { |e| e[:authors] }
74
+ .map { |key, values|
75
+ {
76
+ authors: key,
77
+ downloads: values.reduce(0) { |a, e|a + e[:downloads] }
78
+ }
79
+ }.sort_by { |e| -e[:downloads] }
80
+ .take(limit)
81
+ end
82
+ end
@@ -1,4 +1,4 @@
1
1
  # ItamaeSonar
2
2
  module ItamaeSonar
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
@@ -125,7 +125,7 @@ describe ItamaeSonar do
125
125
  case_before c
126
126
 
127
127
  # -- given --
128
- allow(Gems).to receive(:search).and_return(itamae_mock)
128
+ allow(ItamaeSonar).to receive(:search).and_return(itamae_mock)
129
129
 
130
130
  # -- when --
131
131
  actual = ItamaeSonar.random
@@ -208,7 +208,7 @@ describe ItamaeSonar do
208
208
  case_before c
209
209
 
210
210
  # -- given --
211
- allow(Gems).to receive(:search).and_return(itamae_mock)
211
+ allow(ItamaeSonar).to receive(:search).and_return(itamae_mock)
212
212
 
213
213
  # -- when --
214
214
  if c[:limit]
@@ -305,7 +305,7 @@ describe ItamaeSonar do
305
305
  case_before c
306
306
 
307
307
  # -- given --
308
- allow(Gems).to receive(:search).and_return(itamae_mock)
308
+ allow(ItamaeSonar).to receive(:search).and_return(itamae_mock)
309
309
 
310
310
  # -- when --
311
311
  if c[:limit]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae-sonar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tbpgr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-04 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -74,10 +74,12 @@ executables:
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
+ - .coveralls.yml
77
78
  - .gitignore
78
79
  - .rspec
79
80
  - .rubocop.yml
80
81
  - .travis.yml
82
+ - CHANGELOG.md
81
83
  - Gemfile
82
84
  - LICENSE.txt
83
85
  - README.md