fakturownia 0.0.1
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.
- data/.gitignore +17 -0
- data/CHANGELOG +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +88 -0
- data/Rakefile +1 -0
- data/fakturownia.gemspec +25 -0
- data/lib/fakturownia.rb +17 -0
- data/lib/fakturownia/api.rb +118 -0
- data/lib/fakturownia/version.rb +3 -0
- data/lib/generators/fakturownia/install_generator.rb +14 -0
- data/lib/generators/templates/fakturownia.rb +8 -0
- metadata +110 -0
data/.gitignore
ADDED
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Krzysztof Kempiński
|
|
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,88 @@
|
|
|
1
|
+
# Fakturownia
|
|
2
|
+
|
|
3
|
+
This gem provides integration with polish invoicing system www.fakturownia.pl
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'fakturownia'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install fakturownia
|
|
18
|
+
|
|
19
|
+
Execute:
|
|
20
|
+
|
|
21
|
+
$ bundle install
|
|
22
|
+
$ rails generate fakturownia:install
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
After installation you have to set two options in config/initializers/fakturownia.rb
|
|
26
|
+
|
|
27
|
+
* api\_token - after register in fakturownia.pl you will have this token
|
|
28
|
+
* account\_name - after login to fakturownia.pl is a first part of URL
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
Get invoice based in invoice ID provided after creation from fakturownia.pl:
|
|
33
|
+
|
|
34
|
+
Fakturownia::API.invoice(123456)
|
|
35
|
+
|
|
36
|
+
Get invoices from given time period:
|
|
37
|
+
|
|
38
|
+
Fakturownia::API.invoices(period, date_from, date_to)
|
|
39
|
+
|
|
40
|
+
where:
|
|
41
|
+
|
|
42
|
+
* period is one of the [:all, :this\_month, :last\_month, :this\_year, :last\_year, :more]. If period = :more than date\_from and date\_to has to be set
|
|
43
|
+
* date\_from and date\_to - dates
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
Get invoice as a PDF:
|
|
47
|
+
|
|
48
|
+
Fakturownia::API.pdf(123456)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
Add new invoice:
|
|
52
|
+
|
|
53
|
+
Fakturownia::API.create(invoice_json)
|
|
54
|
+
|
|
55
|
+
where invoice\_json is a hash with invoice data.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
Update previously added invoice with invoice\_id from fakturownia.pl:
|
|
59
|
+
|
|
60
|
+
Fakturownia::API.update(invoice_id, invoice_json)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
Delete previously added invoice with invoice\_id from fakturownia.pl:
|
|
64
|
+
|
|
65
|
+
Fakturownia::API.delete(invoice_id)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
More details in API requests and invoice JSON structure: https://app.fakturownia.pl/api
|
|
70
|
+
|
|
71
|
+
## TODO
|
|
72
|
+
|
|
73
|
+
* tests
|
|
74
|
+
* products
|
|
75
|
+
* clients
|
|
76
|
+
* payments
|
|
77
|
+
|
|
78
|
+
## Contributing
|
|
79
|
+
|
|
80
|
+
1. Fork it
|
|
81
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
82
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
83
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
84
|
+
5. Create new Pull Request
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
This gem is licensed under the MIT License.
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/fakturownia.gemspec
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'fakturownia/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "fakturownia"
|
|
8
|
+
spec.version = Fakturownia::VERSION
|
|
9
|
+
spec.authors = ["Krzysztof Kempiński"]
|
|
10
|
+
spec.email = ["kkempin@gmail.com"]
|
|
11
|
+
spec.description = %q{This gem gives integration with polish on-line invoicing service: http://fakturownia.pl}
|
|
12
|
+
spec.summary = %q{Integration with fakturownia.pl}
|
|
13
|
+
spec.homepage = "https://github.com/kkempin/fakturownia"
|
|
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.required_rubygems_version = ">= 1.3.6"
|
|
22
|
+
spec.add_dependency "rails", ">= 3.0"
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
24
|
+
spec.add_development_dependency "rake"
|
|
25
|
+
end
|
data/lib/fakturownia.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require "net/https"
|
|
3
|
+
require "fakturownia/version"
|
|
4
|
+
require "fakturownia/api"
|
|
5
|
+
|
|
6
|
+
module Fakturownia
|
|
7
|
+
|
|
8
|
+
# API token
|
|
9
|
+
mattr_accessor :api_token
|
|
10
|
+
|
|
11
|
+
# Account name
|
|
12
|
+
mattr_accessor :account_name
|
|
13
|
+
|
|
14
|
+
def self.setup
|
|
15
|
+
yield self
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
module Fakturownia
|
|
3
|
+
module API
|
|
4
|
+
|
|
5
|
+
# Get JSON-formatted invoice based on invoice id (from Fakturownia)
|
|
6
|
+
def self.invoice invoice_id
|
|
7
|
+
endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices/#{invoice_id}.json"
|
|
8
|
+
response = self.make_get_request(endpoint)
|
|
9
|
+
|
|
10
|
+
(response.code == '200') ? JSON.parse(response.body) : nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Get JSON-formatted invoice based on order id
|
|
14
|
+
def self.invoice_by_order_id order_id
|
|
15
|
+
endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices"
|
|
16
|
+
response = self.make_get_request(endpoint, { :oid => order_id })
|
|
17
|
+
|
|
18
|
+
(response.code == '200') ? JSON.parse(response.body) : nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Get JSON-formatted invoices based from given period
|
|
22
|
+
# Available periods = [:all, :this_month, :last_month, :this_year, :last_year, :more]
|
|
23
|
+
# If period = :more than date_from and date_to has to be set
|
|
24
|
+
def self.invoices period, date_from = nil, date_to = nil
|
|
25
|
+
endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices.json?period=#{period}"
|
|
26
|
+
additional_params = { :period => period }
|
|
27
|
+
if period.to_s == 'more'
|
|
28
|
+
additional_params[:date_from] = date_from
|
|
29
|
+
additional_params[:date_to] = date_to
|
|
30
|
+
end
|
|
31
|
+
response = self.make_get_request(endpoint, additional_params)
|
|
32
|
+
|
|
33
|
+
(response.code == '200') ? JSON.parse(response.body) : nil
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Get invoice PDF based on invoice id
|
|
37
|
+
def self.pdf invoice_id
|
|
38
|
+
endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices/#{invoice_id}.pdf"
|
|
39
|
+
response = self.make_get_request(endpoint)
|
|
40
|
+
|
|
41
|
+
(response.code == '200') ? response.body : nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# Create new invoice
|
|
46
|
+
def self.create invoice_json
|
|
47
|
+
endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices.json"
|
|
48
|
+
uri = URI.parse(endpoint)
|
|
49
|
+
|
|
50
|
+
json_params = {
|
|
51
|
+
"api_token" => Fakturownia.api_token,
|
|
52
|
+
"invoice" => invoice_json
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
request = Net::HTTP::Post.new(uri.path)
|
|
56
|
+
request.body = JSON.generate(json_params)
|
|
57
|
+
request["Content-Type"] = "application/json"
|
|
58
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
59
|
+
http.use_ssl = true
|
|
60
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
61
|
+
response = http.start {|h| h.request(request)}
|
|
62
|
+
(response.code == '201') ? JSON.parse(response.body) : nil
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# Update invoice
|
|
67
|
+
# invoice_id - id of invoice from fakturownia
|
|
68
|
+
def self.update invoice_id, invoice_json
|
|
69
|
+
endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices/#{invoice.fakturownia_id}.json"
|
|
70
|
+
uri = URI.parse(endpoint)
|
|
71
|
+
|
|
72
|
+
json_params = {
|
|
73
|
+
"api_token" => Fakturownia.api_token,
|
|
74
|
+
"invoice" => invoice_json
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
request = Net::HTTP::Put.new(uri.path)
|
|
78
|
+
request.body = JSON.generate(json_params)
|
|
79
|
+
request["Content-Type"] = "application/json"
|
|
80
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
81
|
+
http.use_ssl = true
|
|
82
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
83
|
+
response = http.start {|h| h.request(request)}
|
|
84
|
+
|
|
85
|
+
(response.code == '201') ? JSON.parse(response.body) : nil
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# Delete invoice
|
|
90
|
+
def self.delete invoice_id
|
|
91
|
+
endpoint = "https://#{Fakturownia.account_name}.fakturownia.pl/invoices/#{invoice_id}.json"
|
|
92
|
+
uri = URI.parse(endpoint)
|
|
93
|
+
whole_url = uri.path + "?api_token=#{Fakturownia.api_token}"
|
|
94
|
+
|
|
95
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
96
|
+
http.use_ssl = true
|
|
97
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
98
|
+
http.delete(whole_url)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# Make GET request returning response
|
|
103
|
+
def self.make_get_request endpoint, additional_params = {}
|
|
104
|
+
uri = URI.parse(endpoint)
|
|
105
|
+
whole_url = uri.path + "?api_token=#{Fakturownia.api_token}"
|
|
106
|
+
additional_params.each_pair do |k, v|
|
|
107
|
+
whole_url += "&#{k}=#{v}"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
request = Net::HTTP::Get.new(whole_url)
|
|
111
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
112
|
+
http.use_ssl = true
|
|
113
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
114
|
+
http.start {|h| h.request(request)}
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Fakturownia
|
|
2
|
+
module Generators
|
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
|
4
|
+
@@root = File.expand_path("../../templates", __FILE__)
|
|
5
|
+
source_root @@root
|
|
6
|
+
|
|
7
|
+
desc "Copy files ..."
|
|
8
|
+
|
|
9
|
+
def copy_initializer
|
|
10
|
+
template "fakturownia.rb", "config/initializers/fakturownia.rb"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fakturownia
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Krzysztof Kempiński
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-06-11 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rails
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '3.0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '3.0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: bundler
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ~>
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '1.3'
|
|
38
|
+
type: :development
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ~>
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '1.3'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: rake
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
description: ! 'This gem gives integration with polish on-line invoicing service:
|
|
63
|
+
http://fakturownia.pl'
|
|
64
|
+
email:
|
|
65
|
+
- kkempin@gmail.com
|
|
66
|
+
executables: []
|
|
67
|
+
extensions: []
|
|
68
|
+
extra_rdoc_files: []
|
|
69
|
+
files:
|
|
70
|
+
- .gitignore
|
|
71
|
+
- CHANGELOG
|
|
72
|
+
- Gemfile
|
|
73
|
+
- LICENSE.txt
|
|
74
|
+
- README.md
|
|
75
|
+
- Rakefile
|
|
76
|
+
- fakturownia.gemspec
|
|
77
|
+
- lib/fakturownia.rb
|
|
78
|
+
- lib/fakturownia/api.rb
|
|
79
|
+
- lib/fakturownia/version.rb
|
|
80
|
+
- lib/generators/fakturownia/install_generator.rb
|
|
81
|
+
- lib/generators/templates/fakturownia.rb
|
|
82
|
+
homepage: https://github.com/kkempin/fakturownia
|
|
83
|
+
licenses:
|
|
84
|
+
- MIT
|
|
85
|
+
post_install_message:
|
|
86
|
+
rdoc_options: []
|
|
87
|
+
require_paths:
|
|
88
|
+
- lib
|
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
|
+
none: false
|
|
91
|
+
requirements:
|
|
92
|
+
- - ! '>='
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0'
|
|
95
|
+
segments:
|
|
96
|
+
- 0
|
|
97
|
+
hash: 2964144164709439946
|
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
|
+
none: false
|
|
100
|
+
requirements:
|
|
101
|
+
- - ! '>='
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: 1.3.6
|
|
104
|
+
requirements: []
|
|
105
|
+
rubyforge_project:
|
|
106
|
+
rubygems_version: 1.8.23
|
|
107
|
+
signing_key:
|
|
108
|
+
specification_version: 3
|
|
109
|
+
summary: Integration with fakturownia.pl
|
|
110
|
+
test_files: []
|