agaon 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +10 -0
- data/agaon.gemspec +30 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/agaon.rb +4 -0
- data/lib/agaon/client.rb +125 -0
- data/lib/agaon/version.rb +3 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3cd3a70b7769e992af1b5991ff70847e7d57f33b
|
4
|
+
data.tar.gz: 007aa63bb9eb36a39c1a1848f5534bc456ba3dcd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ebb5d8bca78e05807ae09a36ff6b5eb65033bda17c949785d8e7086236a95326c0a475eae0f0e9a252ea73a97e831cbfc635e9854b4b4ae5a7fa521ddc23185e
|
7
|
+
data.tar.gz: 848800d468807a8b30f9ab3f00d8f8e261fbbbd1a3e1a48364841beb46cffb909ed2ff5e3f94b3158a73fc9b505dd82466b3d78cfe29de2e9aac85e688505a2a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Espen Antonsen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Agaon
|
2
|
+
|
3
|
+
Ruby API wrapper for Fiken. See https://fiken.no/api/doc/ for information about the API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'agaon'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install agaon
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Authentication
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
fiken = Agaon::Client.new( username, password )
|
27
|
+
```
|
28
|
+
|
29
|
+
This will allow you to only list companies connected to your user account.
|
30
|
+
|
31
|
+
To access data in each company you need to specify a company for the Agaon client.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
fiken = Agaon::Client.new( username, password, company_href )
|
35
|
+
```
|
36
|
+
|
37
|
+
### Endpoints
|
38
|
+
|
39
|
+
#### Companies
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
companies = fiken.companies
|
43
|
+
```
|
44
|
+
|
45
|
+
#### Sales, Contacts, Accounts, Invoices
|
46
|
+
|
47
|
+
Using examples for the contacts endpoint.
|
48
|
+
|
49
|
+
List:
|
50
|
+
```ruby
|
51
|
+
client.contacts
|
52
|
+
```
|
53
|
+
Get:
|
54
|
+
```ruby
|
55
|
+
client.get_contact(contact_href)
|
56
|
+
```
|
57
|
+
Create:
|
58
|
+
```ruby
|
59
|
+
client.contact(contact_attributes)
|
60
|
+
```
|
61
|
+
Update:
|
62
|
+
```ruby
|
63
|
+
client.contact(contact_href,contact_attributes)
|
64
|
+
```
|
65
|
+
|
66
|
+
#### Create Invoice, Document Sending Service, Create General Journal Entry Service, Search
|
67
|
+
|
68
|
+
Using example for the create invoice endpoint.
|
69
|
+
|
70
|
+
Action:
|
71
|
+
```ruby
|
72
|
+
client.create_invoice(invoice_attributes)
|
73
|
+
```
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/espen/agaon.
|
78
|
+
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
83
|
+
|
data/Rakefile
ADDED
data/agaon.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 'agaon/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "agaon"
|
8
|
+
spec.version = Agaon::VERSION
|
9
|
+
spec.authors = ["Espen Antonsen"]
|
10
|
+
spec.email = ["espen@inspired.no"]
|
11
|
+
|
12
|
+
spec.summary = "Fiken API wrapper"
|
13
|
+
spec.homepage = "https://github.com/espen/agaon"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "hyperclient"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
+
spec.add_development_dependency "vcr"
|
29
|
+
spec.add_development_dependency "dotenv"
|
30
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "agaon"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/agaon.rb
ADDED
data/lib/agaon/client.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
module Agaon
|
2
|
+
class Client
|
3
|
+
class Error < StandardError; end
|
4
|
+
class NotAuthenticated < Error; end
|
5
|
+
[:NotAuthenticated].each do |const|
|
6
|
+
Error.const_set(const, Agaon::Client.const_get(const))
|
7
|
+
end
|
8
|
+
|
9
|
+
API_BASE = 'https://fiken.no/api/v1'
|
10
|
+
|
11
|
+
attr_accessor :email, :password, :company_href
|
12
|
+
|
13
|
+
def initialize(email, password, company_href=nil)
|
14
|
+
@email = email
|
15
|
+
@password = password
|
16
|
+
@company_href = company_href
|
17
|
+
end
|
18
|
+
|
19
|
+
def who_am_i
|
20
|
+
url = API_BASE + '/whoAmI'
|
21
|
+
|
22
|
+
response = get(url)
|
23
|
+
response.to_hash
|
24
|
+
end
|
25
|
+
|
26
|
+
def current_company
|
27
|
+
get_company(@company_href)
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_company(href)
|
31
|
+
response = get(href)
|
32
|
+
response.to_hash
|
33
|
+
end
|
34
|
+
|
35
|
+
[:companies, :accounts, :bank_accounts, :contacts, :products, :invoices, :sales].each do |method_name|
|
36
|
+
define_method method_name do |*args|
|
37
|
+
raise 'No company set' if method_name != :companies && !self.company_href
|
38
|
+
if method_name == :companies
|
39
|
+
base_url = API_BASE
|
40
|
+
else
|
41
|
+
base_url = self.company_href
|
42
|
+
end
|
43
|
+
url = base_url + '/' + method_name.to_s.tr('_'.freeze, '-'.freeze)
|
44
|
+
if method_name == :accounts
|
45
|
+
raise 'No year set' if args.length == 0
|
46
|
+
year = args.first.to_s
|
47
|
+
url += '/' + year
|
48
|
+
end
|
49
|
+
|
50
|
+
response = get(url)
|
51
|
+
response._embedded.first.last.collect{|c|c.to_hash.merge('href' => c._links['self'].to_s) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
[:account, :bank_account, :contact, :product, :invoice, :sale].each do |method_name|
|
56
|
+
define_method method_name do |*args|
|
57
|
+
url = self.company_href + '/' + method_name.to_s.tr('_'.freeze, '-'.freeze) + 's'
|
58
|
+
if method_name == :account
|
59
|
+
raise 'No year set' if args.length < 2
|
60
|
+
year = args.first.to_s
|
61
|
+
object = args.second
|
62
|
+
url += '/' + year
|
63
|
+
else
|
64
|
+
object = args.first
|
65
|
+
end
|
66
|
+
|
67
|
+
response = post(url,object)
|
68
|
+
response._response.headers[:location]
|
69
|
+
end
|
70
|
+
|
71
|
+
define_method "get_#{method_name}" do |href|
|
72
|
+
response = get(href)
|
73
|
+
response.to_hash
|
74
|
+
end
|
75
|
+
|
76
|
+
define_method "update_#{method_name}" do |href, object|
|
77
|
+
response = put(href,object)
|
78
|
+
response.to_s
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
[:create_invoice, :create_general_journal_entry, :document_sending].each do |method_name|
|
83
|
+
define_method method_name do |object|
|
84
|
+
endpoint = method_name.to_s.tr('_'.freeze, '-'.freeze) + '-service'
|
85
|
+
endpoint = 'createGeneralJournalEntriesService' if endpoint == 'create-general-journal-entry-service'
|
86
|
+
url = self.company_href + '/' + endpoint
|
87
|
+
|
88
|
+
response = post(url,object)
|
89
|
+
response._response.headers[:location]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def search(object)
|
94
|
+
endpoint = 'search'
|
95
|
+
url = self.company_href + '/' + endpoint
|
96
|
+
|
97
|
+
response = post(url,object)
|
98
|
+
response._embedded.first.last.collect{|c|c.to_hash.merge('href' => c._links['self'].to_s) }
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
[:get, :post, :put, :delete].each do |method_name|
|
104
|
+
define_method method_name do |url,object=nil|
|
105
|
+
api = Hyperclient.new(url) do |client|
|
106
|
+
client.basic_auth(self.email, self.password)
|
107
|
+
end
|
108
|
+
begin
|
109
|
+
if method_name == :get
|
110
|
+
api.send("_#{method_name}")
|
111
|
+
else
|
112
|
+
api.send("_#{method_name}", object)
|
113
|
+
end
|
114
|
+
rescue => e
|
115
|
+
if e.response[:status] == 401
|
116
|
+
raise Agaon::Client::Error::NotAuthenticated
|
117
|
+
else
|
118
|
+
raise "ERROR: #{e.response[:body]}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
api
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: agaon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Espen Antonsen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hyperclient
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dotenv
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- espen@inspired.no
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- agaon.gemspec
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- lib/agaon.rb
|
113
|
+
- lib/agaon/client.rb
|
114
|
+
- lib/agaon/version.rb
|
115
|
+
homepage: https://github.com/espen/agaon
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.6.11
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Fiken API wrapper
|
139
|
+
test_files: []
|