fortnox-ruby 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/fortnox-ruby.gemspec +3 -0
  3. data/lib/fortnox-ruby.rb +4 -0
  4. data/lib/fortnox.rb +49 -15
  5. data/lib/fortnox/client.rb +3 -25
  6. data/lib/fortnox/configurable.rb +2 -3
  7. data/lib/fortnox/default.rb +0 -6
  8. data/lib/fortnox/json_fields_mapper.rb +36 -0
  9. data/lib/fortnox/relation.rb +15 -0
  10. data/lib/fortnox/relation_builder.rb +25 -0
  11. data/lib/fortnox/request.rb +42 -0
  12. data/lib/fortnox/resource.rb +83 -4
  13. data/lib/fortnox/resources/account.rb +8 -0
  14. data/lib/fortnox/resources/account_chart.rb +5 -0
  15. data/lib/fortnox/resources/archive.rb +5 -0
  16. data/lib/fortnox/resources/article.rb +11 -0
  17. data/lib/fortnox/resources/article_file_connection.rb +5 -0
  18. data/lib/fortnox/resources/article_url_connection.rb +5 -0
  19. data/lib/fortnox/resources/company_setting.rb +9 -0
  20. data/lib/fortnox/resources/contract.rb +14 -0
  21. data/lib/fortnox/resources/contract_accrual.rb +6 -0
  22. data/lib/fortnox/resources/contract_template.rb +8 -0
  23. data/lib/fortnox/resources/cost_center.rb +5 -0
  24. data/lib/fortnox/resources/currency.rb +5 -0
  25. data/lib/fortnox/resources/customer.rb +14 -8
  26. data/lib/fortnox/resources/financial_year.rb +5 -0
  27. data/lib/fortnox/resources/inbox.rb +4 -0
  28. data/lib/fortnox/resources/invoice.rb +20 -0
  29. data/lib/fortnox/resources/invoice_accrual.rb +6 -0
  30. data/lib/fortnox/resources/invoice_payment.rb +9 -0
  31. data/lib/fortnox/resources/locked_period.rb +5 -0
  32. data/lib/fortnox/resources/mode_of_payment.rb +5 -0
  33. data/lib/fortnox/resources/offer.rb +16 -0
  34. data/lib/fortnox/resources/order.rb +18 -0
  35. data/lib/fortnox/resources/price.rb +5 -0
  36. data/lib/fortnox/resources/price_list.rb +5 -0
  37. data/lib/fortnox/resources/print_template.rb +5 -0
  38. data/lib/fortnox/resources/project.rb +5 -0
  39. data/lib/fortnox/resources/supplier.rb +12 -0
  40. data/lib/fortnox/resources/supplier_invoice.rb +10 -0
  41. data/lib/fortnox/resources/supplier_invoice_accrual.rb +7 -0
  42. data/lib/fortnox/resources/supplier_invoice_external_url_connection.rb +5 -0
  43. data/lib/fortnox/resources/supplier_invoice_file_connection.rb +5 -0
  44. data/lib/fortnox/resources/supplier_invoice_payment.rb +9 -0
  45. data/lib/fortnox/resources/tax_reduction.rb +9 -0
  46. data/lib/fortnox/resources/terms_of_delivery.rb +5 -0
  47. data/lib/fortnox/resources/terms_of_payment.rb +5 -0
  48. data/lib/fortnox/resources/unit.rb +5 -0
  49. data/lib/fortnox/resources/voucher.rb +7 -0
  50. data/lib/fortnox/resources/voucher_file_connection.rb +5 -0
  51. data/lib/fortnox/resources/voucher_series.rb +5 -0
  52. data/lib/fortnox/resources/way_of_delivery.rb +5 -0
  53. data/lib/fortnox/version.rb +1 -1
  54. metadata +62 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 877675a2208a85a6c996d1f0f879632036f1e571
4
- data.tar.gz: 0f20a586bac0adeaf84e0bea11e26173678c05cd
3
+ metadata.gz: ee8bf6ab8bac2b6b7552fef0ecd51c9f4c89a45b
4
+ data.tar.gz: 4f07c987bdeb1d1b775ea4c415a4f7ac2c8cb058
5
5
  SHA512:
6
- metadata.gz: 4eb2aa4d8a9ea18e007e5d84f3b33140a74ac2e4bc8f9e913846c6f2b37bf89bb3537d5a001d3cbf9fdb5455a527191ea78de6d27e9ac9593fc44c3764b20148
7
- data.tar.gz: 785bebce3acf38def0cdac0b9676fe47241154e41c761524833733e212411e01cc2724502d1bd8014206e1f68e51756b16b99f23d9e2d0931680aa67446309de
6
+ metadata.gz: 38e10da807cada44738b55d5e7e956304aeac1309320e44f86edc3b17f4611fb955079be6ce7f340b975212fea76cd82f8fb09af5e44779c965744556f34ec27
7
+ data.tar.gz: 6cb161afb2d1c01a0ba12ee4c482301d96959af439bcfc17176a6e2034799cb14158c10c8fda2bf94ad7702f8f280babf66079f763549e7b847ec10745e6bb39
data/fortnox-ruby.gemspec CHANGED
@@ -18,9 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.required_ruby_version = '~> 2.0'
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.10"
22
24
  spec.add_development_dependency "rake", "~> 10.0"
23
25
  spec.add_development_dependency "rspec"
24
26
  spec.add_development_dependency "dotenv", "~> 2.0"
25
27
  spec.add_dependency "httparty", "~> 0.13"
28
+ spec.add_dependency "activesupport", "~> 4.2"
26
29
  end
@@ -0,0 +1,4 @@
1
+ require 'dotenv'
2
+ Dotenv.load
3
+
4
+ require 'fortnox'
data/lib/fortnox.rb CHANGED
@@ -1,7 +1,55 @@
1
1
  require 'httparty'
2
- require 'fortnox/version'
2
+
3
+ require 'fortnox/configurable'
3
4
  require 'fortnox/client'
4
5
  require 'fortnox/default'
6
+ require 'fortnox/error'
7
+ require 'fortnox/json_fields_mapper'
8
+ require 'fortnox/relation'
9
+ require 'fortnox/relation_builder'
10
+ require 'fortnox/resource'
11
+ require 'fortnox/request'
12
+ require 'fortnox/version'
13
+
14
+ require 'fortnox/resources/account'
15
+ require 'fortnox/resources/account_chart'
16
+ require 'fortnox/resources/archive'
17
+ require 'fortnox/resources/article'
18
+ require 'fortnox/resources/article_file_connection'
19
+ require 'fortnox/resources/article_url_connection'
20
+ require 'fortnox/resources/company_setting'
21
+ require 'fortnox/resources/contract'
22
+ require 'fortnox/resources/contract_accrual'
23
+ require 'fortnox/resources/contract_template'
24
+ require 'fortnox/resources/cost_center'
25
+ require 'fortnox/resources/currency'
26
+ require 'fortnox/resources/customer'
27
+ require 'fortnox/resources/financial_year'
28
+ require 'fortnox/resources/inbox'
29
+ require 'fortnox/resources/invoice_accrual'
30
+ require 'fortnox/resources/invoice_payment'
31
+ require 'fortnox/resources/locked_period'
32
+ require 'fortnox/resources/mode_of_payment'
33
+ require 'fortnox/resources/offer'
34
+ require 'fortnox/resources/order'
35
+ require 'fortnox/resources/price'
36
+ require 'fortnox/resources/price_list'
37
+ require 'fortnox/resources/print_template'
38
+ require 'fortnox/resources/project'
39
+ require 'fortnox/resources/supplier'
40
+ require 'fortnox/resources/supplier_invoice'
41
+ require 'fortnox/resources/supplier_invoice_accrual'
42
+ require 'fortnox/resources/supplier_invoice_external_url_connection'
43
+ require 'fortnox/resources/supplier_invoice_file_connection'
44
+ require 'fortnox/resources/supplier_invoice_payment'
45
+ require 'fortnox/resources/tax_reduction'
46
+ require 'fortnox/resources/terms_of_delivery'
47
+ require 'fortnox/resources/terms_of_payment'
48
+ require 'fortnox/resources/unit'
49
+ require 'fortnox/resources/voucher'
50
+ require 'fortnox/resources/voucher_file_connection'
51
+ require 'fortnox/resources/voucher_series'
52
+ require 'fortnox/resources/way_of_delivery'
5
53
 
6
54
  module Fortnox
7
55
  class << self
@@ -10,20 +58,6 @@ module Fortnox
10
58
  def client
11
59
  @client ||= Fortnox::Client.new(options)
12
60
  end
13
-
14
- private
15
-
16
- def respond_to_missing?(method_name, include_private=false)
17
- client.respond_to?(method_name, include_private)
18
- end
19
-
20
- def method_missing(method_name, *args, &block)
21
- if client.respond_to?(method_name)
22
- client.send(method_name, *args, &block)
23
- else
24
- super
25
- end
26
- end
27
61
  end
28
62
  end
29
63
 
@@ -1,6 +1,4 @@
1
1
  require 'fortnox/configurable'
