moloni_api 0.1.3 → 0.1.4
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 +4 -4
- data/.irbrc +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -1
- data/Rakefile +5 -2
- data/lib/moloni_api/api.rb +3 -3
- data/lib/moloni_api/client.rb +24 -13
- data/lib/moloni_api/configuration.rb +4 -2
- data/lib/moloni_api/models/product.rb +22 -19
- data/lib/moloni_api/version.rb +1 -1
- data/moloni_api.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d4ce20574d9044023df19c350c588d21ff192530da34e92b20185c70cf9fffe3
|
|
4
|
+
data.tar.gz: e40027e3826ea130df3e9f8ab435522958eb549232dc85c87e883c004c7daa93
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0c94ad5acf50457127342b81d97f463a4874ea417232ff25dc954b3b69da1fe8338f4a533af16baf422577f7b3949ccf7b84f79fc3da050b2a12084949a79e37
|
|
7
|
+
data.tar.gz: 0f84659d5f1183ec4b4d75c0c6bf5eaa7ec1ffa2e86dfcaf2ef13c1bd4fc488646b2852df2b80c2764d5a5d4f65a35c2ac358a2222b591723ced38cc204241c3
|
data/.irbrc
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# MoloniApi
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
3
5
|
Implementation of the [Moloni API](https://www.moloni.pt/dev/endpoints/).
|
|
4
6
|
It's still a rough draft but already usable.
|
|
5
7
|
I will be adding more method implementation but it should be easy for anyone to add new methods (Pull Requests are welcome!).
|
|
@@ -38,7 +40,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
38
40
|
|
|
39
41
|
## Contributing
|
|
40
42
|
|
|
41
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/dlage/
|
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dlage/moloni_api_gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/dlage/moloni_api_gem/blob/master/CODE_OF_CONDUCT.md).
|
|
42
44
|
|
|
43
45
|
## License
|
|
44
46
|
|
data/Rakefile
CHANGED
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
require 'bundler/gem_tasks'
|
|
4
4
|
require 'rspec/core/rake_task'
|
|
5
5
|
|
|
6
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
7
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
|
8
|
+
end
|
|
7
9
|
|
|
8
10
|
require 'rubocop/rake_task'
|
|
9
11
|
|
|
10
12
|
RuboCop::RakeTask.new
|
|
11
13
|
|
|
12
|
-
task default: %i[spec rubocop]
|
|
14
|
+
# task default: %i[spec rubocop]
|
|
15
|
+
task default: %i[spec]
|
data/lib/moloni_api/api.rb
CHANGED
|
@@ -6,8 +6,8 @@ require_relative 'constants'
|
|
|
6
6
|
require_relative 'http_status_codes'
|
|
7
7
|
require 'json'
|
|
8
8
|
|
|
9
|
+
# Core class responsible for api interface operations
|
|
9
10
|
module MoloniApi
|
|
10
|
-
# Core class responsible for api interface operations
|
|
11
11
|
class API
|
|
12
12
|
include ApiExceptions
|
|
13
13
|
include Constants
|
|
@@ -86,7 +86,7 @@ module MoloniApi
|
|
|
86
86
|
req.body = params.to_json if params.size
|
|
87
87
|
end
|
|
88
88
|
logger = Logger.new $stderr
|
|
89
|
-
logger.debug(
|
|
89
|
+
logger.debug("Response: #{response.body}")
|
|
90
90
|
|
|
91
91
|
if response_successful?(response)
|
|
92
92
|
parsed_response = Oj.load(response.body)
|
|
@@ -115,7 +115,7 @@ module MoloniApi
|
|
|
115
115
|
# :nodoc:
|
|
116
116
|
case method_name.to_s
|
|
117
117
|
when /^(.*)\?$/
|
|
118
|
-
|
|
118
|
+
!send(Regexp.last_match(1).to_s).nil?
|
|
119
119
|
when /^clear_(.*)$/
|
|
120
120
|
send("#{Regexp.last_match(1)}=", nil)
|
|
121
121
|
else
|
data/lib/moloni_api/client.rb
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'logger'
|
|
5
5
|
require_relative 'api'
|
|
6
|
-
require_relative 'models/product'
|
|
6
|
+
# require_relative 'models/product'
|
|
7
7
|
|
|
8
|
+
# Main client class that implements communication with the API
|
|
8
9
|
module MoloniApi
|
|
9
|
-
# Main client class that implements communication with the API
|
|
10
10
|
# other_params - view documentation for additional options:
|
|
11
11
|
# https://www.moloni.pt/dev/endpoints/
|
|
12
12
|
# - qty
|
|
@@ -16,7 +16,6 @@ module MoloniApi
|
|
|
16
16
|
# - json
|
|
17
17
|
# - human_errors
|
|
18
18
|
class Client < API
|
|
19
|
-
|
|
20
19
|
attr_accessor :api_access_token, :api_refresh_token
|
|
21
20
|
|
|
22
21
|
def authenticate(user_username, user_password)
|
|
@@ -35,7 +34,7 @@ module MoloniApi
|
|
|
35
34
|
res = process_response(response)
|
|
36
35
|
self.api_access_token = res[:access_token]
|
|
37
36
|
self.api_refresh_token = res[:refresh_token]
|
|
38
|
-
|
|
37
|
+
res
|
|
39
38
|
end
|
|
40
39
|
|
|
41
40
|
def renew_token(refresh_token = nil)
|
|
@@ -52,12 +51,12 @@ module MoloniApi
|
|
|
52
51
|
)
|
|
53
52
|
res = process_response(response)
|
|
54
53
|
@api_access_token = res[:access_token]
|
|
55
|
-
|
|
54
|
+
res
|
|
56
55
|
end
|
|
57
56
|
|
|
58
57
|
def companies(other_params: {})
|
|
59
58
|
response = request(
|
|
60
|
-
http_method: :
|
|
59
|
+
http_method: :post,
|
|
61
60
|
endpoint: 'companies/getAll/',
|
|
62
61
|
query_params: other_params
|
|
63
62
|
)
|
|
@@ -73,7 +72,7 @@ module MoloniApi
|
|
|
73
72
|
company_id: company_id,
|
|
74
73
|
customer_id: customer_id,
|
|
75
74
|
your_reference: your_reference,
|
|
76
|
-
our_reference: our_reference
|
|
75
|
+
our_reference: our_reference
|
|
77
76
|
}.merge(other_params)
|
|
78
77
|
)
|
|
79
78
|
process_response(response)
|
|
@@ -87,7 +86,7 @@ module MoloniApi
|
|
|
87
86
|
company_id: company_id,
|
|
88
87
|
customer_id: customer_id,
|
|
89
88
|
your_reference: your_reference,
|
|
90
|
-
our_reference: our_reference
|
|
89
|
+
our_reference: our_reference
|
|
91
90
|
}.merge(other_params)
|
|
92
91
|
)
|
|
93
92
|
process_response(response)
|
|
@@ -101,7 +100,7 @@ module MoloniApi
|
|
|
101
100
|
company_id: company_id,
|
|
102
101
|
customer_id: customer_id,
|
|
103
102
|
your_reference: your_reference,
|
|
104
|
-
our_reference: our_reference
|
|
103
|
+
our_reference: our_reference
|
|
105
104
|
}.merge(other_params)
|
|
106
105
|
)
|
|
107
106
|
process_response(response)
|
|
@@ -131,6 +130,18 @@ module MoloniApi
|
|
|
131
130
|
process_response(response)
|
|
132
131
|
end
|
|
133
132
|
|
|
133
|
+
# economicActivityClassificationCodes/getAll/
|
|
134
|
+
def economic_activity_classification_codes(company_id, other_params: {})
|
|
135
|
+
response = request(
|
|
136
|
+
http_method: :post,
|
|
137
|
+
endpoint: 'economicActivityClassificationCodes/getAll/',
|
|
138
|
+
params: {
|
|
139
|
+
company_id: company_id
|
|
140
|
+
}
|
|
141
|
+
)
|
|
142
|
+
process_response(response)
|
|
143
|
+
end
|
|
144
|
+
|
|
134
145
|
# customers/getByNumber/
|
|
135
146
|
def customers_getByNumber(company_id, customer_number)
|
|
136
147
|
response = request(
|
|
@@ -138,7 +149,7 @@ module MoloniApi
|
|
|
138
149
|
endpoint: 'customers/getByNumber/',
|
|
139
150
|
params: {
|
|
140
151
|
company_id: company_id,
|
|
141
|
-
number: customer_number
|
|
152
|
+
number: customer_number
|
|
142
153
|
}
|
|
143
154
|
)
|
|
144
155
|
process_response(response)
|
|
@@ -224,7 +235,7 @@ module MoloniApi
|
|
|
224
235
|
endpoint: 'products/getBySearch/',
|
|
225
236
|
params: {
|
|
226
237
|
company_id: company_id,
|
|
227
|
-
search: search_str
|
|
238
|
+
search: search_str
|
|
228
239
|
}.merge(other_params)
|
|
229
240
|
)
|
|
230
241
|
process_response(response)
|
|
@@ -236,7 +247,7 @@ module MoloniApi
|
|
|
236
247
|
endpoint: 'products/getByReference/',
|
|
237
248
|
params: {
|
|
238
249
|
company_id: company_id,
|
|
239
|
-
reference: reference
|
|
250
|
+
reference: reference
|
|
240
251
|
}.merge(other_params)
|
|
241
252
|
)
|
|
242
253
|
process_response(response)
|
|
@@ -298,7 +309,7 @@ module MoloniApi
|
|
|
298
309
|
case result
|
|
299
310
|
when Hash
|
|
300
311
|
result.transform_keys!(&:to_sym)
|
|
301
|
-
result.
|
|
312
|
+
result.each_value do |r|
|
|
302
313
|
process_response(r)
|
|
303
314
|
end
|
|
304
315
|
when Array
|
|
@@ -7,6 +7,8 @@ module MoloniApi
|
|
|
7
7
|
# Stores the configuration
|
|
8
8
|
class Configuration < API::Config
|
|
9
9
|
API_ENDPOINT = 'https://api.moloni.pt/sandbox/'
|
|
10
|
+
API_CLIENT_ID = 'apigem'
|
|
11
|
+
API_CLIENT_SECRET = 'c9c9f4274658da2ad78b55a452894942898b5614'
|
|
10
12
|
|
|
11
13
|
property :follow_redirects, default: true
|
|
12
14
|
|
|
@@ -28,7 +30,7 @@ module MoloniApi
|
|
|
28
30
|
property :stack
|
|
29
31
|
|
|
30
32
|
property :api_access_token
|
|
31
|
-
property :api_client_id, default: ENV['MOLONI_API_CLIENT_ID']
|
|
32
|
-
property :api_client_secret, default: ENV['MOLONI_API_CLIENT_SECRET']
|
|
33
|
+
property :api_client_id, default: ENV['MOLONI_API_CLIENT_ID'] || API_CLIENT_ID
|
|
34
|
+
property :api_client_secret, default: ENV['MOLONI_API_CLIENT_SECRET'] || API_CLIENT_SECRET
|
|
33
35
|
end
|
|
34
36
|
end
|
|
@@ -1,39 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module MoloniApi
|
|
2
4
|
module Models
|
|
5
|
+
# Model to map product
|
|
3
6
|
class Product
|
|
4
7
|
##
|
|
5
8
|
# company_id int
|
|
6
|
-
#
|
|
9
|
+
# Mandatory
|
|
7
10
|
#
|
|
8
11
|
# category_id int
|
|
9
|
-
#
|
|
12
|
+
# Mandatory
|
|
10
13
|
#
|
|
11
14
|
# type int
|
|
12
|
-
#
|
|
15
|
+
# Mandatory
|
|
13
16
|
#
|
|
14
17
|
# name string
|
|
15
|
-
#
|
|
18
|
+
# Mandatory
|
|
16
19
|
#
|
|
17
20
|
# summary string
|
|
18
21
|
# Facultativo
|
|
19
22
|
#
|
|
20
23
|
# reference string
|
|
21
|
-
#
|
|
24
|
+
# Mandatory
|
|
22
25
|
#
|
|
23
26
|
# ean string
|
|
24
27
|
# Facultativo
|
|
25
28
|
#
|
|
26
29
|
# price float
|
|
27
|
-
#
|
|
30
|
+
# Mandatory
|
|
28
31
|
#
|
|
29
32
|
# unit_id int
|
|
30
|
-
#
|
|
33
|
+
# Mandatory
|
|
31
34
|
#
|
|
32
35
|
# has_stock int
|
|
33
|
-
#
|
|
36
|
+
# Mandatory
|
|
34
37
|
#
|
|
35
38
|
# stock float
|
|
36
|
-
#
|
|
39
|
+
# Mandatory
|
|
37
40
|
#
|
|
38
41
|
# minimum_stock float
|
|
39
42
|
# Facultativo
|
|
@@ -51,25 +54,25 @@ module MoloniApi
|
|
|
51
54
|
# Facultativo
|
|
52
55
|
#
|
|
53
56
|
# tax_id int
|
|
54
|
-
#
|
|
57
|
+
# Mandatory
|
|
55
58
|
#
|
|
56
59
|
# value float
|
|
57
|
-
#
|
|
60
|
+
# Mandatory
|
|
58
61
|
#
|
|
59
62
|
# order int
|
|
60
|
-
#
|
|
63
|
+
# Mandatory
|
|
61
64
|
#
|
|
62
65
|
# cumulative int
|
|
63
|
-
#
|
|
66
|
+
# Mandatory
|
|
64
67
|
#
|
|
65
68
|
# suppliers array
|
|
66
69
|
# Facultativo
|
|
67
70
|
#
|
|
68
71
|
# supplier_id int
|
|
69
|
-
#
|
|
72
|
+
# Mandatory
|
|
70
73
|
#
|
|
71
74
|
# cost_price float
|
|
72
|
-
#
|
|
75
|
+
# Mandatory
|
|
73
76
|
#
|
|
74
77
|
# referenceint
|
|
75
78
|
# Facultativo
|
|
@@ -78,19 +81,19 @@ module MoloniApi
|
|
|
78
81
|
# Facultativo
|
|
79
82
|
#
|
|
80
83
|
# property_id int
|
|
81
|
-
#
|
|
84
|
+
# Mandatory
|
|
82
85
|
#
|
|
83
86
|
# value string
|
|
84
|
-
#
|
|
87
|
+
# Mandatory
|
|
85
88
|
#
|
|
86
89
|
# warehouses array
|
|
87
90
|
# Facultativo
|
|
88
91
|
#
|
|
89
92
|
# warehouse_id int
|
|
90
|
-
#
|
|
93
|
+
# Mandatory
|
|
91
94
|
#
|
|
92
95
|
# stock float
|
|
93
|
-
#
|
|
96
|
+
# Mandatory
|
|
94
97
|
def initialize(raw_result)
|
|
95
98
|
@raw_result = raw_result
|
|
96
99
|
|
data/lib/moloni_api/version.rb
CHANGED
data/moloni_api.gemspec
CHANGED
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
|
14
14
|
spec.license = 'MIT'
|
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
|
16
16
|
|
|
17
|
-
spec.metadata['allowed_push_host'] =
|
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
18
18
|
|
|
19
19
|
spec.metadata['homepage_uri'] = spec.homepage
|
|
20
20
|
spec.metadata['source_code_uri'] = 'https://github.com/dlage/moloni_api_gem'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: moloni_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dinis
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-10-
|
|
11
|
+
date: 2022-10-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|