trlo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
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
+
19
+ .trlo
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tr.gemspec
4
+ gemspec :development_group => :dev
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Vincent Siebert
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.
@@ -0,0 +1,29 @@
1
+ # Trlo
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'trlo'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install trlo
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+
5
+ lib = (Pathname.new(__FILE__).realpath.dirname + '../lib').to_s
6
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
7
+
8
+ require 'trlo'
9
+
10
+ Trlo::UI.new ARGV
@@ -0,0 +1,11 @@
1
+ require "trlo/version"
2
+ require "rubygems"
3
+
4
+ module Trlo
5
+ class InputError < StandardError; end
6
+ end
7
+
8
+ require 'trlo/client'
9
+ require 'trlo/data_row'
10
+ require 'trlo/data_table'
11
+ require 'trlo/ui'
@@ -0,0 +1,27 @@
1
+ require 'trello'
2
+
3
+ module Trlo
4
+ class Client
5
+
6
+ attr_accessor :config
7
+
8
+ include Trello
9
+ include Trello::Authorization
10
+
11
+ def initialize(config)
12
+ @config = config
13
+ Trello::Authorization.const_set :AuthPolicy, OAuthPolicy
14
+ OAuthPolicy.consumer_credential = OAuthCredential.new @config[:key], @config[:secret]
15
+ OAuthPolicy.token = OAuthCredential.new @config[:token], nil
16
+ @project = nil
17
+ end
18
+
19
+ def get_board(board_id)
20
+ Board.find(board_id)
21
+ end
22
+
23
+ def get_boards
24
+ Member.find(@config[:username]).boards
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ require 'iconv' unless "older_ruby?".respond_to?(:force_encoding)
2
+
3
+ class Trlo::DataRow
4
+
5
+ attr_accessor :num, :record
6
+
7
+ def initialize(orig, dataset)
8
+ @record = orig
9
+ @num = dataset.index(orig) + 1
10
+ end
11
+
12
+ def method_missing(method)
13
+ str = @record.send(method).to_s
14
+ str.respond_to?(:force_encoding) ? str.force_encoding('utf-8') : Iconv.iconv('UTF-8', 'UTF-8', str)
15
+ end
16
+
17
+ def to_s
18
+ @record.send(self.to_s_attribute)
19
+ end
20
+
21
+ def to_s_attribute
22
+ @n.to_s
23
+ end
24
+
25
+ end
@@ -0,0 +1,63 @@
1
+ require 'hirb'
2
+
3
+ module Trlo
4
+ class DataTable
5
+
6
+ extend ::Hirb::Console
7
+
8
+ def initialize(dataset)
9
+ @rows = dataset.map{ |row| DataRow.new(row, dataset) }
10
+ end
11
+
12
+ def print(config={})
13
+ if @rows.empty?
14
+ puts "\n#{'-- empty list --'.center(36)}\n"
15
+ else
16
+ self.class.table @rows, :fields => [:num] + self.class.fields,
17
+ :unicode => true, :description => false,
18
+ :max_width => config[:max_width]
19
+ end
20
+ end
21
+
22
+ def [](pos)
23
+ pos = pos.to_i
24
+ (pos < 1 || pos > @rows.length) ? nil : @rows[pos-1].record
25
+ end
26
+
27
+ def length
28
+ @rows.length
29
+ end
30
+
31
+ def self.fields
32
+ []
33
+ end
34
+
35
+ end
36
+
37
+
38
+ class BoardTable < DataTable
39
+
40
+ def self.fields
41
+ [:name]
42
+ end
43
+
44
+ end
45
+
46
+
47
+ class TasksTable < DataTable
48
+
49
+ def self.fields
50
+ [:name, :current_state, :id]
51
+ end
52
+
53
+ end
54
+
55
+ class MembersTable < DataTable
56
+
57
+ def self.fields
58
+ [:name]
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,115 @@
1
+ require 'yaml'
2
+ require 'colored'
3
+ require 'highline'
4
+
5
+ module Trlo
6
+ class UI
7
+ GLOBAL_CONFIG_PATH = "#{ENV['HOME']}/.trlo"
8
+ LOCAL_CONFIG_PATH = "#{Dir.pwd}/.trlo"
9
+
10
+ def initialize(args)
11
+ # require 'trlo/debugger' if ARGV.delete('--debug')
12
+ @io = HighLine.new
13
+ @global_config = load_global_config
14
+ @client = Trlo::Client.new(@global_config)
15
+ @local_config = load_local_config
16
+ @board = @client.get_board(@local_config[:board_id])
17
+ # command = args[0].to_sym rescue :my_work
18
+ # @params = args[1..-1]
19
+ # commands.include?(command.to_sym) ? send(command.to_sym) : help
20
+ end
21
+
22
+ def load_global_config
23
+ config = YAML.load(File.read(GLOBAL_CONFIG_PATH)) rescue {}
24
+ # if config.empty?
25
+ # message "I can't find info about your Trello account in #{GLOBAL_CONFIG_PATH}."
26
+ # # while !config[:api_key] do
27
+ # # config[:email] = ask "What is your email?"
28
+ # # password = ask_secret "And your password? (won't be displayed on screen)"
29
+ # # begin
30
+ # # # config[:api_number] = Trlo::Client.get_api_token(config[:email], password)
31
+ # # rescue PT::InputError => e
32
+ # # error e.message + " Please try again."
33
+ # # end
34
+ # # end
35
+ # congrats "Thanks!",
36
+ # "Your API key is " + config[:api_key],
37
+ # "I'm saving it in #{GLOBAL_CONFIG_PATH} so you don't have to log in again."
38
+ # save_config(config, GLOBAL_CONFIG_PATH)
39
+ # end
40
+ config
41
+ end
42
+
43
+ def load_local_config
44
+ check_local_config_path
45
+ config = YAML.load(File.read(LOCAL_CONFIG_PATH)) rescue {}
46
+ if config.empty?
47
+ message "I can't find info about this project in #{LOCAL_CONFIG_PATH}"
48
+ boards = Trlo::BoardTable.new(@client.get_boards)
49
+ board = select("Please select the board for the current directory", boards)
50
+ config[:board_id], config[:board_name] = board.id, board.name
51
+ project = @client.get_board(board.id)
52
+ # membership = @client.get_membership(project, @global_config[:email])
53
+ # config[:user_name], config[:user_id], config[:user_initials] = membership.name, membership.id, membership.initials
54
+ congrats "Thanks! I'm saving this project's info",
55
+ "in #{LOCAL_CONFIG_PATH}: remember to .gitignore it!"
56
+ save_config(config, LOCAL_CONFIG_PATH)
57
+ end
58
+ config
59
+ end
60
+
61
+ def check_local_config_path
62
+ if GLOBAL_CONFIG_PATH == LOCAL_CONFIG_PATH
63
+ error("Please execute .trlo inside your project directory and not in your home.")
64
+ exit
65
+ end
66
+ end
67
+
68
+ def save_config(config, path)
69
+ File.new(path, 'w') unless File.exists?(path)
70
+ File.open(path, 'w') {|f| f.write(config.to_yaml) }
71
+ end
72
+ # I/O
73
+
74
+ def split_lines(text)
75
+ text.respond_to?(:join) ? text.join("\n") : text
76
+ end
77
+
78
+ def title(*msg)
79
+ puts "\n#{split_lines(msg)}".bold
80
+ end
81
+
82
+ def congrats(*msg)
83
+ puts "\n#{split_lines(msg).green.bold}"
84
+ end
85
+
86
+ def message(*msg)
87
+ puts "\n#{split_lines(msg)}"
88
+ end
89
+
90
+ def error(*msg)
91
+ puts "\n#{split_lines(msg).red.bold}"
92
+ end
93
+
94
+ def select(msg, table)
95
+ if table.length > 0
96
+ begin
97
+ table.print @global_config
98
+ row = ask "#{msg} (1-#{table.length}, 'q' to exit)"
99
+ quit if row == 'q'
100
+ selected = table[row]
101
+ error "Invalid selection, try again:" unless selected
102
+ end until selected
103
+ selected
104
+ else
105
+ table.print @global_config
106
+ message "Sorry, there are no options to select."
107
+ quit
108
+ end
109
+ end
110
+
111
+ def ask(msg)
112
+ @io.ask("#{msg.bold}")
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,3 @@
1
+ module Trlo
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/trlo/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Vincent Siebert"]
6
+ gem.email = ["vincent@siebert.im"]
7
+ gem.description = %q{Trello comman line tool}
8
+ gem.summary = %q{Trello comman line tool}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "trlo"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Trlo::VERSION
17
+ gem.platform = Gem::Platform::RUBY
18
+
19
+ gem.add_dependency "ruby-trello"
20
+ gem.add_dependency "hirb"
21
+ gem.add_dependency "colored"
22
+ gem.add_dependency "highline"
23
+
24
+ gem.add_development_dependency "pry"
25
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trlo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vincent Siebert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ruby-trello
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: hirb
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: colored
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: highline
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Trello comman line tool
95
+ email:
96
+ - vincent@siebert.im
97
+ executables:
98
+ - trlo
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - Gemfile
104
+ - LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - bin/trlo
108
+ - lib/trlo.rb
109
+ - lib/trlo/client.rb
110
+ - lib/trlo/data_row.rb
111
+ - lib/trlo/data_table.rb
112
+ - lib/trlo/ui.rb
113
+ - lib/trlo/version.rb
114
+ - trlo.gemspec
115
+ homepage: ''
116
+ licenses: []
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 1.8.19
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: Trello comman line tool
139
+ test_files: []