2
- require 'fortnox/resource'
3
- require 'fortnox/error'
4
2
 
5
3
  module Fortnox
6
4
  class Client
@@ -16,13 +14,12 @@ module Fortnox
16
14
  headers 'Accept' => 'application/json', 'Content-Type' => 'application/json'
17
15
 
18
16
  format :json
17
+ base_uri 'https://api.fortnox.se/3/'.freeze
19
18
 
20
19
  def initialize(options = {})
21
20
  Fortnox::Configurable.keys.each do |key|
22
21
  instance_variable_set(:"@#{key}", options[key] || Fortnox.instance_variable_get(:"@#{key}"))
23
22
  end
24
-
25
- self.class.default_options.merge!(base_uri: api_endpoint)
26
23
  end
27
24
 
28
25
  def fetch_access_token
@@ -31,27 +28,8 @@ module Fortnox
31
28
  'Authorization-Code' => authorization_code
32
29
  }
33
30
 
34
- response = get(root_path, headers: headers)
35
- @access_token = extract_token(response)
36
- end
37
-
38
- def request(verb, url, options = {})
39
- response = send(verb, url, options.merge(headers: auth_headers))
40
- if response.success?
41
- response
42
- else
43
- raise Fortnox::Error.from_response(response)
44
- end
45
- end
46
-
47
- private
48
-
49
- def extract_token(response)
50
- response.fetch('Authorization').fetch('AccessToken')
51
- end
52
-
53
- def root_path
54
- '/'.freeze
31
+ response = get('/', headers: headers)
32
+ @access_token = response.fetch('Authorization').fetch('AccessToken')
55
33
  end
56
34
 
57
35
  def auth_headers
@@ -1,14 +1,13 @@
1
1
  module Fortnox
2
2
  module Configurable
3
3
 
4
- attr_accessor :access_token, :client_id, :client_secret, :authorization_code, :api_endpoint
4
+ attr_accessor :access_token, :client_id, :client_secret, :authorization_code
5
5
 
6
6
  class << self
7
7
  def keys
8
8
  @keys ||= [
9
- :access_token,
10
- :api_endpoint,
11
9
  :client_id,
10
+ :access_token,
12
11
  :client_secret,
13
12
  :authorization_code
14
13
  ]
@@ -1,7 +1,5 @@
1
1
  module Fortnox
2
2
  module Default
3
- API_ENDPOINT = 'https://api.fortnox.se/3/'.freeze
4
-
5
3
  class << self
6
4
  def options
7
5
  Hash[Fortnox::Configurable.keys.map{|key| [key, send(key)]}]
@@ -19,10 +17,6 @@ module Fortnox
19
17
  ENV['FORTNOX_CLIENT_SECRET']
20
18
  end
21
19
 
22
- def api_endpoint
23
- ENV['FORTNOX_API_ENDPOINT'] || API_ENDPOINT
24
- end
25
-
26
20
  def authorization_code
27
21
  ENV['FORTNOX_AUTHORIZATION_CODE']
28
22
  end
