Skip to content

Commit

Permalink
Created ActiveResource branch and created first tests for AR branch
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrussell committed Oct 20, 2009
1 parent c520687 commit 711f7f5
Show file tree
Hide file tree
Showing 14 changed files with 373 additions and 204 deletions.
46 changes: 0 additions & 46 deletions lib/freeagent/base.rb

This file was deleted.

20 changes: 0 additions & 20 deletions lib/freeagent/contact.rb

This file was deleted.

27 changes: 0 additions & 27 deletions lib/freeagent/invoice.rb

This file was deleted.

13 changes: 0 additions & 13 deletions lib/freeagent/invoice_item.rb

This file was deleted.

20 changes: 0 additions & 20 deletions lib/freeagent/project.rb

This file was deleted.

14 changes: 0 additions & 14 deletions lib/freeagent/task.rb

This file was deleted.

27 changes: 0 additions & 27 deletions lib/freeagent/timeslip.rb

This file was deleted.

187 changes: 174 additions & 13 deletions lib/freeagent_api.rb
@@ -1,29 +1,190 @@
require 'rubygems'
require 'nokogiri'
require 'net/https'
require 'api_cache'
require 'activesupport'
require 'activeresource'

# Require Freeagent library files
Dir[File.join(File.dirname(__FILE__), "freeagent/*.rb")].each { |f| require f }

module Freeagent

class << self
attr_accessor :domain, :username, :password
end

class Error < StandardError; end

def self.domain=(domain)
@domain = domain
class Base < ActiveResource::Base
def self.authenticate
self.site = "https://#{Freeagent.domain}"
self.user = Freeagent.username
self.password = Freeagent.password
end
end

# Find contacts
#
# Contact.find :all # find all contacts
# Contact.find contact_id # find specific contact by ID
#
# Create contact
#
# Required attributes
# :first_name
# :last_name
#
# contact = Contact.new :first_name => 'Joe', :last_name => 'Bloggs'
# contact.save
#
# Update contact
#
# contact = Contact.find contact_id
# contact.first_name = 'Joe'
# contact.last_name = 'Bloggs'
# contact.save
#
# Delete contact
#
# Contact.delete contact_id
# contact.destroy
#

class Contact < Base
end

# Find projects
#
# Project.find :all # find all projects
# Project.find project_id # find specific project by ID
#
# Create project
#
# Required attributes
# :contact_id
# :name
# :payment_term_in_days
# :billing_basis # must be 1, 7, 7.5, or 8
# :budget_units # must be Hours, Days, or Monetary
# :status # must be Active or Completed
#
# Project = Project.new params
# contact.save
#
# Update project
#
# project = Project.find project_id
# project.name = 'Website redesign and build'
# project.save
#
# Delete project
#
# Project.delete project_id
# project.destroy
#

class Project < Base

def self.username=(username)
@username = username
def invoices
Invoice.find :all, :params => {:project_id => id}
end

def tasks
Task.find :all, :params => {:project_id => id}
end

def timeslips
Timeslip.find :all, :params => {:project_id => id}
end

def self.password=(password)
@password = password
end

# Find invoices
#
# Invoice.find :all
# Invoice.find :all, :params => {:project_id => project_id}
# Invoice.find task_id
#
#TODO Create invoice
#
#TODO Update invoice
#
#TODO Delete project
#
##TODO add Change status methods
# /invoices/invoice_id/mark_as_draft
# /invoices/invoice_id/mark_as_sent
# /invoices/invoice_id/mark_as_cancelled


class Invoice < Base

def self.find(*args)
opts = args.slice!(1) || {}
self.prefix = "/projects/#{opts[:params][:project_id]}/" if opts[:params] && opts[:params][:project_id]
super
end

end

# Find invoice items
#
# InvoiceItem.find :all, :params => {:invoice_id => invoice_id}
# InvoiceItem.find invoice_item_id, :params => {:invoice_id => invoice_id}
#
#TODO Create invoice item
#

class InvoiceItem < Base
self.prefix = '/invoices/:invoice_id/'
end

# Find tasks
#
# Task.find :all
# Task.find :all, :params => {:project_id => project_id}
# Task.find task_id
#
#TODO Create task
#
#TODO Update task
#
#TODO Delete project
#

class Task < Base

self.prefix = '/projects/:project_id/'

# def self.find(*args)
# opts = args.slice!(1) || {}
# self.prefix = "/projects/#{opts[:params][:project_id]}/" if opts[:params] && opts[:params][:project_id]
# super
# end

end

# Find timeslips
#
# Timeslip.find :all, :params => {:view => '2009-01-01_2009-10-01'}
# Timeslip.find :all, :params => {:project_id => project_id}
# Timeslip.find :timeslip_id


class Timeslip < Base

def self.find(*args)
opts = args.slice!(1) || {}
self.prefix = "/projects/#{opts[:params][:project_id]}/" if opts[:params] && opts[:params][:project_id]
super
end

end

# class ActiveResource::Connection
# def http
# http = Net::HTTP.new(@site.host, @site.port)
# http.use_ssl = @site.is_a?(URI::HTTPS)
# http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
# http.read_timeout = @timeout if @timeout
# #Here's the addition that allows you to see the output
# http.set_debug_output $stderr
# return http
# end
# end

end

0 comments on commit 711f7f5

Please sign in to comment.