bentrackergem 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +13 -0
- data/bentrackergem.gemspec +27 -0
- data/lib/bentrackergem.rb +65 -0
- data/lib/bentrackergem/version.rb +3 -0
- data/spec/bentrackergem_spec.rb +88 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e056a6aa55e53e07f175a6858ff36b26214f9269
|
4
|
+
data.tar.gz: 4c521e854e92947a62c2787f70788422396d59df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 81ba5313fd3f70cb8e61d73a0c3fbb5a125ef6b665bfd2da2c803b2afcea769669ea3f181a2b6f0ecf07a85ea6d9ec4b2795787f35071044a12408979ccc775a
|
7
|
+
data.tar.gz: b62eb3419366d342d434f7e8300f5f839d632f05436ab6a72a0cc143847be9dac5e151fdd5e61c7697705af79dc566ee8e4c8a4af7a02b7e8c5bb17a443b1c9c
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ben Brostoff
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# BenTrackerGem
|
2
|
+
|
3
|
+
A gem that records my daily FitBit steps, GitHub contributions and summaries I write to myself. The intent here is for the gem to function as a personal API diary; as of this writing, it has little utility beyond me (unless you wish to know what I did on a given day).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bentrackergem'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bentrackergem
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/bentrackergem/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'bundler'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
desc 'Default: run specs.'
|
8
|
+
task :default => :spec
|
9
|
+
|
10
|
+
desc "Run specs"
|
11
|
+
RSpec::Core::RakeTask.new do |t|
|
12
|
+
t.pattern = "./spec/**/*_spec.rb"
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bentrackergem/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bentrackergem"
|
8
|
+
spec.version = BenTrackerGem::VERSION
|
9
|
+
spec.authors = ["Ben Brostoff"]
|
10
|
+
spec.email = ["ben.brostoff@gmail.com"]
|
11
|
+
spec.summary = %q{A simple Ruby gem that serves as my virtual code, fitness and diary tracker.}
|
12
|
+
spec.description = %q{Leverages FitBit and GitHub to track fitness and code; messages can be input via the command line and are emailed to me via the Mandrill API.}
|
13
|
+
spec.homepage = "https://github.com/BenBrostoff/BenTrackerGem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "json"
|
25
|
+
spec.add_development_dependency "rest_client"
|
26
|
+
spec.add_development_dependency "date"
|
27
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "bentrackergem/version"
|
2
|
+
require "rest_client"
|
3
|
+
require "json"
|
4
|
+
require "date"
|
5
|
+
|
6
|
+
module BenTrackerGem
|
7
|
+
|
8
|
+
URL_GET = 'http://brostofftrack.herokuapp.com/history.json'
|
9
|
+
URL_POST = 'http://brostofftrack.herokuapp.com/email'
|
10
|
+
HISTORY = JSON.parse(RestClient.get URL_GET).to_h["days"]
|
11
|
+
|
12
|
+
VALID_CATS = ["message", "code", "fitness"]
|
13
|
+
|
14
|
+
def self.valid_format(date)
|
15
|
+
date = DateTime.parse(date, "%Y-%m-%d").to_s[0..9]
|
16
|
+
now = Time.now.to_s[0..9]
|
17
|
+
if date > now || date < "2014-09-30"
|
18
|
+
raise ArgumentError, "Date outside range (data begins 2014-09-30)"
|
19
|
+
end
|
20
|
+
date
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.filter_hash(hash)
|
24
|
+
{:day_of => hash["day_of"],
|
25
|
+
:message => hash["message"],
|
26
|
+
:code => hash["code"],
|
27
|
+
:fitness => hash["fitness"]}
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.day_stats(date)
|
31
|
+
date = valid_format(date)
|
32
|
+
HISTORY.each do |summary|
|
33
|
+
if summary["day_of"] == date
|
34
|
+
return filter_hash(summary)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.date_range(begin_date, end_date)
|
40
|
+
begin_date, end_date, hold = valid_format(begin_date), valid_format(end_date), []
|
41
|
+
filter = HISTORY.select { |summary| summary["day_of"] >= begin_date &&
|
42
|
+
summary["day_of"] <= end_date }.
|
43
|
+
map { |summary| day_stats(summary["day_of"]) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.date_range_visual(req, begin_date, end_date, sort = 0)
|
47
|
+
raise ArgumentError, "must select valid category" if !VALID_CATS.include? req
|
48
|
+
|
49
|
+
filter = date_range(begin_date, end_date)
|
50
|
+
filter = filter.reverse if sort == 1
|
51
|
+
filter.each do |visi|
|
52
|
+
puts visi[:day_of] + ". " + visi[req.to_sym].to_s
|
53
|
+
end
|
54
|
+
"COMPLETE"
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.post_message(message)
|
58
|
+
raise ArgumentError, "must enter message as String" if !message.is_a? String
|
59
|
+
|
60
|
+
RestClient.post URL_POST, { 'message' => message }.to_json,
|
61
|
+
:content_type => :json,
|
62
|
+
:accept => :json
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'Bentrackergem'
|
2
|
+
|
3
|
+
describe 'BenTrackerGem' do
|
4
|
+
|
5
|
+
let (:response_get) { RestClient.get('http://brostofftrack.herokuapp.com/history.json') }
|
6
|
+
let (:response_post) { BenTrackerGem.post_message("Test Suite") }
|
7
|
+
|
8
|
+
context "get-based methods" do
|
9
|
+
|
10
|
+
it "successfully gets the data " do
|
11
|
+
expect(response_get.code).to eq(200)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
context "#post_message" do
|
17
|
+
|
18
|
+
it "raises an error if the user does not enter a message as String" do
|
19
|
+
expect{
|
20
|
+
BenTrackerGem.post_message(12345)
|
21
|
+
}.to raise_error(ArgumentError, "must enter message as String")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "successfully posts the data " do
|
25
|
+
expect(response_post.code).to eq(200)
|
26
|
+
expect(response_post).to eq("{}")
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context "#valid_format" do
|
32
|
+
|
33
|
+
it "should raise an argument error for invalid date format" do
|
34
|
+
expect{
|
35
|
+
BenTrackerGem.valid_format("COO")
|
36
|
+
}.to raise_error(ArgumentError, "invalid date")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should raise an argument error if date is outside range" do
|
40
|
+
expect {
|
41
|
+
BenTrackerGem.valid_format("2014-01-01")
|
42
|
+
}.to raise_error(ArgumentError, "Date outside range (data begins 2014-09-30)")
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
context "#day_stats" do
|
48
|
+
|
49
|
+
it "should return a summary of the day in hash format" do
|
50
|
+
expect(BenTrackerGem.day_stats("2014-10-06")).to eq({
|
51
|
+
:day_of => "2014-10-06",
|
52
|
+
:code => 6,
|
53
|
+
:fitness => 15142,
|
54
|
+
:message => "Interview with Avant. Run. Working on app."
|
55
|
+
})
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
context "#date_range" do
|
61
|
+
|
62
|
+
it "should return an array of day summaries given valid begin and end dates" do
|
63
|
+
expect(BenTrackerGem.date_range("2014-10-03", "2014-10-05")).to eq(
|
64
|
+
[BenTrackerGem.day_stats("2014-10-03"),
|
65
|
+
BenTrackerGem.day_stats("2014-10-04"),
|
66
|
+
BenTrackerGem.day_stats("2014-10-05")]
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
context "#date_range_visual" do
|
73
|
+
|
74
|
+
it "should raise an error if user requests invalid category" do
|
75
|
+
expect{
|
76
|
+
BenTrackerGem.date_range_visual("COO", "2014-10-03", "2014-10-05")
|
77
|
+
}.to raise_error(ArgumentError, "must select valid category")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should execute without error when valid category and dates are input" do
|
81
|
+
expect(
|
82
|
+
BenTrackerGem.date_range_visual("message", "2014-10-03", "2014-10-06")
|
83
|
+
).to eq("COMPLETE")
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bentrackergem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Brostoff
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest_client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: date
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Leverages FitBit and GitHub to track fitness and code; messages can be
|
98
|
+
input via the command line and are emailed to me via the Mandrill API.
|
99
|
+
email:
|
100
|
+
- ben.brostoff@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- .rspec
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bentrackergem.gemspec
|
112
|
+
- lib/bentrackergem.rb
|
113
|
+
- lib/bentrackergem/version.rb
|
114
|
+
- spec/bentrackergem_spec.rb
|
115
|
+
homepage: https://github.com/BenBrostoff/BenTrackerGem
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.4.1
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: A simple Ruby gem that serves as my virtual code, fitness and diary tracker.
|
139
|
+
test_files:
|
140
|
+
- spec/bentrackergem_spec.rb
|