@@ -0,0 +1,36 @@
1
+ module Fortnox
2
+ class JSONFieldsMapper
3
+ def self.mapping
4
+ {
5
+ bg: "BG",
6
+ pg: "PG",
7
+ bic: "BIC",
8
+ ean: "EAN",
9
+ ocr: "OCR",
10
+ sru: "SRU",
11
+ vat: "VAT",
12
+ www: "WWW",
13
+ iban: "IBAN",
14
+ vat_code: "VATCode",
15
+ vat_type: "VATType",
16
+ total_vat: "TotalVAT",
17
+ vat_number: "VATNumber",
18
+ eu_account: "EUAccount",
19
+ freight_vat: "FreightVAT",
20
+ invoice_ocr: "InvoiceOCR",
21
+ vat_included: "VATIncluded",
22
+ euvat_account: "EUVATAccount",
23
+ url_connection: "URLConnection",
24
+ email_order_cc: "EmailOrderCC",
25
+ email_offer_cc: "EmailOfferCC",
26
+ email_order_bcc: "EmailOrderBCC",
27
+ email_offer_bcc: "EmailOfferBCC",
28
+ email_invoice_cc: "EmailInvoiceCC",
29
+ email_invoice_bcc: "EmailInvoiceBCC",
30
+ administration_fee_vat: "AdministrationFeeVAT",
31
+ show_price_vat_included: "ShowPriceVATIncluded",
32
+ external_url_connection: "ExternalURLConnection"
33
+ }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,15 @@
1
+ module Fortnox
2
+ class Relation
3
+ attr_reader :name, :type, :class_override
4
+
5
+ def initialize(name, type, class_override: nil)
6
+ @name = name.to_s
7
+ @type = type
8
+ @class_override = class_override
9
+ end
10
+
11
+ def relation_class
12
+ "Fortnox::#{class_override || name.classify}".constantize
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ module Fortnox
2
+ class RelationBuilder
3
+ attr_reader :resource, :attributes
4
+
5
+ def initialize(resource, attributes)
6
+ @resource = resource
7
+ @attributes = attributes
8
+ end
9
+
10
+ def call
11
+ resource.class.relations.each do |relation|
12
+ build_relation(relation)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def build_relation(relation)
19
+ if attrs = attributes.delete(relation.name)
20
+ value = relation.relation_class.build_objects(attrs)
21
+ resource.public_send("#{relation.name}=", value)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,42 @@
1
+ module Fortnox
2
+ class Request
3
+ attr_reader :url, :type, :params
4
+
5
+ def initialize(type, url, params = {})
6
+ @url = url
7
+ @type = type
8
+ @params = params
9
+ end
10
+
11
+ def content
12
+ case type
13
+ when :post, :put
14
+ { body: params.to_json }
15
+ when :get
16
+ { query: params }
17
+ when :delete
18
+ {}
19
+ end
20
+ end
21
+
22
+ def execute
23
+ response.success? ? response.parsed_response : raise_from(response)
24
+ end
25
+
26
+ def raise_from(response)
27
+ raise Fortnox::Error.from_response(response)
28
+ end
29
+
30
+ def response
31
+ @response ||= client.send(type, url, {headers: auth_headers}.merge(Fortnox::Client.headers))
32
+ end
33
+
34
+ def auth_headers
35
+ client.auth_headers
36
+ end
37
+
38
+ def client
39
+ Fortnox.client
40
+ end
41
+ end
42
+ end
@@ -1,15 +1,94 @@
1
+ require 'active_support/core_ext/string/inflections.rb'
2
+
1
3
  module Fortnox
2
4
  class Resource
3
- attr_accessor :attributes
5
+ class << self
6
+ def relations
7
+ @relations ||= Set.new
8
+ end
9
+
10
+ def relation(name, type, class_override: nil)
11
+ relations << Relation.new(name, type, class_override: class_override)
12
+ attr_accessor name
13
+ end
14
+
15
+ def build_objects(data)
16
+ case data
17
+ when Hash then new(data)
18
+ when Array then data.map{|item| build_objects(item) }
19
+ else data
20
+ end
21
+ end
22
+
23
+ attr_writer :default_search_options
24
+
25
+ def default_search_options
26
+ @default_search_options ||= { page: 1, page_size: 50 }
27
+ end
28
+
29
+ def endpoint(value = nil)
30
+ @endpoint = value if value
31
+ @endpoint || name.demodulize.downcase.pluralize
32
+ end
33
+
34
+ def search(options = {})
35
+ query = default_search_options.merge(options)
36
+ perform_request(:get, "/#{endpoint}", query)
37
+ end
38
+
39
+ def fetch(id = nil)
40
+ perform_request(:get, "/#{endpoint}/#{id}")
41
+ end
42
+
43
+ def create(attributes)
44
+ perform_request(:post, "/#{endpoint}", attributes)
45
+ end
46
+
47
+ def perform_request(type, url, params = {})
48
+ response = Request.new(type, url, params).execute
49
+ build_objects(response)
50
+ end
51
+ end
4
52
 
5
53
  def initialize(attributes = {})
6
- @attributes = attributes
54
+ Hash(attributes[self.class.name.demodulize]).each do |key, value|
55
+ next if /@/ === key
56
+ public_send("#{key.underscore}=", value)
57
+ end
58
+
59
+ RelationBuilder.new(self, attributes).call
60
+ end
61
+
62
+ def to_json(*args)
63
+ to_hash.to_json(*args)
64
+ end
65
+
66
+ def to_hash
67
+ fields_mapping = JSONFieldsMapper.mapping
68
+
69
+ instance_variables
70
+ .each_with_object({}) do |variable, obj|
71
+ value = instance_variable_get(variable)
72
+
73
+ case value
74
+ when Resource
75
+ value = value.to_hash
76
+ when Array
77
+ value = value.map(&:to_hash)
78
+ end
79
+
80
+ field = variable[1..-1]
81
+ key = fields_mapping.fetch(field.to_sym, field.camelize)
82
+ obj[key] = value
83
+ end
7
84
  end
8
85
 
9
- def resource_path(id)
86
+ def update(attributes)
87
+ self.class.perform_request(:put, "#{endpoint}/#{id}", attributes)
10
88
  end
