billogram 0.0.1 → 0.2.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: 01b1c1e7b6c92ecce8df12e6677b5e21c1e20a57
4
- data.tar.gz: e2d5a6d94146f3668670cf17a80fda2de712b03f
3
+ metadata.gz: 413126d96eb6392012e781f51b6e55ee2aa96caa
4
+ data.tar.gz: 4b6ade05a3d41a5f93d3e6fb117b1e6bf02b1a3e
5
5
  SHA512:
6
- metadata.gz: 6ab92336c7e385b5797b67a2b9550da4f871d1fb0f61426a27bfc3bc98d102519517a42c9ba4235bc4afce6fdc54f5be33f6efbaa8d883af800d20dfc5d20301
7
- data.tar.gz: 171be03c425b66915032ee90d8bf85687e2e575f394dc24d02618a1514dae4ca7b0539d349be79734435ebb1681aa093e6cd8b0427c182027684012dcfa0e2d8
6
+ metadata.gz: cd39f9925577645dce7f92eadb6e6fdc37cd30b07df889fb9f1fd4b777d6372954ab0a9f9d9c33a430c3bb2347ea12ff9f119b6556d1c63ff3bd21f87938e0d8
7
+ data.tar.gz: ca621f3971aa723a343c3188576bbdbdabffbc126d2dd0d01e987c60990acd0711373c616089de46d4eddf93777c798aa3a0a4bba875b90655bbaa1cb72bbe10
data/.gitignore CHANGED
@@ -7,11 +7,3 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
15
- .ruby-gemset
16
- .ruby-version
17
- test/fixtures
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.2.1
4
+ before_install: gem install bundler -v 1.10.6
data/LICENSE.txt CHANGED
@@ -1,22 +1,21 @@
1
- Copyright (c) 2015 Mark
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2015 Mark
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
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:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
15
14
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 CHANGED
@@ -1,25 +1,41 @@
1
1
  # Billogram
2
2
 
