Skip to content
This repository has been archived by the owner on Dec 23, 2020. It is now read-only.

Commit

Permalink
Compatibilty for the new restful API where we are responsible for cre…
Browse files Browse the repository at this point in the history
…ating the project.
  • Loading branch information
kommen committed Jan 10, 2009
1 parent 38d40d9 commit a699e37
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $hoe = Hoe.new('freckle-gem', FreckleGem::VERSION) do |p|
p.rubyforge_name = p.name
p.extra_deps = [
['json', '>= 1.1.3'],
['activeresource', '>= 2.2.2']
]
p.extra_dev_deps = [
['newgem', ">= #{::Newgem::VERSION}"]
Expand Down
9 changes: 6 additions & 3 deletions lib/freckle-gem/entry.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
require 'json'
require 'activeresource'

module FreckleGem

class Entry < ActiveResource::Base
self.site = "http://#{Freckle::AppConfig.subdomain}.#{Freckle::AppConfig.host}:#{Freckle::AppConfig.port}/api/"

attr_accessor :project

def self.headers
@headers ||= { 'X_FRECKLETOKEN' => Freckle::AppConfig.authtoken }
end

def attributes
{ :date => Date.today }.merge(@attributes || {})
{ :date => Date.today, :project_id => project ? project.id : nil }.merge(@attributes || {})
end

def project_name=(name)
self.project = Project.find_or_create_by_name(name)
end
end
end
6 changes: 5 additions & 1 deletion lib/freckle-gem/project.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'json'

module FreckleGem

Expand All @@ -8,5 +7,10 @@ class Project < ActiveResource::Base
def self.headers
@headers ||= { 'X_FRECKLETOKEN' => Freckle::AppConfig.authtoken }
end

def self.find_or_create_by_name(name)
raise "Invalid Argument: Name can't be blank." if name.nil? || name.empty?
find(:first, :params => { :name => name }) || create(:name => name)
end
end
end
16 changes: 9 additions & 7 deletions lib/freckle/cli.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
require 'rubygems'
require 'optparse'
require 'net/http'
require 'uri'
require 'yaml'
require 'json'
require 'activeresource'
require 'freckle/app_config'
require 'freckle-gem/entry'
require 'freckle-gem/project'

module Freckle
class CLI
def self.execute(stdout, arguments=[])

options = {}
entry_attributes = {}
mandatory_options = %w( )

parser = OptionParser.new do |opts|
Expand All @@ -24,10 +25,10 @@ def self.execute(stdout, arguments=[])
BANNER
opts.separator ""

opts.on("-t", "--time=TIME") { |arg| options[:minutes] = arg }
opts.on("-p", "--project=PROJECT") { |arg| options[:project] = arg }
opts.on("-d", "--description=DESCRIPTION") { |arg| options[:description] = arg }
opts.on("-D", "--date=DATE") { |arg| options[:date] = arg }
opts.on("-t", "--time=TIME") { |arg| entry_attributes[:minutes] = arg }
opts.on("-p", "--project=PROJECT") { |arg| options[:project_name] = arg }
opts.on("-d", "--description=DESCRIPTION") { |arg| entry_attributes[:description] = arg }
opts.on("-D", "--date=DATE") { |arg| entry_attributes[:date] = arg }

opts.on("-h", "--help",
"Show this help message.") { stdout.puts opts; exit }
Expand All @@ -38,7 +39,8 @@ def self.execute(stdout, arguments=[])
end
end

entry = FreckleGem::Entry.new(options.merge(:user => Freckle::AppConfig.user))
entry = FreckleGem::Entry.new(entry_attributes.merge(:user => Freckle::AppConfig.user))
entry.project_name = options[:project_name] if options[:project_name]
entry.save
end
end
Expand Down

0 comments on commit a699e37

Please sign in to comment.