easybill-api 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/easybill/api.rb +2 -1
- data/lib/easybill/api/base.rb +8 -7
- data/lib/easybill/api/client.rb +6 -1
- data/lib/easybill/api/response_handler.rb +29 -0
- data/lib/easybill/api/version.rb +1 -1
- data/lib/easybill/errors.rb +16 -0
- metadata +4 -3
- data/lib/easybill/errors/errors.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f62664c9d8edede9217d467541ce52a50616e446
|
4
|
+
data.tar.gz: b41807b02912fb9982e826eec13f1172f6d3c0cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e351285426de4a30e8b848f16e1b2623412c2f84d94fd4f3edbfa702fdd1baed742b15a296f57d92f70554b50d833cbd0283d112d49263624aaff0c2bac3ceab
|
7
|
+
data.tar.gz: 201351f72741c8b7e51d73c3925ff063d52d18832753bd39a7a834dc1e5b88abf0bbad74b25a036b5b351e175867647e0cc0c0bfb9fa479b7fda3b688e8e7dda
|
data/lib/easybill/api.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require "easybill/api/version"
|
2
2
|
|
3
|
-
require "easybill/errors
|
3
|
+
require "easybill/errors"
|
4
4
|
require "easybill/api/client"
|
5
|
+
require "easybill/api/response_handler"
|
5
6
|
require "easybill/api/base"
|
6
7
|
require "easybill/api/attachments"
|
7
8
|
require "easybill/api/contacts"
|
data/lib/easybill/api/base.rb
CHANGED
@@ -16,6 +16,7 @@ module Easybill
|
|
16
16
|
|
17
17
|
class Base
|
18
18
|
include HTTParty
|
19
|
+
include ResponseHandler
|
19
20
|
|
20
21
|
HEADERS = {
|
21
22
|
"User-Agent" => "Ruby.Easybill.Api",
|
@@ -33,14 +34,14 @@ module Easybill
|
|
33
34
|
# Set the authorization header by providing your easybill +api_key+
|
34
35
|
|
35
36
|
def authenticate(api_key)
|
36
|
-
headers
|
37
|
+
headers("authorization" => "Bearer #{api_key}")
|
37
38
|
end
|
38
39
|
|
39
40
|
##
|
40
41
|
# Fetches all resources. You can set custom +query+ parameters.
|
41
42
|
|
42
43
|
def list(query: {})
|
43
|
-
get resource_path, query: query
|
44
|
+
handle(get resource_path, query: query)
|
44
45
|
end
|
45
46
|
|
46
47
|
##
|
@@ -48,7 +49,7 @@ module Easybill
|
|
48
49
|
# api.find(id, query: {group: 1})
|
49
50
|
|
50
51
|
def find(id, query: {})
|
51
|
-
get "#{resource_path}/#{id}", query: query
|
52
|
+
handle(get "#{resource_path}/#{id}", query: query)
|
52
53
|
end
|
53
54
|
|
54
55
|
##
|
@@ -62,7 +63,7 @@ module Easybill
|
|
62
63
|
# api.create(data)
|
63
64
|
|
64
65
|
def create(data)
|
65
|
-
post resource_path, body: data.to_json
|
66
|
+
handle(post resource_path, body: data.to_json)
|
66
67
|
end
|
67
68
|
|
68
69
|
##
|
@@ -77,7 +78,7 @@ module Easybill
|
|
77
78
|
# api.update(id, data)
|
78
79
|
|
79
80
|
def update(id, data)
|
80
|
-
put "#{resource_path}/#{id}", body: data.to_json
|
81
|
+
handle(put "#{resource_path}/#{id}", body: data.to_json)
|
81
82
|
end
|
82
83
|
|
83
84
|
##
|
@@ -85,7 +86,7 @@ module Easybill
|
|
85
86
|
# api.destroy(id)
|
86
87
|
|
87
88
|
def destroy(id)
|
88
|
-
delete "#{resource_path}/#{id}"
|
89
|
+
handle(delete "#{resource_path}/#{id}")
|
89
90
|
end
|
90
91
|
|
91
92
|
protected
|
@@ -97,7 +98,7 @@ module Easybill
|
|
97
98
|
request_options[:query] = query unless query.empty?
|
98
99
|
request_options[:headers] = headers unless headers.empty?
|
99
100
|
|
100
|
-
public_send method, path, request_options
|
101
|
+
handle(public_send method, path, request_options)
|
101
102
|
end
|
102
103
|
|
103
104
|
private
|
data/lib/easybill/api/client.rb
CHANGED
@@ -7,6 +7,8 @@ module Easybill
|
|
7
7
|
|
8
8
|
class Client
|
9
9
|
|
10
|
+
ENTITIES = [:Base, :Attachments, :Contacts, :Customers, :CustomerGroups, :Documents, :DocumentPayments, :Positions, :PositionGroups, :PostBoxes, :Projects, :Tasks, :TextTemplates, :TimeTrackings].freeze
|
11
|
+
|
10
12
|
##
|
11
13
|
# Create a new client instance with an +api_key+
|
12
14
|
#
|
@@ -14,7 +16,10 @@ module Easybill
|
|
14
16
|
# @api = Easybill::Api::Client.new("api_key")
|
15
17
|
|
16
18
|
def initialize(api_key)
|
17
|
-
|
19
|
+
ENTITIES.each do |entity|
|
20
|
+
eval("Easybill::Api::#{entity}").authenticate api_key
|
21
|
+
end
|
22
|
+
self
|
18
23
|
end
|
19
24
|
|
20
25
|
##
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Easybill
|
2
|
+
module Api
|
3
|
+
module ResponseHandler
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def handle(response)
|
10
|
+
case response.code
|
11
|
+
when 200..299
|
12
|
+
response
|
13
|
+
when 400
|
14
|
+
raise Easybill::Errors::BadRequestError, response.message
|
15
|
+
when 401
|
16
|
+
raise Easybill::Errors::NotAuthorizedError, response.message
|
17
|
+
when 404
|
18
|
+
raise Easybill::Errors::ResourceNotFoundError, response.message
|
19
|
+
when 429
|
20
|
+
raise Easybill::Errors::RateLimitExceededError, response.message
|
21
|
+
when 500...600
|
22
|
+
raise Easybill::Errors::ServerError, "Failed with: #{response.code} #{response.message}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
data/lib/easybill/api/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Easybill
|
2
|
+
module Errors
|
3
|
+
class BaseError < StandardError; end
|
4
|
+
|
5
|
+
class ServerError < StandardError; end
|
6
|
+
|
7
|
+
class ClientError < BaseError; end
|
8
|
+
class RateLimitExceededError < ClientError; end
|
9
|
+
class ResourceNotFoundError < ClientError; end
|
10
|
+
class BadRequestError < ClientError; end
|
11
|
+
class NotAuthorizedError < ClientError; end
|
12
|
+
|
13
|
+
class ResourceNotCreatableError < BaseError; end
|
14
|
+
class ResourceNotUpdatableError < BaseError; end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easybill-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Schnetger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,11 +117,12 @@ files:
|
|
117
117
|
- lib/easybill/api/positions.rb
|
118
118
|
- lib/easybill/api/post_boxes.rb
|
119
119
|
- lib/easybill/api/projects.rb
|
120
|
+
- lib/easybill/api/response_handler.rb
|
120
121
|
- lib/easybill/api/tasks.rb
|
121
122
|
- lib/easybill/api/text_templates.rb
|
122
123
|
- lib/easybill/api/time_trackings.rb
|
123
124
|
- lib/easybill/api/version.rb
|
124
|
-
- lib/easybill/errors
|
125
|
+
- lib/easybill/errors.rb
|
125
126
|
homepage: https://www.github.com/schnika/easybill
|
126
127
|
licenses:
|
127
128
|
- MIT
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Easybill
|
2
|
-
module Errors
|
3
|
-
class BaseError < StandardError; end
|
4
|
-
|
5
|
-
class ApiError < BaseError; end
|
6
|
-
class RateLimitExceededError < ApiError; end
|
7
|
-
|
8
|
-
class ResourceNotCreatableError < BaseError; end
|
9
|
-
class ResourceNotUpdatableError < BaseError; end
|
10
|
-
end
|
11
|
-
end
|