centrum_faktur 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .project
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ notifications:
2
+ disabled: true
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.3
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org'
1
+ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
data/README.markdown CHANGED
@@ -1,14 +1,14 @@
1
- # Centrum Faktur #
1
+ # Centrum Faktur
2
2
 
3
3
  Ruby client for [Centrum Faktur API](http://centrumfaktur.pl/api/)
4
4
 
5
- ## Installation ##
5
+ ## Installation
6
6
 
7
7
  ```
8
8
  gem install centrum_faktur
9
9
  ```
10
10
 
11
- ## Configuration ##
11
+ ## Configuration
12
12
 
13
13
  ``` ruby
14
14
  require "centrum_faktur"
@@ -20,7 +20,7 @@ CentrumFaktur.configure do |config|
20
20
  end
21
21
  ```
22
22
 
23
- ## Usage ##
23
+ ## Usage
24
24
 
25
25
  Requests return Array or Hash, where keys are strings.
26
26
  When other format than json (default) or yaml is specified, response is not parsed.
@@ -30,16 +30,16 @@ So for xml and pickle requests string is returned.
30
30
  CentrumFaktur::Invoice.show("/api/1.0/invoices/1/", :format => :xml)
31
31
  ```
32
32
 
33
- All params that respond to `strftime` (i.e. Date, Time) will be normalized to format
34
- required by API, that is: `"YYYY-MM-DD"`
35
-
36
33
  Writing invoice to pdf can be done as follows:
37
34
 
38
35
  ``` ruby
39
36
  File.open("my-invoice.pdf", "w") { |file| file.write(CentrumFaktur::Invoice.show("/api/1.0/invoices/1/", :format => :pdf)) }
40
37
  ```
41
38
 
42
- ### Account ###
39
+ All params that respond to `strftime` (i.e. Date, Time) will be normalized to format
40
+ required by API, that is: `"YYYY-MM-DD"`
41
+
42
+ ### Account
43
43
 
44
44
  Only listing accounts is supported via API
45
45
 
@@ -47,7 +47,7 @@ Only listing accounts is supported via API
47
47
  CentrumFaktur::Account.list
48
48
  ```
49
49
 
50
- ### Comment ###
50
+ ### Comment
51
51
 
52
52
  Listing all comments:
53
53
 
@@ -69,7 +69,7 @@ You must pass path to resource comment and required attributes:
69
69
  CentrumFaktur::Comment.create("/api/1.0/estimates/1/comments/", {:body => "cool", :is_public => false})
70
70
  ```
71
71
 
72
- ### Estimate ###
72
+ ### Estimate
73
73
 
74
74
  Listing all estimates:
75
75
 
@@ -101,7 +101,7 @@ Removing estimate:
101
101
  CentrumFaktur::Estimate.destroy("/api/1.0/estimates/1/")
102
102
  ```
103
103
 
104
- ### Invoice ###
104
+ ### Invoice
105
105
 
106
106
  Listing all invoices:
107
107
 
@@ -147,8 +147,16 @@ Only listing users is supported via API
147
147
  CentrumFaktur::User.list
148
148
  ```
149
149
 
150
- ## Copyright ##
150
+ ## Continuous Integration
151
+
152
+ [![Build Status](https://secure.travis-ci.org/morgoth/centrum_faktur.png)](http://travis-ci.org/morgoth/centrum_faktur)
153
+
154
+ ## Contributors
155
+
156
+ * [Grzegorz Pawlik](https://github.com/pawlik)
157
+
158
+ ## Copyright
151
159
 
152
160
  Created during development for [Ragnarson](http://ragnarson.com/)
153
161
 
154
- Copyright © 2011 Wojciech Wnętrzak. See LICENSE for details.
162
+ Copyright © Wojciech Wnętrzak. See LICENSE for details.
data/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # Centrum Faktur
2
+
3
+ Ruby client for [Centrum Faktur API](http://centrumfaktur.pl/api/)
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem install centrum_faktur
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ ``` ruby
14
+ 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
21
+ ```
22
+
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
+ ``` ruby
30
+ CentrumFaktur::Invoice.show("/api/1.0/invoices/1/", :format => :xml)
31
+ ```
32
+
33
+ Writing invoice to pdf can be done as follows:
34
+
35
+ ``` ruby
36
+ File.open("my-invoice.pdf", "w") { |file| file.write(CentrumFaktur::Invoice.show("/api/1.0/invoices/1/", :format => :pdf)) }
37
+ ```
38
+
39
+ All params that respond to `strftime` (i.e. Date, Time) will be normalized to format
40
+ required by API, that is: `"YYYY-MM-DD"`
41
+
42
+ ### Account
43
+
44
+ Only listing accounts is supported via API
45
+
46
+ ``` ruby
47
+ CentrumFaktur::Account.list
48
+ ```
49
+
50
+ ### Comment
51
+
52
+ Listing all comments:
53
+
54
+ ``` ruby
55
+ CentrumFaktur::Comment.list
56
+ ```
57
+
58
+ Or listing comments for given resource:
59
+
60
+ ``` ruby
61
+ CentrumFaktur::Comment.list("/api/1.0/estimates/1/comments/")
62
+ ```
63
+
64
+ Creating comment:
65
+
66
+ You must pass path to resource comment and required attributes:
67
+
68
+ ``` ruby
69
+ CentrumFaktur::Comment.create("/api/1.0/estimates/1/comments/", {:body => "cool", :is_public => false})
70
+ ```
71
+
72
+ ### Estimate
73
+
74
+ Listing all estimates:
75
+
76
+ ``` ruby
77
+ CentrumFaktur::Estimate.list
78
+ ```
79
+
80
+ Monitoring estimate changes (with optional filter param):
81
+
82
+ ``` ruby
83
+ CentrumFaktur::Estimate.list_updates(:updated_since => "2012-01-12")
84
+ ```
85
+
86
+ Creating estimate (check required attributes in API description):
87
+
88
+ ``` ruby
89
+ CentrumFaktur::Estimate.create({})
90
+ ```
91
+
92
+ Updating estimate:
93
+
94
+ ``` ruby
95
+ CentrumFaktur::Estimate.update("/api/1.0/estimates/1/", {})
96
+ ```
97
+
98
+ Removing estimate:
99
+
100
+ ``` ruby
101
+ CentrumFaktur::Estimate.destroy("/api/1.0/estimates/1/")
102
+ ```
103
+
104
+ ### Invoice
105
+
106
+ Listing all invoices:
107
+
108
+ ``` ruby
109
+ CentrumFaktur::Invoice.list
110
+ ```
111
+
112
+ Monitoring invoice changes:
113
+
114
+ ``` ruby
115
+ CentrumFaktur::Invoice.list_updates
116
+ ```
117
+
118
+ Displaying invoice:
119
+
120
+ ``` ruby
121
+ CentrumFaktur::Invoice.show("/api/1.0/invoices/1/")
122
+ ```
123
+
124
+ Creating invoice (check required attributes in API description):
125
+
126
+ ``` ruby
127
+ CentrumFaktur::Invoice.create({})
128
+ ```
129
+
130
+ Updating invoice:
131
+
132
+ ``` ruby
133
+ CentrumFaktur::Invoice.update("/api/1.0/invoices/1/", {})
134
+ ```
135
+
136
+ Removing invoice:
137
+
138
+ ``` ruby
139
+ CentrumFaktur::Invoice.destroy("/api/1.0/invoices/1/")
140
+ ```
141
+
142
+ ### User ###
143
+
144
+ Only listing users is supported via API
145
+
146
+ ``` ruby
147
+ CentrumFaktur::User.list
148
+ ```
149
+
150
+ ## Continuous Integration
151
+ [![Build Status](https://secure.travis-ci.org/morgoth/centrum_faktur.png)](http://travis-ci.org/morgoth/centrum_faktur)
152
+
153
+ ## Copyright
154
+
155
+ Created during development for [Ragnarson](http://ragnarson.com/)
156
+
157
+ Copyright © Wojciech Wnętrzak. See LICENSE for details.
@@ -32,8 +32,8 @@ class CentrumFaktur::Connection
32
32
  # TODO: unify
33
33
  def get(to, params = {})
34
34
  @format = params.fetch(:format, :json)
35
- @path = path_with_params(to, params)
36
- request = Net::HTTP::Get.new(@path.to_s, headers)
35
+ @path = CentrumFaktur::Utils.path_with_params(to, params)
36
+ request = Net::HTTP::Get.new(@path, headers)
37
37
  request.basic_auth(login, password)
38
38
  @response = http.request(request)
39
39
  self
@@ -43,7 +43,7 @@ class CentrumFaktur::Connection
43
43
  @path = URI.parse(to).to_s
44
44
  request = Net::HTTP::Post.new(@path, headers)
45
45
  request.basic_auth(login, password)
46
- request.body = MultiJson.encode(normalize_params(params))
46
+ request.body = MultiJson.encode(CentrumFaktur::Utils.normalize_params(params))
47
47
  @response = http.request(request)
48
48
  self
49
49
  end
@@ -52,7 +52,7 @@ class CentrumFaktur::Connection
52
52
  @path = URI.parse(to).to_s
53
53
  request = Net::HTTP::Put.new(@path, headers)
54
54
  request.basic_auth(login, password)
55
- request.body = MultiJson.encode(normalize_params(params))
55
+ request.body = MultiJson.encode(CentrumFaktur::Utils.normalize_params(params))
56
56
  @response = http.request(request)
57
57
  self
58
58
  end
@@ -65,33 +65,6 @@ class CentrumFaktur::Connection
65
65
  self
66
66
  end
67
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 normalize_params(params)
78
- params.inject({}) do |normalized, (key, value)|
79
- normalized[key] =
80
- if value.is_a?(Hash)
81
- normalize_params(value)
82
- elsif value.is_a?(Array)
83
- value.map { |v| v.is_a?(Hash) ? normalize_params(v) : normalize_value(v) }
84
- else
85
- normalize_value(value)
86
- end
87
- normalized
88
- end
89
- end
90
-
91
- def normalize_value(value)
92
- value.respond_to?(:strftime) ? value.strftime("%Y-%m-%d") : value
93
- end
94
-
95
68
  def parse_response
96
69
  case format.to_sym
97
70
  when :json
@@ -0,0 +1,11 @@
1
+ class CentrumFaktur::Payment
2
+ def self.list(comment_uri = "/api/1.0/payments/", options = {})
3
+ request = CentrumFaktur::Connection.new.get(comment_uri, options)
4
+ request.handle_response
5
+ end
6
+
7
+ def self.create(payment_uri, params)
8
+ request = CentrumFaktur::Connection.new.post(payment_uri, params)
9
+ request.handle_response
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ module CentrumFaktur::Utils
2
+ def inline_params(params)
3
+ params.map { |k, v| "#{k}=#{v}" }.join("&")
4
+ end
5
+
6
+ def path_with_params(path, params)
7
+ path = path + "?" + inline_params(params) unless params.empty?
8
+ URI.parse(path).to_s
9
+ end
10
+
11
+ def normalize_params(params)
12
+ raise ArgumentError.new("Only hash params can be normalized") unless params.kind_of?(Hash)
13
+ params.inject({}) do |normalized, (key, value)|
14
+ normalized[key] =
15
+ if value.kind_of?(Hash)
16
+ normalize_params(value)
17
+ elsif value.kind_of?(Array)
18
+ value.map { |v| v.kind_of?(Hash) ? normalize_params(v) : normalize_value(v) }
19
+ else
20
+ normalize_value(value)
21
+ end
22
+ normalized
23
+ end
24
+ end
25
+
26
+ def normalize_value(value)
27
+ value.respond_to?(:strftime) ? value.strftime("%Y-%m-%d") : value
28
+ end
29
+
30
+ module_function :inline_params, :path_with_params, :normalize_params, :normalize_value
31
+ end
@@ -1,3 +1,3 @@
1
1
  module CentrumFaktur
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "centrum_faktur/version"
2
+ require "centrum_faktur/utils"
2
3
  require "centrum_faktur/exceptions"
3
4
  require "centrum_faktur/connection"
4
5
  require "centrum_faktur/account"
@@ -7,6 +8,7 @@ require "centrum_faktur/customer"
7
8
  require "centrum_faktur/estimate"
8
9
  require "centrum_faktur/invoice"
9
10
  require "centrum_faktur/user"
11
+ require "centrum_faktur/payment"
10
12
 
11
13
  module CentrumFaktur
12
14
  API_VERSION = "1.0"
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "helper"
3
+
4
+ describe "Comment" 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 "should return estimate comments list limited to one" do
14
+ 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)
16
+ 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
+ assert_equal expected, response
18
+ end
19
+
20
+ it "should create comment" do
21
+ FakeWeb.register_uri(:post, "https://john:secret@john.centrumfaktur.pl/api/1.0/estimates/14587/comments/", :response => fixture("new_comment.txt"))
22
+ response = CentrumFaktur::Comment.create("/api/1.0/estimates/14587/comments/", {:body => "cool", :is_public => false})
23
+ 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}
24
+ assert_equal expected, response
25
+ end
26
+ end
@@ -9,56 +9,7 @@ describe "Connection" do
9
9
  end
10
10
  end
11
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
12
  it "should return url to custom profile" do
28
13
  assert_equal "https://fake.centrumfaktur.pl", CentrumFaktur::Connection.new.uri.to_s
29
14
  end
30
-
31
- it "should normalize date to required format" do
32
- normalized = CentrumFaktur::Connection.new.normalize_value(Time.mktime(2012, 01, 01))
33
- assert_equal "2012-01-01", normalized
34
- end
35
-
36
- it "should not normalize not Date values" do
37
- normalized = CentrumFaktur::Connection.new.normalize_value("value")
38
- assert_equal "value", normalized
39
- end
40
-
41
- it "should normalize params hash" do
42
- params = {:body => "value", :date => Time.mktime(2012, 01, 01)}
43
- normalized = CentrumFaktur::Connection.new.normalize_params(params)
44
- assert_equal({:body => "value", :date => "2012-01-01"}, normalized)
45
- end
46
-
47
- it "should normalize nested params hash" do
48
- params = {:body => "value", :nested => {:date => Time.mktime(2012, 01, 01)}}
49
- normalized = CentrumFaktur::Connection.new.normalize_params(params)
50
- assert_equal({:body => "value", :nested => {:date => "2012-01-01"}}, normalized)
51
- end
52
-
53
- it "should normalize nested array params hash" do
54
- params = {:body => "value", :items => [:date1 => Time.mktime(2012, 01, 01), :date2 => Time.mktime(2012, 01, 02)]}
55
- normalized = CentrumFaktur::Connection.new.normalize_params(params)
56
- assert_equal({:body => "value", :items => [:date1 => "2012-01-01", :date2 => "2012-01-02"]}, normalized)
57
- end
58
-
59
- it "should normalize nested array values" do
60
- params = {:body => "value", :items => [Time.mktime(2012, 01, 01), "value"]}
61
- normalized = CentrumFaktur::Connection.new.normalize_params(params)
62
- assert_equal({:body => "value", :items => ["2012-01-01", "value"]}, normalized)
63
- end
64
15
  end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "helper"
3
+
4
+ describe "Customer" 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 "should return 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
16
+ 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
+ assert_equal expected, response
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ HTTP/1.0 200 OK
2
+ Vary: Authorization
3
+ Content-Type: application/json; charset=utf-8
4
+ Date: Thu, 16 Jun 2011 19:51:18 GMT
5
+ Server: lighttpd
6
+ X-Cache: MISS from pxy1.mirumee.com
7
+ X-Cache-Lookup: MISS from pxy1.mirumee.com:80
8
+ Via: 1.0 pxy1.mirumee.com:80 (squid/2.6.STABLE21)
9
+ Connection: close
10
+
11
+ [
12
+ {
13
+ "body": "cool",
14
+ "user_uri": "/api/1.0/users/749/",
15
+ "comment_type": "user",
16
+ "created": "2011-06-14 20:06:36",
17
+ "commented_object_type": "estimate",
18
+ "commented_object_uri": "/api/1.0/estimates/20527/",
19
+ "is_public": false
20
+ }
21
+ ]
@@ -0,0 +1,20 @@
1
+ HTTP/1.0 200 OK
2
+ Vary: Authorization
3
+ Content-Type: application/json; charset=utf-8
4
+ Date: Thu, 16 Jun 2011 19:40:49 GMT
5
+ Server: lighttpd
6
+ X-Cache: MISS from pxy1.mirumee.com
7
+ X-Cache-Lookup: MISS from pxy1.mirumee.com:80
8
+ Via: 1.0 pxy1.mirumee.com:80 (squid/2.6.STABLE21)
9
+ Connection: close
10
+
11
+ [
12
+ {
13
+ "name": "Stefan Stefański",
14
+ "contact": "",
15
+ "address": "Stefanowo\r\nul. Stefańska 1",
16
+ "resource_uri": "/api/1.0/customers/3138/",
17
+ "email": "w.wnetrzak+stefan@gmail.com",
18
+ "tax_id": ""
19
+ }
20
+ ]
@@ -0,0 +1,10 @@
1
+ HTTP/1.0 204 No Content
2
+ Vary: Authorization
3
+ Content-Type: text/plain
4
+ Date: Thu, 16 Jun 2011 20:06:01 GMT
5
+ Server: lighttpd
6
+ X-Cache: MISS from pxy1.mirumee.com
7
+ X-Cache-Lookup: MISS from pxy1.mirumee.com:80
8
+ Via: 1.0 pxy1.mirumee.com:80 (squid/2.6.STABLE21)
9
+ Connection: close
10
+
@@ -0,0 +1,12 @@
1
+ HTTP/1.0 404 Not Found
2
+ Vary: Authorization
3
+ Content-Type: text/plain
4
+ Content-Length: 9
5
+ Date: Thu, 16 Jun 2011 20:12:49 GMT
6
+ Server: lighttpd
7
+ X-Cache: MISS from pxy1.mirumee.com
8
+ X-Cache-Lookup: MISS from pxy1.mirumee.com:80
9
+ Via: 1.0 pxy1.mirumee.com:80 (squid/2.6.STABLE21)
10
+ Connection: close
11
+
12
+ Not Found
@@ -0,0 +1,20 @@
1
+ HTTP/1.0 200 OK
2
+ Vary: Authorization
3
+ Content-Type: application/json; charset=utf-8
4
+ Content-Length: 257
5
+ Date: Thu, 16 Jun 2011 19:55:03 GMT
6
+ Server: lighttpd
7
+ X-Cache: MISS from pxy1.mirumee.com
8
+ X-Cache-Lookup: MISS from pxy1.mirumee.com:80
9
+ Via: 1.0 pxy1.mirumee.com:80 (squid/2.6.STABLE21)
10
+ Connection: close
11
+
12
+ {
13
+ "body": "thanks",
14
+ "user_uri": "/api/1.0/users/749/",
15
+ "comment_type": "user",
16
+ "created": "2011-06-16 21:55:03",
17
+ "commented_object_type": "estimate",
18
+ "commented_object_uri": "/api/1.0/estimates/20627/",
19
+ "is_public": false
20
+ }
@@ -0,0 +1,17 @@
1
+ HTTP/1.0 200 OK
2
+ Vary: Authorization
3
+ Content-Type: application/json; charset=utf-8
4
+ Content-Length: 257
5
+ Date: Thu, 16 Jun 2011 19:55:03 GMT
6
+ Server: lighttpd
7
+ X-Cache: MISS from pxy1.mirumee.com
8
+ X-Cache-Lookup: MISS from pxy1.mirumee.com:80
9
+ Via: 1.0 pxy1.mirumee.com:80 (squid/2.6.STABLE21)
10
+ Connection: close
11
+
12
+ {
13
+ "date": "2011-06-10",
14
+ "amount": 99.00,
15
+ "created": "2012-01-01",
16
+ "resource_uri": "/api/1.0/payments/99999/"
17
+ }
@@ -0,0 +1,18 @@
1
+ HTTP/1.0 200 OK
2
+ Vary: Authorization
3
+ Content-Type: application/json; charset=utf-8
4
+ Date: Thu, 16 Jun 2011 19:51:18 GMT
5
+ Server: lighttpd
6
+ X-Cache: MISS from pxy1.mirumee.com
7
+ X-Cache-Lookup: MISS from pxy1.mirumee.com:80
8
+ Via: 1.0 pxy1.mirumee.com:80 (squid/2.6.STABLE21)
9
+ Connection: close
10
+
11
+ [
12
+ {
13
+ "date": "2007-01-01",
14
+ "resource_uri": "/api/1.0/users/749/",
15
+ "created": "2011-06-14 20:06:36",
16
+ "amount": 10.0
17
+ }
18
+ ]
@@ -0,0 +1,19 @@
1
+ HTTP/1.0 200 OK
2
+ Vary: Authorization
3
+ Content-Type: application/json; charset=utf-8
4
+ Date: Thu, 16 Jun 2011 19:24:48 GMT
5
+ Server: lighttpd
6
+ X-Cache: MISS from pxy1.mirumee.com
7
+ X-Cache-Lookup: MISS from pxy1.mirumee.com:80
8
+ Via: 1.0 pxy1.mirumee.com:80 (squid/2.6.STABLE21)
9
+ Connection: close
10
+
11
+ [
12
+ {
13
+ "login": "morgoth",
14
+ "first_name": "Wojciech",
15
+ "last_name": "Wnętrzak",
16
+ "email": "w.wnetrzak@gmail.com",
17
+ "resource_uri": "/api/1.0/users/749/"
18
+ }
19
+ ]
data/test/helper.rb CHANGED
@@ -7,4 +7,10 @@ class MiniTest::Unit::TestCase
7
7
  def setup
8
8
  FakeWeb.allow_net_connect = false
9
9
  end
10
+
11
+ # Recording response is as simple as writing in terminal:
12
+ # curl -isu login:password 'https://subdomain.centrumfaktur.pl/api/1.0/customers/' -X GET > test/fixtures/customers.txt
13
+ def fixture(filename)
14
+ File.read(File.join("test", "fixtures", filename))
15
+ end
10
16
  end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "helper"
3
+
4
+ describe "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 "should detroy 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
+ assert_equal nil, response
17
+ end
18
+
19
+ it "should raise error when invoice does not exist" do
20
+ FakeWeb.register_uri(:delete, "https://john:secret@john.centrumfaktur.pl/api/1.0/invoices/666/", :response => fixture("destroy_invoice_404.txt"))
21
+ assert_raises CentrumFaktur::ResponseError do
22
+ CentrumFaktur::Invoice.destroy("/api/1.0/invoices/666/")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ require "helper"
2
+
3
+ describe "Payment" do
4
+ before do
5
+ CentrumFaktur.configure do |config|
6
+ config.login = "john"
7
+ config.password = "secret"
8
+ config.subdomain = "john"
9
+ end
10
+ end
11
+
12
+ it "should get payment" do
13
+ FakeWeb.register_uri(:get,
14
+ "https://john:secret@john.centrumfaktur.pl/api/1.0/invoices/22933/payments",
15
+ :response => fixture("payments.txt")
16
+ )
17
+ response = CentrumFaktur::Payment.list("/api/1.0/invoices/22933/payments")
18
+ expected = [{
19
+ "date" => "2007-01-01", "amount" => 10.0, "resource_uri" => "/api/1.0/users/749/",
20
+ "created" => "2011-06-14 20:06:36"
21
+ }]
22
+
23
+ assert_equal expected, response
24
+ end
25
+
26
+ it "should create payment" do
27
+ 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",
29
+ {:date => "2011-06-10", :amount => 99.00}
30
+ )
31
+
32
+ expected = {"date"=>"2011-06-10",
33
+ "amount" => 99.00, "created" => "2012-01-01", "resource_uri"=>"/api/1.0/payments/99999/"
34
+ }
35
+ assert_equal expected, response
36
+ end
37
+ end
data/test/user_test.rb ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "helper"
3
+
4
+ describe "User" 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 "should return 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
16
+ expected = [{"login"=>"morgoth", "first_name"=>"Wojciech", "last_name"=>"Wnętrzak", "email"=>"w.wnetrzak@gmail.com", "resource_uri"=>"/api/1.0/users/749/"}]
17
+ assert_equal expected, response
18
+ end
19
+ end
@@ -0,0 +1,52 @@
1
+ require "helper"
2
+
3
+ describe "Utils" do
4
+ it "should convert params to inline style" do
5
+ params = CentrumFaktur::Utils.inline_params({:offset => 2, :limit => 10})
6
+ assert_equal "offset=2&limit=10", params
7
+ end
8
+
9
+ it "should convert params to inline style with path" do
10
+ path = CentrumFaktur::Utils.path_with_params("/api/1.0/invoices/", {:offset => 2, :limit => 10})
11
+ assert_equal "/api/1.0/invoices/?offset=2&limit=10", path.to_s
12
+ end
13
+
14
+ it "should return path when no params provided" do
15
+ path = CentrumFaktur::Utils.path_with_params("/api/1.0/invoices/", {})
16
+ assert_equal "/api/1.0/invoices/", path.to_s
17
+ end
18
+
19
+ it "should normalize date to required format" do
20
+ normalized = CentrumFaktur::Utils.normalize_value(Time.mktime(2012, 01, 01))
21
+ assert_equal "2012-01-01", normalized
22
+ end
23
+
24
+ it "should not normalize not Date values" do
25
+ normalized = CentrumFaktur::Utils.normalize_value("value")
26
+ assert_equal "value", normalized
27
+ end
28
+
29
+ it "should normalize params hash" do
30
+ params = {:body => "value", :date => Time.mktime(2012, 01, 01)}
31
+ normalized = CentrumFaktur::Utils.normalize_params(params)
32
+ assert_equal({:body => "value", :date => "2012-01-01"}, normalized)
33
+ end
34
+
35
+ it "should normalize nested params hash" do
36
+ params = {:body => "value", :nested => {:date => Time.mktime(2012, 01, 01)}}
37
+ normalized = CentrumFaktur::Utils.normalize_params(params)
38
+ assert_equal({:body => "value", :nested => {:date => "2012-01-01"}}, normalized)
39
+ end
40
+
41
+ it "should normalize nested array params hash" do
42
+ params = {:body => "value", :items => [:date1 => Time.mktime(2012, 01, 01), :date2 => Time.mktime(2012, 01, 02)]}
43
+ normalized = CentrumFaktur::Utils.normalize_params(params)
44
+ assert_equal({:body => "value", :items => [:date1 => "2012-01-01", :date2 => "2012-01-02"]}, normalized)
45
+ end
46
+
47
+ it "should normalize nested array values" do
48
+ params = {:body => "value", :items => [Time.mktime(2012, 01, 01), "value"]}
49
+ normalized = CentrumFaktur::Utils.normalize_params(params)
50
+ assert_equal({:body => "value", :items => ["2012-01-01", "value"]}, normalized)
51
+ end
52
+ end
metadata CHANGED
@@ -1,53 +1,61 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: centrum_faktur
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
4
5
  prerelease:
5
- version: 0.1.0
6
6
  platform: ruby
7
- authors:
8
- - "Wojciech Wn\xC4\x99trzak"
7
+ authors:
8
+ - Wojciech Wnętrzak
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-14 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: multi_json
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: fakeweb
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fakeweb
32
+ requirement: !ruby/object:Gem::Requirement
30
33
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
35
38
  type: :development
36
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
37
46
  description: Ruby client for Centrum Faktur API
38
- email:
47
+ email:
39
48
  - w.wnetrzak@gmail.com
40
49
  executables: []
41
-
42
50
  extensions: []
43
-
44
51
  extra_rdoc_files: []
45
-
46
- files:
52
+ files:
47
53
  - .gitignore
54
+ - .travis.yml
48
55
  - Gemfile
49
56
  - LICENSE
50
57
  - README.markdown
58
+ - README.md
51
59
  - Rakefile
52
60
  - centrum_faktur.gemspec
53
61
  - lib/centrum_faktur.rb
@@ -58,37 +66,49 @@ files:
58
66
  - lib/centrum_faktur/estimate.rb
59
67
  - lib/centrum_faktur/exceptions.rb
60
68
  - lib/centrum_faktur/invoice.rb
69
+ - lib/centrum_faktur/payment.rb
61
70
  - lib/centrum_faktur/user.rb
71
+ - lib/centrum_faktur/utils.rb
62
72
  - lib/centrum_faktur/version.rb
73
+ - test/comment_test.rb
63
74
  - test/configuration_test.rb
64
75
  - test/connection_test.rb
76
+ - test/customer_test.rb
77
+ - test/fixtures/comments.txt
78
+ - test/fixtures/customers.txt
79
+ - test/fixtures/destroy_invoice.txt
80
+ - test/fixtures/destroy_invoice_404.txt
81
+ - test/fixtures/new_comment.txt
82
+ - test/fixtures/new_payment.txt
83
+ - test/fixtures/payments.txt
84
+ - test/fixtures/users.txt
65
85
  - test/helper.rb
86
+ - test/invoice_test.rb
87
+ - test/payments_test.rb
88
+ - test/user_test.rb
89
+ - test/utils_test.rb
66
90
  homepage: https://github.com/morgoth/centrum_faktur
67
91
  licenses: []
68
-
69
92
  post_install_message:
70
93
  rdoc_options: []
71
-
72
- require_paths:
94
+ require_paths:
73
95
  - lib
74
- required_ruby_version: !ruby/object:Gem::Requirement
96
+ required_ruby_version: !ruby/object:Gem::Requirement
75
97
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: "0"
80
- required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
103
  none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- version: "0"
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
86
108
  requirements: []
87
-
88
109
  rubyforge_project:
89
- rubygems_version: 1.8.5
110
+ rubygems_version: 1.8.18
90
111
  signing_key:
91
112
  specification_version: 3
92
113
  summary: Ruby client for Centrum Faktur API
93
114
  test_files: []
94
-