git-sleep 0.1.1 → 0.2.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: 39869b4105c7850d0cdaa2e08489931c48973804
4
+ data.tar.gz: b6d2cb1bb7642b5224decc33b8d70a8782845c35
5
+ SHA512:
6
+ metadata.gz: 04a7e59ff9279ea0cd9fe7a2a734cb8f24e1456f70722cbcc961253b659dae6d9daaecd06ea9d80c4c8578ab5736c46aaba65b4d2b318cf2e1ac273bd05c1615
7
+ data.tar.gz: 9f96c492798302c26f4589a2d77c97562688d093dc6800aac4b0a2a19429522a387451083954dbb78078dc677034d467fef60a464a1e17336f2310e9682271b1
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .DS_STORE
2
- *.gem
2
+ *.gem
3
+ /spec/spec_helper/support/.netrc
data/README.md CHANGED
@@ -1,8 +1,3 @@
1
- ### TODOS
2
-
3
- * use their name they gave jawbone, not their env[username]
4
- * maybe use their ssh public key to identify them, not their jawbone xid? at any rate needs some layer of security. that could be it. actually, wait, that doesn't make sense.
5
-
6
1
  # git sleep
7
2
 
8
3
  `gem install git-sleep`
@@ -13,6 +8,8 @@ to be used in conjunction with [gitsleep.com](http://www.gitsleep.com)
13
8
 
14
9
  `git sleep authorize` will walk you through authorizing with Jawbone
15
10
 
16
- `git sleep init` (from within a git repo) will install a git pre-commit hook for you
11
+ `git sleep init` (from within a git repo) will install two git hooks:
12
+
13
+ * a git pre-commit hook that can prevent commits if you haven't slept enough
14
+ * a git post-commit hook which will annotate your successful commits with sleep data
17
15
 
18
- now when you try to commit to this repo, it will check if you really *should* be committing to this repo
@@ -1,35 +1,32 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
4
- require 'netrc'
5
3
  require File.expand_path('../../lib/git-sleep', __FILE__)
6
4
 
7
- netrc = Netrc.read(GitSleep::NETRC_PATH)
5
+ auth = GitSleep::Authorizer.instance
8
6
 
9
7
  help_text = "Available commands:
10
8
  git sleep authorize
11
9
  git sleep init"
12
10
 
13
- CURRENT_PATH = File.expand_path(".")
11
+ CURRENT_PATH = File.expand_path('.')
14
12
  PATH_TO_THIS_REPOS_HOOKS = "#{CURRENT_PATH}/.git/hooks"
15
13
 
16
14
  def install_hook(event)
17
15
  hook_code = File.read(File.expand_path("../../hooks/#{event}", __FILE__))
18
16
  path_to_new_hook = File.expand_path("#{PATH_TO_THIS_REPOS_HOOKS}/#{event}")
19
- if File.exists? path_to_new_hook
17
+ if File.exist?(path_to_new_hook)
20
18
  puts "You already have a #{event} hook and we don't want to overwrite it..."
21
- print "Is it okay? [y/n] "
19
+ print 'Is it okay? [y/n] '
22
20
  ok = $stdin.gets.chomp
23
- return unless ok == "y"
21
+ return unless ok == 'y'
24
22
  end
25
- File.open(path_to_new_hook, "w") do |f|
23
+ File.open(path_to_new_hook, 'w') do |f|
26
24
  f.write hook_code
27
25
  end
28
26
  `chmod a+x #{path_to_new_hook}`
29
- puts "Hook installed and made executable"
27
+ puts 'Hook installed and made executable'
30
28
  end
31
29
 
32
-
33
30
  case ARGV.length
34
31
  when 0
35
32
  puts help_text
@@ -37,40 +34,41 @@ when 1
37
34
  case ARGV.first.downcase.to_sym
38
35
  when :init
39
36
 
40
- if !Dir.entries(CURRENT_PATH).include? ".git"
41
- puts "This is not a git repo. Would you like to initialize one?"
42
- print "[y/n] "
37
+ unless Dir.entries(CURRENT_PATH).include?('.git')
38
+ puts 'This is not a git repo. Would you like to initialize one?'
39
+ print '[y/n] '
43
40
  ok = $stdin.gets.chomp
44
- if ok == "y"
41
+ if ok == 'y'
45
42
  `git init`
46
43
  else
47
44
  exit 0
48
45
  end
49
46
  end
50
47
 
51
- puts "Install the pre-commit hook that prevents commits when you haven't sleep enough?"
52
- print "Is it okay? [y/n] "
48
+ puts 'Install the pre-commit hook that prevents ' \
49
+ "commits when you haven't sleep enough?"
50
+ print 'Is it okay? [y/n] '
53
51
  ok = $stdin.gets.chomp
54
- install_hook("pre-commit") if ok == "y"
52
+ install_hook('pre-commit') if ok == 'y'
55
53
 
56
- puts "Install the post-commit hook that adds git notes about your sleep data?"
57
- print "Is it okay? [y/n] "
54
+ puts 'Install the post-commit hook that adds ' \
55
+ 'git notes about your sleep data?'
56
+ print 'Is it okay? [y/n] '
58
57
  ok = $stdin.gets.chomp
59
- install_hook("post-commit") if ok =="y"
58
+ install_hook('post-commit') if ok == 'y'
60
59
 
61
60
  when :authorize
62
61
  puts "Visit #{GitSleep::OUR_SITE} to get the necessary information"
63
- puts "what is your xid?"
64
- print "> "
62
+ puts 'what is your xid?'
63
+ print '> '
65
64
  xid = $stdin.gets.chomp
66
- netrc.new_item_prefix = "\n# jawbone xid\n"
67
- netrc["gitsleep.com"] = xid, "no_password"
68
- netrc.save
69
- when :"-v"
65
+ auth.xid = xid
66
+ when :'-v'
70
67
  puts "Git Sleep v#{GitSleep::VERSION}"
71
68
  else # unrecognized command
72
69
  puts help_text
73
70
  end
74
71
  else # other amounts of arguments
75
72
  puts help_text
76
- end
73
+ end
74
+
@@ -1,25 +1,35 @@
1
- require File.expand_path("../lib/git-sleep", __FILE__)
1
+ require File.expand_path('../lib/git-sleep', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |git_sleep|
4
- git_sleep.name = "git-sleep"
5
- git_sleep.version = GitSleep::VERSION
6
- git_sleep.date = GitSleep::LAST_UPDATED
7
- git_sleep.summary = "Uses Jawbone to figure out if you are awake enough to code based on your sleep data"
8
- git_sleep.description = "Uses Jawbone to figure out if you are awake enough to code"
9
- git_sleep.authors = ["Max Jacobson", "Ruthie Nachmany", "Sarah Duve"]
10
- git_sleep.email = ["maxwell.jacobson@gmail.com", "ruthie.nachmany@flatironschool.com", "saduve@gmail.com"]
4
+ git_sleep.name = 'git-sleep'
5
+ git_sleep.version = GitSleep::VERSION
6
+ git_sleep.summary = 'Uses Jawbone to figure out if you are awake enough' \
7
+ 'to code based on your sleep data'
8
+ git_sleep.description = 'Uses Jawbone to figure out if you are awake ' \
9
+ 'enough to code'
10
+ git_sleep.authors = ['Max Jacobson', 'Ruthie Nachmany', 'Sarah Duve']
11
+ git_sleep.email = [
12
+ 'max@hardscrabble.net',
13
+ 'ruthie.nachmany@flatironschool.com',
14
+ 'saduve@gmail.com'
15
+ ]
11
16
  git_sleep.files = Dir[
12
- './*.{md,gemspec}',
13
- './.gitignore',
14
- './hooks/*',
15
- './bin/*',
16
- './lib/*'
17
- ]
18
- git_sleep.require_paths = ["lib"]
19
- git_sleep.executables = ["git-sleep"]
17
+ './*.{md,gemspec}',
18
+ './.gitignore',
19
+ './hooks/*',
20
+ './bin/*',
21
+ './lib/*',
22
+ './lib/git-sleep/*'
23
+ ]
24
+ git_sleep.require_paths = ['lib']
25
+ git_sleep.executables = ['git-sleep']
20
26
  git_sleep.homepage = GitSleep::OUR_SITE
21
- git_sleep.license = "MIT"
22
- git_sleep.required_ruby_version = '>= 1.8.7'
23
- git_sleep.add_runtime_dependency 'httparty'
24
- git_sleep.add_runtime_dependency 'netrc'
27
+ git_sleep.license = 'MIT'
28
+ git_sleep.required_ruby_version = '>= 2.0.0'
29
+ git_sleep.add_runtime_dependency 'httparty', '~> 0.13'
30
+ git_sleep.add_runtime_dependency 'netrc', '~> 0.8'
31
+ git_sleep.add_development_dependency 'rubocop', '~> 0.27'
32
+ git_sleep.add_development_dependency 'rspec', '~> 3.1'
33
+ git_sleep.add_development_dependency 'pry', '~> 0.10'
25
34
  end
35
+
@@ -1,24 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
4
- require 'netrc'
5
3
  require 'git-sleep'
6
4
  require 'httparty'
7
5
 
8
- netrc = Netrc.read(GitSleep::NETRC_PATH)
9
- xid = netrc["gitsleep.com"].first
10
-
11
- raise "Need to `git sleep authorize`" if xid.nil?
12
-
6
+ auth = GitSleep::Authorizer.instance
13
7
 
14
8
  begin
15
9
  response = HTTParty.get(
16
- "http://www.gitsleep.com/api/need_sleep",
17
- :body => {
18
- :xid => xid
10
+ 'http://www.gitsleep.com/api/need_sleep',
11
+ body: {
12
+ xid: auth.xid
19
13
  }
20
14
  )
21
- rescue Exception => e
15
+ rescue StandardError => _
22
16
  puts "Can't connect to gitsleep.com"
23
17
  exit 0
24
18
  end
@@ -34,7 +28,7 @@ if response.response.code.to_i == 200
34
28
 
35
29
  elsif response.response.code.to_i == 401
36
30
  puts "Must first authorize at #{GitSleep::OUR_SITE}"
37
- puts "Then run `git sleep authorize`"
31
+ puts 'Then run `git sleep authorize`'
38
32
  else
39
33
  # could not communicate with our server
40
34
  # uh oh!
@@ -1,43 +1,40 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
4
- require 'netrc'
5
3
  require 'git-sleep'
6
4
  require 'httparty'
7
5
 
8
- netrc = Netrc.read(GitSleep::NETRC_PATH)
9
- xid = netrc["gitsleep.com"].first
10
-
11
- raise "Need to `git sleep authorize`" if xid.nil?
6
+ auth = GitSleep::Authorizer.instance
12
7
 
13
8
  begin
14
9
  response = HTTParty.get(
15
- "http://www.gitsleep.com/api/need_sleep",
16
- :body => {
17
- :xid => xid
10
+ 'http://www.gitsleep.com/api/need_sleep',
11
+ body: {
12
+ xid: auth.xid
18
13
  }
19
14
  )
20
- rescue Exception => e
15
+ rescue StandardError => _
21
16
  puts "Can't connect to gitsleep.com"
22
17
  exit 0
23
18
  end
24
19
 
25
-
26
-
27
20
  if response.response.code.to_i == 200
28
21
  data = response.parsed_response
29
- if data["can_commit"]
30
- puts "Great job #{ENV['USER']}! You slept #{data['sleep24']} hours in the last 24 hours"
22
+ if data['can_commit']
23
+ puts "Great job #{ENV['USER']}! " \
24
+ "You slept #{data['sleep24']} hours in the last 24 hours"
31
25
  else
32
- puts "You have only slept #{data["sleep24"]} hours in the last 24 hours!!"
33
- puts "You'll have to git some sleep #{ENV["USER"]} before you can commit again"
34
- puts "(if you're sure you want to commit right now, run: git commit --no-verify)"
26
+ puts "You have only slept #{data['sleep24']} hours in the last 24 hours!!"
27
+ puts "You'll have to git some sleep #{ENV['USER']} " \
28
+ 'before you can commit again'
29
+ puts "(if you're sure you want to commit right now, " \
30
+ 'run: git commit --no-verify)'
35
31
  exit(1)
36
32
  end
37
33
  elsif response.response.code.to_i == 401
38
34
  puts "Must first authorize at #{GitSleep::OUR_SITE}"
39
- puts "Then run `git sleep authorize`"
35
+ puts 'Then run `git sleep authorize`'
40
36
  else
41
37
  # could not communicate with our server
42
38
  # uh oh!
43
39
  end
40
+
@@ -1,6 +1,8 @@
1
+ require_relative './git-sleep/exceptions'
2
+ require_relative './git-sleep/authorizer'
3
+
1
4
  module GitSleep
2
- VERSION = "0.1.1"
3
- LAST_UPDATED = "2013-08-20"
4
- NETRC_PATH = File.expand_path('~/.netrc')
5
- OUR_SITE = "http://www.gitsleep.com"
6
- end
5
+ VERSION = '0.2.0'
6
+ OUR_SITE = 'http://www.gitsleep.com'
7
+ end
8
+
@@ -0,0 +1,49 @@
1
+ require 'netrc'
2
+ require 'singleton'
3
+ require_relative './credentials_file'
4
+
5
+ module GitSleep
6
+ class Authorizer
7
+ include Singleton
8
+
9
+ # add credentials to user's netrc file
10
+ def xid=(xid)
11
+ netrc['gitsleep.com'] = xid, 'no_password'
12
+ netrc.save
13
+ end
14
+
15
+ def setup?
16
+ credentials_file.present? && !credentials.nil? && valid_keys?
17
+ end
18
+
19
+ def xid
20
+ validate_setup
21
+ credentials.first
22
+ end
23
+
24
+ private
25
+
26
+ def validate_setup
27
+ raise GitSleep::NotSetupError unless setup?
28
+ end
29
+
30
+ def valid_keys?
31
+ credentials.length == 2
32
+ end
33
+
34
+ def credentials
35
+ netrc['gitsleep.com']
36
+ end
37
+
38
+ def netrc
39
+ @netrc ||= Netrc.read(credentials_file.path).tap do |netrc|
40
+ netrc.new_item_prefix = "\n# jawbone xid\n"
41
+ end
42
+ end
43
+
44
+ def credentials_file
45
+ CredentialsFile.instance
46
+ end
47
+ end
48
+ end
49
+
@@ -0,0 +1,23 @@
1
+ require 'singleton'
2
+
3
+ module GitSleep
4
+ class CredentialsFile
5
+ include Singleton
6
+
7
+ def present?
8
+ File.exist?(path)
9
+ end
10
+
11
+ def destroy
12
+ File.delete(path)
13
+ true
14
+ rescue Errno::ENOENT
15
+ false
16
+ end
17
+
18
+ def path
19
+ @path ||= File.expand_path('~/.netrc')
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,4 @@
1
+ module GitSleep
2
+ class NotSetupError < StandardError; end
3
+ end
4
+
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-sleep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Max Jacobson
@@ -11,43 +10,81 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2013-08-20 00:00:00.000000000 Z
13
+ date: 2014-11-16 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: httparty
18
17
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
- - - ! '>='
19
+ - - "~>"
22
20
  - !ruby/object:Gem::Version
23
- version: '0'
21
+ version: '0.13'
24
22
  type: :runtime
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
25
  requirements:
29
- - - ! '>='
26
+ - - "~>"
30
27
  - !ruby/object:Gem::Version
31
- version: '0'
28
+ version: '0.13'
32
29
  - !ruby/object:Gem::Dependency
33
30
  name: netrc
34
31
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
32
  requirements:
37
- - - ! '>='
33
+ - - "~>"
38
34
  - !ruby/object:Gem::Version
39
- version: '0'
35
+ version: '0.8'
40
36
  type: :runtime
41
37
  prerelease: false
42
38
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
39
  requirements:
45
- - - ! '>='
40
+ - - "~>"
46
41
  - !ruby/object:Gem::Version
47
- version: '0'
42
+ version: '0.8'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rubocop
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.27'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.27'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.1'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.1'
71
+ - !ruby/object:Gem::Dependency
72
+ name: pry
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '0.10'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '0.10'
48
85
  description: Uses Jawbone to figure out if you are awake enough to code
49
86
  email:
50
- - maxwell.jacobson@gmail.com
87
+ - max@hardscrabble.net
51
88
  - ruthie.nachmany@flatironschool.com
52
89
  - saduve@gmail.com
53
90
  executables:
@@ -55,38 +92,40 @@ executables:
55
92
  extensions: []
56
93
  extra_rdoc_files: []
57
94
  files:
58
- - ./README.md
59
- - ./git-sleep.gemspec
60
- - ./.gitignore
61
- - ./hooks/post-commit
62
- - ./hooks/pre-commit
63
- - ./bin/git-sleep
64
- - ./lib/git-sleep.rb
95
+ - "./.gitignore"
96
+ - "./README.md"
97
+ - "./bin/git-sleep"
98
+ - "./git-sleep.gemspec"
99
+ - "./hooks/post-commit"
100
+ - "./hooks/pre-commit"
101
+ - "./lib/git-sleep.rb"
102
+ - "./lib/git-sleep/authorizer.rb"
103
+ - "./lib/git-sleep/credentials_file.rb"
104
+ - "./lib/git-sleep/exceptions.rb"
65
105
  - bin/git-sleep
66
106
  homepage: http://www.gitsleep.com
67
107
  licenses:
68
108
  - MIT
109
+ metadata: {}
69
110
  post_install_message:
70
111
  rdoc_options: []
71
112
  require_paths:
72
113
  - lib
73
114
  required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
115
  requirements:
76
- - - ! '>='
116
+ - - ">="
77
117
  - !ruby/object:Gem::Version
78
- version: 1.8.7
118
+ version: 2.0.0
79
119
  required_rubygems_version: !ruby/object:Gem::Requirement
80
- none: false
81
120
  requirements:
82
- - - ! '>='
121
+ - - ">="
83
122
  - !ruby/object:Gem::Version
84
123
  version: '0'
85
124
  requirements: []
86
125
  rubyforge_project:
87
- rubygems_version: 1.8.25
126
+ rubygems_version: 2.2.2
88
127
  signing_key:
89
- specification_version: 3
90
- summary: Uses Jawbone to figure out if you are awake enough to code based on your
91
- sleep data
128
+ specification_version: 4
129
+ summary: Uses Jawbone to figure out if you are awake enoughto code based on your sleep
130
+ data
92
131
  test_files: []