centrum_faktur 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  notifications:
2
2
  disabled: true
3
3
  rvm:
4
- - 1.8.7
5
4
  - 1.9.3
data/Gemfile CHANGED
@@ -2,5 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
+ ruby "1.9.3"
6
+
5
7
  gem "rake"
6
- gem "minitest", :platform => :ruby_18
data/README.md CHANGED
@@ -7,33 +7,25 @@ Ruby client for [Centrum Faktur API](http://centrumfaktur.pl/api/)
7
7
  ```
8
8
  gem install centrum_faktur
9
9
  ```
10
+ ## Usage
10
11
 
11
- ## Configuration
12
+ Request returns Array or Hash, where keys are strings.
13
+ When other format than `json` (default) or `yaml` is specified, response is not parsed.
14
+ So for `xml` and `pickle` requests, string is returned.
12
15
 
13
- ``` ruby
16
+ ```ruby
14
17
  require "centrum_faktur"
15
-
16
- CentrumFaktur.configure do |config|
17
- config.login = "your_login"
18
- config.subdomain = "your-subdomain"
19
- config.password = "your-password"
20
- end
18
+ client = CentrumFaktur::Client.new(login: "your_login", password: "your-password", subdomain: "your-subodomain")
21
19
  ```
22
20
 
23
- ## Usage
24
-
25
- Requests return Array or Hash, where keys are strings.
26
- When other format than json (default) or yaml is specified, response is not parsed.
27
- So for xml and pickle requests string is returned.
28
-
29
21
  ``` ruby
30
- CentrumFaktur::Invoice.show("/api/1.0/invoices/1/", :format => :xml)
22
+ client.invoice.show("/api/1.0/invoices/1/", format: :xml)
31
23
  ```
32
24
 
33
25
  Writing invoice to pdf can be done as follows:
34
26
 
35
27
  ``` ruby
36
- File.open("my-invoice.pdf", "w") { |file| file.write(CentrumFaktur::Invoice.show("/api/1.0/invoices/1/", :format => :pdf)) }
28
+ File.open("my-invoice.pdf", "w") { |file| file.write(client.invoice.show("/api/1.0/invoices/1/", format: :pdf)) }
37
29
  ```
38
30
 
39
31
  All params that respond to `strftime` (i.e. Date, Time) will be normalized to format
@@ -44,7 +36,7 @@ required by API, that is: `"YYYY-MM-DD"`
44
36
  Only listing accounts is supported via API
45
37
 
46
38
  ``` ruby
47
- CentrumFaktur::Account.list
39
+ client.account.list
48
40
  ```
49
41
 
50
42
  ### Comment
@@ -52,13 +44,13 @@ CentrumFaktur::Account.list
52
44
  Listing all comments:
53
45
 
54
46
  ``` ruby
55
- CentrumFaktur::Comment.list
47
+ client.comment.list
56
48
  ```
57
49
 
58
50
  Or listing comments for given resource:
59
51
 
60
52
  ``` ruby
61
- CentrumFaktur::Comment.list("/api/1.0/estimates/1/comments/")
53
+ client.comment.list("/api/1.0/estimates/1/comments/")
62
54
  ```
63
55
 
64
56
  Creating comment:
@@ -66,7 +58,7 @@ Creating comment:
66
58
  You must pass path to resource comment and required attributes:
67
59
 
68
60
  ``` ruby
69
- CentrumFaktur::Comment.create("/api/1.0/estimates/1/comments/", {:body => "cool", :is_public => false})
61
+ client.comment.create("/api/1.0/estimates/1/comments/", {body: "cool", is_public: false})
70
62
  ```
71
63
 
72
64
  ### Estimate
@@ -74,31 +66,31 @@ CentrumFaktur::Comment.create("/api/1.0/estimates/1/comments/", {:body => "cool"
74
66
  Listing all estimates:
75
67
 
76
68
  ``` ruby
77
- CentrumFaktur::Estimate.list
69
+ client.estimate.list
78
70
  ```
79
71
 
80
72
  Monitoring estimate changes (with optional filter param):
81
73
 
82
74
  ``` ruby
83
- CentrumFaktur::Estimate.list_updates(:updated_since => "2012-01-12")
75
+ client.estimate.list_updates(updated_since: "2012-01-12")
84
76
  ```
85
77
 
86
78
  Creating estimate (check required attributes in API description):
87
79
 
88
80
  ``` ruby
89
- CentrumFaktur::Estimate.create({})
81
+ client.estimate.create({})
90
82
  ```
91
83
 
92
84
  Updating estimate:
93
85
 
94
86
  ``` ruby
95
- CentrumFaktur::Estimate.update("/api/1.0/estimates/1/", {})
87
+ client.estimate.update("/api/1.0/estimates/1/", {})
96
88
  ```
97
89
 
98
90
  Removing estimate:
99
91
 
100
92
  ``` ruby
101
- CentrumFaktur::Estimate.destroy("/api/1.0/estimates/1/")
93
+ client.estimate.destroy("/api/1.0/estimates/1/")
102
94
  ```
103
95
 
104
96
  ### Invoice
@@ -106,37 +98,37 @@ CentrumFaktur::Estimate.destroy("/api/1.0/estimates/1/")
106
98
  Listing all invoices:
107
99
 
108
100
  ``` ruby
109
- CentrumFaktur::Invoice.list
101
+ client.invoice.list
110
102
  ```
111
103
 
112
104
  Monitoring invoice changes:
113
105
 
114
106
  ``` ruby
115
- CentrumFaktur::Invoice.list_updates
107
+ client.invoice.list_updates
116
108
  ```
117
109
 
118
110
  Displaying invoice:
119
111
 
120
112
  ``` ruby
121
- CentrumFaktur::Invoice.show("/api/1.0/invoices/1/")
113
+ client.invoice.show("/api/1.0/invoices/1/")
122
114
  ```
123
115
 
124
116
  Creating invoice (check required attributes in API description):
125
117
 
126
118
  ``` ruby
127
- CentrumFaktur::Invoice.create({})
119
+ client.invoice.create({})
128
120
  ```
129
121
 
130
122
  Updating invoice:
131
123
 
132
124
  ``` ruby
133
- CentrumFaktur::Invoice.update("/api/1.0/invoices/1/", {})
125
+ client.invoice.update("/api/1.0/invoices/1/", {})
134
126
  ```
135
127
 
136
128
  Removing invoice:
137
129
 
138
130
  ``` ruby
139
- CentrumFaktur::Invoice.destroy("/api/1.0/invoices/1/")
131
+ client.invoice.destroy("/api/1.0/invoices/1/")
140
132
  ```
141
133
 
142
134
  ### User ###
@@ -144,7 +136,7 @@ CentrumFaktur::Invoice.destroy("/api/1.0/invoices/1/")
144
136
  Only listing users is supported via API
145
137
 
146
138
  ``` ruby
147
- CentrumFaktur::User.list
139
+ client.user.list
148
140
  ```
149
141
 
150
142
  ## Continuous Integration
data/Rakefile CHANGED
@@ -8,4 +8,4 @@ Rake::TestTask.new(:test) do |test|
8
8
  test.verbose = true
9
9
  end
10
10
 
11
- task :default => :test
11
+ task default: :test
@@ -17,15 +17,4 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency "multi_json", "~> 1.3.2"
19
19
  gem.add_development_dependency "fakeweb"
20
-
21
- gem.post_install_message = %{
22
- *************************************************************************
23
-
24
- Interface of version 0.3 of this gem will change with backward incompatibilities.
25
-
26
- If you don't want to update your code, please specify in your Gemfile:
27
- gem "centrum_faktur", "~> 0.2.0"
28
-
29
- *************************************************************************
30
- }
31
20
  end
@@ -0,0 +1,10 @@
1
+ require "centrum_faktur/api/base"
2
+
3
+ module CentrumFaktur::API
4
+ class Account < Base
5
+ def list(options = {})
6
+ request = connection.get("/api/1.0/accounts/", options)
7
+ request.handle_response
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ require "centrum_faktur/api/base"
2
+
3
+ module CentrumFaktur::API
4
+ class Base
5
+ attr_reader :client
6
+
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ private
12
+
13
+ def connection
14
+ CentrumFaktur::Connection.new(client)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require "centrum_faktur/api/base"
2
+
3
+ module CentrumFaktur::API
4
+ class Comment < Base
5
+ def list(comment_uri = "/api/1.0/comments/", options = {})
6
+ request = connection.get(comment_uri, options)
7
+ request.handle_response
8
+ end
9
+
10
+ def create(comment_uri, params)
11
+ request = connection.post(comment_uri, params)
12
+ request.handle_response
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ require "centrum_faktur/api/base"
2
+
3
+ module CentrumFaktur::API
4
+ class Customer < Base
5
+ def list(options = {})
6
+ request = connection.get("/api/1.0/customers/", options)
7
+ request.handle_response
8
+ end
9
+
10
+ def show(customer_uri, options = {})
11
+ request = connection.get(customer_uri, options)
12
+ request.handle_response
13
+ end
14
+
15
+ def create(params)
16
+ request = connection.post("/api/1.0/customers/", params)
17
+ request.handle_response
18
+ end
19
+
20
+ def update(customer_uri, params)
21
+ request = connection.put(customer_uri, params)
22
+ request.handle_response
23
+ end
24
+
25
+ def destroy(customer_uri)
26
+ request = connection.delete(customer_uri)
27
+ request.handle_response
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ require "centrum_faktur/api/base"
2
+
3
+ module CentrumFaktur::API
4
+ class Estimate < Base
5
+ def list(options = {})
6
+ request = connection.get("/api/1.0/estimates/", options)
7
+ request.handle_response
8
+ end
9
+
10
+ def list_updates(options = {})
11
+ request = connection.get("/api/1.0/estimates/updates/", options)
12
+ request.handle_response
13
+ end
14
+
15
+ def show(estimate_uri, options = {})
16
+ request = connection.get(estimate_uri, options)
17
+ request.handle_response
18
+ end
19
+
20
+ def create(params)
21
+ request = connection.post("/api/1.0/estimates/", params)
22
+ request.handle_response
23
+ end
24
+
25
+ def update(estimate_uri, params)
26
+ request = connection.put(estimate_uri, params)
27
+ request.handle_response
28
+ end
29
+
30
+ def destroy(estimate_uri)
31
+ request = connection.delete(estimate_uri)
32
+ request.handle_response
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require "centrum_faktur/api/base"
2
+
3
+ module CentrumFaktur::API
4
+ class Invoice < Base
5
+ def list(options = {})
6
+ request = connection.get("/api/1.0/invoices/", options)
7
+ request.handle_response
8
+ end
9
+
10
+ def list_updates(options = {})
11
+ request = connection.get("/api/1.0/invoices/updates/", options)
12
+ request.handle_response
13
+ end
14
+
15
+ def show(invoice_uri, options = {})
16
+ request = connection.get(invoice_uri, options)
17
+ request.handle_response
18
+ end
19
+
20
+ def create(params)
21
+ request = connection.post("/api/1.0/invoices/", params)
22
+ request.handle_response
23
+ end
24
+
25
+ def update(invoice_uri, params)
26
+ request = connection.put(invoice_uri, params)
27
+ request.handle_response
28
+ end
29
+
30
+ def destroy(invoice_uri)
31
+ request = connection.delete(invoice_uri)
32
+ request.handle_response
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require "centrum_faktur/api/base"
2
+
3
+ module CentrumFaktur::API
4
+ class Payment < Base
5
+ def list(comment_uri = "/api/1.0/payments/", options = {})
6
+ request = connection.get(comment_uri, options)
7
+ request.handle_response
8
+ end
9
+
10
+ def create(payment_uri, params)
11
+ request = connection.post(payment_uri, params)
12
+ request.handle_response
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ require "centrum_faktur/api/base"
2
+
3
+ module CentrumFaktur::API
4
+ class User < Base
5
+ def list(options = {})
6
+ request = connection.get("/api/1.0/users/", options)
7
+ request.handle_response
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,39 @@
1
+ module CentrumFaktur
2
+ class Client
3
+ attr_reader :login, :password, :subdomain
4
+
5
+ def initialize(configuration = {})
6
+ @login = configuration[:login] || raise(ArgumentError.new("You must specify login"))
7
+ @password = configuration[:password] || raise(ArgumentError.new("You must specify password"))
8
+ @subdomain = configuration[:subdomain] || raise(ArgumentError.new("You must specify subdomain"))
9
+ end
10
+
11
+ def account
12
+ API::Account.new(self)
13
+ end
14
+
15
+ def comment
16
+ API::Comment.new(self)
17
+ end
18
+
19
+ def customer
20
+ API::Customer.new(self)
21
+ end
22
+
23
+ def estimate
24
+ API::Estimate.new(self)
25
+ end
26
+
27
+ def invoice
28
+ API::Invoice.new(self)
29
+ end
30
+
31
+ def payment
32
+ API::Payment.new(self)
33
+ end
34
+
35
+ def user
36
+ API::User.new(self)
37
+ end
38
+ end
39
+ end
@@ -4,92 +4,90 @@ require "uri"
4
4
  require "yaml"
5
5
  require "multi_json"
6
6
 
7
- class CentrumFaktur::Connection
8
- attr_reader :response, :path
9
- attr_accessor :login, :password, :subdomain
7
+ module CentrumFaktur
8
+ class Connection
9
+ attr_reader :client, :response, :path
10
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
11
+ def initialize(client)
12
+ @client = client
13
+ end
16
14
 
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
15
+ def http
16
+ http = Net::HTTP.new(uri.host, uri.port)
17
+ http.use_ssl = true
18
+ http
19
+ end
23
20
 
24
- def uri
25
- @uri ||= URI.parse("https://#{subdomain}.centrumfaktur.pl")
26
- end
21
+ def uri
22
+ @uri ||= URI.parse("https://#{client.subdomain}.centrumfaktur.pl")
23
+ end
27
24
 
28
- def format
29
- @format ||= :json
30
- end
25
+ def format
26
+ @format ||= :json
27
+ end
31
28
 
32
- # TODO: unify
33
- def get(to, params = {})
34
- @format = params.fetch(:format, :json)
35
- @path = CentrumFaktur::Utils.path_with_params(to, params)
36
- request = Net::HTTP::Get.new(@path, headers)
37
- request.basic_auth(login, password)
38
- @response = http.request(request)
39
- self
40
- end
29
+ # TODO: unify
30
+ def get(to, params = {})
31
+ @format = params.fetch(:format, :json)
32
+ @path = CentrumFaktur::Utils.path_with_params(to, params)
33
+ request = Net::HTTP::Get.new(@path, headers)
34
+ request.basic_auth(client.login, client.password)
35
+ @response = http.request(request)
36
+ self
37
+ end
41
38
 
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 = MultiJson.dump(CentrumFaktur::Utils.normalize_params(params))
47
- @response = http.request(request)
48
- self
49
- end
39
+ def post(to, params = {})
40
+ @path = URI.parse(to).to_s
41
+ request = Net::HTTP::Post.new(@path, headers)
42
+ request.basic_auth(client.login, client.password)
43
+ request.body = MultiJson.dump(CentrumFaktur::Utils.normalize_params(params))
44
+ @response = http.request(request)
45
+ self
46
+ end
50
47
 
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 = MultiJson.encode(CentrumFaktur::Utils.normalize_params(params))
56
- @response = http.request(request)
57
- self
58
- end
48
+ def put(to, params = {})
49
+ @path = URI.parse(to).to_s
50
+ request = Net::HTTP::Put.new(@path, headers)
51
+ request.basic_auth(client.login, client.password)
52
+ request.body = MultiJson.encode(CentrumFaktur::Utils.normalize_params(params))
53
+ @response = http.request(request)
54
+ self
55
+ end
59
56
 
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
57
+ def delete(to)
58
+ @path = URI.parse(to).to_s
59
+ request = Net::HTTP::Delete.new(@path, headers)
60
+ request.basic_auth(client.login, client.password)
61
+ @response = http.request(request)
62
+ self
63
+ end
67
64
 
68
- def parse_response
69
- case format.to_sym
70
- when :json
71
- response.body ? MultiJson.load(response.body) : nil
72
- when :yaml
73
- response.body ? YAML.load(response.body) : nil
74
- when :xml, :pickle, :pdf
75
- response.body
76
- else
77
- raise StandardError.new("Unknown format: #{@format}")
65
+ def parse_response
66
+ case format.to_sym
67
+ when :json
68
+ response.body ? MultiJson.load(response.body) : nil
69
+ when :yaml
70
+ response.body ? YAML.load(response.body) : nil
71
+ when :xml, :pickle, :pdf
72
+ response.body
73
+ else
74
+ raise StandardError.new("Unknown format: #{@format}")
75
+ end
78
76
  end
79
- end
80
77
 
81
- def handle_response
82
- case response.code.to_i
83
- when 200...300
84
- parse_response
85
- when 300...600
86
- raise CentrumFaktur::ResponseError.new(response)
87
- else
88
- raise StandardError.new("Unknown response code")
78
+ def handle_response
79
+ case response.code.to_i
80
+ when 200...300
81
+ parse_response
82
+ when 300...600
83
+ raise CentrumFaktur::ResponseError.new(response)
84
+ else
85
+ raise StandardError.new("Unknown response code")
86
+ end
89
87
  end
90
- end
91
88
 
92
- def headers
93
- {"Content-Type" => "application/json", "User-Agent" => "ruby-gem-v#{CentrumFaktur::VERSION}"}
89
+ def headers
90
+ {"Content-Type" => "application/json", "User-Agent" => "ruby-gem-v#{CentrumFaktur::VERSION}"}
91
+ end
94
92
  end
95
93
  end
@@ -1,3 +1,5 @@
1
+ require "uri"
2
+
1
3
  module CentrumFaktur::Utils
2
4
  def inline_params(params)
3
5
  params.map { |k, v| "#{k}=#{v}" }.join("&")
@@ -1,3 +1,3 @@
1
1
  module CentrumFaktur
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -2,22 +2,16 @@ require "centrum_faktur/version"
2
2
  require "centrum_faktur/utils"
3
3
  require "centrum_faktur/exceptions"
4
4
  require "centrum_faktur/connection"
5
- require "centrum_faktur/account"
6
- require "centrum_faktur/comment"
7
- require "centrum_faktur/customer"
8
- require "centrum_faktur/estimate"
9
- require "centrum_faktur/invoice"
10
- require "centrum_faktur/user"
11
- require "centrum_faktur/payment"
5
+ require "centrum_faktur/client"
6
+
7
+ require "centrum_faktur/api/account"
8
+ require "centrum_faktur/api/comment"
9
+ require "centrum_faktur/api/customer"
10
+ require "centrum_faktur/api/estimate"
11
+ require "centrum_faktur/api/invoice"
12
+ require "centrum_faktur/api/user"
13
+ require "centrum_faktur/api/payment"
12
14
 
13
15
  module CentrumFaktur
14
16
  API_VERSION = "1.0"
15
-
16
- class << self
17
- attr_accessor :login, :password, :subdomain
18
-
19
- def configure
20
- yield self
21
- end
22
- end
23
17
  end
@@ -1,18 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require "helper"
3
3
 
4
- describe CentrumFaktur::Comment do
4
+ describe CentrumFaktur::API::Comment do
5
5
  before do
6
- CentrumFaktur.configure do |config|
7
- config.login = "john"
8
- config.password = "secret"
9
- config.subdomain = "john"
10
- end
6
+ @client = CentrumFaktur::Client.new(login: "john", password: "secret", subdomain: "john")
11
7
  end
12
8
 
13
9
  it "returns estimate comments list limited to one" do
14
10
  FakeWeb.register_uri(:get, "https://john:secret@john.centrumfaktur.pl/api/1.0/estimates/14587/comments/?limit=1", :response => fixture("comments.txt"))
15
- response = CentrumFaktur::Comment.list("/api/1.0/estimates/14587/comments/", :limit => 1)
11
+ response = CentrumFaktur::API::Comment.new(@client).list("/api/1.0/estimates/14587/comments/", :limit => 1)
16
12
  expected = [{"body"=>"cool", "user_uri"=>"/api/1.0/users/749/", "comment_type"=>"user", "created"=>"2011-06-14 20:06:36", "commented_object_type"=>"estimate", "commented_object_uri"=>"/api/1.0/estimates/20527/", "is_public"=>false}]
17
13
 
18
14
  assert_equal expected, response
@@ -20,7 +16,7 @@ describe CentrumFaktur::Comment do
20
16
 
21
17
  it "creates comment" do
22
18
  FakeWeb.register_uri(:post, "https://john:secret@john.centrumfaktur.pl/api/1.0/estimates/14587/comments/", :response => fixture("new_comment.txt"))
23
- response = CentrumFaktur::Comment.create("/api/1.0/estimates/14587/comments/", {:body => "cool", :is_public => false})
19
+ response = CentrumFaktur::API::Comment.new(@client).create("/api/1.0/estimates/14587/comments/", {:body => "cool", :is_public => false})
24
20
  expected = {"body"=>"thanks", "user_uri"=>"/api/1.0/users/749/", "comment_type"=>"user", "created"=>"2011-06-16 21:55:03", "commented_object_type"=>"estimate", "commented_object_uri"=>"/api/1.0/estimates/20627/", "is_public"=>false}
25
21
 
26
22
  assert_equal expected, response
@@ -1,18 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require "helper"
3
3
 
4
- describe CentrumFaktur::Customer do
4
+ describe CentrumFaktur::API::Customer do
5
5
  before do
6
- CentrumFaktur.configure do |config|
7
- config.login = "john"
8
- config.password = "secret"
9
- config.subdomain = "john"
10
- end
6
+ @client = CentrumFaktur::Client.new(login: "john", password: "secret", subdomain: "john")
11
7
  end
12
8
 
13
9
  it "returns customers list" do
14
- FakeWeb.register_uri(:get, "https://john:secret@john.centrumfaktur.pl/api/1.0/customers/", :response => fixture("customers.txt"))
15
- response = CentrumFaktur::Customer.list
10
+ FakeWeb.register_uri(:get, "https://john:secret@john.centrumfaktur.pl/api/1.0/customers/", response: fixture("customers.txt"))
11
+ response = CentrumFaktur::API::Customer.new(@client).list
16
12
  expected = [{"name"=>"Stefan Stefański", "contact"=>"", "address"=>"Stefanowo\r\nul. Stefańska 1", "resource_uri"=>"/api/1.0/customers/3138/", "email"=>"w.wnetrzak+stefan@gmail.com", "tax_id"=>""}]
17
13
 
18
14
  assert_equal expected, response
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "helper"
3
+
4
+ describe CentrumFaktur::API::Invoice do
5
+ before do
6
+ @client = CentrumFaktur::Client.new(login: "john", password: "secret", subdomain: "john")
7
+ end
8
+
9
+ it "detroys invoice" do
10
+ FakeWeb.register_uri(:delete, "https://john:secret@john.centrumfaktur.pl/api/1.0/invoices/666/", response: fixture("destroy_invoice.txt"))
11
+ response = CentrumFaktur::API::Invoice.new(@client).destroy("/api/1.0/invoices/666/")
12
+
13
+ assert_equal nil, response
14
+ end
15
+
16
+ it "raises error when invoice does not exist" do
17
+ FakeWeb.register_uri(:delete, "https://john:secret@john.centrumfaktur.pl/api/1.0/invoices/666/", response: fixture("destroy_invoice_404.txt"))
18
+
19
+ assert_raises CentrumFaktur::ResponseError do
20
+ CentrumFaktur::API::Invoice.new(@client).destroy("/api/1.0/invoices/666/")
21
+ end
22
+ end
23
+ end
@@ -1,12 +1,8 @@
1
1
  require "helper"
2
2
 
3
- describe CentrumFaktur::Payment do
3
+ describe CentrumFaktur::API::Payment do
4
4
  before do
5
- CentrumFaktur.configure do |config|
6
- config.login = "john"
7
- config.password = "secret"
8
- config.subdomain = "john"
9
- end
5
+ @client = CentrumFaktur::Client.new(login: "john", password: "secret", subdomain: "john")
10
6
  end
11
7
 
12
8
  it "gets payment" do
@@ -14,7 +10,7 @@ describe CentrumFaktur::Payment do
14
10
  "https://john:secret@john.centrumfaktur.pl/api/1.0/invoices/22933/payments",
15
11
  :response => fixture("payments.txt")
16
12
  )
17
- response = CentrumFaktur::Payment.list("/api/1.0/invoices/22933/payments")
13
+ response = CentrumFaktur::API::Payment.new(@client).list("/api/1.0/invoices/22933/payments")
18
14
  expected = [{
19
15
  "date" => "2007-01-01", "amount" => 10.0, "resource_uri" => "/api/1.0/users/749/",
20
16
  "created" => "2011-06-14 20:06:36"
@@ -25,7 +21,7 @@ describe CentrumFaktur::Payment do
25
21
 
26
22
  it "creates payment" do
27
23
  FakeWeb.register_uri(:post, "https://john:secret@john.centrumfaktur.pl/api/1.0/invoices/22933/payments", :response => fixture("new_payment.txt"))
28
- response = CentrumFaktur::Payment.create("/api/1.0/invoices/22933/payments",
24
+ response = CentrumFaktur::API::Payment.new(@client).create("/api/1.0/invoices/22933/payments",
29
25
  {:date => "2011-06-10", :amount => 99.00}
30
26
  )
31
27
 
@@ -1,18 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require "helper"
3
3
 
4
- describe CentrumFaktur::User do
4
+ describe CentrumFaktur::API::User do
5
5
  before do
6
- CentrumFaktur.configure do |config|
7
- config.login = "john"
8
- config.password = "secret"
9
- config.subdomain = "john"
10
- end
6
+ @client = CentrumFaktur::Client.new(login: "john", password: "secret", subdomain: "john")
11
7
  end
12
8
 
13
9
  it "returns users list" do
14
- FakeWeb.register_uri(:get, "https://john:secret@john.centrumfaktur.pl/api/1.0/users/", :response => fixture("users.txt"))
15
- response = CentrumFaktur::User.list
10
+ FakeWeb.register_uri(:get, "https://john:secret@john.centrumfaktur.pl/api/1.0/users/", response: fixture("users.txt"))
11
+ response = CentrumFaktur::API::User.new(@client).list
16
12
  expected = [{
17
13
  "login" => "morgoth",
18
14
  "first_name" => "Wojciech",
@@ -0,0 +1,21 @@
1
+ require "helper"
2
+
3
+ describe CentrumFaktur::Client do
4
+ it "raises Argument Error when login not present" do
5
+ assert_raises ArgumentError, /login/ do
6
+ CentrumFaktur::Client.new(password: "secret", subdomain: "john")
7
+ end
8
+ end
9
+
10
+ it "raises Argument Error when password not present" do
11
+ assert_raises ArgumentError, /password/ do
12
+ CentrumFaktur::Client.new(login: "john", subdomain: "john")
13
+ end
14
+ end
15
+
16
+ it "raises Argument Error when subdomain not present" do
17
+ assert_raises ArgumentError, /subdomain/ do
18
+ CentrumFaktur::Client.new(login: "john", password: "secret")
19
+ end
20
+ end
21
+ end
@@ -2,14 +2,10 @@ require "helper"
2
2
 
3
3
  describe CentrumFaktur::Connection do
4
4
  before do
5
- CentrumFaktur.configure do |config|
6
- config.login = "fake"
7
- config.password = "fake"
8
- config.subdomain = "fake"
9
- end
5
+ @client = CentrumFaktur::Client.new(login: "john", password: "secret", subdomain: "john")
10
6
  end
11
7
 
12
8
  it "returns url to custom profile" do
13
- assert_equal "https://fake.centrumfaktur.pl", CentrumFaktur::Connection.new.uri.to_s
9
+ assert_equal "https://john.centrumfaktur.pl", CentrumFaktur::Connection.new(@client).uri.to_s
14
10
  end
15
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: centrum_faktur
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-30 00:00:00.000000000 Z
12
+ date: 2012-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -58,21 +58,26 @@ files:
58
58
  - Rakefile
59
59
  - centrum_faktur.gemspec
60
60
  - lib/centrum_faktur.rb
61
- - lib/centrum_faktur/account.rb
62
- - lib/centrum_faktur/comment.rb
61
+ - lib/centrum_faktur/api/account.rb
62
+ - lib/centrum_faktur/api/base.rb
63
+ - lib/centrum_faktur/api/comment.rb
64
+ - lib/centrum_faktur/api/customer.rb
65
+ - lib/centrum_faktur/api/estimate.rb
66
+ - lib/centrum_faktur/api/invoice.rb
67
+ - lib/centrum_faktur/api/payment.rb
68
+ - lib/centrum_faktur/api/user.rb
69
+ - lib/centrum_faktur/client.rb
63
70
  - lib/centrum_faktur/connection.rb
64
- - lib/centrum_faktur/customer.rb
65
- - lib/centrum_faktur/estimate.rb
66
71
  - lib/centrum_faktur/exceptions.rb
67
- - lib/centrum_faktur/invoice.rb
68
- - lib/centrum_faktur/payment.rb
69
- - lib/centrum_faktur/user.rb
70
72
  - lib/centrum_faktur/utils.rb
71
73
  - lib/centrum_faktur/version.rb
72
- - test/comment_test.rb
73
- - test/configuration_test.rb
74
+ - test/api/comment_test.rb
75
+ - test/api/customer_test.rb
76
+ - test/api/invoice_test.rb
77
+ - test/api/payments_test.rb
78
+ - test/api/user_test.rb
79
+ - test/client_test.rb
74
80
  - test/connection_test.rb
75
- - test/customer_test.rb
76
81
  - test/fixtures/comments.txt
77
82
  - test/fixtures/customers.txt
78
83
  - test/fixtures/destroy_invoice.txt
@@ -82,17 +87,10 @@ files:
82
87
  - test/fixtures/payments.txt
83
88
  - test/fixtures/users.txt
84
89
  - test/helper.rb
85
- - test/invoice_test.rb
86
- - test/payments_test.rb
87
- - test/user_test.rb
88
90
  - test/utils_test.rb
89
91
  homepage: https://github.com/morgoth/centrum_faktur
90
92
  licenses: []
91
- post_install_message: ! "\n *************************************************************************\n\n
92
- \ Interface of version 0.3 of this gem will change with backward incompatibilities.\n\n
93
- \ If you don't want to update your code, please specify in your Gemfile:\n gem
94
- \"centrum_faktur\", \"~> 0.2.0\"\n\n *************************************************************************\n
95
- \ "
93
+ post_install_message:
96
94
  rdoc_options: []
97
95
  require_paths:
98
96
  - lib
@@ -1,8 +0,0 @@
1
- class CentrumFaktur::Account
2
- class << self
3
- def list(options = {})
4
- request = CentrumFaktur::Connection.new.get("/api/1.0/accounts/", options)
5
- request.handle_response
6
- end
7
- end
8
- end
@@ -1,13 +0,0 @@
1
- class CentrumFaktur::Comment
2
- class << self
3
- def list(comment_uri = "/api/1.0/comments/", options = {})
4
- request = CentrumFaktur::Connection.new.get(comment_uri, options)
5
- request.handle_response
6
- end
7
-
8
- def create(comment_uri, params)
9
- request = CentrumFaktur::Connection.new.post(comment_uri, params)
10
- request.handle_response
11
- end
12
- end
13
- end
@@ -1,28 +0,0 @@
1
- class CentrumFaktur::Customer
2
- class << self
3
- def list(options = {})
4
- request = CentrumFaktur::Connection.new.get("/api/1.0/customers/", options)
5
- request.handle_response
6
- end
7
-
8
- def show(customer_uri, options = {})
9
- request = CentrumFaktur::Connection.new.get(customer_uri, options)
10
- request.handle_response
11
- end
12
-
13
- def create(params)
14
- request = CentrumFaktur::Connection.new.post("/api/1.0/customers/", params)
15
- request.handle_response
16
- end
17
-
18
- def update(customer_uri, params)
19
- request = CentrumFaktur::Connection.new.put(customer_uri, params)
20
- request.handle_response
21
- end
22
-
23
- def destroy(customer_uri)
24
- request = CentrumFaktur::Connection.new.delete(customer_uri)
25
- request.handle_response
26
- end
27
- end
28
- end
@@ -1,33 +0,0 @@
1
- class CentrumFaktur::Estimate
2
- class << self
3
- def list(options = {})
4
- request = CentrumFaktur::Connection.new.get("/api/1.0/estimates/", options)
5
- request.handle_response
6
- end
7
-
8
- def list_updates(options = {})
9
- request = CentrumFaktur::Connection.new.get("/api/1.0/estimates/updates/", options)
10
- request.handle_response
11
- end
12
-
13
- def show(estimate_uri, options = {})
14
- request = CentrumFaktur::Connection.new.get(estimate_uri, options)
15
- request.handle_response
16
- end
17
-
18
- def create(params)
19
- request = CentrumFaktur::Connection.new.post("/api/1.0/estimates/", params)
20
- request.handle_response
21
- end
22
-
23
- def update(estimate_uri, params)
24
- request = CentrumFaktur::Connection.new.put(estimate_uri, params)
25
- request.handle_response
26
- end
27
-
28
- def destroy(estimate_uri)
29
- request = CentrumFaktur::Connection.new.delete(estimate_uri)
30
- request.handle_response
31
- end
32
- end
33
- end
@@ -1,33 +0,0 @@
1
- class CentrumFaktur::Invoice
2
- class << self
3
- def list(options = {})
4
- request = CentrumFaktur::Connection.new.get("/api/1.0/invoices/", options)
5
- request.handle_response
6
- end
7
-
8
- def list_updates(options = {})
9
- request = CentrumFaktur::Connection.new.get("/api/1.0/invoices/updates/", options)
10
- request.handle_response
11
- end
12
-
13
- def show(invoice_uri, options = {})
14
- request = CentrumFaktur::Connection.new.get(invoice_uri, options)
15
- request.handle_response
16
- end
17
-
18
- def create(params)
19
- request = CentrumFaktur::Connection.new.post("/api/1.0/invoices/", params)
20
- request.handle_response
21
- end
22
-
23
- def update(invoice_uri, params)
24
- request = CentrumFaktur::Connection.new.put(invoice_uri, params)
25
- request.handle_response
26
- end
27
-
28
- def destroy(invoice_uri)
29
- request = CentrumFaktur::Connection.new.delete(invoice_uri)
30
- request.handle_response
31
- end
32
- end
33
- end
@@ -1,13 +0,0 @@
1
- class CentrumFaktur::Payment
2
- class << self
3
- def list(comment_uri = "/api/1.0/payments/", options = {})
4
- request = CentrumFaktur::Connection.new.get(comment_uri, options)
5
- request.handle_response
6
- end
7
-
8
- def create(payment_uri, params)
9
- request = CentrumFaktur::Connection.new.post(payment_uri, params)
10
- request.handle_response
11
- end
12
- end
13
- end
@@ -1,8 +0,0 @@
1
- class CentrumFaktur::User
2
- class << self
3
- def list(options = {})
4
- request = CentrumFaktur::Connection.new.get("/api/1.0/users/", options)
5
- request.handle_response
6
- end
7
- end
8
- end
@@ -1,15 +0,0 @@
1
- require "helper"
2
-
3
- describe "Configuration" do
4
- it "allows 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
data/test/invoice_test.rb DELETED
@@ -1,27 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require "helper"
3
-
4
- describe CentrumFaktur::Invoice do
5
- before do
6
- CentrumFaktur.configure do |config|
7
- config.login = "john"
8
- config.password = "secret"
9
- config.subdomain = "john"
10
- end
11
- end
12
-
13
- it "detroys invoice" do
14
- FakeWeb.register_uri(:delete, "https://john:secret@john.centrumfaktur.pl/api/1.0/invoices/666/", :response => fixture("destroy_invoice.txt"))
15
- response = CentrumFaktur::Invoice.destroy("/api/1.0/invoices/666/")
16
-
17
- assert_equal nil, response
18
- end
19
-
20
- it "raises error when invoice does not exist" do
21
- FakeWeb.register_uri(:delete, "https://john:secret@john.centrumfaktur.pl/api/1.0/invoices/666/", :response => fixture("destroy_invoice_404.txt"))
22
-
23
- assert_raises CentrumFaktur::ResponseError do
24
- CentrumFaktur::Invoice.destroy("/api/1.0/invoices/666/")
25
- end
26
- end
27
- end