billogram 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d19c8617149c997055c24fe28e8cf5246e7ef935
4
- data.tar.gz: 6a6eb3b078172b0a9601ab22d5fd969ce2d105bd
3
+ metadata.gz: 2d7211264da1c2a244ae49fe823f3a40a2a18e98
4
+ data.tar.gz: 9d66bdce3035c05061059e04fa1361d44722bb54
5
5
  SHA512:
6
- metadata.gz: 5cfa00c57beb5c319928ef035d57b0b74a97d240727241108bb1d8d4b39d569ce26790b526bf987ccc44b1105ec7c310d6317132afb8a075b3ba51757aac3fd0
7
- data.tar.gz: 913bd36349fc91fc4578a239af5be0ef1ef5ca42ba0b2af8579c32e3c60b16ff290b716a1526335959642b26d7da0d48bd440c380c9a873a54ac0ef71c592ef3
6
+ metadata.gz: 6837655055e15ddb79db3decf6e7282b5fc61135e8af8120c8c0d366b57884f0e3e426e85e5f5b07789dc4fc383e695d79be1373531974ddb868825d1cdca6d2
7
+ data.tar.gz: 361595e478a07938f8ea6d94269d22da334e0eefd3b715d566a0ffeaff2e86c524c7c6cd4d2e8842734c26935e6efecd8f930b6612d5c0d7bcb31e80ae0586a0
data/README.md CHANGED
@@ -22,20 +22,20 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- First you need to configure the client
25
+ TODO: Write usage instructions here
26
26
 
27
- ```ruby
28
- Billogram.configure do |config|
29
- config.username = '6012-qJzHT0qU'
30
- config.password = '55105e0460d5844274dc8f7070fc0a41'
31
- config.base_uri = "https://sandbox.billogram.com/api/v2/"
32
- end
27
+ ## Development
33
28
 
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
30
 
35
- Billogram::Customer.search({filter_type: :field, filter_field: :customer_no, filter_value: 1})
36
- ````
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
32
 
38
- List of available methods:
39
- ```ruby
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/billogram.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
41
 
