billogram 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -5
- data/billogram.gemspec +1 -2
- data/lib/billogram.rb +8 -1
- data/lib/billogram/client.rb +5 -22
- data/lib/billogram/endpoint.rb +0 -4
- data/lib/billogram/error.rb +15 -10
- data/lib/billogram/request.rb +9 -1
- data/lib/billogram/resource.rb +16 -3
- data/lib/billogram/resources/invoice.rb +1 -0
- data/lib/billogram/resources/item.rb +4 -0
- data/lib/billogram/resources/settings.rb +6 -6
- data/lib/billogram/version.rb +1 -1
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 018140ce51586895b8b6126ac450537e8591d5dd
|
4
|
+
data.tar.gz: a96d6e9e69756df541e6120ae4c5624a3ebd46b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33c07c2eb69403500864bab82c19cf2163aae70d03df52a355f0be39bf08117dcd2c38ff32a610702c5dd894e136315fd18410f3c22b4317051108cc2f39d6b2
|
7
|
+
data.tar.gz: 490ac7762d7a05fb1b4271eb8bb545d6ccdde426b0494611d43dc6e1b6c39a43ed91e71db9a0913c29f03f0e171d257ce90525eb04ee8a379ce18db8bbd16fdd
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Billogram
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Simple ruby wrapper for [Billogram](https://billogram.com) API
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,32 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
First you need to configure the client
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Billogram.configure do |config|
|
27
|
+
config.username = "6402-qz0UHqRJ"
|
28
|
+
config.password = "55e041056840d54dc8274f70c0a4170f"
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
Add this code to `config/initializers/billogram.rb` if you're using Rails and don't forget to restart the server.
|
33
|
+
|
34
|
+
Next step is to actually make API calls. Dead simple.
|
35
|
+
|
36
|
+
## Resources
|
37
|
+
|
38
|
+
We have 7 endpoints each represented by a class: `Invoice`, `Item`, `Customer`, `Event`, `Settings`, `Report`, `Logotype`
|
39
|
+
|
40
|
+
Most of them support create, fetch, update actions as well as [search](https://billogram.com/api/documentation#object_search_parameters).
|
41
|
+
|
42
|
+
Also there are nested resources (Address for instance), you cannot get them directly but only through the resource they belong.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
Billogram::Address.search() # => undefined method `search' for Billogram::Address:Class
|
46
|
+
customer = Billogram::Customer.fetch(32)
|
47
|
+
customer.address # => #<Billogram::Address:0x007f9aebafd358>
|
48
|
+
````
|
26
49
|
|
27
50
|
## Development
|
28
51
|
|
@@ -38,4 +61,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
38
61
|
## License
|
39
62
|
|
40
63
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/billogram.gemspec
CHANGED
@@ -23,8 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.10"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
-
spec.add_development_dependency "rspec", "~> 3.
|
27
|
-
spec.add_development_dependency "rspec-its"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
28
27
|
spec.add_development_dependency "webmock", "~> 1.21"
|
29
28
|
spec.add_development_dependency "dotenv", "~> 2.0"
|
30
29
|
spec.add_dependency "httparty", "~> 0.13"
|
data/lib/billogram.rb
CHANGED
@@ -31,7 +31,10 @@ require "billogram/version"
|
|
31
31
|
|
32
32
|
module Billogram
|
33
33
|
class << self
|
34
|
-
|
34
|
+
BASE_URI = "https://billogram.com/api/v2/"
|
35
|
+
|
36
|
+
attr_accessor :username, :password
|
37
|
+
attr_writer :base_uri
|
35
38
|
|
36
39
|
def client
|
37
40
|
@client ||= Client.new(username, password, base_uri)
|
@@ -40,5 +43,9 @@ module Billogram
|
|
40
43
|
def configure
|
41
44
|
yield self if block_given?
|
42
45
|
end
|
46
|
+
|
47
|
+
def base_uri
|
48
|
+
@base_uri ||= BASE_URI
|
49
|
+
end
|
43
50
|
end
|
44
51
|
end
|
data/lib/billogram/client.rb
CHANGED
@@ -1,32 +1,15 @@
|
|
1
1
|
module Billogram
|
2
2
|
class Client
|
3
3
|
include HTTParty
|
4
|
-
format :json
|
5
4
|
|
6
|
-
|
7
|
-
self.class.default_options.merge!(base_uri: base_uri, basic_auth: {username: username, password: password})
|
8
|
-
end
|
5
|
+
extend Forwardable
|
9
6
|
|
10
|
-
|
11
|
-
handle_request(:get, *args)
|
12
|
-
end
|
13
|
-
|
14
|
-
def post(*args)
|
15
|
-
handle_request(:post, *args)
|
16
|
-
end
|
7
|
+
delegate [:get, :post, :put, :delete] => self
|
17
8
|
|
18
|
-
|
19
|
-
handle_request(:put, *args)
|
20
|
-
end
|
21
|
-
|
22
|
-
def delete(*args)
|
23
|
-
handle_request(:delete, *args)
|
24
|
-
end
|
9
|
+
format :json
|
25
10
|
|
26
|
-
def
|
27
|
-
|
28
|
-
return response.parsed_response["data"] if response.success?
|
29
|
-
raise Billogram::Error.from_response(response)
|
11
|
+
def initialize(username, password, base_uri)
|
12
|
+
self.class.default_options.merge!(base_uri: base_uri, basic_auth: {username: username, password: password})
|
30
13
|
end
|
31
14
|
end
|
32
15
|
end
|
data/lib/billogram/endpoint.rb
CHANGED
data/lib/billogram/error.rb
CHANGED
@@ -7,16 +7,21 @@ module Billogram
|
|
7
7
|
class NotFound < Error; end
|
8
8
|
class InternalServerError < Error; end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
class << self
|
11
|
+
def from_response(response)
|
12
|
+
message = response["data"]["message"]
|
13
|
+
error_class(response).new(message)
|
14
|
+
end
|
15
|
+
|
16
|
+
def error_class(response)
|
17
|
+
case response.code.to_i
|
18
|
+
when 400 then BadRequest
|
19
|
+
when 401 then Unauthorized
|
20
|
+
when 403 then Forbidden
|
21
|
+
when 404 then NotFound
|
22
|
+
when 500 then InternalServerError
|
23
|
+
else Billogram::Error
|
24
|
+
end
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
data/lib/billogram/request.rb
CHANGED
@@ -20,7 +20,15 @@ module Billogram
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def execute
|
23
|
-
|
23
|
+
response.success? ? response["data"] : raise_from(response)
|
24
|
+
end
|
25
|
+
|
26
|
+
def raise_from(response)
|
27
|
+
raise Billogram::Error.from_response(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
def response
|
31
|
+
@response ||= Billogram.client.send(type, url, content)
|
24
32
|
end
|
25
33
|
end
|
26
34
|
end
|
data/lib/billogram/resource.rb
CHANGED
@@ -30,10 +30,23 @@ module Billogram
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def to_json(*args)
|
33
|
+
to_hash.to_json(*args)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_hash
|
33
37
|
instance_variables
|
34
|
-
.
|
35
|
-
|
36
|
-
|
38
|
+
.each_with_object({}) do |variable, obj|
|
39
|
+
value = instance_variable_get(variable)
|
40
|
+
|
41
|
+
case value
|
42
|
+
when Resource
|
43
|
+
value = value.to_hash
|
44
|
+
when Array
|
45
|
+
value = value.map(&:to_hash)
|
46
|
+
end
|
47
|
+
|
48
|
+
obj[variable[1..-1]] = value
|
49
|
+
end
|
37
50
|
end
|
38
51
|
end
|
39
52
|
end
|
@@ -19,6 +19,7 @@ module Billogram
|
|
19
19
|
|
20
20
|
relation :items, :many
|
21
21
|
relation :events, :many
|
22
|
+
relation :automatic_reminders_settings, :many, class_override: 'AutomaticReminder'
|
22
23
|
|
23
24
|
COMMANDS = [ :sell, :remind, :collect, :writeoff, :resend, :remind, :payment, :credit, :message, :attach ]
|
24
25
|
|
@@ -4,11 +4,11 @@ module Billogram
|
|
4
4
|
|
5
5
|
attr_accessor :name, :org_no
|
6
6
|
|
7
|
-
relation :
|
8
|
-
relation :
|
9
|
-
relation :
|
10
|
-
relation :
|
11
|
-
relation :
|
12
|
-
relation :
|
7
|
+
relation :tax, :one
|
8
|
+
relation :contact, :one
|
9
|
+
relation :address, :one
|
10
|
+
relation :payment, :one
|
11
|
+
relation :invoices, :one, class_override: "InvoiceDefaults"
|
12
|
+
relation :bookkeeping, :one
|
13
13
|
end
|
14
14
|
end
|
data/lib/billogram/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: billogram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Birman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,28 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec-its
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
54
|
+
version: '3.3'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: webmock
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|