pe_accounting 0.3.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 846d79de6e9ca386cd4a9b42099687a158865524
4
- data.tar.gz: 7c78c8124ffdf7c3964538dacb6fe76d1c60a4c9
3
+ metadata.gz: 8eadbdc0a1d1955ba945cfce651f806134e176ef
4
+ data.tar.gz: 66bdd63cebe537836bde71d5e48fce5f73cb8365
5
5
  SHA512:
6
- metadata.gz: 3d2ad909081085b647d2f8b75bb0dd10359cd14efa900ede39c6a6d4b286616e80e3ff9ee0fa34a998410c6370b48c8aba524b66f8229323cc2fb473703abd51
7
- data.tar.gz: aed1983fa8f54c2f19189e8dbafca3641246a4c81671cfb539ae84138003dbe659508ba33c698d59e2cf3821758541809a26e95f96d6988fc8fba5443f5d5ad2
6
+ metadata.gz: 1f41e9f6d88b0a2a5948a700489856691ed023e00f59fbb7f11574c5b625c5ccf4eab823f89633bd2234a5b286cf3fd9a375c31d7a07f97c73cff666a90d3e74
7
+ data.tar.gz: d66104433bf5b75e1d3e46fd2aaef276467308f56d6aed9908610f79fb5d8b342defee37850b3d2895451d6042893a8aaf727c8bf4a71f8a6609ddacbdd74e30
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in peaccounting-client.gemspec
3
+ # Specify your gem's dependencies in pe_accounting.gemspec
4
4
  gemspec
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "pe_accounting/client"
4
+ require "pe_accounting"
5
+
5
6
 
6
7
  require "irb"
7
8
  IRB.start(__FILE__)
@@ -1 +1,2 @@
1
1
  require 'pe_accounting/client'
2
+ require 'pe_accounting/helpers'
@@ -45,7 +45,7 @@ module PeAccounting
45
45
 
46
46
  # Performs a PUT request
47
47
  #
48
- # @param request [String] opts = {} The options to pass to the method
48
+ # @param request [String] The options to pass to the method
49
49
  # @param payload [Hash] A native Ruby hash describing the data to send
50
50
  # @param root [String] The enclosing root of the object (useful for xml)
51
51
  # @return [Hash] A hash containing the result of the request
@@ -87,25 +87,27 @@ module PeAccounting
87
87
  request(:delete, uri(request))
88
88
  end
89
89
 
90
+ # Public for debugging purposes
91
+ def generate_payload(payload)
92
+ if @format == :xml
93
+ Gyoku.xml(payload)
94
+ else
95
+ MultiJson.dump(payload)
96
+ end
97
+ end
98
+
90
99
  private
91
100
 
92
101
  def uri(path)
93
102
  URI.parse("#{@endpoint}company/#{@company_id}/#{path}")
94
103
  end
95
104
 
105
+ # Unused for now, but can be useful for object editing if we go more high-level
96
106
  def denilize(h)
97
107
  h.each_with_object({}) { |(k,v),g|
98
108
  g[k] = (Hash === v) ? denilize(v) : v ? v : '' }
99
109
  end
100
110
 
101
- def generate_payload(payload)
102
- if @format == :xml
103
- Gyoku.xml(payload)
104
- else
105
- MultiJson.dump(payload)
106
- end
107
- end
108
-
109
111
  def handle_body(body)
110
112
  if @format == :xml
111
113
  parser = Nori.new(convert_dashes_to_underscores: false,
@@ -115,11 +117,13 @@ module PeAccounting
115
117
  hash = MultiJson.load(body)
116
118
  end
117
119
 
118
- while hash.is_a?(Hash) && hash.length == 1
119
- hash = hash.values.first
120
+ # Try to get a more proper ruby object when doing JSON
121
+ if @format == :json
122
+ while hash.is_a?(Hash) && hash.length == 1
123
+ hash = hash.values.first
124
+ end
120
125
  end
121
126
  hash
122
-
123
127
  end
124
128
 
125
129
  def request(method, uri, payload = nil)
@@ -139,14 +143,5 @@ module PeAccounting
139
143
  raise PeAccouningError, (res.read_body ? handle_body(res.body) : res)
140
144
  end
141
145
  end
142
-
143
- # Converts a File to its hexadecimal representation
144
- #
145
- # @param f [File] A binary file.
146
- # @return [String] A string representing the file in hexadecimal form.
147
- def file_to_hex(f)
148
- f.read.unpack('H*').first
149
- end
150
-
151
146
  end
152
147
  end
@@ -0,0 +1,24 @@
1
+ module PeAccounting
2
+ refine Object do
3
+ def file(name, file)
4
+ return {
5
+ "filename": name,
6
+ "data": file_to_hex(file)
7
+ }
8
+ end
9
+
10
+ def date(datetime)
11
+ datetime.strftime("%Y-%m-%d")
12
+ end
13
+
14
+ private
15
+
16
+ # Converts a File to its hexadecimal representation
17
+ #
18
+ # @param f [File] A binary file.
19
+ # @return [String] A string representing the file in hexadecimal form.
20
+ def file_to_hex(f)
21
+ f.unpack('H*').first
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module PeAccounting
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pe_accounting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehdi Rejraji
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-02 00:00:00.000000000 Z
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -115,6 +115,7 @@ files:
115
115
  - bin/setup
116
116
  - lib/pe_accounting.rb
117
117
  - lib/pe_accounting/client.rb
118
+ - lib/pe_accounting/helpers.rb
118
119
  - lib/pe_accounting/version.rb
119
120
  - pe_accounting.gemspec
120
121
  homepage: https://github.com/ridem/pe-accounting-ruby-client