invoice2go 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +7 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +71 -0
- data/LICENSE.txt +22 -0
- data/README.md +58 -0
- data/Rakefile +10 -0
- data/invoice2go.gemspec +30 -0
- data/lib/faraday/auth.rb +14 -0
- data/lib/invoice2go.rb +25 -0
- data/lib/invoice2go/api.rb +29 -0
- data/lib/invoice2go/client.rb +10 -0
- data/lib/invoice2go/client/accounts.rb +13 -0
- data/lib/invoice2go/client/clients.rb +9 -0
- data/lib/invoice2go/client/documents.rb +13 -0
- data/lib/invoice2go/configuration.rb +56 -0
- data/lib/invoice2go/connection.rb +33 -0
- data/lib/invoice2go/request.rb +100 -0
- data/lib/invoice2go/response.rb +12 -0
- data/lib/invoice2go/token.rb +11 -0
- data/lib/invoice2go/version.rb +3 -0
- data/spec/fixtures/account.json +4 -0
- data/spec/fixtures/accounts_list.json +10 -0
- data/spec/fixtures/clients_list.json +52 -0
- data/spec/fixtures/document.json +89 -0
- data/spec/fixtures/documents_list.json +164 -0
- data/spec/invoice2go/client.rb +12 -0
- data/spec/invoice2go/clients/accounts_spec.rb +38 -0
- data/spec/invoice2go/clients/clients_spec.rb +24 -0
- data/spec/invoice2go/clients/documents_spec.rb +39 -0
- data/spec/invoice2go_spec.rb +77 -0
- data/spec/spec_helper.rb +91 -0
- metadata +215 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38e2b724f8ceed2662a5f4b2ebf22e26316c6812
|
4
|
+
data.tar.gz: 737e195013a9365a38a90cf17508e8f1722a1f15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 878b102378c66b0fc7ba4754bee920a5dd01355c110d30e797732989c21bf23058d9b381ab86fa5f50149433c87bc71c6e130d0648062ce3661801325308d22f
|
7
|
+
data.tar.gz: c0a0b739e3486495f2b33341dead7cf2b7f31483e3ed9e8a1f294da3a376f36deea1ec871bb55b0c849457c0e7152eff189597cfd6b2c963724cc9b1a5bed277
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
invoice2go (0.0.2)
|
5
|
+
activesupport (~> 4.2)
|
6
|
+
faraday (~> 0.9)
|
7
|
+
faraday_middleware (~> 0.10)
|
8
|
+
hashie (~> 3.4)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (4.2.5)
|
14
|
+
i18n (~> 0.7)
|
15
|
+
json (~> 1.7, >= 1.7.7)
|
16
|
+
minitest (~> 5.1)
|
17
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
addressable (2.3.8)
|
20
|
+
byebug (8.2.1)
|
21
|
+
crack (0.4.2)
|
22
|
+
safe_yaml (~> 1.0.0)
|
23
|
+
diff-lcs (1.2.5)
|
24
|
+
faraday (0.9.2)
|
25
|
+
multipart-post (>= 1.2, < 3)
|
26
|
+
faraday_middleware (0.10.0)
|
27
|
+
faraday (>= 0.7.4, < 0.10)
|
28
|
+
hashie (3.4.3)
|
29
|
+
httpclient (2.6.0.1)
|
30
|
+
i18n (0.7.0)
|
31
|
+
json (1.8.3)
|
32
|
+
minitest (5.8.3)
|
33
|
+
multipart-post (2.0.0)
|
34
|
+
patron (0.5.0)
|
35
|
+
rake (10.4.2)
|
36
|
+
rspec (3.3.0)
|
37
|
+
rspec-core (~> 3.3.0)
|
38
|
+
rspec-expectations (~> 3.3.0)
|
39
|
+
rspec-mocks (~> 3.3.0)
|
40
|
+
rspec-core (3.3.2)
|
41
|
+
rspec-support (~> 3.3.0)
|
42
|
+
rspec-expectations (3.3.1)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.3.0)
|
45
|
+
rspec-mocks (3.3.2)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.3.0)
|
48
|
+
rspec-support (3.3.0)
|
49
|
+
safe_yaml (1.0.4)
|
50
|
+
thread_safe (0.3.5)
|
51
|
+
tzinfo (1.2.2)
|
52
|
+
thread_safe (~> 0.1)
|
53
|
+
webmock (1.21.0)
|
54
|
+
addressable (>= 2.3.6)
|
55
|
+
crack (>= 0.3.2)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
ruby
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
bundler (~> 1.3)
|
62
|
+
byebug (~> 8.2)
|
63
|
+
httpclient
|
64
|
+
invoice2go!
|
65
|
+
patron
|
66
|
+
rake (~> 10.4)
|
67
|
+
rspec (~> 3.1)
|
68
|
+
webmock (~> 1.6)
|
69
|
+
|
70
|
+
BUNDLED WITH
|
71
|
+
1.10.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Customer Lobby
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Invoice2go
|
2
|
+
|
3
|
+
A Ruby wrapper for the Invoice2go REST API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'invoice2go'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install invoice2go
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Configuration
|
22
|
+
|
23
|
+
Before you can make calls to Invoice2go you must configure the library with a valid API Token. You can request
|
24
|
+
a token be generated by Invoice2go. The API Token ties the API request to a particular Invoice2go company id.
|
25
|
+
|
26
|
+
There are two ways to configure the gem. You can pass a hash of configuration options when you create
|
27
|
+
a client, or you can use a configure block.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
client = Invoice2go.client({api_key: "YOUR_TOKEN_HERE"})
|
31
|
+
```
|
32
|
+
|
33
|
+
Middleware has been built in to automatically refresh the api_token when it expires if the details below are provided.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
Invoice2go.configure do |config|
|
37
|
+
config.api_key = "YOUR_TOKEN_HERE"
|
38
|
+
config.client_id = "YOUR_CLIENT_ID"
|
39
|
+
config.client_secret = "YOUR_CLIENT_SECRET"
|
40
|
+
config.refresh_token = "YOUR_REFRESH_TOKEN"
|
41
|
+
end
|
42
|
+
|
43
|
+
client = Invoice2go.client
|
44
|
+
|
45
|
+
You can manually refresh the api and refresh tokens by calling client.refresh_token!
|
46
|
+
```
|
47
|
+
|
48
|
+
```
|
49
|
+
There are only a limited number of calls available currently:
|
50
|
+
|
51
|
+
client.accounts
|
52
|
+
client.clients(account_id)
|
53
|
+
client.documents(account_id)
|
54
|
+
|
55
|
+
You can pass params to these calls as defined in the invoice2go api. i.e.
|
56
|
+
|
57
|
+
client.documents(account_id, {page: 1, page_size: 1000})
|
58
|
+
```
|
data/Rakefile
ADDED
data/invoice2go.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'invoice2go/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "invoice2go"
|
8
|
+
spec.version = Invoice2go::VERSION
|
9
|
+
spec.authors = ["Customer Lobby"]
|
10
|
+
spec.email = ["dev@customerlobby.com"]
|
11
|
+
spec.description = %q{Client for the Invoice2go API}
|
12
|
+
spec.summary = 'Client to interact with the Invoice2go API'
|
13
|
+
spec.homepage = "https://bitbucket.org/customerlobby/invoice2go"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
23
|
+
spec.add_development_dependency('rspec', '~> 3.1')
|
24
|
+
spec.add_development_dependency('webmock', '~> 1.6')
|
25
|
+
spec.add_development_dependency('byebug', '~> 8.2')
|
26
|
+
spec.add_runtime_dependency('hashie', '~> 3.4')
|
27
|
+
spec.add_runtime_dependency('faraday', '~> 0.9')
|
28
|
+
spec.add_runtime_dependency('faraday_middleware', '~> 0.10')
|
29
|
+
spec.add_runtime_dependency('activesupport', '~> 4.2')
|
30
|
+
end
|
data/lib/faraday/auth.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module FaradayMiddleware
|
2
|
+
class Invoice2goAuth < Faraday::Middleware
|
3
|
+
|
4
|
+
def initialize(app, api_key)
|
5
|
+
@app = app
|
6
|
+
@api_key = api_key
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:request_headers] = env[:request_headers].merge('Authorization' => "Bearer #{@api_key}")
|
11
|
+
@app.call env
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/invoice2go.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'active_support/all'
|
4
|
+
require 'invoice2go/version'
|
5
|
+
|
6
|
+
Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f}
|
7
|
+
require File.expand_path('../invoice2go/configuration', __FILE__)
|
8
|
+
require File.expand_path('../invoice2go/api', __FILE__)
|
9
|
+
require File.expand_path('../invoice2go/client', __FILE__)
|
10
|
+
|
11
|
+
module Invoice2go
|
12
|
+
|
13
|
+
extend Configuration
|
14
|
+
# Alias for Invoice2go::Client.new
|
15
|
+
# @return [Invoice2go::Client]
|
16
|
+
def self.client(options = {})
|
17
|
+
Invoice2go::Client.new(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Delegate to Invoice2go::Client
|
21
|
+
def self.method_missing(method, *args, &block)
|
22
|
+
return super unless client.respond_to?(method)
|
23
|
+
client.send(method, *args, &block)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('../request', __FILE__)
|
2
|
+
require File.expand_path('../response', __FILE__)
|
3
|
+
require File.expand_path('../connection', __FILE__)
|
4
|
+
|
5
|
+
module Invoice2go
|
6
|
+
class API
|
7
|
+
|
8
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
9
|
+
|
10
|
+
def initialize(options={})
|
11
|
+
options = Invoice2go.options.merge(options)
|
12
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
13
|
+
send("#{key}=", options[key])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def config
|
18
|
+
conf = {}
|
19
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
20
|
+
conf[key] = send key
|
21
|
+
end
|
22
|
+
conf
|
23
|
+
end
|
24
|
+
|
25
|
+
include Request
|
26
|
+
include Response
|
27
|
+
include Connection
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Invoice2go
|
2
|
+
# Wrapper for the Invoice2go REST API.
|
3
|
+
class Client < API
|
4
|
+
Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
|
5
|
+
|
6
|
+
include Invoice2go::Client::Accounts
|
7
|
+
include Invoice2go::Client::Documents
|
8
|
+
include Invoice2go::Client::Clients
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Invoice2go
|
2
|
+
class Client
|
3
|
+
module Documents
|
4
|
+
def documents(account_id, params = {})
|
5
|
+
get("accounts/#{account_id}/documents", params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def document(account_id, id, params = {})
|
9
|
+
get("accounts/#{account_id}/documents/#{id}", params)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Invoice2go
|
2
|
+
module Configuration
|
3
|
+
|
4
|
+
VALID_OPTIONS_KEYS = [
|
5
|
+
:api_key,
|
6
|
+
:api_version,
|
7
|
+
:adapter,
|
8
|
+
:endpoint,
|
9
|
+
:client_id,
|
10
|
+
:client_secret,
|
11
|
+
:grant_type,
|
12
|
+
:refresh_token
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
# By default don't set the api key.
|
16
|
+
DEFAULT_API_KEY = nil
|
17
|
+
|
18
|
+
# By default use V1 of the API.
|
19
|
+
DEFAULT_API_VERSION = ''.freeze
|
20
|
+
|
21
|
+
# Use the Patron adapter as default tends to break on certain headers.
|
22
|
+
DEFAULT_ADAPTER = Faraday::Adapter::Patron
|
23
|
+
|
24
|
+
# By default use the main api URL.
|
25
|
+
DEFAULT_ENDPOINT = 'https://api.2go.com'.freeze
|
26
|
+
|
27
|
+
# By default request JSON data to be returned from the API.
|
28
|
+
DEFAULT_FORMAT = :json
|
29
|
+
|
30
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
31
|
+
|
32
|
+
# Convenience method to allow configuration options to be set in a block
|
33
|
+
def configure
|
34
|
+
yield self
|
35
|
+
end
|
36
|
+
|
37
|
+
def options
|
38
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
39
|
+
option.merge!(key => send(key))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# When this module is extended, reset all settings.
|
44
|
+
def self.extended(base)
|
45
|
+
base.reset
|
46
|
+
end
|
47
|
+
|
48
|
+
# Reset all configuration settings to default values.
|
49
|
+
def reset
|
50
|
+
self.api_key = DEFAULT_API_KEY
|
51
|
+
self.api_version = DEFAULT_API_VERSION
|
52
|
+
self.endpoint = DEFAULT_ENDPOINT
|
53
|
+
self.adapter = DEFAULT_ADAPTER
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require 'httpclient'
|
3
|
+
require 'patron'
|
4
|
+
|
5
|
+
Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f}
|
6
|
+
|
7
|
+
module Invoice2go
|
8
|
+
module Connection
|
9
|
+
private
|
10
|
+
|
11
|
+
def connection
|
12
|
+
options = { url: endpoint }
|
13
|
+
|
14
|
+
Faraday::Connection.new(options) do |connection|
|
15
|
+
connection.use FaradayMiddleware::Invoice2goAuth, api_key
|
16
|
+
connection.use FaradayMiddleware::Mashify
|
17
|
+
connection.use Faraday::Response::RaiseError
|
18
|
+
connection.request :url_encoded
|
19
|
+
connection.response :json, :content_type => 'application/json'
|
20
|
+
connection.adapter :patron
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def connection_refresh
|
25
|
+
Faraday::Connection.new('https://oauth.2go.com/identity/connect/token') do |connection|
|
26
|
+
connection.use FaradayMiddleware::Mashify
|
27
|
+
connection.request :url_encoded
|
28
|
+
connection.response :json, :content_type => /\bjson$/
|
29
|
+
connection.adapter :patron
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|