infakt_api_client 0.1.1 → 0.2.0

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: 66db2a13b4235e6fad5d5b11a0b0b8cb70758b4097fd7e35f51e5c8e8a9ce3cc
4
- data.tar.gz: ebfe4a31360ea49de885982d5ce9738b1e697bf4e212420bdef20ab48b53b10c
3
+ metadata.gz: f125465ce5bf7c15799e628c97fbb803bfb3e1f507bbedea65d66c49d709bbad
4
+ data.tar.gz: 9a3a34e5a354f458aa04f12395a63349bbc4249f2db2c921343e8125185f13f7
5
5
  SHA512:
6
- metadata.gz: 6d3c23ca6ef5f48771e204ef78b02be6330f966f99725cbb63bf2d14b4d3bfec4fa2b382fcdb7dff3494fc153b390d8512a5301e20f68cb0a68740d60a8ce808
7
- data.tar.gz: 604db6ec8ff9c70f9a361d4ad479b2c7fbc6295e6e9d2e4c155d3812ad2868d24c9599621643e9546e96a689d3b9f6e83340cba2807152f8bb0a14efc3ef4786
6
+ metadata.gz: bfde9c31d30ad643123927c01b83cbaffb13c002ae2649a58791729aa383f9b9a0cdc093fad7379f4d7103a31d090c600549c0f9da955eaf1a23d2e5ec0432fe
7
+ data.tar.gz: 004c824feecb65441245dfceb55b99229fd60b8a6dc0cfcf6dc67c904e532921c06083d008bf6970a3e03aa05929f8a025b7cc9e27c74954d4a6964f656a859d
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # InfaktApiClient
2
2
 
3
- A Ruby client library for the Infakt API, providing easy access to Infakt's invoicing and accounting services.
3
+ A Ruby client library for the InFakt API, providing easy access to InFakt's invoicing and accounting services. This client supports both the production and sandbox environments of the InFakt API v3.
4
4
 
5
5
  ## Installation
6
6
 
7
+ ### In a Ruby Application
8
+
7
9
  Add this line to your application's Gemfile:
8
10
 
9
11
  ```ruby
@@ -22,26 +24,82 @@ Or install it yourself as:
22
24
  $ gem install infakt_api_client
23
25
  ```
24
26
 
25
- ## Usage
27
+ ### In a Rails Application
28
+
29
+ After adding the gem to your Gemfile and running `bundle install`, you can run the generator to create an initializer:
30
+
31
+ ```bash
32
+ $ rails generate infakt_api_client:install
33
+ ```
34
+
35
+ This will create a configuration file at `config/initializers/infakt_api_client.rb`.
36
+
37
+ ## Configuration
26
38
 
27
- First, configure the client with your API key:
39
+ Configure the client with your API key:
28
40
 
29
41
  ```ruby
30
42
  InfaktApiClient.configure do |config|
43
+ # Your API key from InFakt
31
44
  config.api_key = 'your_api_key_here'
45
+
46
+ # Optional: Use sandbox mode for testing (default: false)
47
+ config.sandbox_mode = false
48
+
49
+ # Optional: Override the API endpoint (not usually needed)
50
+ # config.api_endpoint = 'https://custom-endpoint.example.com/'
32
51
  end
33
52
  ```
34
53
 
35
- ### Examples
54
+ ### Sandbox Mode
55
+
56
+ For testing purposes, you can use the InFakt sandbox environment:
36
57
 
37
58
  ```ruby
38
- # Create a new client
39
- client = InfaktApiClient.new
59
+ InfaktApiClient.configure do |config|
60
+ config.api_key = 'your_sandbox_api_key'
61
+ config.sandbox_mode = true
62
+ end
63
+ ```
64
+
65
+ ## Usage Examples
66
+
67
+ ### Basic Usage
68
+
69
+ ```ruby
70
+ # Create a client instance
71
+ client = InfaktApiClient::Client.new
40
72
 
41
73
  # Fetch user details
42
74
  user = client.user_details
75
+ puts "User email: #{user.account_data.email}"
76
+ puts "Company name: #{user.company_data.company_name}"
43
77
  ```
44
78
 