11
89
 
12
- def collection_path
90
+ def endpoint
91
+ self.class.endpoint
13
92
  end
14
93
  end
15
94
  end
@@ -0,0 +1,8 @@
1
+ module Fortnox
2
+ class Account < Resource
3
+ attr_accessor :active, :balance_brought_forward, :balance_carried_forward,
4
+ :cost_center, :cost_center_settings, :description, :number, :project,
5
+ :project_settings, :sru, :transaction_information, :transaction_information_settings,
6
+ :vat_code, :year
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class AccountChart < Resource
3
+ attr_accessor :name
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class Archive < Resource
3
+ attr_accessor :email, :files, :folders, :id, :name
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Fortnox
2
+ class Article < Resource
3
+ attr_accessor :article_number, :bulky, :construction_account, :depth,
4
+ :description, :disposable_quantity, :ean, :eu_account, :euvat_account,
5
+ :expired, :export_account, :height, :housework, :housework_type, :manufacturer,
6
+ :manufacturer_article_number, :note, :purchase_account, :purchase_price,
7
+ :quantity_in_stock, :reserved_quantity, :sales_account, :sales_price, :stock_goods,
8
+ :stock_place, :stock_value, :stock_warning, :supplier_name, :supplier_number,
9
+ :type, :unit, :vat, :webshop_article, :weight, :width
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class ArticleFileConnection < Resource
3
+ attr_accessor :file_id, :acticle_number
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class ArticleURLConnection < Resource
3
+ attr_accessor :id, :article_number, :url_connection
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module Fortnox
2
+ class CompanySetting < Resource
3
+ attr_accessor :address, :bg, :bic, :branch_code, :city, :contact_first_name,
4
+ :contact_last_name, :country, :country_code, :database_number, :domicile,
5
+ :email, :fax, :iban, :name, :organization_number, :pg, :phone1, :phone2,
6
+ :tax_enabled, :vat_number, :visit_address, :visit_city, :visit_country,
7
+ :visit_country_code, :visit_name, :visit_zip_code, :www, :zip_code
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Fortnox
2
+ class Contract < Resource
3
+ attr_accessor :active, :administration_fee, :comments, :continuous, :contract_date,
4
+ :contract_length, :contribution_percent, :contribution_value, :cost_center,
5
+ :currency, :customer_name, :customer_number, :document_number, :email_information,
6
+ :external_invoice_reference1, :external_invoice_reference2, :freight, :gross,
7
+ :house_work, :invoice_discount, :invoice_interval, :invoice_rows,
8
+ :invoices_remaining, :language, :last_invoice_date, :net, :ongoing,
9
+ :our_reference, :period_end, :period_start, :price_list, :print_template,
10
+ :project, :remarks, :tax_reduction, :template_name, :template_number,
11
+ :terms_of_delivery, :terms_of_payment, :total, :total_to_pay, :total_vat,
12
+ :vat_included, :way_of_delivery, :your_order_number
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ module Fortnox
2
+ class ContractAccrual < Resource
3
+ attr_accessor :accrual_account, :cost_account, :description, :accrual_rows,
4
+ :document_number, :period, :times, :total, :vat_included
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Fortnox
2
+ class ContractTemplate < Resource
3
+ attr_accessor :administration_fee, :contract_length, :freight, :invoice_interval,
4
+ :invoice_rows, :continuous, :our_reference, :print_template, :remarks,
5
+ :template_name, :template_number, :terms_of_delivery, :terms_of_payment,
6
+ :way_of_delivery
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class CostCenter < Resource
3
+ attr_accessor :code, :description, :note, :active
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class Currency < Resource
3
+ attr_accessor :buy_rate, :code, :date, :description, :sell_rate, :unit
4
+ end
5
+ end
@@ -1,11 +1,17 @@
1
1
  module Fortnox
2
- module Customers
3
- def customers(options = {})
4
- request(:get, collection_path, options)
5
- end
6
-
7
- def customer(id, options = {})
8
- request(:get, resource_path(id), options)
9
- end
2
+ class Customer < Resource
3
+ attr_accessor :address1, :address2, :city, :country, :comments, :currency,
4
+ :cost_center, :country_code, :customer_number, :default_delivery_types,
5
+ :default_templates, :delivery_address1, :delivery_address2, :delivery_city,
6
+ :delivery_country, :delivery_country_code, :delivery_fax, :delivery_name,
7
+ :delivery_phone1, :delivery_phone2, :delivery_zip_code, :email, :email_invoice,
8
+ :email_invoice_bcc, :email_invoice_cc, :email_offer, :email_offer_bcc,
9
+ :email_offer_cc, :email_order, :email_order_bcc, :email_order_cc, :fax,
10
+ :invoice_administration_fee, :invoice_discount, :invoice_freight,
11
+ :invoice_remark, :name, :organisation_number, :our_reference, :phone1,
12
+ :phone2, :price_list, :project, :sales_account, :show_price_vat_included,
13
+ :terms_of_delivery, :terms_of_payment, :type, :vat_number, :vat_type,
14
+ :visiting_address, :visiting_city, :visiting_country, :visiting_country_code,
15
+ :visiting_zip_code, :way_of_delivery, :www, :your_reference, :zip_code
10
16
  end
