pe_accounting 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/bin/console +2 -1
- data/lib/pe_accounting.rb +1 -0
- data/lib/pe_accounting/client.rb +16 -21
- data/lib/pe_accounting/helpers.rb +24 -0
- data/lib/pe_accounting/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8eadbdc0a1d1955ba945cfce651f806134e176ef
|
4
|
+
data.tar.gz: 66bdd63cebe537836bde71d5e48fce5f73cb8365
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f41e9f6d88b0a2a5948a700489856691ed023e00f59fbb7f11574c5b625c5ccf4eab823f89633bd2234a5b286cf3fd9a375c31d7a07f97c73cff666a90d3e74
|
7
|
+
data.tar.gz: d66104433bf5b75e1d3e46fd2aaef276467308f56d6aed9908610f79fb5d8b342defee37850b3d2895451d6042893a8aaf727c8bf4a71f8a6609ddacbdd74e30
|
data/Gemfile
CHANGED
data/bin/console
CHANGED
data/lib/pe_accounting.rb
CHANGED
data/lib/pe_accounting/client.rb
CHANGED
@@ -45,7 +45,7 @@ module PeAccounting
|
|
45
45
|
|
46
46
|
# Performs a PUT request
|
47
47
|
#
|
48
|
-
# @param request [String]
|
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
|
-
|
119
|
-
|
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
|
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.
|
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-
|
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
|