centrum_faktur 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/Gemfile +6 -0
- data/LICENSE +20 -0
- data/README.markdown +21 -0
- data/Rakefile +11 -0
- data/centrum_faktur.gemspec +20 -0
- data/lib/centrum_faktur.rb +21 -0
- data/lib/centrum_faktur/account.rb +6 -0
- data/lib/centrum_faktur/comment.rb +11 -0
- data/lib/centrum_faktur/connection.rb +104 -0
- data/lib/centrum_faktur/customer.rb +26 -0
- data/lib/centrum_faktur/estimate.rb +26 -0
- data/lib/centrum_faktur/exceptions.rb +8 -0
- data/lib/centrum_faktur/invoice.rb +26 -0
- data/lib/centrum_faktur/user.rb +6 -0
- data/lib/centrum_faktur/version.rb +3 -0
- data/test/configuration_test.rb +15 -0
- data/test/connection_test.rb +30 -0
- data/test/helper.rb +10 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2011 Wojciech Wnętrzak
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Centrum Faktur #
|
|
2
|
+
|
|
3
|
+
Ruby client for [Centrum Faktur API](http://centrumfaktur.pl/api/)
|
|
4
|
+
|
|
5
|
+
## Configuration ##
|
|
6
|
+
|
|
7
|
+
``` ruby
|
|
8
|
+
require "centrum_faktur"
|
|
9
|
+
|
|
10
|
+
CentrumFaktur.configure do |config|
|
|
11
|
+
config.login = "your_login"
|
|
12
|
+
config.subdomain = "your-subdomain"
|
|
13
|
+
config.password = "your-password"
|
|
14
|
+
end
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Copyright ##
|
|
18
|
+
|
|
19
|
+
Created during development for [Ragnarson](http://ragnarson.com/)
|
|
20
|
+
|
|
21
|
+
Copyright © 2011 Wojciech Wnętrzak. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path('../lib/centrum_faktur/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.authors = ["Wojciech Wnętrzak"]
|
|
6
|
+
gem.email = ["w.wnetrzak@gmail.com"]
|
|
7
|
+
gem.description = %q{Ruby client for Centrum Faktur API}
|
|
8
|
+
gem.summary = %q{Ruby client for Centrum Faktur API}
|
|
9
|
+
gem.homepage = "https://github.com/morgoth/centrum_faktur"
|
|
10
|
+
|
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
14
|
+
gem.name = "centrum_faktur"
|
|
15
|
+
gem.require_paths = ['lib']
|
|
16
|
+
gem.version = CentrumFaktur::VERSION
|
|
17
|
+
|
|
18
|
+
gem.add_dependency "multi_json"
|
|
19
|
+
gem.add_development_dependency "fakeweb"
|
|
20
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "centrum_faktur/version"
|
|
2
|
+
require "centrum_faktur/exceptions"
|
|
3
|
+
require "centrum_faktur/connection"
|
|
4
|
+
require "centrum_faktur/account"
|
|
5
|
+
require "centrum_faktur/comment"
|
|
6
|
+
require "centrum_faktur/customer"
|
|
7
|
+
require "centrum_faktur/estimate"
|
|
8
|
+
require "centrum_faktur/invoice"
|
|
9
|
+
require "centrum_faktur/user"
|
|
10
|
+
|
|
11
|
+
module CentrumFaktur
|
|
12
|
+
API_VERSION = "1.0"
|
|
13
|
+
|
|
14
|
+
class << self
|
|
15
|
+
attr_accessor :login, :password, :subdomain
|
|
16
|
+
|
|
17
|
+
def configure
|
|
18
|
+
yield self
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class CentrumFaktur::Comment
|
|
2
|
+
def self.list(options = {})
|
|
3
|
+
request = CentrumFaktur::Connection.new.get("/api/1.0/comments/", options)
|
|
4
|
+
request.handle_response
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.create(params)
|
|
8
|
+
request = CentrumFaktur::Connection.new.post("/api/1.0/comments/", params)
|
|
9
|
+
request.handle_response
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require "net/http"
|
|
2
|
+
require "net/https"
|
|
3
|
+
require "uri"
|
|
4
|
+
require "yaml"
|
|
5
|
+
require "multi_json"
|
|
6
|
+
|
|
7
|
+
class CentrumFaktur::Connection
|
|
8
|
+
attr_reader :response, :path
|
|
9
|
+
attr_accessor :login, :password, :subdomain
|
|
10
|
+
|
|
11
|
+
def initialize(options = {})
|
|
12
|
+
self.login = options.fetch(:login, CentrumFaktur.login) || raise(ArgumentError.new("You must specify login"))
|
|
13
|
+
self.password = options.fetch(:password, CentrumFaktur.password) || raise(ArgumentError.new("You must specify password"))
|
|
14
|
+
self.subdomain = options.fetch(:subdomain, CentrumFaktur.subdomain) || raise(ArgumentError.new("You must specify subdomain"))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def http
|
|
18
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
19
|
+
http.use_ssl = true
|
|
20
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
21
|
+
http
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def uri
|
|
25
|
+
@uri ||= URI.parse("https://#{subdomain}.centrumfaktur.pl")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def format
|
|
29
|
+
@format ||= :json
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# TODO: unify
|
|
33
|
+
def get(to, params = {})
|
|
34
|
+
@format = params.fetch(:format, :json)
|
|
35
|
+
@path = path_with_params(to, params)
|
|
36
|
+
request = Net::HTTP::Get.new(@path.to_s, headers)
|
|
37
|
+
request.basic_auth(login, password)
|
|
38
|
+
@response = http.request(request)
|
|
39
|
+
self
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def post(to, params = {})
|
|
43
|
+
@path = URI.parse(to).to_s
|
|
44
|
+
request = Net::HTTP::Post.new(@path, headers)
|
|
45
|
+
request.basic_auth(login, password)
|
|
46
|
+
request.body = params.to_json
|
|
47
|
+
@response = http.request(request)
|
|
48
|
+
self
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def put(to, params = {})
|
|
52
|
+
@path = URI.parse(to).to_s
|
|
53
|
+
request = Net::HTTP::Put.new(@path, headers)
|
|
54
|
+
request.basic_auth(login, password)
|
|
55
|
+
request.body = params.to_json
|
|
56
|
+
@response = http.request(request)
|
|
57
|
+
self
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def delete(to)
|
|
61
|
+
@path = URI.parse(to).to_s
|
|
62
|
+
request = Net::HTTP::Delete.new(@path, headers)
|
|
63
|
+
request.basic_auth(login, password)
|
|
64
|
+
@response = http.request(request)
|
|
65
|
+
self
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def inline_params(params)
|
|
69
|
+
params.map { |k, v| "#{k}=#{v}" }.join("&")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def path_with_params(path, params)
|
|
73
|
+
path = path + "?" + inline_params(params) unless params.empty?
|
|
74
|
+
URI.parse(path)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def parse_response
|
|
78
|
+
case format.to_sym
|
|
79
|
+
when :json
|
|
80
|
+
response.body ? MultiJson.decode(response.body) : nil
|
|
81
|
+
when :yaml
|
|
82
|
+
response.body ? YAML.load(response.body) : nil
|
|
83
|
+
when :xml, :pickle, :pdf
|
|
84
|
+
response.body
|
|
85
|
+
else
|
|
86
|
+
raise StandardError.new("Unknown format: #{@format}")
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def handle_response
|
|
91
|
+
case response.code.to_i
|
|
92
|
+
when 200...300
|
|
93
|
+
parse_response
|
|
94
|
+
when 300...600
|
|
95
|
+
raise CentrumFaktur::ResponseError.new(response)
|
|
96
|
+
else
|
|
97
|
+
raise StandardError.new("Unknown response code")
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def headers
|
|
102
|
+
{"Content-Type" => "application/json", "User-Agent" => "ruby-gem-v#{CentrumFaktur::VERSION}"}
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class CentrumFaktur::Customer
|
|
2
|
+
def self.list(options = {})
|
|
3
|
+
request = CentrumFaktur::Connection.new.get("/api/1.0/customers/", options)
|
|
4
|
+
request.handle_response
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.show(customer_uri, options = {})
|
|
8
|
+
request = CentrumFaktur::Connection.new.get(customer_uri, options)
|
|
9
|
+
request.handle_response
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.create(params)
|
|
13
|
+
request = CentrumFaktur::Connection.new.post("/api/1.0/customers/", params)
|
|
14
|
+
request.handle_response
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.update(customer_uri, params)
|
|
18
|
+
request = CentrumFaktur::Connection.new.put(customer_uri, params)
|
|
19
|
+
request.handle_response
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.destroy(customer_uri)
|
|
23
|
+
request = CentrumFaktur::Connection.new.delete(customer_uri)
|
|
24
|
+
request.handle_response
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class CentrumFaktur::Estimate
|
|
2
|
+
def self.list(options = {})
|
|
3
|
+
request = CentrumFaktur::Connection.new.get("/api/1.0/estimates/", options)
|
|
4
|
+
request.handle_response
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.list_updates(options = {})
|
|
8
|
+
request = CentrumFaktur::Connection.new.get("/api/1.0/estimates/updates/", options)
|
|
9
|
+
request.handle_response
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.show(estimate_uri, options = {})
|
|
13
|
+
request = CentrumFaktur::Connection.new.get(estimate_uri, options)
|
|
14
|
+
request.handle_response
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.create(params)
|
|
18
|
+
request = CentrumFaktur::Connection.new.post("/api/1.0/estimates/", params)
|
|
19
|
+
request.handle_response
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.destroy(estimate_uri)
|
|
23
|
+
request = CentrumFaktur::Connection.new.delete(estimate_uri)
|
|
24
|
+
request.handle_response
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class CentrumFaktur::Invoice
|
|
2
|
+
def self.list(options = {})
|
|
3
|
+
request = CentrumFaktur::Connection.new.get("/api/1.0/invoices/", options)
|
|
4
|
+
request.handle_response
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.list_updates(options = {})
|
|
8
|
+
request = CentrumFaktur::Connection.new.get("/api/1.0/invoices/updates/", options)
|
|
9
|
+
request.handle_response
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.show(invoice_uri, options = {})
|
|
13
|
+
request = CentrumFaktur::Connection.new.get(invoice_uri, options)
|
|
14
|
+
request.handle_response
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.create(params)
|
|
18
|
+
request = CentrumFaktur::Connection.new.post("/api/1.0/invoices/", params)
|
|
19
|
+
request.handle_response
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.destroy(invoice_uri)
|
|
23
|
+
request = CentrumFaktur::Connection.new.delete(invoice_uri)
|
|
24
|
+
request.handle_response
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require "helper"
|
|
2
|
+
|
|
3
|
+
describe "Configuration" do
|
|
4
|
+
it "should allow to set custom settings" do
|
|
5
|
+
CentrumFaktur.configure do |config|
|
|
6
|
+
config.login = "john"
|
|
7
|
+
config.password = "secret"
|
|
8
|
+
config.subdomain = "john-doe"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
assert_equal "john", CentrumFaktur.login
|
|
12
|
+
assert_equal "secret", CentrumFaktur.password
|
|
13
|
+
assert_equal "john-doe", CentrumFaktur.subdomain
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require "helper"
|
|
2
|
+
|
|
3
|
+
describe "Connection" do
|
|
4
|
+
before do
|
|
5
|
+
CentrumFaktur.configure do |config|
|
|
6
|
+
config.login = "fake"
|
|
7
|
+
config.password = "fake"
|
|
8
|
+
config.subdomain = "fake"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should convert params to inline style" do
|
|
13
|
+
params = CentrumFaktur::Connection.new.inline_params({:offset => 2, :limit => 10})
|
|
14
|
+
assert_equal "offset=2&limit=10", params
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should convert params to inline style with path" do
|
|
18
|
+
path = CentrumFaktur::Connection.new.path_with_params("/api/1.0/invoices/", {:offset => 2, :limit => 10})
|
|
19
|
+
assert_equal "/api/1.0/invoices/?offset=2&limit=10", path.to_s
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should return path when no params provided" do
|
|
23
|
+
path = CentrumFaktur::Connection.new.path_with_params("/api/1.0/invoices/", {})
|
|
24
|
+
assert_equal "/api/1.0/invoices/", path.to_s
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should return url to custom profile" do
|
|
28
|
+
assert_equal "https://fake.centrumfaktur.pl", CentrumFaktur::Connection.new.uri.to_s
|
|
29
|
+
end
|
|
30
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: centrum_faktur
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease:
|
|
5
|
+
version: 0.0.1
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- "Wojciech Wn\xC4\x99trzak"
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
|
|
13
|
+
date: 2011-06-14 00:00:00 Z
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: multi_json
|
|
17
|
+
prerelease: false
|
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
19
|
+
none: false
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: "0"
|
|
24
|
+
type: :runtime
|
|
25
|
+
version_requirements: *id001
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: fakeweb
|
|
28
|
+
prerelease: false
|
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
30
|
+
none: false
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: "0"
|
|
35
|
+
type: :development
|
|
36
|
+
version_requirements: *id002
|
|
37
|
+
description: Ruby client for Centrum Faktur API
|
|
38
|
+
email:
|
|
39
|
+
- w.wnetrzak@gmail.com
|
|
40
|
+
executables: []
|
|
41
|
+
|
|
42
|
+
extensions: []
|
|
43
|
+
|
|
44
|
+
extra_rdoc_files: []
|
|
45
|
+
|
|
46
|
+
files:
|
|
47
|
+
- .gitignore
|
|
48
|
+
- Gemfile
|
|
49
|
+
- LICENSE
|
|
50
|
+
- README.markdown
|
|
51
|
+
- Rakefile
|
|
52
|
+
- centrum_faktur.gemspec
|
|
53
|
+
- lib/centrum_faktur.rb
|
|
54
|
+
- lib/centrum_faktur/account.rb
|
|
55
|
+
- lib/centrum_faktur/comment.rb
|
|
56
|
+
- lib/centrum_faktur/connection.rb
|
|
57
|
+
- lib/centrum_faktur/customer.rb
|
|
58
|
+
- lib/centrum_faktur/estimate.rb
|
|
59
|
+
- lib/centrum_faktur/exceptions.rb
|
|
60
|
+
- lib/centrum_faktur/invoice.rb
|
|
61
|
+
- lib/centrum_faktur/user.rb
|
|
62
|
+
- lib/centrum_faktur/version.rb
|
|
63
|
+
- test/configuration_test.rb
|
|
64
|
+
- test/connection_test.rb
|
|
65
|
+
- test/helper.rb
|
|
66
|
+
homepage: https://github.com/morgoth/centrum_faktur
|
|
67
|
+
licenses: []
|
|
68
|
+
|
|
69
|
+
post_install_message:
|
|
70
|
+
rdoc_options: []
|
|
71
|
+
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
none: false
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: "0"
|
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
none: false
|
|
82
|
+
requirements:
|
|
83
|
+
- - ">="
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: "0"
|
|
86
|
+
requirements: []
|
|
87
|
+
|
|
88
|
+
rubyforge_project:
|
|
89
|
+
rubygems_version: 1.8.5
|
|
90
|
+
signing_key:
|
|
91
|
+
specification_version: 3
|
|
92
|
+
summary: Ruby client for Centrum Faktur API
|
|
93
|
+
test_files: []
|
|
94
|
+
|