moloni_api 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ec107d21be2536a63ab97fe0280cf8f7ad4db82759272e6f93a649224e869e3
4
- data.tar.gz: 342955e233c5fb4ea13b0073f856701ce096b559d26229018efa3f17cbafee08
3
+ metadata.gz: 673d8af117bb955354df4f2e33b97db71748da48432fa4f3e5cb92d348316e91
4
+ data.tar.gz: d610ee570e45511f03ad0daf45e6ad07b908c74e49c4bcbbe45ef1069a09bee9
5
5
  SHA512:
6
- metadata.gz: 52589d46b7dba75dbf5f15e938391c3fe65cf1571a35dd1029ff895e5ce2f61da690441d92829362e64840542f2d32c4aa2d108dac4d0136433ec0d8b5c1fb85
7
- data.tar.gz: 998755fc207a05796be2664529ce81123fc141e4b26670e976600df7d36ab551ef9623bbde5a23be8c13438799c3c486de95d8d64b3d3599aade13ff4e613213
6
+ metadata.gz: 519b7cbbdde21394bb9bad14e89a8689352baa80715abce5a6f12af4d3c19c97fb893fdc598796518218dc3420cc083be25f2be2947bdc5002adbbe4ee5c4203
7
+ data.tar.gz: 25d2849b0bff4f596ff2663044b71e06c08cbee836ed898448f49abdcb307ddfc577e71e1cca338bb3ac682bdd68de289e056823c7f42af015abb76b1bff9342
data/CHANGELOG.md CHANGED
@@ -1,2 +1,3 @@
1
+ * 0.2.1 - Compatibility restored by configuring inside the initialization method
1
2
  * 0.2.0 - Breaking change: initialization using a configure block now - dry-configurable
2
3
  * 0.1.5 - Passing tests
@@ -14,9 +14,6 @@ module MoloniApi
14
14
  include HttpStatusCodes
15
15
  include Dry::Configurable
16
16
 
17
- API_ENDPOINT = 'https://api.moloni.pt/sandbox/'
18
- API_CLIENT_ID = 'apigem'
19
- API_CLIENT_SECRET = 'c9c9f4274658da2ad78b55a452894942898b5614'
20
17
  HTTP_STATUS_MAPPING = {
21
18
  HTTP_BAD_REQUEST_CODE => BadRequestError,
22
19
  HTTP_UNAUTHORIZED_CODE => UnauthorizedError,
@@ -49,6 +46,19 @@ module MoloniApi
49
46
  setting :api_client_id, default: ENV['MOLONI_API_CLIENT_ID'] || API_CLIENT_ID, reader: true
50
47
  setting :api_client_secret, default: ENV['MOLONI_API_CLIENT_SECRET'] || API_CLIENT_SECRET, reader: true
51
48
 
49
+ # Create new API
50
+ #
51
+ # @api public
52
+ def initialize(options = {}, &block)
53
+ configure do |c|
54
+ options.each_key do |key|
55
+ c.send("#{key}=", options[key])
56
+ end
57
+ end
58
+
59
+ yield_or_eval(&block) if block_given?
60
+ end
61
+
52
62
  # Call block with argument
53
63
  #
54
64
  # @api private
@@ -178,7 +178,16 @@ module MoloniApi
178
178
  endpoint: 'customers/insert/',
179
179
  params: { company_id: company_id }.merge(customer_data)
180
180
  )
181
- process_response(response)
181
+ p_res = process_response(response)
182
+ case p_res
183
+ when Hash
184
+ p_res
185
+ else
186
+ {
187
+ valid: 0,
188
+ errors: p_res
189
+ }
190
+ end
182
191
  end
183
192
 
184
193
  def invoices_insert(company_id, invoice_params: {}, products: [])
@@ -3,6 +3,11 @@
3
3
  module MoloniApi
4
4
  # Constants
5
5
  module Constants
6
+ # API Defaults
7
+ API_ENDPOINT = 'https://api.moloni.pt/sandbox/'
8
+ API_CLIENT_ID = 'apigem'
9
+ API_CLIENT_SECRET = 'c9c9f4274658da2ad78b55a452894942898b5614'
10
+
6
11
  # Response headers
7
12
  RATELIMIT_REMAINING = 'X-RateLimit-Remaining'
8
13
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MoloniApi
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
data/lib/moloni_api.rb CHANGED
@@ -15,11 +15,14 @@ module MoloniApi
15
15
  class << self
16
16
  # Alias for MoloniApi::Client.new
17
17
  #
18
+ # @param [Hash] options
19
+ # the configuration options
20
+ #
18
21
  # @return [MoloniApi::Client]
19
22
  #
20
23
  # @api public
21
- def new
22
- Client.new
24
+ def new(options = {}, &block)
25
+ Client.new(options, &block)
23
26
  end
24
27
 
25
28
  # Default middleware stack that uses default adapter as specified
@@ -38,17 +41,13 @@ module MoloniApi
38
41
  def method_missing(method_name, *args, &block)
39
42
  if new.respond_to?(method_name)
40
43
  new.send(method_name, *args, &block)
41
- elsif new.config.respond_to?(method_name)
42
- MoloniApi::Client.config.send(method_name, *args, &block)
43
44
  else
44
45
  super.respond_to_missing?
45
46
  end
46
47
  end
47
48
 
48
49
  def respond_to_missing?(method_name, include_private = false)
49
- new.respond_to?(method_name, include_private) ||
50
- configuration.respond_to?(method_name) ||
51
- super(method_name, include_private)
50
+ new.respond_to?(method_name, include_private) || super(method_name, include_private)
52
51
  end
53
52
  end
54
53
  end
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.2.0
4
+ version: 0.2.1
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-28 00:00:00.000000000 Z
11
+ date: 2022-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday