-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Johan van Zonneveld
committed
Sep 13, 2010
0 parents
commit 274cda0
Showing
13 changed files
with
493 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>zoho_invoice</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.rubypeople.rdt.core.rubybuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.rubypeople.rdt.core.rubynature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'zoho_invoice' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'httparty' | ||
require 'hashie' | ||
|
||
require 'zoho_invoice/client' | ||
|
||
module ZohoInvoice | ||
VERSION = '0.0.1' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'zoho_invoice/customers' | ||
require 'zoho_invoice/items' | ||
require 'zoho_invoice/invoices' | ||
require 'zoho_invoice/expenses' | ||
require 'zoho_invoice/expense_categories' | ||
require 'zoho_invoice/estimates' | ||
require 'zoho_invoice/payments' | ||
|
||
module ZohoInvoice | ||
class Client | ||
include HTTParty | ||
base_uri 'https://invoice.zoho.com/api' | ||
|
||
def initialize(options = {}) | ||
zoho_config = YAML::load_file(RAILS_ROOT+'/config/zoho_invoice.yml') | ||
|
||
api_key = zoho_config['api_key'] | ||
secret_key = zoho_config['secret_key'] # dont't know what it's used for o_0 | ||
username = zoho_config['username'] | ||
password = zoho_config['password'] | ||
last_ticket_date = zoho_config['last_ticket_date'] | ||
|
||
# a zoho ticket stays valid for 7 days | ||
# create a new one if ticket is expired | ||
if last_ticket_date + 7.days <= Date.today | ||
response = self.class.get("https://accounts.zoho.com/login", | ||
:format => :html, | ||
:query => { | ||
:service_name => 'ZohoInvoice', | ||
:FROM_AGENT => true, | ||
:LOGIN_ID => username, | ||
:PASSWORD => password | ||
}) | ||
ticket = response.scan(/TICKET=(.{32})/).to_s | ||
zoho_config['ticket'] = ticket | ||
zoho_config['last_ticket_date'] = Date.today | ||
File.open("#{RAILS_ROOT}/config/zoho_invoice.yml", 'w') { |f| YAML.dump(zoho_config, f) } | ||
else | ||
ticket = zoho_config['ticket'] | ||
end | ||
|
||
@authorization = {:ticket => ticket, :apikey => api_key} | ||
end | ||
|
||
def request_body(params) | ||
body = {:XMLString => params.to_xml} | ||
body.merge!(@authorization) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module ZohoInvoice | ||
class Client | ||
|
||
def list_customers | ||
response = self.class.get('/customers', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def list_inactive_customers | ||
response = self.class.get('/customers/inactive', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# Search for a customer by passing either "Customer Name" or "Customer Notes". Only active customers will be listed. | ||
def find_customers(query) | ||
@authorization.merge!(:searchtext => query) | ||
response = self.class.get('/view/search/customers', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def view_customer(id) | ||
response = self.class.get("/customers/#{id}", :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# EXAMPLE: create_customer(:customer => {:name => 'Someone'}) | ||
def create_customer(params = {}) | ||
response = self.class.post('/customers/create', request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def update_customer(params = {}) | ||
response = self.class.post('/customers/update', :query => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def delete_customer(id) | ||
response = self.class.post("/customers/delete/#{id}", :body => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def mark_customer_as_inactive(id) | ||
response = self.class.post("/customers/markasinactive/#{id}", :body => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# Sends a statement to the Customer specified. | ||
# Params to be passed: Custom.Subject, Custom.Body, CustomerID, StartDate, EndDate | ||
def send_customer_statement(params ={}) | ||
response = self.class.post('/customers/sendstatement', :query => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# View a customer statement. | ||
# Params to be passed: CustomerID, StartDate, EndDate | ||
def view_customer_statement(params ={}) | ||
response = self.class.post('/customers/getstatement ', :query => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module ZohoInvoice | ||
class Client | ||
|
||
def list_estimates | ||
response = self.class.get('/estimates', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# Search for an invoice by passing either "Estimate Number" or "Customer Name".Only active estimates will be listed. | ||
def find_estimates(query) | ||
@authorization.merge!(:searchtext => query) | ||
response = self.class.get('/view/search/estimates', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def list_estimates_for_customer(customer_id) | ||
response = self.class.post("/estimates/customer/#{customer_id}", :body => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def view_estimate(id) | ||
response = self.class.get("/estimates/#{id}", :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# EXAMPLE: | ||
def create_estimate(params = {}) | ||
response = self.class.post('/estimates/create', :query => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def update_estimate(params = {}) | ||
response = self.class.post('/estimates/update', :query => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def delete_estimate(id) | ||
response = self.class.post("/estimates/delete/#{id}", :body => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# Sends an estimate to the Customer for whom the estimate was raised. | ||
# Parameters to be passed: Custom.Subject, Custom.Body, EstimateID | ||
def send_estimate(params = {}) | ||
response = self.class.post('/estimates/send', :query => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def mark_estimate_as_send(id) | ||
response = self.class.post("/estimates/markassent/#{id}", :body => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module ZohoInvoice | ||
class Client | ||
|
||
def list_expense_categories | ||
response = self.class.get('/expensecategories', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def list_inactive_expense_categories | ||
response = self.class.get('/expensecategories/inactive', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def list_active_expense_categories | ||
response = self.class.get('/expensecategories/active', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def find_expense_categories(query) | ||
@authorization.merge!(:searchtext => query) | ||
response = self.class.get('/view/search/expensecategories', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def view_expense_category(id) | ||
response = self.class.get("/expensecategories/#{id}", :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# EXAMPLE: | ||
def create_expense_category(params = {}) | ||
response = self.class.post('/expensecategories/create', :body => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# EXAMPLE: | ||
def update_expense_category(params = {}) | ||
response = self.class.post('/expensecategories/update', :body => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def delete_expense_category(id) | ||
response = self.class.post("/expensecategories/delete/#{id}", :body => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def mark_expense_category_as_inactive(id) | ||
response = self.class.post("/expensecategories/markasinactive/#{id}", :body => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module ZohoInvoice | ||
class Client | ||
|
||
def list_expenses | ||
response = self.class.get('/expenses', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# Search for an expense by passing either "Category Name", "Expense Description" or "Customer Name". | ||
def find_expenses(query) | ||
@authorization.merge!(:searchtext => query) | ||
response = self.class.get('/view/search/expenses', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def view_expense(id) | ||
response = self.class.get("/expenses/#{id}", :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# EXAMPLE: | ||
def create_expense(params = {}) | ||
response = self.class.post('/expenses/create', :body => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# EXAMPLE: | ||
def update_expense(params = {}) | ||
response = self.class.post('/expenses/update', :body => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def delete_expense(id) | ||
response = self.class.post("/expensess/delete/#{id}", :body => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module ZohoInvoice | ||
class Client | ||
|
||
def list_invoices | ||
response = self.class.get('/invoices', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# Search for an invoice by passing either "Invoice Number" or "Customer Name". Only active invoices will be listed. | ||
def find_invoices(query) | ||
@authorization.merge!(:searchtext => query) | ||
response = self.class.get('/view/search/invoices', :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def list_invoices_for_customer(customer_id) | ||
response = self.class.post("/invoices/customer/#{customer_id}", :body => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def view_invoice(id) | ||
response = self.class.get("/invoices/#{id}", :query => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# EXAMPLE: create_customer(:customer => {:name => 'Someone'}) | ||
def create_invoice(params = {}) | ||
response = self.class.post('/invoices/create', :query => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def update_invoice(params = {}) | ||
response = self.class.post('/invoices/update', :query => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def delete_invoice(id) | ||
response = self.class.post("/invoices/delete/#{id}", :body => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# Sends an Invoice to the Customer for whom the invoice was raised. | ||
# Parameters to be passed: Custom.Subject, Custom.Body, InvoiceID | ||
def send_invoice(params = {}) | ||
response = self.class.post('/invoices/send', :query => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
# Sends an Invoice to the Customer for whom the invoice was raised. | ||
# Parameters to be passed: Custom.Subject, Custom.Body, InvoiceID | ||
def send_invoice_reminder(params = {}) | ||
response = self.class.post('/invoices/sendreminder', :query => request_body(params), :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def convert_invoice_to_open(id) | ||
response = self.class.post("/invoices/converttoopen/#{id}", :body => @authorization, :format => :xml) | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.