dotplan 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ pkg
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ### 0.0.2
2
+
3
+ * minor tweaks in auth
4
+
5
+ ### 0.0.1
6
+
7
+ * auth, help, and register
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dotplan-gem.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dotplan (0.0.1)
5
+ colorize
6
+ hashie
7
+ json
8
+ rest-client
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ colorize (0.5.8)
14
+ hashie (1.2.0)
15
+ json (1.6.5)
16
+ mime-types (1.17.2)
17
+ rest-client (1.6.7)
18
+ mime-types (>= 1.16)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ dotplan!
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/dotplan ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "dotplan"
5
+
6
+ commands = {
7
+ # user commands
8
+ 'auth' => proc { DotPlan::Command::Auth.run },
9
+ 'register' => proc { DotPlan::Command::Register.run },
10
+ 'help' => proc { DotPlan::Command::Help.run },
11
+ }
12
+
13
+ if ARGV.first && commands.keys.include?(ARGV.first.downcase)
14
+ begin
15
+ commands[ARGV.first.downcase].call
16
+ rescue => e
17
+ puts e
18
+ end
19
+ else
20
+ begin
21
+ puts "todo".green
22
+ rescue => e
23
+ puts e
24
+ end
25
+ end
data/dotplan.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "./lib/dotplan/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "dotplan"
6
+ s.version = DotPlan::VERSION
7
+ s.authors = ["Dave Paola"]
8
+ s.email = ["dpaola2@gmail.com"]
9
+ s.summary = %q{The simplest way to manage your .plans}
10
+ s.description = %q{The simplest way to manage your .plans}
11
+
12
+ s.rubyforge_project = "dotplan"
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency "json"
20
+ s.add_runtime_dependency "colorize"
21
+ s.add_runtime_dependency "rest-client"
22
+ s.add_runtime_dependency "hashie"
23
+ end
@@ -0,0 +1,54 @@
1
+ require "colorize"
2
+ require "rest-client"
3
+
4
+ module DotPlan
5
+ module Command
6
+ class Auth
7
+ def self.run(*args)
8
+ login
9
+ end
10
+
11
+ def self.login
12
+ print "Username: "
13
+ username = $stdin.gets.chomp
14
+
15
+ print "Password: "
16
+ system "stty -echo"
17
+ password = $stdin.gets.chomp
18
+ system "stty echo"
19
+
20
+ print "\n"
21
+
22
+ begin
23
+ credentials = authenticate(:username => username, :password => password)
24
+ write_credentials(credentials)
25
+ puts "Saved to #{DotPlan::CREDENTIALS_PATH}.".green
26
+ rescue => e
27
+ puts e
28
+ end
29
+ end
30
+
31
+ def self.authenticate(options)
32
+ raise "Must provide a username".red unless options[:username]
33
+ raise "Must provide a password".red unless options[:password]
34
+ begin
35
+ response = RestClient.get("#{DotPlan::DOTPLAN_URL}/user/#{options[:username]}/auth", :Password => options[:password])
36
+ rescue => e
37
+ response = JSON.parse(e.response)
38
+ raise response["error"].red
39
+ end
40
+ credentials = JSON.parse(response.body)
41
+ credentials
42
+ end
43
+
44
+ private
45
+
46
+ def self.write_credentials(credentials)
47
+ FileUtils.mkdir_p(File.dirname(DotPlan::CREDENTIALS_PATH))
48
+ FileUtils.touch(DotPlan::CREDENTIALS_PATH)
49
+
50
+ File.open(DotPlan::CREDENTIALS_PATH, "w+") { |file| file << credentials.to_json }
51
+ end
52
+ end
53
+ end
54
+ end
File without changes
@@ -0,0 +1,23 @@
1
+ module DotPlan
2
+ module Command
3
+ class Help
4
+
5
+ def self.run(*args)
6
+ helpstring = <<-eos
7
+ Usage:
8
+ dotplan [auth | register | log | finger]
9
+
10
+ If a command is omitted, you'll be dropped into $EDITOR to interact with today's .plan.
11
+
12
+ Commands:
13
+ auth Authenticate by entering your username and password
14
+ register Register for a new account
15
+ log See your recent .plans
16
+ finger <user> Retrieve the .plan stream for <user>
17
+
18
+ eos
19
+ puts helpstring
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ module DotPlan
2
+ module Command
3
+ class Register
4
+ def self.run(*args)
5
+ print "Desired username: "
6
+ username = $stdin.gets.chomp
7
+
8
+ print "Password: "
9
+ system "stty -echo"
10
+ password = $stdin.gets.chomp
11
+ system "stty echo"
12
+
13
+ print "\n"
14
+
15
+ begin
16
+ credentials = register(:username => username, :password => password)
17
+ puts 'Registered! Run "dotplan auth" now.'
18
+ rescue => e
19
+ puts e
20
+ end
21
+ end
22
+
23
+ def self.register(options)
24
+ raise "No username provided".red unless options[:username]
25
+ raise "No password provided".red unless options[:password]
26
+ begin
27
+ resource = RestClient::Resource.new("#{DotPlan::DOTPLAN_URL}/user/#{options[:username]}", :Password => options[:password])
28
+ response = resource.post nil, :Password => options[:password]
29
+ rescue => e
30
+ response = JSON.parse(e.response)
31
+ raise response["error"].red
32
+ end
33
+ credentials = JSON.parse(response.body)
34
+ credentials
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ require "dotplan/command/auth.rb"
2
+ require "dotplan/command/register.rb"
3
+ require "dotplan/command/default.rb"
4
+ require "dotplan/command/help.rb"
5
+
6
+ module DotPlan
7
+ module Command
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module DotPlan
2
+ DOTPLAN_URL = ENV['DOTPLAN_URL'] || "http://dotplanstream.herokuapp.com"
3
+ CREDENTIALS_PATH = File.join(ENV["HOME"], ".dotplan", "credentials.json")
4
+ end
@@ -0,0 +1,3 @@
1
+ module DotPlan
2
+ VERSION = "0.0.2"
3
+ end
data/lib/dotplan.rb ADDED
@@ -0,0 +1,12 @@
1
+ $:.push File.expand_path("./lib")
2
+
3
+ require "colorize"
4
+ require "json"
5
+ require "hashie"
6
+
7
+ require "dotplan/version"
8
+ require "dotplan/command"
9
+ require "dotplan/constants"
10
+
11
+ module DotPlan
12
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dotplan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dave Paola
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-12 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &70232884581560 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70232884581560
25
+ - !ruby/object:Gem::Dependency
26
+ name: colorize
27
+ requirement: &70232884581140 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70232884581140
36
+ - !ruby/object:Gem::Dependency
37
+ name: rest-client
38
+ requirement: &70232884580720 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70232884580720
47
+ - !ruby/object:Gem::Dependency
48
+ name: hashie
49
+ requirement: &70232884580300 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70232884580300
58
+ description: The simplest way to manage your .plans
59
+ email:
60
+ - dpaola2@gmail.com
61
+ executables:
62
+ - dotplan
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - CHANGELOG.md
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - Rakefile
71
+ - bin/dotplan
72
+ - dotplan.gemspec
73
+ - lib/dotplan.rb
74
+ - lib/dotplan/command.rb
75
+ - lib/dotplan/command/auth.rb
76
+ - lib/dotplan/command/default.rb
77
+ - lib/dotplan/command/help.rb
78
+ - lib/dotplan/command/register.rb
79
+ - lib/dotplan/constants.rb
80
+ - lib/dotplan/version.rb
81
+ homepage:
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project: dotplan
101
+ rubygems_version: 1.8.15
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: The simplest way to manage your .plans
105
+ test_files: []