moloni_api 0.1.1 → 0.1.3

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
  SHA256:
3
- metadata.gz: 2cc0888f69d92fa88c0a05fa447f841f29289b2e8ab44ed9a22e446d2a1155b2
4
- data.tar.gz: 0f40cc723684575b0659735e85a4793d4abe218dd5d246006fc7f09f9d3c0acb
3
+ metadata.gz: 74d28c5f93cc5740ba6cf9f0af4937b931701c0b8914f795a5f888275b119bf3
4
+ data.tar.gz: 87d99c68508f7cb982f97e8b561f53620ae993509fd95ab3ed7ade1c31b0e8f8
5
5
  SHA512:
6
- metadata.gz: ad88efc407714ef37b5a1e7659d0b868565df5d83f58aea2c456c5cbbb1b85c231fba5962acfa77d13915c14195ddad054a4a92a1483f90a32c11943ba0ac25b
7
- data.tar.gz: '0739379b6fe2beb1c62c30316d7827f3bc6b6091da77919223f2717fcc6decd64ab83477cfa1c082b6fc438a279996742992a762a0bc6b059f98c71612096d63'
6
+ metadata.gz: d59fa669a82f34f31b520a340aaa245d2236d1b253e73d70f7c00cf9470cbb02fc938e227e1df92115196136b762e4cd2bf7705460f49a1075a005baac073de1
7
+ data.tar.gz: 28e247ea912108102b9725adba774564b5354c0840f5933573f903139a305d07b2e12ce010061465e39f94908ae36c5ac14dd301d26de679002d0938d07aebf4
data/.gitignore CHANGED
@@ -16,3 +16,5 @@ moloni_api.iml
16
16
 
17
17
  # custom ignores
18
18
  .env
19
+ *.gem
20
+ /.irb_history
data/.irbrc ADDED
@@ -0,0 +1,5 @@
1
+ require 'irb'
2
+ require 'irb/completion'
3
+ require 'rubygems'
4
+ require 'pp'
5
+ IRB.conf[:SAVE_HISTORY] = 300
data/Dockerfile CHANGED
@@ -3,6 +3,7 @@ FROM ruby:3.0
3
3
  WORKDIR /usr/src/app
4
4
 
5
5
  COPY Gemfile .
6
+ COPY Gemfile.lock .
6
7
  COPY moloni_api.gemspec .
7
8
  COPY lib/moloni_api/version.rb lib/moloni_api/version.rb
8
9
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- moloni_api (0.1.0)
4
+ moloni_api (0.1.2)
5
5
  faraday (~> 1.3.0)
6
6
  oj (~> 3.11)
7
7
 
@@ -15,14 +15,14 @@ GEM
15
15
  rexml
16
16
  diff-lcs (1.4.4)
17
17
  dotenv (2.7.6)
18
- faraday (1.3.0)
18
+ faraday (1.3.1)
19
19
  faraday-net_http (~> 1.0)
20
20
  multipart-post (>= 1.2, < 3)
21
- ruby2_keywords
21
+ ruby2_keywords (>= 0.0.4)
22
22
  faraday-net_http (1.0.1)
23
23
  hashdiff (1.0.1)
24
- multipart-post (2.1.1)
25
- oj (3.11.3)
24
+ multipart-post (2.2.3)
25
+ oj (3.13.21)
26
26
  parallel (1.20.1)
27
27
  parser (3.0.0.0)
28
28
  ast (~> 2.4.1)
@@ -56,7 +56,7 @@ GEM
56
56
  rubocop-ast (1.4.1)
57
57
  parser (>= 2.7.1.5)
58
58
  ruby-progressbar (1.11.0)
59
- ruby2_keywords (0.0.4)
59
+ ruby2_keywords (0.0.5)
60
60
  unicode-display_width (1.7.0)
61
61
  vcr (6.0.0)
62
62
  webmock (3.12.2)
