bestgems 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/bestgems/client/trends.rb +15 -2
- data/lib/bestgems/version.rb +1 -1
- data/spec/bestgems/trends_spec.rb +28 -16
- data/spec/cassettes/growth.yml +73 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14c1d35feeed1b53232a0901bfd270044e5c6a84
|
4
|
+
data.tar.gz: 7161163e4c619fa77fcf9e3e1656a3211f0f5a45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 346c7b72320e0513b4b08e60fd894b1d7998dcc01acaeeaacf408423dd7b18d133e1d4442aaa1d2360d65981ce72d63c2ec8677cef761e93c689c1dd38fcb333
|
7
|
+
data.tar.gz: b40ac9844cfc417e4b19c2af59480b21c6a811eaaa0d6b4bff985d7b64a812fb397c5ad29247cc870d38fe64ce5f5152c9a8d2106ad0f419ae5fee7a447156f1
|
data/README.md
CHANGED
@@ -27,13 +27,13 @@ require 'bestgems'
|
|
27
27
|
|
28
28
|
client = Bestgems.client
|
29
29
|
|
30
|
-
client.total_downloads(:rack) # =>
|
30
|
+
client.total_downloads(:rack) # => {"2014-08-08"=>48484297, "2014-08-07"=>48426620, "2014-08-06"=>48365953, "2014-08-05"=>48305390, "2014-08-04"=>48246069, "2014-08-03"=>48203248, ... }
|
31
31
|
|
32
|
-
client.daily_downloads(:rack) # =>
|
32
|
+
client.daily_downloads(:rack) # => {"2014-08-08"=>57677, "2014-08-07"=>60667, "2014-08-06"=>60563, "2014-08-05"=>59321, "2014-08-04"=>42821, "2014-08-03"=>30640, ... }
|
33
33
|
|
34
|
-
client.total_ranking(:rack) # =>
|
34
|
+
client.total_ranking(:rack) # => {"2014-08-08"=>2, "2014-08-07"=>2, "2014-08-06"=>2, "2014-08-05"=>2, "2014-08-04"=>2, "2014-08-03"=>2, "2014-08-02"=>2, "2014-08-01"=>2, "2014-07-31"=>2, ... }
|
35
35
|
|
36
|
-
client.daily_ranking(:rack) # =>
|
36
|
+
client.daily_ranking(:rack) # => {"2014-08-08"=>6, "2014-08-07"=>6, "2014-08-06"=>6, "2014-08-05"=>7, "2014-08-04"=>4, "2014-08-03"=>3, "2014-08-02"=>3, "2014-08-01"=>6, "2014-07-31"=>6, ... }
|
37
37
|
```
|
38
38
|
|
39
39
|
## Contributing
|
@@ -23,9 +23,22 @@ module Bestgems
|
|
23
23
|
json2rb_obj(res)
|
24
24
|
end
|
25
25
|
|
26
|
+
# return: growth point based on diff between total and daily ranking
|
27
|
+
# in base_days(default: 5).
|
28
|
+
def growth(gem_name, base_days:5)
|
29
|
+
total = total_ranking(gem_name)
|
30
|
+
daily = daily_ranking(gem_name)
|
31
|
+
total, daily = [total, daily].map do |data|
|
32
|
+
data.take(base_days).inject(0) { |m, (_, rank)| rank ? m + rank : m }
|
33
|
+
end
|
34
|
+
(total - daily) / base_days
|
35
|
+
end
|
36
|
+
|
26
37
|
def json2rb_obj(data)
|
27
|
-
JSON.parse(data).
|
28
|
-
|
38
|
+
JSON.parse(data).inject({}) do |mem, h|
|
39
|
+
date, val = h.values
|
40
|
+
mem[date] = val
|
41
|
+
mem
|
29
42
|
end
|
30
43
|
end
|
31
44
|
end
|
data/lib/bestgems/version.rb
CHANGED
@@ -4,11 +4,11 @@ describe Bestgems::Client do
|
|
4
4
|
let(:client) { Bestgems::Client.new }
|
5
5
|
|
6
6
|
describe "#total_downloads", vcr:{cassette_name:'total_downloads'} do
|
7
|
-
it "gets
|
7
|
+
it "gets a hash with date key and download value" do
|
8
8
|
res = client.total_downloads('colcolor')
|
9
|
-
expect(res).to be_a
|
10
|
-
expect(res.first).to
|
11
|
-
expect(res.first
|
9
|
+
expect(res).to be_a Hash
|
10
|
+
expect(res.keys.first).to match(/\A\d{4}\-\d{2}-\d{2}\z/)
|
11
|
+
expect(res.values.first).to be_a Fixnum
|
12
12
|
end
|
13
13
|
|
14
14
|
context "with an absent gem name", vcr:{cassette_name:'total_downloads_error'} do
|
@@ -19,29 +19,41 @@ describe Bestgems::Client do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#daily_downloads", vcr:{cassette_name:'daily_downloads'} do
|
22
|
-
it "gets
|
22
|
+
it "gets a hash with date key and download value" do
|
23
23
|
res = client.daily_downloads('colcolor')
|
24
|
-
expect(res).to be_a
|
25
|
-
expect(res.first).to
|
26
|
-
expect(res.first
|
24
|
+
expect(res).to be_a Hash
|
25
|
+
expect(res.keys.first).to match(/\A\d{4}\-\d{2}-\d{2}\z/)
|
26
|
+
expect(res.values.first).to be_a Fixnum
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "#total_ranking", vcr:{cassette_name:'total_ranking'} do
|
31
|
-
it "gets
|
31
|
+
it "gets a hash with date key and ranking value" do
|
32
32
|
res = client.total_ranking('colcolor')
|
33
|
-
expect(res).to be_a
|
34
|
-
expect(res.first).to
|
35
|
-
expect(res.first
|
33
|
+
expect(res).to be_a Hash
|
34
|
+
expect(res.keys.first).to match(/\A\d{4}\-\d{2}-\d{2}\z/)
|
35
|
+
expect(res.values.first).to be_a Fixnum
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "#daily_ranking", vcr:{cassette_name:'daily_ranking'} do
|
40
|
-
it "gets
|
40
|
+
it "gets a hash with date key and ranking value" do
|
41
41
|
res = client.daily_ranking('colcolor')
|
42
|
-
expect(res).to be_a
|
43
|
-
expect(res.first).to
|
44
|
-
expect(res.first
|
42
|
+
expect(res).to be_a Hash
|
43
|
+
expect(res.keys.first).to match(/\A\d{4}\-\d{2}-\d{2}\z/)
|
44
|
+
expect(res.values.first).to be_a Fixnum
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#growth", vcr:{cassette_name:'growth'} do
|
49
|
+
it "returns growth point with recent 5 days" do
|
50
|
+
res = client.growth('colcolor')
|
51
|
+
expect(res).to eq 60885
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns growth point with recent 2 days" do
|
55
|
+
res = client.growth('colcolor', base_days:2)
|
56
|
+
expect(res).to eq 58805
|
45
57
|
end
|
46
58
|
end
|
47
59
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://bestgems.org/api/v1/gems/colcolor/total_ranking.json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx/1.2.1
|
23
|
+
Date:
|
24
|
+
- Sat, 09 Aug 2014 09:29:28 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Content-Length:
|
28
|
+
- '1145'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
X-Content-Type-Options:
|
32
|
+
- nosniff
|
33
|
+
body:
|
34
|
+
encoding: UTF-8
|
35
|
+
string: '[{"date":"2014-08-08","total_ranking":68184},{"date":"2014-08-07","total_ranking":68277},{"date":"2014-08-06","total_ranking":68455},{"date":"2014-08-05","total_ranking":68680},{"date":"2014-08-04","total_ranking":69046},{"date":"2014-08-03","total_ranking":69224},{"date":"2014-08-02","total_ranking":69541},{"date":"2014-08-01","total_ranking":69947},{"date":"2014-07-31","total_ranking":70141},{"date":"2014-07-30","total_ranking":71403},{"date":"2014-07-29","total_ranking":72594},{"date":"2014-07-28","total_ranking":72913},{"date":"2014-07-27","total_ranking":73372},{"date":"2014-07-26","total_ranking":73442},{"date":"2014-07-25","total_ranking":73451},{"date":"2014-07-24","total_ranking":73564},{"date":"2014-07-23","total_ranking":75108},{"date":"2014-07-22","total_ranking":75538},{"date":"2014-07-21","total_ranking":75521},{"date":"2014-07-20","total_ranking":75921},{"date":"2014-07-19","total_ranking":76196},{"date":"2014-07-18","total_ranking":76330},{"date":"2014-07-17","total_ranking":76306},{"date":"2014-07-16","total_ranking":76358},{"date":"2014-07-15","total_ranking":77198},{"date":"2014-07-14","total_ranking":78402}]'
|
36
|
+
http_version:
|
37
|
+
recorded_at: Sat, 09 Aug 2014 09:28:58 GMT
|
38
|
+
- request:
|
39
|
+
method: get
|
40
|
+
uri: http://bestgems.org/api/v1/gems/colcolor/daily_ranking.json
|
41
|
+
body:
|
42
|
+
encoding: US-ASCII
|
43
|
+
string: ''
|
44
|
+
headers:
|
45
|
+
User-Agent:
|
46
|
+
- Faraday v0.9.0
|
47
|
+
Accept-Encoding:
|
48
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
49
|
+
Accept:
|
50
|
+
- "*/*"
|
51
|
+
response:
|
52
|
+
status:
|
53
|
+
code: 200
|
54
|
+
message: OK
|
55
|
+
headers:
|
56
|
+
Server:
|
57
|
+
- nginx/1.2.1
|
58
|
+
Date:
|
59
|
+
- Sat, 09 Aug 2014 09:29:28 GMT
|
60
|
+
Content-Type:
|
61
|
+
- application/json
|
62
|
+
Content-Length:
|
63
|
+
- '1082'
|
64
|
+
Connection:
|
65
|
+
- keep-alive
|
66
|
+
X-Content-Type-Options:
|
67
|
+
- nosniff
|
68
|
+
body:
|
69
|
+
encoding: UTF-8
|
70
|
+
string: '[{"date":"2014-08-08","daily_ranking":8984},{"date":"2014-08-07","daily_ranking":9867},{"date":"2014-08-06","daily_ranking":8533},{"date":"2014-08-05","daily_ranking":5292},{"date":"2014-08-04","daily_ranking":5541},{"date":"2014-08-03","daily_ranking":3311},{"date":"2014-08-02","daily_ranking":8345},{"date":"2014-08-01","daily_ranking":6557},{"date":"2014-07-31","daily_ranking":3900},{"date":"2014-07-30","daily_ranking":8676},{"date":"2014-07-29","daily_ranking":13927},{"date":"2014-07-28","daily_ranking":5333},{"date":"2014-07-27","daily_ranking":5050},{"date":"2014-07-26","daily_ranking":11628},{"date":"2014-07-25","daily_ranking":24633},{"date":"2014-07-24","daily_ranking":4591},{"date":"2014-07-23","daily_ranking":4898},{"date":"2014-07-22","daily_ranking":30629},{"date":"2014-07-21","daily_ranking":5702},{"date":"2014-07-20","daily_ranking":6884},{"date":"2014-07-19","daily_ranking":11234},{"date":"2014-07-18","daily_ranking":27172},{"date":"2014-07-17","daily_ranking":9930},{"date":"2014-07-16","daily_ranking":3749},{"date":"2014-07-15","daily_ranking":1694}]'
|
71
|
+
http_version:
|
72
|
+
recorded_at: Sat, 09 Aug 2014 09:28:58 GMT
|
73
|
+
recorded_with: VCR 2.9.2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bestgems
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kyoendo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- spec/cassettes/daily_downloads.yml
|
92
92
|
- spec/cassettes/daily_ranking.yml
|
93
93
|
- spec/cassettes/get.yml
|
94
|
+
- spec/cassettes/growth.yml
|
94
95
|
- spec/cassettes/total_downloads.yml
|
95
96
|
- spec/cassettes/total_downloads_error.yml
|
96
97
|
- spec/cassettes/total_ranking.yml
|
@@ -126,6 +127,7 @@ test_files:
|
|
126
127
|
- spec/cassettes/daily_downloads.yml
|
127
128
|
- spec/cassettes/daily_ranking.yml
|
128
129
|
- spec/cassettes/get.yml
|
130
|
+
- spec/cassettes/growth.yml
|
129
131
|
- spec/cassettes/total_downloads.yml
|
130
132
|
- spec/cassettes/total_downloads_error.yml
|
131
133
|
- spec/cassettes/total_ranking.yml
|