npm_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f1e6f8d9b1c8a78b9b269299c6297406f087da1
4
+ data.tar.gz: d100d336a86a9ba5118d6173232047c28f205bb3
5
+ SHA512:
6
+ metadata.gz: 06c2dd30c94918f65d37dd7fddc71633419188f96ae9fbc5412874f16ed0da0b0e4ccfce7f594b63968c344f9fc15e93a8ec846bc1ec2e4aad678f5104b149a9
7
+ data.tar.gz: 6daccc8ccd0a2ddec43ee56f956736cc3edbfffe5beebfa324bfcd4f939bd829da2883a9e1159dee66a07233b5f79e45f723c818811c8ad2d83345d0c36e144f
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.16.0.pre.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in npm_api.gemspec
6
+ gemspec
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ npm_api (0.1.0)
5
+ activesupport
6
+ rest-client
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.1.4)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (~> 0.7)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ concurrent-ruby (1.0.5)
17
+ diff-lcs (1.3)
18
+ domain_name (0.5.20170404)
19
+ unf (>= 0.0.5, < 1.0.0)
20
+ http-cookie (1.0.3)
21
+ domain_name (~> 0.5)
22
+ i18n (0.8.6)
23
+ mime-types (3.1)
24
+ mime-types-data (~> 3.2015)
25
+ mime-types-data (3.2016.0521)
26
+ minitest (5.10.3)
27
+ netrc (0.11.0)
28
+ rake (10.5.0)
29
+ rest-client (2.0.2)
30
+ http-cookie (>= 1.0.2, < 2.0)
31
+ mime-types (>= 1.16, < 4.0)
32
+ netrc (~> 0.8)
33
+ rspec (3.6.0)
34
+ rspec-core (~> 3.6.0)
35
+ rspec-expectations (~> 3.6.0)
36
+ rspec-mocks (~> 3.6.0)
37
+ rspec-core (3.6.0)
38
+ rspec-support (~> 3.6.0)
39
+ rspec-expectations (3.6.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.6.0)
42
+ rspec-mocks (3.6.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.6.0)
45
+ rspec-support (3.6.0)
46
+ thread_safe (0.3.6)
47
+ tzinfo (1.2.3)
48
+ thread_safe (~> 0.1)
49
+ unf (0.1.4)
50
+ unf_ext
51
+ unf_ext (0.0.7.4)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ bundler (~> 1.16.a)
58
+ npm_api!
59
+ rake (~> 10.0)
60
+ rspec (~> 3.0)
61
+
62
+ BUNDLED WITH
63
+ 1.16.0.pre.2
@@ -0,0 +1,11 @@
1
+ # NpmApi
2
+
3
+ Get stats about NPM's download counts, https://github.com/npm/download-counts.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'npm_api'
11
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "npm_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ require "npm_api/version"
2
+
3
+ require "npm_api/client"
4
+ require "npm_api/download"
5
+
6
+
7
+ require "date"
8
+ require "active_support/all"
9
+ require "rest-client"
10
+
11
+ module NpmApi
12
+ end
@@ -0,0 +1,12 @@
1
+ module NpmApi
2
+ class Client
3
+
4
+ def self.get(path)
5
+ base_url = "https://api.npmjs.org/"
6
+ url = base_url + path
7
+ res = RestClient.get(url)
8
+ JSON.parse(res.body)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ module NpmApi
2
+ class Download
3
+
4
+ def self.month_of(start_day, package=nil)
5
+ raise "start_day must be a 'String'. eg, 2017-04-23" unless start_day.is_a?(String)
6
+
7
+ d = DateTime.parse(start_day)
8
+ sd = d.beginning_of_month
9
+ ed = d.end_of_month
10
+
11
+ path = "downloads/point/#{format_dt(sd)}:#{format_dt(ed)}/#{package}"
12
+
13
+ json = Client.get(path)
14
+ end
15
+
16
+ def self.last_day(package=nil)
17
+ path = "downloads/point/last-day/#{package}"
18
+ json = Client.get(path)
19
+ end
20
+
21
+ def self.last_week(package=nil)
22
+ path = "downloads/point/last-week/#{package}"
23
+ json = Client.get(path)
24
+ end
25
+
26
+ def self.last_month(package=nil)
27
+ path = "downloads/point/last-month/#{package}"
28
+ json = Client.get(path)
29
+ end
30
+
31
+ private
32
+
33
+ def self.format_dt(dt)
34
+ dt.strftime("%Y-%m-%d")
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module NpmApi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ Copyright 2017 Weston Platter
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "npm_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "npm_api"
8
+ spec.version = NpmApi::VERSION
9
+ spec.authors = ["Weston Platter"]
10
+ spec.email = ["westonplatter@gmail.com"]
11
+
12
+ spec.summary = %q{get stats from npm's stats service}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/westonplatter/npm_api"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "activesupport"
24
+ spec.add_dependency "rest-client"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16.a"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: npm_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Weston Platter
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.16.a
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.16.a
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: ''
84
+ email:
85
+ - westonplatter@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/npm_api.rb
100
+ - lib/npm_api/client.rb
101
+ - lib/npm_api/download.rb
102
+ - lib/npm_api/version.rb
103
+ - license.md
104
+ - npm_api.gemspec
105
+ homepage: https://github.com/westonplatter/npm_api
106
+ licenses: []
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.5.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: get stats from npm's stats service
128
+ test_files: []