11
17
  end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class FinancialYear < Resource
3
+ attr_accessor :id, :from_date, :to_date, :account_chart_type
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Fortnox
2
+ class Inbox < Resource
3
+ end
4
+ end
@@ -0,0 +1,20 @@
1
+ module Fortnox
2
+ class Invoice < Resource
3
+ attr_accessor :address1, :address2, :administration_fee, :administration_fee_vat,
4
+ :balance, :basis_tax_reduction, :booked, :cancelled, :city, :comments, :contract_reference,
5
+ :contribution_percent, :contribution_value, :cost_center, :country, :credit,
6
+ :credit_invoice_reference, :currency, :currency_rate, :currency_unit, :customer_name,
7
+ :customer_number, :delivery_address1, :delivery_address2, :delivery_city,
8
+ :delivery_country, :delivery_date, :delivery_name, :delivery_zip_code, :document_number,
9
+ :due_date, :edi_information, :eu_quarterly_report, :email_information,
10
+ :external_invoice_reference1, :external_invoice_reference2, :freight, :freight_vat,
11
+ :gross, :house_work, :invoice_date, :invoice_period_end, :invoice_period_start,
12
+ :invoice_reference, :invoice_rows, :invoice_type, :language, :last_remind_date,
13
+ :net, :not_completed, :ocr, :offer_reference, :order_reference, :organisation_number,
14
+ :our_reference, :payment_way, :phone1, :phone2, :price_list, :print_template,
15
+ :project, :remarks, :reminders, :round_off, :sent, :tax_reduction,
16
+ :terms_of_delivery, :terms_of_payment, :total, :total_to_pay, :total_vat,
17
+ :vat_included, :voucher_number, :voucher_series, :voucher_year, :way_of_delivery,
18
+ :your_order_number, :your_reference, :zip_code
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ module Fortnox
2
+ class InvoiceAccrual < Resource
3
+ attr_accessor :accrual_account, :description, :end_date, :invoice_accrual_rows,
4
+ :invoice_number, :period, :revenue_account, :start_date, :times, :total, :vat_included
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ module Fortnox
2
+ class InvoicePayment < Resource
3
+ attr_accessor :amount, :amount_currency, :booked, :currency, :currency_rate,
4
+ :currency_unit, :external_invoice_reference1, :external_invoice_reference2,
5
+ :invoice_customer_name, :invoice_customer_number, :invoice_number, :invoice_due_date,
6
+ :invoice_ocr, :invoice_total, :mode_of_payment, :number, :payment_date,
7
+ :voucher_number, :voucher_series, :voucher_year, :source, :write_offs
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class LockedPeriod < Resource
3
+ attr_accessor :end_date
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class ModeOfPayment < Resource
3
+ attr_accessor :code, :description, :account_number
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ module Fortnox
2
+ class Offer < Resource
3
+ attr_accessor :administration_fee, :administration_fee_vat, :address1, :address2,
4
+ :basis_tax_reduction, :cancelled, :city, :comments, :contribution_percent,
5
+ :contribution_value, :copy_remarks, :country, :cost_center, :currency,
6
+ :currency_rate, :currency_unit, :customer_name, :customer_number,
7
+ :delivery_address1, :delivery_address2, :delivery_city, :delivery_country,
8
+ :delivery_date, :delivery_name, :delivery_zip_code, :document_number,
9
+ :email_information, :expire_date, :freight, :freight_vat, :gross, :house_work,
10
+ :invoice_reference, :language, :net, :not_completed, :offer_date, :offer_rows,
11
+ :order_reference, :organisation_number, :our_reference, :phone1, :phone2,
12
+ :price_list, :print_template, :project, :remarks, :round_off, :sent, :tax_reduction,
13
+ :terms_of_delivery, :terms_of_payment, :total, :total_to_pay, :total_vat,
14
+ :vat_included, :way_of_delivery, :your_reference, :your_reference_number, :zip_code
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module Fortnox
2
+ class Order < Resource
3
+ attr_accessor :administration_fee, :administration_fee_vat, :address1,
4
+ :address2, :basis_tax_reduction, :cancelled, :city, :comments,
5
+ :contribution_percent, :contribution_value, :copy_remarks, :country,
6
+ :cost_center, :currency, :currency_rate, :currency_unit, :customer_name,
7
+ :customer_number, :delivery_address1, :delivery_address2, :delivery_city,
8
+ :delivery_country, :delivery_date, :delivery_name, :delivery_zip_code,
9
+ :document_number, :email_information, :external_invoice_reference1,
10
+ :external_invoice_reference2, :freight, :freight_vat, :gross, :house_work,
11
+ :invoice_reference, :language, :net, :not_completed, :offer_reference,
12
+ :order_date, :order_rows, :organisation_number, :our_reference, :phone1,
13
+ :phone2, :price_list, :print_template, :project, :remarks, :round_off, :sent,
14
+ :tax_reduction, :terms_of_delivery, :terms_of_payment, :total, :total_to_pay,
15
+ :total_vat, :vat_included, :way_of_delivery, :your_reference, :your_order_number,
16
+ :zip_code
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class Price < Resource
3
+ attr_accessor :article_number, :date, :from_quantity, :percent, :price, :price_list
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class PriceList < Resource
3
+ attr_accessor :code, :description, :comments
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class PrintTemplate < Resource
3
+ attr_accessor :template, :name
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class Project < Resource
3
+ attr_accessor :comments, :contact_person, :description, :end_date, :project_leader, :project_number, :status, :start_date
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ module Fortnox
2
+ class Supplier < Resource
3
+ attr_accessor :active, :address1, :address2, :bank, :bank_account_number,
4
+ :bg, :bic, :branch_code, :city, :clearing_number, :comments, :cost_center,
5
+ :country, :country_code, :currency, :disable_payment_file, :email, :fax,
6
+ :iban, :name, :organisation_number, :our_reference, :our_customer_number,
7
+ :pg, :phone1, :phone2, :pre_defined_account, :project, :supplier_number,
8
+ :terms_of_payment, :vat_number, :vat_type, :visiting_address, :visiting_city,
9
+ :visiting_country, :visiting_country_code, :visiting_zip_code, :work_place,
10
+ :www, :your_reference, :zip_code
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module Fortnox
2
+ class SupplierInvoice < Resource
3
+ attr_accessor :administration_fee, :balance, :booked, :cancelled, :comments,
4
+ :cost_center, :credit, :credit_reference, :currency, :currency_rate,
5
+ :currency_unit, :disable_payment_file, :due_date, :external_invoice_number,
6
+ :external_invoice_series, :freight, :given_number, :invoice_date, :invoice_number,
7
+ :ocr, :our_reference, :project, :round_off_value, :sales_type,
8
+ :supplier_invoice_rows, :supplier_number, :supplier_name, :total, :vat, :your_reference
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Fortnox
2
+ class SupplierInvoiceAccrual < Resource
3
+ attr_accessor :accrual_account, :cost_account, :description, :end_date,
4
+ :supplier_invoice_number, :period, :supplier_invoice_accrual_rows,
5
+ :start_date, :times, :total, :vat_included
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class SupplierInvoiceExternalURLConnection < Resource
3
+ attr_accessor :id, :supplier_invoice_number, :external_url_connection
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class SupplierInvoiceFileConnection < Resource
3
+ attr_accessor :file_id, :name, :supplier_invoice_number, :supplier_name
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module Fortnox
2
+ class SupplierInvoicePayment < Resource
3
+ attr_accessor :amount, :amount_currency, :booked, :currency, :currency_rate,
4
+ :currency_unit, :information, :invoice_number, :invoice_due_date,
5
+ :invoice_ocr, :invoice_supplier_name, :invoice_supplier_number,
6
+ :invoice_total, :mode_of_payment, :number, :payment_date, :source,
7
+ :voucher_number, :voucher_series, :voucher_year, :write_offs
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Fortnox
2
+ class TaxReduction < Resource
3
+ attr_accessor :approved_amount, :asked_amount, :billed_amount, :customer_name,
4
+ :id, :property_designation, :reference_document_type, :reference_number,
5
+ :request_sent, :residence_association_organisation_number,
6
+ :social_security_number, :type_of_reduction, :voucher_number, :voucher_series,
7
+ :voucher_year
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class TermsOfDelivery < Resource
3
+ attr_accessor :code, :description
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class TermsOfPayment < Resource
3
+ attr_accessor :code, :description
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class Unit < Resource
3
+ attr_accessor :code, :description
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Fortnox
2
+ class Voucher < Resource
3
+ attr_accessor :comments, :cost_center, :description, :project, :reference_number,
4
+ :reference_type, :transaction_date, :voucher_number, :voucher_rows,
5
+ :voucher_series, :year
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class VoucherFileConnection < Resource
3
+ attr_accessor :file_id, :voucher_description, :voucher_number, :voucher_series, :voucher_year
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class VoucherSeries < Resource
3
+ attr_accessor :code, :description, :manual, :next_voucher_number, :year
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Fortnox
2
+ class WayOfDelivery < Resource
3
+ attr_accessor :code, :description
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Fortnox
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fortnox-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-08 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.2'
83
97
  description:
