Class: Basecamper
Instance Attribute Summary collapse
-
#basecamp ⇒ Object
readonly
Returns the value of attribute basecamp.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#person_id ⇒ Object
readonly
Returns the value of attribute person_id.
-
#projects ⇒ Object
readonly
Returns the value of attribute projects.
-
#times ⇒ Object
readonly
Returns the value of attribute times.
Instance Method Summary collapse
- #cancel! ⇒ Object
-
#configure!(url, user_name, password, use_ssl) ⇒ Object
main API.
- #configured? ⇒ Boolean
-
#current_project ⇒ Object
secondary API.
- #delete_time(time_id = nil) ⇒ Object
-
#initialize ⇒ Basecamper
constructor
A new instance of Basecamper.
- #inspect ⇒ Object
- #log_time(duration, message, project = nil) ⇒ Object
- #minutes_elapsed(end_time = nil) ⇒ Object
- #pause! ⇒ Object
- #paused? ⇒ Boolean
- #project_id(name) ⇒ Object
- #project_name(project_id) ⇒ Object
- #save(record) ⇒ Object
- #set!(key, value) ⇒ Object
- #start!(start_time = nil) ⇒ Object
- #start_time ⇒ Object
- #started? ⇒ Boolean
- #stop!(message, end_time = nil) ⇒ Object
- #sync_basecamp ⇒ Object
- #test_basecamp! ⇒ Object
Constructor Details
#initialize ⇒ Basecamper
Returns a new instance of Basecamper.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/basecamper.rb', line 8 def initialize initialize_data! # need to make booleans a special case and transform there here forevermore ["use_ssl"].each do |key| @config[key] = true if @config[key] == "true" @config[key] = false if @config[key] == "false" end # defaults {"rounding" => 15, "minutes_logged" => 0}.each_pair {|key, value| @config[key] ||= value} @basecamp = Basecamp.new @config.url, @config.user_name, @config.password, @config.use_ssl # set up a couple of attr_readers @person_id = @config.person_id @projects = @config.projects end |
Instance Attribute Details
#basecamp ⇒ Object (readonly)
Returns the value of attribute basecamp.
6 7 8 |
# File 'lib/basecamper.rb', line 6 def basecamp @basecamp end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/basecamper.rb', line 6 def config @config end |
#person_id ⇒ Object (readonly)
Returns the value of attribute person_id.
6 7 8 |
# File 'lib/basecamper.rb', line 6 def person_id @person_id end |
#projects ⇒ Object (readonly)
Returns the value of attribute projects.
6 7 8 |
# File 'lib/basecamper.rb', line 6 def projects @projects end |
#times ⇒ Object (readonly)
Returns the value of attribute times.
6 7 8 |
# File 'lib/basecamper.rb', line 6 def times @times end |
Instance Method Details
#cancel! ⇒ Object
54 55 56 57 58 |
# File 'lib/basecamper.rb', line 54 def cancel! return unless started? or paused? write_config("start_time" => nil, "minutes_logged" => 0) end |
#configure!(url, user_name, password, use_ssl) ⇒ Object
main API
29 30 31 32 |
# File 'lib/basecamper.rb', line 29 def configure!(url, user_name, password, use_ssl) write_config("url" => url, "user_name" => user_name, "password" => password, "use_ssl" => use_ssl) test_basecamp! end |
#configured? ⇒ Boolean
90 91 92 |
# File 'lib/basecamper.rb', line 90 def configured? @config.configured end |
#current_project ⇒ Object
secondary API
86 87 88 |
# File 'lib/basecamper.rb', line 86 def current_project @config.current_project.capitalize_all end |
#delete_time(time_id = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/basecamper.rb', line 73 def delete_time(time_id = nil) time = time_id ? find_time(time_id) : @times.first return unless time @basecamp.delete_time(time.id, time.project_id) @times.delete time write_times time end |
#inspect ⇒ Object
145 146 147 148 149 |
# File 'lib/basecamper.rb', line 145 def inspect config = @config.dup config.projects = config.projects.values.map {|name| name.capitalize_all}.join(", ") config.to_yaml.gsub(/^---/, "") end |
#log_time(duration, message, project = nil) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/basecamper.rb', line 66 def log_time(duration, , project = nil) project_id = project_id(project || current_project) return unless project_id save @basecamp.log_time(project_id, @person_id, Time.now, duration, ) end |
#minutes_elapsed(end_time = nil) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/basecamper.rb', line 115 def minutes_elapsed(end_time = nil) if started? @config.minutes_logged + (end_time || Time.now).minutes_since(start_time) else @config.minutes_logged end end |
#pause! ⇒ Object
60 61 62 63 64 |
# File 'lib/basecamper.rb', line 60 def pause! return unless started? write_config("start_time" => nil, "minutes_logged" => minutes_elapsed) end |
#paused? ⇒ Boolean
111 112 113 |
# File 'lib/basecamper.rb', line 111 def paused? !started? and (@config.minutes_logged > 0) end |
#project_id(name) ⇒ Object
131 132 133 |
# File 'lib/basecamper.rb', line 131 def project_id(name) @projects.invert[name.to_s.downcase] end |
#project_name(project_id) ⇒ Object
127 128 129 |
# File 'lib/basecamper.rb', line 127 def project_name(project_id) @projects[project_id].capitalize_all end |
#save(record) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/basecamper.rb', line 135 def save(record) return unless record record = record.to_hash record.created_at = Time.now @times.unshift record prune_times write_times @times.first end |
#set!(key, value) ⇒ Object
34 35 36 37 |
# File 'lib/basecamper.rb', line 34 def set!(key, value) write_config(key.to_s => value) test_basecamp! if key.in? ["url", "user_name", "password", "use_ssl"] end |
#start!(start_time = nil) ⇒ Object
39 40 41 42 43 |
# File 'lib/basecamper.rb', line 39 def start!(start_time = nil) return if started? write_config("start_time" => (start_time.to_time || Time.now)) end |
#start_time ⇒ Object
123 124 125 |
# File 'lib/basecamper.rb', line 123 def start_time @config.start_time end |
#started? ⇒ Boolean
107 108 109 |
# File 'lib/basecamper.rb', line 107 def started? !@config.start_time.nil? end |
#stop!(message, end_time = nil) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/basecamper.rb', line 45 def stop!(, end_time = nil) return unless started? minutes = minutes_elapsed(end_time).round_to(@config.rounding.to_i) write_config("start_time" => nil, "minutes_logged" => 0) log_time(":#{minutes}", ) end |
#sync_basecamp ⇒ Object
100 101 102 103 104 105 |
# File 'lib/basecamper.rb', line 100 def sync_basecamp puts "Initializing, may take a few seconds..." $stdout.flush if $stdout and $stdout.respond_to? :flush get_person(@config.user_name) get_projects end |