zoho_invoice 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -3
- data/Rakefile +1 -0
- data/lib/zoho_invoice/base.rb +6 -7
- data/lib/zoho_invoice/client.rb +11 -0
- data/lib/zoho_invoice/collection.rb +25 -0
- data/lib/zoho_invoice/customer.rb +0 -1
- data/lib/zoho_invoice/invoice_item.rb +2 -2
- data/lib/zoho_invoice/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/zoho_invoice/collection_spec.rb +39 -0
- metadata +5 -2
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# Zoho Invoice
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/neovintage/zoho_invoice.png?branch=master)](https://travis-ci.org/neovintage/zoho_invoice)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/neovintage/zoho_invoice/badge.png?branch=master)](https://coveralls.io/r/neovintage/zoho_invoice)
|
5
|
+
|
6
|
+
Need to interact with the Zoho Invoice API? The zoho_invoice gem has your back.
|
7
|
+
|
8
|
+
Until the gem reaches 1.0, the interface for interacting with the gem could change. On top of that the gem does not support the entire API just yet. Just the minimum number of domain objects to actually create customers and invoices. This will change over time.
|
4
9
|
|
5
10
|
## Installation
|
6
11
|
|
@@ -16,9 +21,43 @@ Or install it yourself as:
|
|
16
21
|
|
17
22
|
$ gem install zoho_invoice
|
18
23
|
|
24
|
+
## Configuration
|
25
|
+
|
26
|
+
The Zoho Invoice API service requires that you generate an auth token ahead of time using the API, just once. Fortunately, the gem can handle that in console for you, all you need is your username and password.
|
27
|
+
Then you can save the authtoken in your project based on however you do your configuration.
|
28
|
+
|
29
|
+
```
|
30
|
+
homebase $ irb
|
31
|
+
> require 'zoho_invoice'
|
32
|
+
=> true
|
33
|
+
> result = ZohoInvoice::AuthToken.generate_authtoken('dude@example.com', 'thisismysweetpassword')
|
34
|
+
=> #<struct ZohoInvoice::AuthToken::AuthTokenResult authtoken="blahblahblahnumbersnstuff", cause=nil>
|
35
|
+
> result.success?
|
36
|
+
=> true
|
37
|
+
> result.authtoken
|
38
|
+
=> "blahblahblahnumbersnstuff"
|
39
|
+
```
|
40
|
+
|
19
41
|
## Usage
|
20
42
|
|
21
|
-
|
43
|
+
```ruby
|
44
|
+
require 'zoho_invoice'
|
45
|
+
|
46
|
+
client = ZohoInvoice::Client.new(:authtoken => 'my authtoken', :apikey => 'my apikey')
|
47
|
+
|
48
|
+
invoice = ZohoInvoice::Invoice.new(client, :customer_id => 'asdf')
|
49
|
+
invoice.save
|
50
|
+
```
|
51
|
+
|
52
|
+
If you're so inclined, you can scope the resources through the client.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require 'zoho_invoice'
|
56
|
+
|
57
|
+
client = ZohoInvoice::Client.new(:authtoken => 'my authtoken', :apikey => 'my apikey')
|
58
|
+
invoice = client.invoices.new(:customer_id => 'asdf')
|
59
|
+
invoice.save
|
60
|
+
```
|
22
61
|
|
23
62
|
## Contributing
|
24
63
|
|
data/Rakefile
CHANGED
data/lib/zoho_invoice/base.rb
CHANGED
@@ -95,6 +95,12 @@ module ZohoInvoice
|
|
95
95
|
build_attributes.to_xml(*args)
|
96
96
|
end
|
97
97
|
|
98
|
+
def self.create_attributes(attrs)
|
99
|
+
attrs.each do |attr|
|
100
|
+
attr_accessor attr
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
98
104
|
protected
|
99
105
|
|
100
106
|
def process_error(request_result)
|
@@ -140,12 +146,5 @@ module ZohoInvoice
|
|
140
146
|
end
|
141
147
|
end
|
142
148
|
|
143
|
-
private
|
144
|
-
|
145
|
-
def self.create_attributes(attrs)
|
146
|
-
attrs.each do |attr|
|
147
|
-
attr_accessor attr
|
148
|
-
end
|
149
|
-
end
|
150
149
|
end
|
151
150
|
end
|
data/lib/zoho_invoice/client.rb
CHANGED
@@ -1,7 +1,18 @@
|
|
1
|
+
require 'zoho_invoice/collection'
|
2
|
+
|
1
3
|
module ZohoInvoice
|
2
4
|
class Client
|
3
5
|
include ZohoInvoice::Configurable
|
4
6
|
|
7
|
+
RESOURCES = [
|
8
|
+
:customers,
|
9
|
+
:invoices
|
10
|
+
]
|
11
|
+
|
12
|
+
RESOURCES.each do |resource|
|
13
|
+
define_method(resource, ->{ ZohoInvoice::Collection.new(resource, self) })
|
14
|
+
end
|
15
|
+
|
5
16
|
def initialize(options = {})
|
6
17
|
ZohoInvoice::Configurable.keys.each do |key|
|
7
18
|
instance_variable_set(:"@#{key}", options[key] || ZohoInvoice.instance_variable_get(:"@#{key}"))
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ZohoInvoice
|
2
|
+
class Collection
|
3
|
+
|
4
|
+
attr_reader :resource, :klass, :client
|
5
|
+
|
6
|
+
def initialize(resource, client)
|
7
|
+
@resource = resource
|
8
|
+
@klass = "ZohoInvoice::#{resource[0..-2].capitalize}".split('::').reduce(Module, :const_get)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
def search(*args, &block)
|
13
|
+
@klass.search(@client, *args, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def new(*args, &block)
|
17
|
+
@klass.new(@client, *args, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(*args, &block)
|
21
|
+
@klass.create(@client, *args, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/lib/zoho_invoice/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZohoInvoice::Collection do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = ZohoInvoice::Client.new
|
7
|
+
@customers = ZohoInvoice::Collection.new(:customers, @client)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should correctly find the resource" do
|
11
|
+
expect(@customers.resource ).to eq(:customers)
|
12
|
+
expect(@customers.klass ).to eq(ZohoInvoice::Customer)
|
13
|
+
expect(@customers.client ).to eq(@client)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should forward the initialize call to the underlying resource and pass the client" do
|
17
|
+
customer = nil
|
18
|
+
expect{ customer = @customers.new }.not_to raise_error
|
19
|
+
expect(customer.class).to eq(ZohoInvoice::Customer)
|
20
|
+
expect(customer.client).to eq(@client)
|
21
|
+
|
22
|
+
expect{ customer = @customers.new(:name => 'Dude') }.not_to raise_error
|
23
|
+
expect(customer.name).to eq('Dude')
|
24
|
+
expect(customer.client).to eq(@client)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should forward the search call to the resource and pass the client" do
|
28
|
+
ZohoInvoice::Customer.stub(:search)
|
29
|
+
ZohoInvoice::Customer.should_receive(:search)
|
30
|
+
expect{ @customers.search('find it') }.not_to raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should forward the create method to the resource" do
|
34
|
+
ZohoInvoice::Customer.stub(:create)
|
35
|
+
ZohoInvoice::Customer.should_receive(:create)
|
36
|
+
expect{ @customers.create(:name => 'Dude') }.not_to raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zoho_invoice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/zoho_invoice/auth_token.rb
|
111
111
|
- lib/zoho_invoice/base.rb
|
112
112
|
- lib/zoho_invoice/client.rb
|
113
|
+
- lib/zoho_invoice/collection.rb
|
113
114
|
- lib/zoho_invoice/configurable.rb
|
114
115
|
- lib/zoho_invoice/contact.rb
|
115
116
|
- lib/zoho_invoice/customer.rb
|
@@ -131,6 +132,7 @@ files:
|
|
131
132
|
- spec/zoho_invoice/auth_token_spec.rb
|
132
133
|
- spec/zoho_invoice/base_spec.rb
|
133
134
|
- spec/zoho_invoice/client_spec.rb
|
135
|
+
- spec/zoho_invoice/collection_spec.rb
|
134
136
|
- spec/zoho_invoice/contact_spec.rb
|
135
137
|
- spec/zoho_invoice_spec.rb
|
136
138
|
- zoho_invoice.gemspec
|
@@ -171,5 +173,6 @@ test_files:
|
|
171
173
|
- spec/zoho_invoice/auth_token_spec.rb
|
172
174
|
- spec/zoho_invoice/base_spec.rb
|
173
175
|
- spec/zoho_invoice/client_spec.rb
|
176
|
+
- spec/zoho_invoice/collection_spec.rb
|
174
177
|
- spec/zoho_invoice/contact_spec.rb
|
175
178
|
- spec/zoho_invoice_spec.rb
|