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 CHANGED
@@ -1,6 +1,11 @@
1
- # ZohoInvoice
1
+ # Zoho Invoice
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
@@ -5,3 +5,4 @@ require 'rspec/core/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
 
7
7
  task :test => :spec
8
+ task :default => :spec
@@ -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
@@ -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
@@ -22,7 +22,6 @@ module ZohoInvoice
22
22
  has_many :contacts
23
23
 
24
24
  def self.search(client, input_text)
25
-
26
25
  end
27
26
 
28
27
  end
@@ -1,7 +1,7 @@
1
+ require 'zoho_invoice/item'
2
+
1
3
  module ZohoInvoice
2
4
  class InvoiceItem < Item
3
5
 
4
- primary_key :item_id
5
-
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module ZohoInvoice
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -14,6 +14,7 @@ require 'zoho_invoice'
14
14
  require 'webmock/rspec'
15
15
  require 'pry'
16
16
 
17
+ Coveralls.wear!
17
18
  WebMock.disable_net_connect!
18
19
 
19
20
  RSpec.configure do |config|
@@ -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.1
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-03 00:00:00.000000000 Z
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