84
98
  email:
85
99
  - birmanmark@gmail.com
@@ -98,13 +112,57 @@ files:
98
112
  - bin/console
99
113
  - bin/setup
100
114
  - fortnox-ruby.gemspec
115
+ - lib/fortnox-ruby.rb
101
116
  - lib/fortnox.rb
102
117
  - lib/fortnox/client.rb
103
118
  - lib/fortnox/configurable.rb
104
119
  - lib/fortnox/default.rb
105
120
  - lib/fortnox/error.rb
121
+ - lib/fortnox/json_fields_mapper.rb
122
+ - lib/fortnox/relation.rb
123
+ - lib/fortnox/relation_builder.rb
124
+ - lib/fortnox/request.rb
106
125
  - lib/fortnox/resource.rb
126
+ - lib/fortnox/resources/account.rb
127
+ - lib/fortnox/resources/account_chart.rb
128
+ - lib/fortnox/resources/archive.rb
129
+ - lib/fortnox/resources/article.rb
130
+ - lib/fortnox/resources/article_file_connection.rb
131
+ - lib/fortnox/resources/article_url_connection.rb
132
+ - lib/fortnox/resources/company_setting.rb
133
+ - lib/fortnox/resources/contract.rb
134
+ - lib/fortnox/resources/contract_accrual.rb
135
+ - lib/fortnox/resources/contract_template.rb
136
+ - lib/fortnox/resources/cost_center.rb
137
+ - lib/fortnox/resources/currency.rb
107
138
  - lib/fortnox/resources/customer.rb
