moneybird 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dab722d83709b10c7b270ce93f7be1e2788bf0b8
4
+ data.tar.gz: f1ab282131eddae6da3233621ba6fda5538389e3
5
+ SHA512:
6
+ metadata.gz: 109f072481d347616421e212bff2a5f4ba77ecf4b88c85c520e5cf1ce9c81cddd47a92eba7087c0d2b8a1870c3e9c8f441a2db07e18067ee45d3825838bb64a9
7
+ data.tar.gz: 9d0721e8e2af058b18b5de23694230edaaf88ddddc92e5831d52fa4f9043ff1bdaeba79de7110fa2950ad25a10f0f795aa0f6e4c2dca09f18514947bea8a32da
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at maartenvanvliet@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in moneybird.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Maarten van Vliet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Moneybird
2
+
3
+ Gem to talk to the Moneybird REST API. Right now you'll need to get a 'bearer' token for the client to work, oauth2 support may added later. This gem is still under construction and any methods may still change signature without notice until 1.0 is released.
4
+
5
+ Feel free to file Pull Requests
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'moneybird'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install moneybird
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+
27
+ Moneybird::Client.new('fe3f7f9e239e7d925f9caf695028e60fd3e5c2085f7aebb983cea731dea6b44f').administrations.first.sales_invoices.first
28
+
29
+ ```
30
+
31
+ ## Development
32
+
33
+ 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
+
35
+ 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).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/maartenvanvliet/moneybird. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
40
+
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
45
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "moneybird"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/moneybird.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'json'
2
+ require "moneybird/resource"
3
+ require "moneybird/client"
4
+ require "moneybird/contact"
5
+ require "moneybird/administration"
6
+ require "moneybird/sales_invoice"
7
+ require "moneybird/version"
8
+
9
+ module Moneybird
10
+ end
@@ -0,0 +1,39 @@
1
+ module Moneybird
2
+ class Administration
3
+ include Moneybird::Resource
4
+ extend Moneybird::Resource::ClassMethods
5
+
6
+ has_attributes %i(
7
+ id
8
+ name
9
+ language
10
+ currency
11
+ country
12
+ time_zone
13
+ )
14
+
15
+ def sales_invoices
16
+ Moneybird::SalesInvoice::Service.new(@client, id).all
17
+ end
18
+
19
+ def contacts
20
+ Moneybird::Contact::Service.new(@client, id).all
21
+ end
22
+
23
+ class Service
24
+ attr_reader :client
25
+
26
+ def initialize(client)
27
+ @client = client
28
+ end
29
+
30
+ def all
31
+ result = client.get('/administrations')
32
+
33
+ JSON.parse(result.body).map do |administration|
34
+ Administration.new(client, administration)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,74 @@
1
+ module Moneybird
2
+ class Client
3
+ attr_reader :bearer, :_last_response
4
+ attr_accessor :errors
5
+
6
+ def initialize(bearer)
7
+ @bearer = bearer
8
+ end
9
+
10
+ def base_url
11
+ "https://moneybird.com/api/#{version}/"
12
+ end
13
+
14
+ def version
15
+ @version ||= 'v2'
16
+ end
17
+
18
+ def http
19
+ @http ||= begin
20
+ uri = uri_for_path(base_url)
21
+ http = Net::HTTP.new(uri.host, uri.port)
22
+ http.use_ssl = uri.scheme == 'https'
23
+ http
24
+ end
25
+ end
26
+
27
+ def headers
28
+ {
29
+ 'Accept' => 'application/json',
30
+ 'Content-Type' => 'application/json',
31
+ 'Authorization' => "Bearer #{bearer}"
32
+ }
33
+ end
34
+
35
+ def uri_for_path(path)
36
+ URI.parse(File.join(base_url, path))
37
+ end
38
+
39
+ def get(path, headers={})
40
+ uri = uri_for_path(path)
41
+ http = Net::HTTP::Get.new(uri.request_uri, self.headers.merge(headers))
42
+ perform(http)
43
+ end
44
+
45
+ def put(path, body=nil, headers={})
46
+ uri = uri_for_path(path)
47
+ http = Net::HTTP::Put.new(uri.request_uri, self.headers.merge(headers))
48
+ http.body = body
49
+ perform(http)
50
+ end
51
+
52
+ def post(path, body=nil, headers={})
53
+ uri = uri_for_path(path)
54
+ http = Net::HTTP::Post.new(uri.request_uri, self.headers.merge(headers))
55
+ http.body = body
56
+ perform(http)
57
+ end
58
+
59
+ def delete(path, headers={})
60
+ uri = uri_for_path(path)
61
+ http = Net::HTTP::Delete.new(uri.request_uri, self.headers.merge(headers))
62
+ perform(http)
63
+ end
64
+
65
+ def administrations
66
+ Moneybird::Administration::Service.new(self).all
67
+ end
68
+
69
+ private
70
+ def perform(request)
71
+ @_last_response = http.request(request)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,64 @@
1
+ module Moneybird
2
+ class Contact
3
+ include Moneybird::Resource
4
+ extend Moneybird::Resource::ClassMethods
5
+
6
+ has_attributes %i(
7
+ id
8
+ company_name
9
+ firstname
10
+ lastname
11
+ attention
12
+ address1
13
+ address2
14
+ zipcode
15
+ city
16
+ country
17
+ email
18
+ phone
19
+ delivery_method
20
+ customer_id
21
+ tax_number
22
+ chamber_of_commerce
23
+ bank_account
24
+ send_invoices_to_attention
25
+ send_invoices_to_email
26
+ send_estimates_to_attention
27
+ send_estimates_to_email
28
+ sepa_active
29
+ sepa_iban
30
+ sepa_iban_account_name
31
+ sepa_bic
32
+ sepa_mandate_id
33
+ sepa_mandate_date
34
+ sepa_sequence_type
35
+ credit_card_number
36
+ credit_card_reference
37
+ credit_card_type
38
+ tax_number_validated_at
39
+ created_at
40
+ updated_at
41
+ notes
42
+ custom_fields
43
+ )
44
+
45
+ class Service
46
+ attr_reader :client, :administation_id
47
+
48
+ def initialize(client, administation_id)
49
+ @client = client
50
+ @administation_id = administation_id
51
+ end
52
+
53
+ def all
54
+ result = client.get("#{administation_id}/contacts")
55
+
56
+ JSON.parse(result.body).map do |invoice|
57
+ Contact.new(self, invoice)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+
@@ -0,0 +1,100 @@
1
+ module Moneybird
2
+ module Resource
3
+ attr_reader :attributes
4
+ attr_accessor :errors
5
+
6
+ def initialize(client, attributes)
7
+ @client = client
8
+ self.attributes = attributes
9
+ end
10
+
11
+ def attributes=(attributes)
12
+ @attributes = attributes
13
+ attributes.each do |attribute, value|
14
+ if respond_to?(writer = attribute.to_s + '=')
15
+ send(writer, value)
16
+ else
17
+ raise "#{self.class} does not have an `#{attribute}' attribute"
18
+ end
19
+ end
20
+ end
21
+
22
+ def attributes
23
+ self.class.attributes.inject({}) do |attributes, attribute|
24
+ value = send(attribute)
25
+ if !value.nil?
26
+ if value.respond_to?(:attributes)
27
+ attributes["#{attribute}_attributes"] = value.attributes
28
+ else
29
+ unless self.class.nillable_attributes && self.class.nillable_attributes.include?(attribute)
30
+ attributes[attribute] = value
31
+ end
32
+ end
33
+ end; attributes
34
+ end
35
+ end
36
+
37
+ def to_json
38
+ JSON.generate(attributes)
39
+ end
40
+
41
+ module ClassMethods
42
+ attr_reader :attributes, :nillable_attributes
43
+
44
+ def has_attributes(attributes)
45
+ attr_accessor(*@attributes = attributes)
46
+ end
47
+
48
+ def has_nillable_attributes(attributes)
49
+ @nillable_attributes = attributes
50
+ end
51
+
52
+ def has_boolean_attributes(attributes)
53
+ attributes.each do |attribute|
54
+ define_method(attribute) do
55
+ input = instance_variable_get('@' + attribute)
56
+ if input.kind_of?(String)
57
+ if input == 'true'
58
+ true
59
+ elsif input == 'false'
60
+ false
61
+ else
62
+ nil
63
+ end
64
+ else
65
+ input
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def has_integer_attributes(attributes)
72
+ attributes.each do |attribute|
73
+ define_method(attribute) do
74
+ input = instance_variable_get('@' + attribute)
75
+ if input.kind_of?(String)
76
+ input.to_i
77
+ else
78
+ input
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ def has_datetime_attributes(attributes)
85
+ attributes.each do |attribute|
86
+ define_method(attribute) do
87
+ input = instance_variable_get('@' + attribute)
88
+ if input.kind_of?(Time)
89
+ input
90
+ elsif input.kind_of?(Date)
91
+ input.to_time
92
+ elsif input.kind_of?(String)
93
+ input.strip == '' ? nil : Time.parse(input)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,60 @@
1
+ module Moneybird
2
+ class SalesInvoice
3
+ include Moneybird::Resource
4
+ extend Moneybird::Resource::ClassMethods
5
+
6
+ has_attributes %i(
7
+ attachments
8
+ contact
9
+ contact_id
10
+ created_at
11
+ currency
12
+ custom_fields
13
+ details
14
+ discount
15
+ document_style_id
16
+ due_date
17
+ id
18
+ identity_id
19
+ invoice_date
20
+ invoice_id
21
+ language
22
+ notes
23
+ original_sales_invoice_id
24
+ paid_at
25
+ payment_conditions
26
+ payments
27
+ prices_are_incl_tax
28
+ reference
29
+ sent_at
30
+ state
31
+ total_paid
32
+ total_price_excl_tax
33
+ total_price_excl_tax_base
34
+ total_price_incl_tax
35
+ total_price_incl_tax_base
36
+ total_unpaid
37
+ updated_at
38
+ url
39
+ workflow_id
40
+ )
41
+
42
+ class Service
43
+ attr_reader :client, :administation_id
44
+
45
+ def initialize(client, administation_id)
46
+ @client = client
47
+ @administation_id = administation_id
48
+ end
49
+
50
+ def all
51
+ result = client.get("#{administation_id}/sales_invoices")
52
+
53
+ JSON.parse(result.body).map do |invoice|
54
+ SalesInvoice.new(self, invoice)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+
@@ -0,0 +1,3 @@
1
+ module Moneybird
2
+ VERSION = "0.1.0"
3
+ end
data/moneybird.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'moneybird/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "moneybird"
8
+ spec.version = Moneybird::VERSION
9
+ spec.authors = ["Maarten van Vliet"]
10
+ spec.email = ["maartenvanvliet@gmail.com"]
11
+
12
+ spec.summary = %q{Library to interface with Moneybird API}
13
+ spec.description = %q{Library to interface with Moneybird API: http://developer.moneybird.com/}
14
+ spec.homepage = "https://github.com/maartenvanvliet/moneybird"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.4"
26
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moneybird
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Maarten van Vliet
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description: 'Library to interface with Moneybird API: http://developer.moneybird.com/'
56
+ email:
57
+ - maartenvanvliet@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/moneybird.rb
73
+ - lib/moneybird/administration.rb
74
+ - lib/moneybird/client.rb
75
+ - lib/moneybird/contact.rb
76
+ - lib/moneybird/resource.rb
77
+ - lib/moneybird/sales_invoice.rb
78
+ - lib/moneybird/version.rb
79
+ - moneybird.gemspec
80
+ homepage: https://github.com/maartenvanvliet/moneybird
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.2.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Library to interface with Moneybird API
104
+ test_files: []