41
- ```
data/lib/billogram.rb CHANGED
@@ -1,21 +1,27 @@
1
1
  require "httparty"
2
2
  require "billogram/client"
3
3
  require "billogram/error"
4
+ require "billogram/relation"
4
5
  require "billogram/relation_builder"
5
6
  require "billogram/resource"
6
- require 'billogram/resources/address'
7
- require 'billogram/resources/bookkeeping'
8
- require 'billogram/resources/callbacks'
9
- require 'billogram/resources/contact'
10
- require 'billogram/resources/customer'
11
- require 'billogram/resources/data'
12
- require 'billogram/resources/detailed_sums'
13
- require 'billogram/resources/delivery_address'
14
- require 'billogram/resources/event'
15
- require 'billogram/resources/info'
16
- require 'billogram/resources/invoice'
17
- require 'billogram/resources/item'
18
- require 'billogram/resources/regional_sweden'
7
+ require "billogram/resources/address"
8
+ require "billogram/resources/bookkeeping"
9
+ require "billogram/resources/callbacks"
10
+ require "billogram/resources/contact"
11
+ require "billogram/resources/customer"
12
+ require "billogram/resources/data"
13
+ require "billogram/resources/detailed_sums"
14
+ require "billogram/resources/domestic_bank_account"
15
+ require "billogram/resources/event"
16
+ require "billogram/resources/info"
17
+ require "billogram/resources/international_bank_account"
18
+ require "billogram/resources/invoice"
19
+ require "billogram/resources/invoice_defaults"
20
+ require "billogram/resources/item"
21
+ require "billogram/resources/regional_sweden"
22
+ require "billogram/resources/payment"
23
+ require "billogram/resources/settings"
24
+ require "billogram/resources/tax"
19
25
  require "billogram/version"
20
26
 
21
27
  require "billogram/inflections"
@@ -0,0 +1,27 @@
1
+ module Billogram
2
+ class Relation
3
+ attr_reader :name, :type, :class_override
4
+
5
+ def initialize(name, type, class_override: nil)
6
+ @name = name
7
+ @type = type
8
+ @class_override = class_override
9
+ end
10
+
11
+ def relation_class
12
+ "Billogram::#{class_override || class_name}".constantize
13
+ end
14
+
15
+ def class_name
16
+ @class_name ||= send("class_name_for_#{type}").classify
17
+ end
18
+
19
+ def class_name_for_one
20
+ name.to_s
21
+ end
22
+
23
+ def class_name_for_many
24
+ name.to_s.singularize
25
+ end
26
+ end
27
+ end
@@ -8,38 +8,34 @@ module Billogram
8
8
  end
9
9
 
10
10
  def call
11
- resource_relations.each do |type, relation_names|
12
- build_relation(type, relation_names)
11
+ resource_relations.each do |relation|
12
+ build_relation(relation)
13
13
  end
14
14
  end
15
15
 
16
16
  private
17
17
 
18
- def relation_class(relation_name)
19
- "Billogram::#{relation_name.to_s.classify}".constantize
20
- end
21
-
22
- def relation_attributes(relation_name)
23
- attributes.delete(relation_name.to_s)
18
+ def extract_attributes(relation)
19
+ attributes.delete(relation.name.to_s)
24
20
  end
25
21
 
26
22
  def resource_relations
27
23
  resource.class.relations
28
24
  end
29
25
 
30
- def build_relation(type, relation_names)
31
- relation_names.each do |name|
32
- if attrs = relation_attributes(name)
33
- if type == :one
34
- value = relation_class(name).new(attrs)
35
- elsif type == :many
36
- singular = name.to_s.singularize
37
- value = attrs.map{|item| relation_class(singular).new(item) }
38
- end
39
-
40
- resource.public_send("#{name}=", value)
41
- end
26
+ def build_relation(relation)
27
+ if attrs = extract_attributes(relation)
28
+ value = send("build_#{relation.type}", relation, attrs)
29
+ resource.public_send("#{relation.name}=", value)
42
30
  end
43
31
  end
32
+
33
+ def build_one(relation, attrs)
34
+ relation.relation_class.new(attrs)
35
+ end
36
+
37
+ def build_many(relation, attrs)
38
+ attrs.map{|item| relation.relation_class.new(item) }
39
+ end
44
40
  end
45
41
  end
@@ -6,7 +6,7 @@ module Billogram
6
6
 
7
7
  class << self
8
8
  def relations
9
- @relations ||= { one: Set.new, many: Set.new }
9
+ @relations ||= []
10
10
  end
11
11
 
12
12
  def endpoint(value = nil)
@@ -19,7 +19,7 @@ module Billogram
19
19
  perform_request("#{endpoint}", :get, query)
20
20
  end
21
21
 
22
- def fetch(id)
22
+ def fetch(id = nil)
23
23
  perform_request("#{endpoint}/#{id}", :get)
24
24
  end
25
25
 
@@ -35,9 +35,9 @@ module Billogram
35
35
  Billogram.client.put("#{endpoint}/#{id}")
36
36
  end
37
37
 
38
- def relation(relation_name, relation_type = :one)
39
- relations[relation_type] << relation_name
40
- attr_accessor relation_name
38
+ def relation(name, type, class_override: nil)
39
+ relations << Relation.new(name, type, class_override: class_override)
40
+ attr_accessor name
41
41
  end
42
42
 
43
43
  def build_objects(data)
@@ -1,5 +1,6 @@
1
1
  module Billogram
2
2
  class Address < Resource
3
- attr_accessor :street_address, :careof, :use_careof_as_attention, :zipcode, :city, :country
3
+ attr_accessor :street_address, :careof, :use_careof_as_attention, :zipcode,
4
+ :city, :country, :name
4
5
  end
5
6
  end
@@ -1,5 +1,12 @@
1
1
  module Billogram
2
2
  class Bookkeeping < Resource
3
- attr_accessor :income_account, :vat_account
3
+ attr_accessor :income_account, :vat_account, :income_account_for_vat_25,
4
+ :income_account_for_vat_12, :income_account_for_vat_6,
5
+ :income_account_for_vat_0, :reversed_vat_account, :vat_account_for_vat_25,
6
+ :vat_account_for_vat_12, :vat_account_for_vat_6, :account_receivable_account,
7
+ :client_funds_account, :banking_account, :interest_fee_account,
8
+ :reminder_fee_account, :rounding_account, :factoring_receivable_account
9
+
10
+ relation :regional_sweden, :one
4
11
  end
5
12
  end
@@ -1,9 +1,10 @@
1
1
  module Billogram
2
2
  class Customer < Resource
3
- attr_accessor :customer_no, :name, :notes, :org_no, :vat_no, :created_at, :updated_at, :company_type
3
+ attr_accessor :customer_no, :name, :notes, :org_no, :vat_no, :created_at,
4
+ :updated_at, :company_type
4
5
 
5
6
  relation :address, :one
6
7
  relation :contact, :one
7
- relation :delivery_address, :one
8
+ relation :delivery_address, :one, class_override: "Address"
8
9
  end
9
10
  end
@@ -0,0 +1,5 @@
1
+ module Billogram
2
+ class DomesticBankAccount < Resource
3
+ attr_accessor :account_no, :clearing_no
4
+ end
5
+ end
@@ -4,6 +4,6 @@ module Billogram
4
4
 
5
5
  attr_accessor :created_at, :type
6
6
 
7
- relation :data, :one
7
+ relation :data, :one, class_override: "Data"
8
8
  end
9
9
  end
@@ -0,0 +1,5 @@
1
+ module Billogram
2
+ class InternationalBankAccount < Resource
3
+ attr_accessor :bank, :iban, :bic, :swift
4
+ end
5
+ end
@@ -12,8 +12,8 @@ module Billogram
12
12
  relation :info, :one
13
13
  relation :customer, :one
14
14
  relation :regional_sweden, :one
15
- relation :callbacks, :one
16
- relation :detailed_sums, :one
15
+ relation :callbacks, :one, class_override: "Callbacks"
16
+ relation :detailed_sums, :one, class_override: "DetailedSums"
17
17
 
18
18
  relation :items, :many
19
19
  relation :events, :many
@@ -0,0 +1,6 @@
1
+ module Billogram
2
+ class InvoiceDefaults < Resource
3
+ attr_accessor :default_message, :default_interest_rate, :default_reminder_fee,
4
+ :default_invoice_fee, :automatic_reminders
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Billogram
2
+ class Payment < Resource
3
+ attr_accessor :bankgiro, :plusgiro
4
+
5
+ relation :domestic_bank_account, :one
6
+ relation :international_bank_account, :one
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ module Billogram
2
+ class Settings < Resource
3
+
4
+ attr_accessor :name, :org_no
5
+
6
+ relation :contact, :one
7
+ relation :address, :one
8
+ relation :payment, :one
9
+ relation :tax, :one
10
+ relation :bookkeeping, :one
11
+ relation :invoices, :one, class_override: "InvoiceDefaults"
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Billogram
2
+ class Tax < Resource
3
+ attr_accessor :is_vat_registered, :has_fskatt, :vat_no
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Billogram
2
- VERSION = "0.3.6"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.6
4
+ version: 0.4.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-09-03 00:00:00.000000000 Z
11
+ date: 2015-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,7 +143,7 @@ files:
143
143
  - lib/billogram.rb
144
144
  - lib/billogram/client.rb
145
145
  - lib/billogram/error.rb
146
- - lib/billogram/inflections.rb
146
+ - lib/billogram/relation.rb
147
147
  - lib/billogram/relation_builder.rb
148
148
  - lib/billogram/resource.rb
149
149
  - lib/billogram/resources/address.rb
@@ -152,13 +152,18 @@ files:
152
152
  - lib/billogram/resources/contact.rb
153
153
  - lib/billogram/resources/customer.rb
154
154
  - lib/billogram/resources/data.rb
155
- - lib/billogram/resources/delivery_address.rb
156
155
  - lib/billogram/resources/detailed_sums.rb
156
+ - lib/billogram/resources/domestic_bank_account.rb
157
157
  - lib/billogram/resources/event.rb
158
158
  - lib/billogram/resources/info.rb
159
+ - lib/billogram/resources/international_bank_account.rb
159
160
  - lib/billogram/resources/invoice.rb
161
+ - lib/billogram/resources/invoice_defaults.rb
160
162
  - lib/billogram/resources/item.rb
163
+ - lib/billogram/resources/payment.rb
161
164
  - lib/billogram/resources/regional_sweden.rb
165
+ - lib/billogram/resources/settings.rb
166
+ - lib/billogram/resources/tax.rb
162
167
  - lib/billogram/version.rb
163
168
  homepage: http://github.com/mbirman/billogram
164
169
  licenses:
@@ -1,5 +0,0 @@
1
- ActiveSupport::Inflector.inflections do |inflect|
2
- inflect.irregular 'data', 'data'
3
- inflect.irregular 'callbacks', 'callbacks'
4
- inflect.irregular 'sums', 'sums'
5
- end
@@ -1,5 +0,0 @@
1
- module Billogram
2
- class DeliveryAddress < Address
3
- attr_accessor :name
4
- end
5
- end