139
+ - lib/fortnox/resources/financial_year.rb
140
+ - lib/fortnox/resources/inbox.rb
141
+ - lib/fortnox/resources/invoice.rb
142
+ - lib/fortnox/resources/invoice_accrual.rb
143
+ - lib/fortnox/resources/invoice_payment.rb
144
+ - lib/fortnox/resources/locked_period.rb
145
+ - lib/fortnox/resources/mode_of_payment.rb
146
+ - lib/fortnox/resources/offer.rb
147
+ - lib/fortnox/resources/order.rb
148
+ - lib/fortnox/resources/price.rb
149
+ - lib/fortnox/resources/price_list.rb
150
+ - lib/fortnox/resources/print_template.rb
151
+ - lib/fortnox/resources/project.rb
152
+ - lib/fortnox/resources/supplier.rb
153
+ - lib/fortnox/resources/supplier_invoice.rb
154
+ - lib/fortnox/resources/supplier_invoice_accrual.rb
155
+ - lib/fortnox/resources/supplier_invoice_external_url_connection.rb
156
+ - lib/fortnox/resources/supplier_invoice_file_connection.rb
157
+ - lib/fortnox/resources/supplier_invoice_payment.rb
158
+ - lib/fortnox/resources/tax_reduction.rb
159
+ - lib/fortnox/resources/terms_of_delivery.rb
160
+ - lib/fortnox/resources/terms_of_payment.rb
161
+ - lib/fortnox/resources/unit.rb
162
+ - lib/fortnox/resources/voucher.rb
163
+ - lib/fortnox/resources/voucher_file_connection.rb
164
+ - lib/fortnox/resources/voucher_series.rb
165
+ - lib/fortnox/resources/way_of_delivery.rb
108
166
  - lib/fortnox/version.rb
109
167
  homepage: https://github.com/mbirman/fortnox
110
168
  licenses:
@@ -116,9 +174,9 @@ require_paths:
116
174
  - lib
117
175
  required_ruby_version: !ruby/object:Gem::Requirement
118
176
  requirements:
119
- - - ">="
177
+ - - "~>"
120
178
  - !ruby/object:Gem::Version
121
- version: '0'
179
+ version: '2.0'
122
180
  required_rubygems_version: !ruby/object:Gem::Requirement
123
181
  requirements:
124
182
  - - ">="