data/README.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # MoloniApi
2
2
 
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/moloni_api`. 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
3
+ Implementation of the [Moloni API](https://www.moloni.pt/dev/endpoints/).
4
+ It's still a rough draft but already usable.
5
+ I will be adding more method implementation but it should be easy for anyone to add new methods (Pull Requests are welcome!).
6
+ There's already a mix of methods implemented to:
7
+ - Get and insert Customers
8
+ - Get Products
9
+ - Get and create some Documents
10
+ - Get Payment Methods
11
+ Moloni's API is quite extensive, reason why I didn't implement methods for all endpoints, yet.
6
12
 
7
13
  ## Installation
8
14
 
@@ -32,7 +38,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
38
 
33
39
  ## Contributing
34
40
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/moloni_api. 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/[USERNAME]/moloni_api/blob/master/CODE_OF_CONDUCT.md).
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dlage/moloni_api. 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/blob/master/CODE_OF_CONDUCT.md).
36
42
 
37
43
  ## License
38
44
 
@@ -40,4 +46,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
46
 
41
47
  ## Code of Conduct
42
48
 
43
- Everyone interacting in the MoloniApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/moloni_api/blob/master/CODE_OF_CONDUCT.md).
49
+ Everyone interacting in the MoloniApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dlage/moloni_api/blob/master/CODE_OF_CONDUCT.md).
@@ -13,7 +13,7 @@ module MoloniApi
13
13
  include Constants
14
14
  include HttpStatusCodes
15
15
 
16
- attr_reader(*MoloniApi.configuration.property_names, :token, :endpoint)
16
+ attr_reader(*MoloniApi.configuration.property_names)
17
17
 
18
18
  attr_accessor :current_options
19
19
 
@@ -27,7 +27,6 @@ module MoloniApi
27
27
  end
28
28
  end
29
29
 
30
- API_ENDPOINT = 'https://api.moloni.pt/sandbox/'
31
30
  HTTP_STATUS_MAPPING = {
32
31
  HTTP_BAD_REQUEST_CODE => BadRequestError,
33
32
  HTTP_UNAUTHORIZED_CODE => UnauthorizedError,
@@ -47,10 +46,6 @@ module MoloniApi
47
46
  MoloniApi.configuration.property_names.each do |key|
48
47
  send("#{key}=", opts[key])
49
48
  end
50
- @api_access_token = opts[:access_token] # If not provided will need to ask for credentials
51
- @api_client_id = opts[:client_id] || ENV['MOLONI_API_CLIENT_ID']
52
- @api_client_secret = opts[:client_secret] || ENV['MOLONI_API_CLIENT_SECRET']
53
- @api_endpoint = opts[:endpoint] || ENV['MOLONI_API_ENDPOINT'] || API_ENDPOINT
54
49
 
55
50
  yield_or_eval(&block) if block_given?
56
51
  end
@@ -70,11 +65,12 @@ module MoloniApi
70
65
  # provide your own logger
71
66
  logger = Logger.new $stderr
72
67
  logger.level = Logger::DEBUG
73
- @client ||= Faraday.new(@api_endpoint) do |client|
68
+ @client ||= Faraday.new(@endpoint) do |client|
74
69
  client.request :url_encoded
75
- #client.request :json
76
- #client.response :json
70
+ # client.request :json
71
+ # client.response :json
77
72
  client.adapter Faraday.default_adapter
73
+ client.headers['User-Agent'] = @user_agent
78
74
  client.response :logger, logger
79
75
  end
80
76
  end
@@ -21,7 +21,7 @@ module MoloniApi
21
21
 
22
22
  def authenticate(user_username, user_password)
23
23
  response = request(
24
- http_method: :get,
24
+ http_method: :post,
25
25
  endpoint: 'grant/',
26
26
  query_params: {
27
27
  grant_type: 'password',
@@ -40,7 +40,7 @@ module MoloniApi
40
40
 
41
41
  def renew_token(refresh_token = nil)
42
42
  response = request(
43
- http_method: :get,
43
+ http_method: :post,
44
44
  endpoint: 'grant/',
45
45
  query_params: {
46
46
  grant_type: 'refresh_token',
@@ -242,6 +242,55 @@ module MoloniApi
242
242
  process_response(response)
243
243
  end
244
244
 
245
+ #############################################
246
+ ### Global Data Methods
247
+ # Note: Calls to these methods should be cached somewhere
248
+ #############################################
249
+ def countries(other_params: {})
250
+ response = request(
251
+ http_method: :post,
252
+ endpoint: 'countries/getAll/',
253
+ query_params: other_params
254
+ )
255
+ process_response(response)
256
+ end
257
+
258
+ def languages(other_params: {})
259
+ response = request(
260
+ http_method: :post,
261
+ endpoint: 'languages/getAll/',
262
+ query_params: other_params
263
+ )
264
+ process_response(response)
265
+ end
266
+
267
+ def fiscal_zones(other_params: {})
268
+ response = request(
269
+ http_method: :post,
270
+ endpoint: 'fiscalZones/getAll/',
271
+ query_params: other_params
272
+ )
273
+ process_response(response)
274
+ end
275
+
276
+ def currencies(other_params: {})
277
+ response = request(
278
+ http_method: :post,
279
+ endpoint: 'currencies/getAll/',
280
+ query_params: other_params
281
+ )
282
+ process_response(response)
283
+ end
284
+
285
+ def document_models(other_params: {})
286
+ response = request(
287
+ http_method: :post,
288
+ endpoint: 'documentModels/getAll/',
289
+ query_params: other_params
290
+ )
291
+ process_response(response)
292
+ end
293
+
245
294
  protected
246
295
 
247
296
  def process_response(response)
@@ -6,23 +6,29 @@ require_relative 'version'
6
6
  module MoloniApi
7
7
  # Stores the configuration
8
8
  class Configuration < API::Config
9
+ API_ENDPOINT = 'https://api.moloni.pt/sandbox/'
10
+
9
11
  property :follow_redirects, default: true
10
12
 
11
13
  # The api endpoint used to connect to MoloniApi if none is set
12
14
  # prd: https://api.moloni.pt/v1/
13
15
  # sandbox: https://api.moloni.pt/sandbox/
14
- property :endpoint, default: 'https://api.moloni.pt/sandbox/'
16
+ property :endpoint, default: ENV['MOLONI_API_ENDPOINT'] || API_ENDPOINT
15
17
 
16
18
  # The value sent in the http header for 'User-Agent' if none is set
17
- property :user_agent, default: "MoloniApi API Ruby Gem #{MoloniApi::VERSION}"
19
+ property :user_agent, default: "MoloniApi API Ruby Gem #{MoloniApi::VERSION}"
18
20
 
19
21
  # By default uses the Faraday connection options if none is set
20
- property :connection_options, default: {}
22
+ property :connection_options, default: {}
21
23
 
22
24
  # By default display 30 resources
23
25
  property :per_page, default: 20
24
26
 
25
27
  # Add Faraday::RackBuilder to overwrite middleware
26
28
  property :stack
29
+
30
+ 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']
27
33
  end
28
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MoloniApi
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.3'
5
5
  end
data/moloni_api.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['Dinis']
9
9
  spec.email = ['dinis@lage.pw']
10
10
 
11
- spec.summary = 'FantasticStay API Wrapper.'
12
- spec.description = 'A gem that implements functions from the FS API available for its users.'
11
+ spec.summary = 'Moloni API Wrapper.'
12
+ spec.description = 'A gem that implements functions from the Moloni API available for its users.'
13
13
  spec.homepage = 'https://github.com/dlage/moloni_api_gem'
14
14
  spec.license = 'MIT'
15
15
  spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
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.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dinis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-11 00:00:00.000000000 Z
11
+ date: 2022-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,7 +38,8 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.11'
41
- description: A gem that implements functions from the FS API available for its users.
41
+ description: A gem that implements functions from the Moloni API available for its
42
+ users.
42
43
  email:
43
44
  - dinis@lage.pw
44
45
  executables: []
@@ -47,6 +48,7 @@ extra_rdoc_files: []
47
48
  files:
48
49
  - ".github/workflows/main.yml"
49
50
  - ".gitignore"
51
+ - ".irbrc"
50
52
  - ".rspec"
51
53
  - ".rubocop.yml"
52
54
  - CHANGELOG.md
@@ -81,7 +83,7 @@ metadata:
81
83
  homepage_uri: https://github.com/dlage/moloni_api_gem
82
84
  source_code_uri: https://github.com/dlage/moloni_api_gem
83
85
  changelog_uri: https://github.com/dlage/moloni_api_gem/blob/master/CHANGELOG.md
84
- post_install_message:
86
+ post_install_message:
85
87
  rdoc_options: []
86
88
  require_paths:
87
89
  - lib
@@ -96,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
98
  - !ruby/object:Gem::Version
97
99
  version: '0'
98
100
  requirements: []
99
- rubygems_version: 3.3.19
100
- signing_key:
101
+ rubygems_version: 3.2.33
102
+ signing_key:
101
103
  specification_version: 4
102
- summary: FantasticStay API Wrapper.
104
+ summary: Moloni API Wrapper.
103
105
  test_files: []