79
+ ### Error Handling
80
+
81
+ ```ruby
82
+ begin
83
+ client = InfaktApiClient::Client.new
84
+ user = client.user_details
85
+ # Process user data
86
+ rescue InfaktApiClient::Error => e
87
+ puts "API Error: #{e.message}"
88
+ end
89
+ ```
90
+
91
+ ## API Documentation
92
+
93
+ For detailed information about the InFakt API endpoints and parameters, refer to the [official InFakt API documentation](https://docs.infakt.pl/).
94
+
95
+ ## Development
96
+
97
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
102
+
45
103
  ## Documentation
46
104
 
47
105
  For detailed documentation of available methods and options, please visit our [Wiki](https://github.com/mateuszpalak/infakt_api_client/wiki).
@@ -3,12 +3,33 @@
3
3
  module InfaktApiClient
4
4
  module Generators
5
5
  # Generator that installs InfaktApiClient initializer into a Rails application
6
+ # @example Run the generator
7
+ # rails generate infakt_api_client:install
6
8
  class InstallGenerator < Rails::Generators::Base
7
9
  source_root File.expand_path("templates", __dir__)
10
+ desc "Creates an InfaktApiClient initializer for your Rails application"
8
11
 
9
12
  def copy_initializer
10
13
  template "initializer.rb", "config/initializers/infakt_api_client.rb"
11
14
  end
15
+
16
+ def show_readme
17
+ readme "README" if behavior == :invoke
18
+ end
19
+
20
+ private
21
+
22
+ def readme(_path)
23
+ say ""
24
+ say "===============================================================================", :green
25
+ say "InfaktApiClient has been installed successfully!", :green
26
+ say "-------------------------------------------------------------------------------", :green
27
+ say "Please set your API key in config/initializers/infakt_api_client.rb", :yellow
28
+ say ""
29
+ say "For sandbox testing, set config.sandbox_mode = true", :yellow
30
+ say "===============================================================================", :green
31
+ say ""
32
+ end
12
33
  end
13
34
  end
14
35
  end
@@ -4,4 +4,8 @@
4
4
  InfaktApiClient.configure do |config|
5
5
  # Your InFakt API key. You can find it in your InFakt account settings
6
6
  config.api_key = "your_api_key_here"
7
+
8
+ # Set to true to use the sandbox environment for testing
9
+ # Default: false (uses production environment)
10
+ # config.sandbox_mode = false
7
11
  end
@@ -4,10 +4,19 @@ module InfaktApiClient
4
4
  # Client class for interacting with the inFakt API
5
5
  # Manages HTTP communication and authentication with the API endpoints
6
6
  class Client
7
- # Add HTTP status constants for better readability
7
+ # HTTP status constants for better readability
8
8
  HTTP_OK = 200
9
+ HTTP_CREATED = 201
10
+ HTTP_ACCEPTED = 202
11
+ HTTP_NO_CONTENT = 204
12
+ HTTP_BAD_REQUEST = 400
9
13
  HTTP_UNAUTHORIZED = 401
14
+ HTTP_FORBIDDEN = 403
10
15
  HTTP_NOT_FOUND = 404
16
+ HTTP_UNPROCESSABLE_ENTITY = 422
17
+ HTTP_TOO_MANY_REQUESTS = 429
18
+ HTTP_INTERNAL_SERVER_ERROR = 500
19
+ HTTP_SERVICE_UNAVAILABLE = 503
11
20
 
12
21
  def initialize
13
22
  @connection = Faraday.new(url: InfaktApiClient.configuration.api_endpoint) do |faraday|
@@ -15,6 +24,8 @@ module InfaktApiClient
15
24
  end
16
25
  end
17
26
 
27
+ # Get user account details
28
+ # @return [User] User object with account details
18
29
  def user_details
19
30
  response = @connection.get("account/details.json")
20
31
  handle_response(response) do |data|
@@ -27,25 +38,48 @@ module InfaktApiClient
27
38
  def configure_connection(faraday)
28
39
  faraday.headers["X-inFakt-ApiKey"] = InfaktApiClient.configuration.api_key
29
40
  faraday.headers["Content-Type"] = "application/json"
41
+ faraday.headers["Accept"] = "application/json"
30
42
  faraday.adapter Faraday.default_adapter
31
43
  faraday.response :json # Automatically parse JSON responses
32
44
  end
33
45
 
34
46
  def handle_response(response)
35
47
  case response.status
36
- when HTTP_OK
37
- yield response.body # No need to parse JSON manually now
48
+ when HTTP_OK, HTTP_CREATED, HTTP_ACCEPTED, HTTP_NO_CONTENT
49
+ return yield({}) if response.body.nil? || response.body.empty?
50
+
51
+ yield response.body
52
+ when HTTP_BAD_REQUEST
53
+ raise Error, "Bad request - check your parameters: #{response.body}"
38
54
  when HTTP_UNAUTHORIZED
39
55
  raise Error, "Unauthorized - check your API key"
56
+ when HTTP_FORBIDDEN
57
+ raise Error, "Forbidden - you don't have permission to access this resource"
40
58
  when HTTP_NOT_FOUND
41
59
  raise Error, "Resource not found"
60
+ when HTTP_UNPROCESSABLE_ENTITY
61
+ raise Error, "Unprocessable entity: #{response.body}"
62
+ when HTTP_TOO_MANY_REQUESTS
63
+ raise Error, "Too many requests - rate limit exceeded"
64
+ when HTTP_INTERNAL_SERVER_ERROR
65
+ raise Error, "Internal server error"
66
+ when HTTP_SERVICE_UNAVAILABLE
67
+ raise Error, "Service unavailable - try again later"
42
68
  else
43
69
  raise Error, build_error_message(response)
44
70
  end
45
71
  end
46
72
 
47
73
  def build_error_message(response)
48
- "API error (status: #{response.status}): #{response.body}"
74
+ message = "API error (status: #{response.status})"
75
+ if response.body.is_a?(Hash) && response.body["message"]
76
+ message += ": #{response.body["message"]}"
77
+ elsif response.body.is_a?(Hash) && response.body["error"]
78
+ message += ": #{response.body["error"]}"
79
+ elsif response.body.is_a?(String) && !response.body.empty?
80
+ message += ": #{response.body}"
81
+ end
82
+ message
49
83
  end
50
84
  end
51
85
  end
@@ -4,14 +4,23 @@ module InfaktApiClient
4
4
  # Configuration class for InfaktApiClient
5
5
  # Manages API credentials and endpoint settings for the inFakt API integration
6
6
  class Configuration
7
- DEFAULT_ENDPOINT = "https://api.niebieskiorzel.pl/v3/"
7
+ DEFAULT_ENDPOINT = "https://api.infakt.pl/api/v3/"
8
+ SANDBOX_ENDPOINT = "https://api.sandbox-infakt.pl/api/v3/"
8
9
 
9
10
  attr_accessor :api_key
10
- attr_reader :api_endpoint
11
+ attr_reader :api_endpoint, :sandbox_mode
11
12
 
12
13
  def initialize
13
14
  @api_endpoint = DEFAULT_ENDPOINT
14
15
  @api_key = nil
16
+ @sandbox_mode = false
17
+ end
18
+
19
+ # Enable or disable sandbox mode
20
+ # @param value [Boolean] true to enable sandbox mode, false to disable
21
+ def sandbox_mode=(value)
22
+ @sandbox_mode = !value.nil?
23
+ @api_endpoint = sandbox_mode ? SANDBOX_ENDPOINT : DEFAULT_ENDPOINT
15
24
  end
16
25
 
17
26
  def api_endpoint=(url)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InfaktApiClient
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infakt_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Palak
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: faraday
@@ -38,7 +37,7 @@ dependencies:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
39
  version: '2.0'
41
- description: Prosty klient Ruby do integracji z API inFakt.pl
40
+ description: A simple Ruby client for integrating with the InFakt.pl API
42
41
  email:
43
42
  - mateusz.palak@hotmail.com
44
43
  executables: []
@@ -58,7 +57,6 @@ homepage: https://github.com/mateuszpalak/infakt_api_client
58
57
  licenses:
59
58
  - MIT
60
59
  metadata: {}
61
- post_install_message:
62
60
  rdoc_options: []
63
61
  require_paths:
64
62
  - lib
@@ -73,8 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
71
  - !ruby/object:Gem::Version
74
72
  version: '0'
75
73
  requirements: []
76
- rubygems_version: 3.4.19
77
- signing_key:
74
+ rubygems_version: 3.6.8
78
75
  specification_version: 4
79
- summary: Klient API dla systemu fakturowego inFakt.pl
76
+ summary: API client for the InFakt.pl invoicing system
80
77
  test_files: []