3
- A tiny Ruby wrapper for Billogram API.
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/billogram`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
4
6
 
5
7
  ## Installation
6
- $ gem install billogram
7
8
 
8
- ## Configuration
9
- Billogram.configure do |c|
10
- c.api_user = '6302-nibH3Grm'
11
- c.api_key = 'e4d1bf5fba2f6e9df97a636dd8c67d2f'
12
- c.base_url = 'https://sandbox.billogram.com/api/v2'
13
- end
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'billogram'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install billogram
14
22
 
15
23
  ## Usage
16
- # Get an invoice by ID
17
- @billgoram = Billogram::Invoice.get('gQjEEZL')
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
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.
30
+
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).
18
32
 
19
33
  ## Contributing
20
34
 
21
- 1. Fork it ( https://github.com/[my-github-username]/billogram/fork )
22
- 2. Create your feature branch (`git checkout -b my-new-feature`)
23
- 3. Commit your changes (`git commit -am 'Add some feature'`)
24
- 4. Push to the branch (`git push origin my-new-feature`)
25
- 5. Create a new Pull Request
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).
41
+
data/Rakefile CHANGED
@@ -1,9 +1,6 @@
1
- require 'bundler/gem_tasks'
2
-
3
- require 'rake/testtask'
4
- Rake::TestTask.new do |test|
5
- test.libs << 'lib' << 'test'
6
- test.ruby_opts << "-rubygems"
7
- test.pattern = 'test/**/*_test.rb'
8
- test.verbose = true
9
- end
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/billogram.gemspec CHANGED
@@ -8,22 +8,18 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Billogram::VERSION
9
9
  spec.authors = ["Mark Birman"]
10
10
  spec.email = ["birmanmark@gmail.com"]
11
- spec.summary = %q{Ruby wrapper over Billogram API}
12
- spec.description = %q{Ruby wrapper over Billogram API}
13
- spec.homepage = ""
11
+
12
+ spec.summary = %q{Simple ruby wrapper over Billogram API}
13
+ spec.homepage = "http://github.com/mbirman/billogram"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "minitest"
24
- spec.add_development_dependency "fakeweb", ["~> 1.3"]
25
-
23
+ spec.add_development_dependency "rspec"
26
24
  spec.add_dependency "httparty"
27
- spec.add_dependency "json"
28
- spec.add_dependency "hashie"
29
25
  end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "billogram"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/billogram.rb CHANGED
@@ -1,24 +1,31 @@
1
1
  require "httparty"
2
- require "hashie/mash"
3
- require "forwardable"
4
-
5
- Dir[File.dirname(__FILE__) + '/billogram/**/**.rb'].each do |file|
6
- require file
7
- end
2
+ require "billogram/client"
3
+ require "billogram/relation_builder"
4
+ require "billogram/resource"
5
+ require 'billogram/resources/address'
6
+ require 'billogram/resources/bookkeeping'
7
+ require 'billogram/resources/callback'
8
+ require 'billogram/resources/contact'
9
+ require 'billogram/resources/customer'
10
+ require 'billogram/resources/data'
11
+ require 'billogram/resources/delivery_address'
12
+ require 'billogram/resources/event'
13
+ require 'billogram/resources/info'
14
+ require 'billogram/resources/invoice'
15
+ require 'billogram/resources/item'
16
+ require 'billogram/resources/regional_sweden'
17
+ require "billogram/version"
8
18
 
9
19
  module Billogram
10
- CONFIG_KEYS = [:api_key, :api_user, :base_url].freeze
11
-
12
20
  class << self
13
- attr_accessor *CONFIG_KEYS
21
+ attr_accessor :username, :password, :base_uri
14
22
 
15
- def configure
16
- yield self
17
- self
23
+ def client
24
+ @client ||= Client.new(username, password, base_uri)
18
25
  end
19
26
 
20
- def client
21
- @client ||= Client.new(api_user, api_key, base_url)
27
+ def configure
28
+ yield self if block_given?
22
29
  end
23
30
  end
24
31
  end
@@ -1,22 +1,14 @@
1
1
  module Billogram
2
- # https://github.com/lendai/billogram-api-clients/tree/master/ruby
3
2
  class Client
4
3
  include HTTParty
5
- extend Forwardable
6
-
7
- HEADERS = {
8
- "Accept" => "application/json",
9
- "Content-Type" => "application/json"
10
- }
11
-
12
- headers HEADERS
13
4
  format :json
14
5
 
15
- delegate [:get, :post, :put, :delete] => self
6
+ def initialize(username, password, base_uri)
7
+ self.class.default_options.merge!(base_uri: base_uri, basic_auth: {username: username, password: password})
8
+ end
16
9
 
17
- def initialize(username, password, base_uri = Billogram.base_url)
18
- self.class.base_uri base_uri
19
- self.class.basic_auth username, password
10
+ def get(*args)
11
+ self.class.get(*args)
20
12
  end
21
13
  end
22
14
  end
@@ -0,0 +1,55 @@
1
+ module Billogram
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_relations.each do |type, relation_names|
12
+ build_relation(type, relation_names)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def relation_class(relation_name)
19
+ Object.const_get("Billogram::#{relation_name.to_s.split('_').map(&:capitalize).join()}")
20
+ end
21
+
22
+ def relation_attributes(relation_name)
23
+ attributes.delete(relation_name.to_s)
24
+ end
25
+
26
+ def resource_relations
27
+ resource.class.relations
28
+ end
29
+
30
+ def build_relation(type, relation_names)
31
+ relation_names.each do |name|
32
+ if type == :one
33
+ build_one_relation(name)
34
+ elsif type == :many
35
+ build_many_relation(name)
36
+ end
37
+ end
38
+ end
39
+
40
+ def build_one_relation(name)
41
+ if attrs = relation_attributes(name)
42
+ value = relation_class(name).new attrs
43
+ resource.instance_variable_set("@#{name}", value)
44
+ end
45
+ end
46
+
47
+ def build_many_relation(name)
48
+ if attrs = relation_attributes(name)
49
+ singular = name[0..name.length-2]
50
+ value = attrs.map{|item| relation_class(singular).new(item) }
51
+ resource.instance_variable_set("@#{name}", value)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,61 +1,52 @@
1
1
  module Billogram
2
2
  class Resource
3
+ attr_reader :data
4
+
5
+ DEFAULT_OPTIONS = { page: 1, page_size: 2 }
6
+
3
7
  class << self
4
- attr_writer :endpoint
8
+ def relations
9
+ @relations ||= { one: Set.new, many: Set.new }
10
+ end
5
11
 
6
- def endpoint
7
- @endpoint || downcased_class_name
12
+ def endpoint(value = nil)
13
+ @endpoint = value if value
14
+ @endpoint || name.demodulize.underscore.pluralize
8
15
  end
9
16
 
10
- def get(id = '')
11
- get_and_return_new("/#{endpoint}/#{id}")
17
+ def search(options = {})
18
+ query = DEFAULT_OPTIONS.merge(options)
19
+ response = Billogram.client.get("#{endpoint}", {query: query})
20
+ parse_response(response.parsed_response["data"])
12
21
  end
13
22
 
14
- private
23
+ def fetch(id)
24
+ response = Billogram.client.get("#{endpoint}/#{id}")
25
+ parse_response(response.parsed_response["data"])
26
+ end
15
27
 
16
- def downcased_class_name
17
- name.split('::').last.downcase
28
+ def parse_response(data)
29
+ # TODO: refactor, error handling
30
+ case data
31
+ when Hash then new(data)
32
+ when Array then data.map{|item| parse_response(item) }
33
+ when nil
34
+ else data
35
+ end
18
36
  end
19
37
 
20
- def get_and_return_new(url)
21
- response = Billogram.client.get(url)
22
- new response['data']
38
+ def relation(relation_name, relation_type = :one)
39
+ relations[relation_type] << relation_name
40
+ attr_reader relation_name
23
41
  end
24
42
  end
25
43
 
26
- attr_reader :attributes
27
-
28
44
  def initialize(attributes = {})
29
- @attributes = Hashie::Mash.new(attributes)
30
- end
31
-
32
- def update(attributes = {})
33
- Billogram.client.put("/#{endpoint}/#{id}", attributes)
34
- end
35
-
36
- def delete
37
- Billogram.client.delete("/#{endpoint}/#{id}")
38
- end
39
-
40
- private
41
-
42
- def method_missing(method, *args)
43
- method_name = method.to_s
44
-
45
- if method_name =~ /(=|\?)$/
46
- case $1
47
- when '='
48
- attributes[$`] = args.first
49
- when '?'
50
- attributes[$`]
51
- end
52
- else
53
- if attributes.respond_to?(method)
54
- attributes[method]
55
- else
56
- super
57
- end
45
+ Hash(attributes).each do |key, value|
46
+ instance_variable_set("@#{key}", value) if respond_to?(key)
58
47
  end
48
+
49
+ RelationBuilder.new(self, attributes).call
59
50
  end
60
51
  end
61
52
  end
@@ -0,0 +1,5 @@
1
+ module Billogram
2
+ class Address < Resource
3
+ attr_accessor :street_address, :careof, :use_careof_as_attention, :zipcode, :city, :country
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Billogram
2
+ class Bookkeeping < Resource
3
+ attr_accessor :income_account, :vat_account
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ module Billogram
2
+ class Callback < Resource
3
+ attr_accessor :callback_id, :custom, :signature, :sandbox
4
+
5
+ relation :event, :one
6
+ relation :invoice, :one
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Billogram
2
+ class Contact < Resource
3
+ attr_accessor :name, :email, :phone
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module Billogram
2
+ class Customer < Resource
3
+ attr_accessor :customer_no, :name, :notes, :org_no, :vat_no, :created_at, :updated_at, :company_type
4
+
5
+ relation :address, :one
6
+ relation :contact, :one
7
+ relation :delivery_address, :one
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Billogram
2
+ class Data < Resource
3
+ attr_accessor :invoice_no, :delivery_method, :letter_id, :amount, :payer_name,
4
+ :banking_amount, :manual, :reminder_fee, :reminder_count, :interest_rate,
5
+ :customer_email, :ip, :type, :message, :collector_method, :collector_reference,
6
+ :factoring_method, :factoring_reference, :sells_for, :sold_for,
7
+ :total_sum, :remaining_sum, :scanning_central
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Billogram
2
+ class DeliveryAddress < Address
3
+ attr_accessor :name
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module Billogram
2
+ class Event < Resource
3
+ endpoint 'billogram_event'
4
+
5
+ attr_accessor :created_at, :type
6
+
7
+ relation :data, :one
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module Billogram
2
+ class Info < Resource
3
+ attr_accessor :order_no, :order_date, :our_reference, :your_reference,
4
+ :shipping_date, :delivery_date, :reference_number, :message
5
+ end
6
+ end
@@ -1,6 +1,19 @@
1
1
  module Billogram
2
- # https://billogram.com/api/documentation#billogram
3
2
  class Invoice < Resource
4
- self.endpoint = 'billogram'
3
+ endpoint 'billogram'
4
+
5
+ attr_accessor :id, :invoice_no, :ocr_number, :invoice_date, :due_date, :due_days,
6
+ :invoice_fee, :invoice_fee_vat, :reminder_fee, :interest_rate,
7
+ :interest_fee, :currency, :delivery_method, :state, :url, :flags,
8
+ :remaining_sum, :total_sum, :rounding_value, :automatic_reminders,
9
+ :reminder_count, :created_at, :attested_at, :updated_at, :detailed_sums,
10
+ :attachment
11
+
12
+ relation :info, :one
13
+ relation :customer, :one
14
+ relation :regional_sweden, :one
15
+
16
+ relation :items, :many
17
+ relation :events, :many
5
18
  end
6
19
  end
@@ -0,0 +1,8 @@
1
+ module Billogram
2
+ class Item < Resource
3
+ attr_accessor :item_no, :title, :description, :price, :vat, :unit, :created_at, :updated_at
4
+
5
+ relation :bookkeeping, :one
6
+ relation :regional_sweden, :one
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Billogram
2
+ class RegionalSweden < Resource
3
+ attr_accessor :rotavdrag, :rotavdrag_personal_number, :rotavdrag_description, :reversed_vat
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Billogram
2
- VERSION = "0.0.1"
2
+ VERSION = "0.2.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.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Birman
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2015-01-26 00:00:00.000000000 Z
11
+ date: 2015-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '1.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '1.10'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: fakeweb
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.3'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.3'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: httparty
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,35 +66,7 @@ dependencies:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: json
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: hashie
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- description: Ruby wrapper over Billogram API
69
+ description:
112
70
  email:
113
71
  - birmanmark@gmail.com
114
72
  executables: []
@@ -116,26 +74,33 @@ extensions: []
116
74
  extra_rdoc_files: []
117
75
  files:
118
76
  - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
119
79
  - Gemfile
120
80
  - LICENSE.txt
121
81
  - README.md
122
82
  - Rakefile
123
83
  - billogram.gemspec
84
+ - bin/console
85
+ - bin/setup
124
86
  - lib/billogram.rb
125
87
  - lib/billogram/client.rb
88
+ - lib/billogram/relation_builder.rb
126
89
  - lib/billogram/resource.rb
90
+ - lib/billogram/resources/address.rb
91
+ - lib/billogram/resources/bookkeeping.rb
92
+ - lib/billogram/resources/callback.rb
93
+ - lib/billogram/resources/contact.rb
94
+ - lib/billogram/resources/customer.rb
95
+ - lib/billogram/resources/data.rb
96
+ - lib/billogram/resources/delivery_address.rb
97
+ - lib/billogram/resources/event.rb
98
+ - lib/billogram/resources/info.rb
127
99
  - lib/billogram/resources/invoice.rb
100
+ - lib/billogram/resources/item.rb
101
+ - lib/billogram/resources/regional_sweden.rb
128
102
  - lib/billogram/version.rb
129
- - test/billogram_test.rb
130
- - test/fakeweb_helper.rb
131
- - test/resource_test.rb
132
- - test/resources/invoice_test.rb
133
- - test/stubs/errors/403
134
- - test/stubs/errors/404
135
- - test/stubs/invoice/index
136
- - test/stubs/invoice/show
137
- - test/test_helper.rb
138
- homepage: ''
103
+ homepage: http://github.com/mbirman/billogram
139
104
  licenses:
140
105
  - MIT
141
106
  metadata: {}
@@ -155,17 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
120
  version: '0'
156
121
  requirements: []
157
122
  rubyforge_project:
158
- rubygems_version: 2.2.2
123
+ rubygems_version: 2.4.8
159
124
  signing_key:
160
125
  specification_version: 4
161
- summary: Ruby wrapper over Billogram API
162
- test_files:
163
- - test/billogram_test.rb
164
- - test/fakeweb_helper.rb
165
- - test/resource_test.rb
166
- - test/resources/invoice_test.rb
167
- - test/stubs/errors/403
168
- - test/stubs/errors/404
169
- - test/stubs/invoice/index
170
- - test/stubs/invoice/show
171
- - test/test_helper.rb
126
+ summary: Simple ruby wrapper over Billogram API
127
+ test_files: []
@@ -1,26 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe Billogram do
4
- Billogram::CONFIG_KEYS.each do |method|
5
- it "should respond to #{method}" do
6
- Billogram.must_respond_to method
7
- end
8
- end
9
-
10
- describe '.configure' do
11
- it 'should set values' do
12
- Billogram.configure do |config|
13
- Billogram::CONFIG_KEYS.each do |method|
14
- config.send("#{method}=", method.to_s)
15
- Billogram.send(method).must_equal method.to_s
16
- end
17
- end
18
- end
19
- end
20
-
21
- describe '.client' do
22
- it 'should be instance of Billogram::Client' do
23
- Billogram.client.must_be_kind_of Billogram::Client
24
- end
25
- end
26
- end
@@ -1,31 +0,0 @@
1
- require 'fakeweb'
2
-
3
- def stub_file(stub)
4
- File.join(File.dirname(__FILE__), 'stubs', stub)
5
- end
6
-
7
- def fake_it_all
8
- FakeWeb.clean_registry
9
-
10
- {
11
- # GET URLs
12
- :get => {
13
- %r{https://\w+:\w+@billogram.com/api/v2/billogram/$} => File.join('invoice', 'index'),
14
- %r{https://\w+:\w+@billogram.com/api/v2/billogram/\w+} => File.join('invoice', 'show')
15
- },
16
- # POST URLs
17
- :post => {
18
- 'https://billogram.com/api/v2/billogram' => File.join('invoice', 'create'),
19
- %r{https://billogram.com/api/v2/\w+/command/send} => File.join('invoice', 'send')
20
- },
21
- # PUT URLs
22
- :put => {
23
- %r{https://billogram.com/api/v2/\w+} => File.join('invoice', 'update')
24
- }
25
- }.
26
- each do |method, requests|
27
- requests.each do |url, response|
28
- FakeWeb.register_uri(method, url, :response => stub_file(response))
29
- end
30
- end
31
- end
@@ -1,32 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe Billogram::Resource do
4
- describe '.endpoint' do
5
- it 'should set value' do
6
- Billogram::Resource.endpoint = 'test_endpoint'
7
- Billogram::Resource.endpoint.must_equal 'test_endpoint'
8
- end
9
-
10
- it 'should return downcased class name by default' do
11
- Billogram::Resource.endpoint = nil
12
- Billogram::Resource.endpoint.must_equal 'resource'
13
- end
14
- end
15
-
16
- describe '.new' do
17
- it 'should set attributes' do
18
- resource = Billogram::Resource.new({string_attribute: 'test', zero_attribute: 0, integer_attribute: 2, false_attribute: false, nil_attribute: nil})
19
- resource.string_attribute.must_equal 'test'
20
- resource.zero_attribute.must_equal 0
21
- resource.integer_attribute.must_equal 2
22
- resource.false_attribute.must_equal false
23
- resource.nil_attribute.must_equal nil
24
- end
25
- end
26
-
27
- it 'should have setters for attributes' do
28
- resource = Billogram::Resource.new({first: 'test'})
29
- resource.first = 'first'
30
- resource.first.must_equal 'first'
31
- end
32
- end
@@ -1,17 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe Billogram::Invoice do
4
- before(:each) do
5
- configure_billogram
6
- fake_it_all
7
- @billogram = Billogram::Invoice.get('gQjEEZL')
8
- end
9
-
10
- it 'should return an instance of Billogram::Invoice' do
11
- @billogram.must_be_kind_of Billogram::Invoice
12
- end
13
-
14
- it 'should return id' do
15
- @billogram.id.must_equal 'gQjEEZL'
16
- end
17
- end
@@ -1,9 +0,0 @@
1
- HTTP/1.1 403 FORBIDDEN
2
- Content-Type: application/json
3
-
4
- {
5
- "status" : "INVALID_AUTH",
6
- "data" : {
7
- "message" : "Invalid username or password"
8
- }
9
- }
@@ -1,9 +0,0 @@
1
- HTTP/1.1 404 NOT FOUND
2
- Content-Type: application/json
3
-
4
- {
5
- "status" : "NOT_FOUND",
6
- "data" : {
7
- "message" : "no billogram with id=DHjsdkO was found"
8
- }
9
- }
@@ -1,54 +0,0 @@
1
- HTTP/1.1 200 OK
2
- Content-Type: application/json
3
-
4
- {
5
- "status":"OK",
6
- "meta":{
7
- "total_count":171,
8
- "total_remaining_sum":"159145.00"
9
- },
10
- "data":[
11
- {
12
- "customer":{
13
- "name":"Happy customer",
14
- "email":null,
15
- "org_no":null,
16
- "customer_no":5
17
- },
18
- "due_date":"2014-11-01",
19
- "total_sum":3148.0,
20
- "created_at":"2014-10-19 21:32:12",
21
- "invoice_date":"2014-10-17",
22
- "updated_at":"2014-10-19 21:32:12",
23
- "currency":"SEK",
24
- "state":"Unattested",
25
- "remaining_sum":3148.0,
26
- "flags":[
27
- ],
28
- "ocr_number":null,
29
- "invoice_no":null,
30
- "id":"u9PQW3E"
31
- },
32
- {
33
- "customer":{
34
- "name":"Systembolaget",
35
- "email":"invoice@systembolaget.se",
36
- "org_no":"",
37
- "customer_no":1
38
- },
39
- "due_date":"2014-10-15",
40
- "total_sum":72269.0,
41
- "created_at":"2014-09-15 00:55:22",
42
- "invoice_date":"2014-09-15",
43
- "updated_at":"2014-09-15 01:07:19",
44
- "currency":"SEK",
45
- "state":"Unattested",
46
- "remaining_sum":72269.0,
47
- "flags":[
48
- ],
49
- "ocr_number":null,
50
- "invoice_no":null,
51
- "id":"EjWs4CP"
52
- }
53
- ]
54
- }
@@ -1,125 +0,0 @@
1
- HTTP/1.1 200 OK
2
- Content-Type: application/json
3
-
4
- {
5
- "status":"OK",
6
- "data":{
7
- "due_days":15,
8
- "info":{
9
- "reference_number":null,
10
- "our_reference":"John Doe",
11
- "order_no":"AIB033",
12
- "shipping_date":"2014-10-30",
13
- "order_date":"2014-10-24",
14
- "message":"Thank you!",
15
- "delivery_date":"2014-10-30",
16
- "your_reference":""
17
- },
18
- "attested_at":"2014-10-24 07:30:45",
19
- "updated_at":"2015-01-23 23:44:17",
20
- "currency":"SEK",
21
- "detailed_sums":{
22
- "credited_sum":0,
23
- "net_sum":445,
24
- "gross_sum":556.25,
25
- "invoice_fee_vat":0,
26
- "paid_sum":0,
27
- "interest_fee":0,
28
- "vat_sum":111.25,
29
- "reminder_fee":0,
30
- "invoice_fee":0,
31
- "rounding":-0.25,
32
- "regional_sweden":{
33
- "rotavdrag_sum":0
34
- },
35
- "collector_paid_sum":0,
36
- "remaining_sum":556
37
- },
38
- "id":"gQjEEZL",
39
- "reminder_fee":"50",
40
- "interest_rate":8.5,
41
- "state":"Overdue",
42
- "attachment":null,
43
- "automatic_reminders":false,
44
- "rounding_value":-0.25,
45
- "ocr_number":"6409920018890569",
46
- "events":[
47
- {
48
- "type":"BillogramCreated",
49
- "created_at":"2014-10-24 07:30:42",
50
- "data":null
51
- },
52
- {
53
- "type":"BillogramSent",
54
- "created_at":"2014-10-24 07:30:45",
55
- "data":{
56
- "letter_id":"Tk5NTQzQxNjQ14bccc9e8c0YTAwMjRmMGM3NANc8131024c90a0d24b1fc73",
57
- "total_sum":556,
58
- "scanning_central":null,
59
- "remaining_sum":556,
60
- "delivery_method":"Letter",
61
- "invoice_no":190
62
- }
63
- },
64
- {
65
- "type":"Overdue",
66
- "created_at":"2014-11-08 23:00:00",
67
- "data":{
68
- "remaining_sum":"556.00"
69
- }
70
- }
71
- ],
72
- "due_date":"2014-11-08",
73
- "invoice_fee_vat":0,
74
- "invoice_date":"2014-10-24",
75
- "reminder_count":0,
76
- "interest_fee":0.0,
77
- "invoice_no":190,
78
- "customer":{
79
- "name":"Cool Customer",
80
- "vat_no":null,
81
- "phone":"+46 40 44 65 787",
82
- "customer_no":3,
83
- "address":{
84
- "city":"",
85
- "country":"SE",
86
- "attention":"",
87
- "zipcode":"62156",
88
- "careof":"",
89
- "street_address":"Schweitzergr\u00e4nd 10A"
90
- },
91
- "email":null,
92
- "org_no":null
93
- },
94
- "invoice_fee":0,
95
- "url":"https://billogram.com/r/2001905699988640/N9PCC4",
96
- "items":[
97
- {
98
- "count":5.0,
99
- "item_no":"110-1",
100
- "description":"75cl Bigger Lager 7,5% - Imperial Pilsner - All In Brewing/Toccalmatto",
101
- "title":"Bigger Lager 7,5% 75cl",
102
- "regional_sweden":{
103
- "rotavdrag":false
104
- },
105
- "price":89.0,
106
- "discount":0.0,
107
- "unit":"unit",
108
- "vat":25
109
- }
110
- ],
111
- "created_at":"2014-10-24 07:30:42",
112
- "total_sum":556.0,
113
- "delivery_method":"Letter",
114
- "remaining_sum":556.0,
115
- "flags":[
116
-
117
- ],
118
- "regional_sweden":{
119
- "rotavdrag_personal_number":null,
120
- "rotavdrag":0,
121
- "reversed_vat":null,
122
- "rotavdrag_description":null
123
- }
124
- }
125
- }
data/test/test_helper.rb DELETED
@@ -1,14 +0,0 @@
1
- require './lib/billogram'
2
- require 'minitest/autorun'
3
- require 'minitest/spec'
4
- require 'fakeweb_helper.rb'
5
-
6
- FakeWeb.allow_net_connect = false
7
-
8
- def configure_billogram
9
- Billogram.configure do |config|
10
- config.base_url = 'https://billogram.com/api/v2/'
11
- config.api_user = 'username'
12
- config.api_key = 'password'
13
- end
14
- end