pe_accounting 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cde00eb1f7da6b0b3273b8b44988b292a68e96ff
4
+ data.tar.gz: 6d63ce0048c516e31b6f2faa0040c0b07f5ba215
5
+ SHA512:
6
+ metadata.gz: afd51489f1f8dc8b6fee09036985af1412faa0acb205c47e24b3483e3d27a01263d6080582a1eeba215cbe743f1f61eab7507b5f248b10f594c4619f7a3e5ac6
7
+ data.tar.gz: b7554759568b140c0ff0c142d6a9ba5a1d0278b1d91aa38ad74aeaee7206a9e87443d3b9769b5c5a005e3a188b4c43e81ea89de5f6d3a186a04d0832c0c19758
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in peaccounting-client.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2017 Mehdi Rejraji
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # PeAccounting::Client
2
+
3
+ A simple low-level wrapper for PE Accounting's public API.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'pe_accounting'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install pe_accounting
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ 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).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ridem/pe-accounting-ruby-client.
35
+
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pe_accounting/client"
5
+
6
+ require "irb"
7
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1 @@
1
+ require 'pe_accounting/client'
@@ -0,0 +1,64 @@
1
+ require 'rest-client'
2
+ require 'multi_json'
3
+
4
+ module PeAccounting
5
+ class PeAccouningError < StandardError; end
6
+
7
+ class Client
8
+ def initialize(token, endpoint = 'https://my.accounting.pe/api/v1/')
9
+ @token = token
10
+ @endpoint = endpoint
11
+ end
12
+
13
+ def get(kwargs = {})
14
+ unless kwargs[:company_id] && kwargs[:request]
15
+ raise PeAccouningError, 'You must specify a Company ID and a request'
16
+ end
17
+
18
+ request(:get, url(kwargs[:company_id], kwargs[:request]))
19
+ end
20
+
21
+ def put(kwargs = {})
22
+ unless kwargs[:company_id] && kwargs[:request] && kwargs[:payload]
23
+ raise PeAccouningError, 'You must specify a company_id, a request, and a payload'
24
+ end
25
+ request(:put, url(kwargs[:company_id], kwargs[:request]),
26
+ kwargs[:payload])
27
+ end
28
+
29
+ def post(kwargs = {})
30
+ unless kwargs[:company_id] && kwargs[:request] && kwargs[:payload]
31
+ raise PeAccouningError, 'You must specify a company_id, a request, and a payload'
32
+ end
33
+
34
+ request(:post, url(kwargs[:company_id], kwargs[:request]),
35
+ kwargs[:payload])
36
+ end
37
+
38
+ def delete(kwargs = {})
39
+ unless kwargs[:company_id] && kwargs[:request]
40
+ raise PeAccouningError, 'You must specify a Company ID and a request'
41
+ end
42
+ request(:delete, url(kwargs[:company_id], kwargs[:request]))
43
+ end
44
+
45
+ private
46
+
47
+ def url(company_id, path)
48
+ "#{@endpoint}company/#{company_id}/#{path}"
49
+ end
50
+
51
+ def request(method, url, payload = nil)
52
+ res = RestClient::Request.execute(method: method, url: url,
53
+ payload: MultiJson.dump(payload),
54
+ headers: { content_type: :json,
55
+ x_token: @token })
56
+ hash = MultiJson.load(res.body)
57
+ hash.length == 1 ? hash.values.first : hash
58
+ end
59
+
60
+ def file_to_json(file)
61
+ file.read.each_byte.map { |b| b.to_s(16) }.to_json
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ module PeAccounting
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pe_accounting/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'pe_accounting'
8
+ spec.version = PeAccounting::VERSION
9
+ spec.author = 'Mehdi Rejraji'
10
+ spec.email = 'mehdi.rejraji@gmail.com'
11
+
12
+ spec.summary = "A simple Ruby wrapper for PE Accounting's public API."
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = 'https://github.com/ridem/pe-accounting-ruby-client'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ spec.bindir = 'bin'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.14'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_runtime_dependency 'multi_json', '~> 1.3', '>= 1.3.0'
28
+ spec.add_runtime_dependency 'rest-client', '~> 2.0'
29
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pe_accounting
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mehdi Rejraji
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-31 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.3.0
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.3'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.3.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: rest-client
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.0'
75
+ description:
76
+ email: mehdi.rejraji@gmail.com
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - ".gitignore"
82
+ - Gemfile
83
+ - LICENSE.md
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/pe_accounting.rb
89
+ - lib/pe_accounting/client.rb
90
+ - lib/pe_accounting/version.rb
91
+ - pe_accounting.gemspec
92
+ homepage: https://github.com/ridem/pe-accounting-ruby-client
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.5.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A simple Ruby wrapper for PE Accounting's public API.
116
+ test_files: []