invoiceai 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +41 -0
- data/lib/invoiceai/client.rb +71 -0
- data/lib/invoiceai/error.rb +19 -0
- data/lib/invoiceai/resources/base.rb +29 -0
- data/lib/invoiceai/resources/clients.rb +27 -0
- data/lib/invoiceai/resources/invoices.rb +29 -0
- data/lib/invoiceai/resources/products.rb +27 -0
- data/lib/invoiceai/resources/profile.rb +15 -0
- data/lib/invoiceai/resources/quotes.rb +29 -0
- data/lib/invoiceai/resources/stats.rb +11 -0
- data/lib/invoiceai/version.rb +5 -0
- data/lib/invoiceai.rb +36 -0
- metadata +136 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5c346c3ad76415ebfaa9a01eef9af43ffa5f536c0fd0cd5a760df580c58e70af
|
|
4
|
+
data.tar.gz: 3e77b7e098ea6c4eda21346f95c62518ea8c8c58264d6deaf41faeb2a5e8166b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 44f65228fdb35fb8fb66d68f1769b1aa49dd847a5a719c2023e1473ab38987d46b0a75b38e747cb22825128e016ff367f92e984e8486646682dc36546a080ba1
|
|
7
|
+
data.tar.gz: 15d6493174c6300d2fd5ba2308ecf6897f3e722264a12693a1cdbda89dc02dc86f0ba268670fedd1599742710ea4227348aac746b58a5e656749e337530152ce
|
data/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# InvoiceAI Ruby SDK
|
|
2
|
+
|
|
3
|
+
Official Ruby SDK for the InvoiceAI API. Manage invoices, clients, products, quotes, and more.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
gem install invoiceai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or add to your Gemfile:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem 'invoiceai'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
require 'invoiceai'
|
|
21
|
+
|
|
22
|
+
# Initialize with your API key
|
|
23
|
+
client = InvoiceAI::Client.new(api_key: 'your_api_key_here')
|
|
24
|
+
|
|
25
|
+
# List all invoices
|
|
26
|
+
invoices = client.invoices.list
|
|
27
|
+
puts invoices['invoices']
|
|
28
|
+
|
|
29
|
+
# Create a client
|
|
30
|
+
new_client = client.clients.create(
|
|
31
|
+
name: 'John Doe',
|
|
32
|
+
email: 'john@example.com',
|
|
33
|
+
company: 'Acme Inc',
|
|
34
|
+
address: '123 Main St, Johannesburg'
|
|
35
|
+
)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Support
|
|
39
|
+
|
|
40
|
+
- Documentation: https://invoiceai.co.za/api-docs
|
|
41
|
+
- Email: support@invoiceai.co.za
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module InvoiceAI
|
|
4
|
+
class Client
|
|
5
|
+
attr_reader :invoices, :clients, :products, :quotes, :profile, :stats
|
|
6
|
+
|
|
7
|
+
def initialize(api_key: nil, jwt_token: nil, base_url: nil, timeout: nil)
|
|
8
|
+
@api_key = api_key
|
|
9
|
+
@jwt_token = jwt_token
|
|
10
|
+
@base_url = base_url || "https://invoiceai.co.za/api/v1"
|
|
11
|
+
@timeout = timeout || 30
|
|
12
|
+
|
|
13
|
+
@invoices = Resources::Invoices.new(self)
|
|
14
|
+
@clients = Resources::Clients.new(self)
|
|
15
|
+
@products = Resources::Products.new(self)
|
|
16
|
+
@quotes = Resources::Quotes.new(self)
|
|
17
|
+
@profile = Resources::Profile.new(self)
|
|
18
|
+
@stats = Resources::Stats.new(self)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def request(method:, path:, body: nil, params: nil)
|
|
22
|
+
response = connection.send(method) do |req|
|
|
23
|
+
req.url path
|
|
24
|
+
req.params = params if params
|
|
25
|
+
req.body = body.to_json if body
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
handle_response(response)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def connection
|
|
34
|
+
@connection ||= Faraday.new(url: @base_url) do |conn|
|
|
35
|
+
conn.headers["Content-Type"] = "application/json"
|
|
36
|
+
conn.headers["Accept"] = "application/json"
|
|
37
|
+
|
|
38
|
+
if @api_key
|
|
39
|
+
conn.headers["X-API-Key"] = @api_key
|
|
40
|
+
elsif @jwt_token
|
|
41
|
+
conn.headers["Authorization"] = "Bearer #{@jwt_token}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
conn.options.timeout = @timeout
|
|
45
|
+
conn.request :retry, max: 2, interval: 0.5
|
|
46
|
+
conn.adapter Faraday.default_adapter
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def handle_response(response)
|
|
51
|
+
body = response.body.empty? ? {} : JSON.parse(response.body)
|
|
52
|
+
|
|
53
|
+
case response.status
|
|
54
|
+
when 200..299
|
|
55
|
+
body
|
|
56
|
+
when 401
|
|
57
|
+
raise AuthenticationError.new("Authentication failed", status: response.status, body: body)
|
|
58
|
+
when 404
|
|
59
|
+
raise NotFoundError.new("Resource not found", status: response.status, body: body)
|
|
60
|
+
when 422
|
|
61
|
+
raise ValidationError.new(body["message"] || "Validation failed", status: response.status, body: body)
|
|
62
|
+
when 429
|
|
63
|
+
raise RateLimitError.new("Rate limit exceeded", status: response.status, body: body)
|
|
64
|
+
when 500..599
|
|
65
|
+
raise ServerError.new("Server error", status: response.status, body: body)
|
|
66
|
+
else
|
|
67
|
+
raise Error.new("Request failed", status: response.status, body: body)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module InvoiceAI
|
|
4
|
+
class Error < StandardError
|
|
5
|
+
attr_reader :status, :body
|
|
6
|
+
|
|
7
|
+
def initialize(message = nil, status: nil, body: nil)
|
|
8
|
+
@status = status
|
|
9
|
+
@body = body
|
|
10
|
+
super(message)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class AuthenticationError < Error; end
|
|
15
|
+
class NotFoundError < Error; end
|
|
16
|
+
class ValidationError < Error; end
|
|
17
|
+
class RateLimitError < Error; end
|
|
18
|
+
class ServerError < Error; end
|
|
19
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module InvoiceAI
|
|
4
|
+
module Resources
|
|
5
|
+
class Base
|
|
6
|
+
def initialize(client)
|
|
7
|
+
@client = client
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def get(path, params: nil)
|
|
13
|
+
@client.request(method: :get, path: path, params: params)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def post(path, body: nil)
|
|
17
|
+
@client.request(method: :post, path: path, body: body)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def put(path, body: nil)
|
|
21
|
+
@client.request(method: :put, path: path, body: body)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def delete(path)
|
|
25
|
+
@client.request(method: :delete, path: path)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module InvoiceAI
|
|
4
|
+
module Resources
|
|
5
|
+
class Clients < Base
|
|
6
|
+
def list(page: 1, limit: 20)
|
|
7
|
+
get("/clients", params: { page: page, limit: limit })
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def get(id)
|
|
11
|
+
super("/clients/#{id}")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create(data)
|
|
15
|
+
post("/clients", body: data)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def update(id, data)
|
|
19
|
+
put("/clients/#{id}", body: data)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def delete(id)
|
|
23
|
+
super("/clients/#{id}")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module InvoiceAI
|
|
4
|
+
module Resources
|
|
5
|
+
class Invoices < Base
|
|
6
|
+
def list(page: 1, limit: 20, status: nil)
|
|
7
|
+
params = { page: page, limit: limit }
|
|
8
|
+
params[:status] = status if status
|
|
9
|
+
get("/invoices", params: params)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def get(id)
|
|
13
|
+
super("/invoices/#{id}")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def create(data)
|
|
17
|
+
post("/invoices", body: data)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def update(id, data)
|
|
21
|
+
put("/invoices/#{id}", body: data)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def delete(id)
|
|
25
|
+
super("/invoices/#{id}")
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module InvoiceAI
|
|
4
|
+
module Resources
|
|
5
|
+
class Products < Base
|
|
6
|
+
def list(page: 1, limit: 20)
|
|
7
|
+
get("/products", params: { page: page, limit: limit })
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def get(id)
|
|
11
|
+
super("/products/#{id}")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create(data)
|
|
15
|
+
post("/products", body: data)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def update(id, data)
|
|
19
|
+
put("/products/#{id}", body: data)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def delete(id)
|
|
23
|
+
super("/products/#{id}")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module InvoiceAI
|
|
4
|
+
module Resources
|
|
5
|
+
class Quotes < Base
|
|
6
|
+
def list(page: 1, limit: 20, status: nil)
|
|
7
|
+
params = { page: page, limit: limit }
|
|
8
|
+
params[:status] = status if status
|
|
9
|
+
get("/quotes", params: params)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def get(id)
|
|
13
|
+
super("/quotes/#{id}")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def create(data)
|
|
17
|
+
post("/quotes", body: data)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def update(id, data)
|
|
21
|
+
put("/quotes/#{id}", body: data)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def delete(id)
|
|
25
|
+
super("/quotes/#{id}")
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/invoiceai.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "faraday"
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
require_relative "invoiceai/version"
|
|
7
|
+
require_relative "invoiceai/error"
|
|
8
|
+
require_relative "invoiceai/client"
|
|
9
|
+
require_relative "invoiceai/resources/base"
|
|
10
|
+
require_relative "invoiceai/resources/invoices"
|
|
11
|
+
require_relative "invoiceai/resources/clients"
|
|
12
|
+
require_relative "invoiceai/resources/products"
|
|
13
|
+
require_relative "invoiceai/resources/quotes"
|
|
14
|
+
require_relative "invoiceai/resources/profile"
|
|
15
|
+
require_relative "invoiceai/resources/stats"
|
|
16
|
+
|
|
17
|
+
module InvoiceAI
|
|
18
|
+
class << self
|
|
19
|
+
attr_accessor :api_key, :jwt_token, :base_url, :timeout
|
|
20
|
+
|
|
21
|
+
def configure
|
|
22
|
+
self.base_url ||= "https://invoiceai.co.za/api/v1"
|
|
23
|
+
self.timeout ||= 30
|
|
24
|
+
yield self if block_given?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def client
|
|
28
|
+
@client ||= Client.new(
|
|
29
|
+
api_key: api_key,
|
|
30
|
+
jwt_token: jwt_token,
|
|
31
|
+
base_url: base_url,
|
|
32
|
+
timeout: timeout
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: invoiceai
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- InvoiceAI
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-12-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: faraday
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.0'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '3.0'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '1.0'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '3.0'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: faraday-retry
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2.0'
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '2.0'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: rspec
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '3.12'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '3.12'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: webmock
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '3.18'
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '3.18'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: rubocop
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '1.50'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '1.50'
|
|
89
|
+
description: A Ruby client library for the InvoiceAI API. Create and manage invoices,
|
|
90
|
+
clients, products, and quotes programmatically.
|
|
91
|
+
email:
|
|
92
|
+
- support@invoiceai.co.za
|
|
93
|
+
executables: []
|
|
94
|
+
extensions: []
|
|
95
|
+
extra_rdoc_files: []
|
|
96
|
+
files:
|
|
97
|
+
- README.md
|
|
98
|
+
- lib/invoiceai.rb
|
|
99
|
+
- lib/invoiceai/client.rb
|
|
100
|
+
- lib/invoiceai/error.rb
|
|
101
|
+
- lib/invoiceai/resources/base.rb
|
|
102
|
+
- lib/invoiceai/resources/clients.rb
|
|
103
|
+
- lib/invoiceai/resources/invoices.rb
|
|
104
|
+
- lib/invoiceai/resources/products.rb
|
|
105
|
+
- lib/invoiceai/resources/profile.rb
|
|
106
|
+
- lib/invoiceai/resources/quotes.rb
|
|
107
|
+
- lib/invoiceai/resources/stats.rb
|
|
108
|
+
- lib/invoiceai/version.rb
|
|
109
|
+
homepage: https://invoiceai.co.za/api-docs
|
|
110
|
+
licenses:
|
|
111
|
+
- MIT
|
|
112
|
+
metadata:
|
|
113
|
+
homepage_uri: https://invoiceai.co.za/api-docs
|
|
114
|
+
source_code_uri: https://invoiceai.co.za/api-docs
|
|
115
|
+
changelog_uri: https://invoiceai.co.za/api-docs
|
|
116
|
+
documentation_uri: https://invoiceai.co.za/api-docs
|
|
117
|
+
post_install_message:
|
|
118
|
+
rdoc_options: []
|
|
119
|
+
require_paths:
|
|
120
|
+
- lib
|
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - ">="
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: 2.7.0
|
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
requirements: []
|
|
132
|
+
rubygems_version: 3.4.19
|
|
133
|
+
signing_key:
|
|
134
|
+
specification_version: 4
|
|
135
|
+
summary: Official Ruby SDK for the InvoiceAI API
|
|
136
|
+
test_files: []
|