infakt_api_client 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fb835834326f5229f5a2f908fd3dd27b019549c4e20fc80e05713debf88c7dae
4
+ data.tar.gz: c8918b2d0f8fa66f4d82b21d62c66b9e5ed3cb254508b368a6119eb831537b65
5
+ SHA512:
6
+ metadata.gz: d4a2382ff69f5158bd50c279e76982925f3dab2e5b92687da09fb48c631b2a022394216a60b6c4252ab076086616e794cf8b0211b338f767c2a699a2efb74483
7
+ data.tar.gz: ce1d185ee8baad237dea8fddf4c31dd5364e73f3d03e4146044a9030bf6c2ae3e2aaeb3a3cb384f38ac4694b52182c05b75a8c49173fcedf32a47c285f5ec90f
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # InfaktApiClient
2
+
3
+ A Ruby client library for the Infakt API, providing easy access to Infakt's invoicing and accounting services.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'infakt_api_client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install infakt_api_client
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ First, configure the client with your API key:
28
+
29
+ ```ruby
30
+ InfaktApiClient.configure do |config|
31
+ config.api_key = 'your_api_key_here'
32
+ end
33
+ ```
34
+
35
+ ### Examples
36
+
37
+ ```ruby
38
+ # Create a new client
39
+ client = InfaktApiClient.new
40
+
41
+ # Fetch user details
42
+ user = client.user_details
43
+ ```
44
+
45
+ ## Documentation
46
+
47
+ For detailed documentation of available methods and options, please visit our [Wiki](https://github.com/mateuszpalak/infakt_api_client/wiki).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mateuszpalak/infakt_api_client.
52
+
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
57
+
58
+ To install this gem onto your local machine, run `bundle exec rake install`.
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfaktApiClient
4
+ # Client class for interacting with the inFakt API
5
+ # Manages HTTP communication and authentication with the API endpoints
6
+ class Client
7
+ # Add HTTP status constants for better readability
8
+ HTTP_OK = 200
9
+ HTTP_UNAUTHORIZED = 401
10
+ HTTP_NOT_FOUND = 404
11
+
12
+ def initialize
13
+ @connection = Faraday.new(url: InfaktApiClient.configuration.api_endpoint) do |faraday|
14
+ configure_connection(faraday)
15
+ end
16
+ end
17
+
18
+ def user_details
19
+ response = @connection.get("account/details.json")
20
+ handle_response(response) do |data|
21
+ User.new(data)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def configure_connection(faraday)
28
+ faraday.headers["X-inFakt-ApiKey"] = InfaktApiClient.configuration.api_key
29
+ faraday.headers["Content-Type"] = "application/json"
30
+ faraday.adapter Faraday.default_adapter
31
+ faraday.response :json # Automatically parse JSON responses
32
+ end
33
+
34
+ def handle_response(response)
35
+ case response.status
36
+ when HTTP_OK
37
+ yield response.body # No need to parse JSON manually now
38
+ when HTTP_UNAUTHORIZED
39
+ raise Error, "Unauthorized - check your API key"
40
+ when HTTP_NOT_FOUND
41
+ raise Error, "Resource not found"
42
+ else
43
+ raise Error, build_error_message(response)
44
+ end
45
+ end
46
+
47
+ def build_error_message(response)
48
+ "API error (status: #{response.status}): #{response.body}"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfaktApiClient
4
+ # Configuration class for InfaktApiClient
5
+ # Manages API credentials and endpoint settings for the inFakt API integration
6
+ class Configuration
7
+ DEFAULT_ENDPOINT = "https://api.niebieskiorzel.pl/v3/"
8
+
9
+ attr_accessor :api_key
10
+ attr_reader :api_endpoint
11
+
12
+ def initialize
13
+ @api_endpoint = DEFAULT_ENDPOINT
14
+ @api_key = nil
15
+ end
16
+
17
+ def api_endpoint=(url)
18
+ @api_endpoint = url.end_with?("/") ? url : "#{url}/"
19
+ end
20
+
21
+ def valid?
22
+ !api_key.nil? && !api_key.empty? && !api_endpoint.nil? && !api_endpoint.empty?
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfaktApiClient
4
+ # Represents a user in the Infakt API system, containing account information,
5
+ # company details, subscription status, and various settings. This class serves
6
+ # as a wrapper for user-related data returned by the Infakt API.
7
+ class User
8
+ attr_reader :account_data, :company_data, :current_subscription,
9
+ :accounting_settings, :accounting_office_service,
10
+ :foundation_process, :extensions
11
+
12
+ # Represents account-specific information for a user in the Infakt API system.
13
+ # Contains basic user identification and authentication details such as UUID,
14
+ # email, username, and registration information.
15
+ class AccountData
16
+ attr_reader :uuid, :email, :username, :site, :role, :registered_at
17
+
18
+ def initialize(data)
19
+ @uuid = data["uuid"]
20
+ @email = data["email"]
21
+ @username = data["username"]
22
+ @site = data["site"]
23
+ @role = data["role"]
24
+ @registered_at = data["registered_at"]
25
+ end
26
+ end
27
+
28
+ # Represents company-specific information for a user in the Infakt API system.
29
+ # Contains detailed business information such as company name, address details,
30
+ # tax identification numbers, and contact information.
31
+ class CompanyData
32
+ attr_reader :first_name, :last_name, :company_name, :owner_name, :owner_surname,
33
+ :street, :street_name, :street_number, :flat_number, :city,
34
+ :postal_code, :tax_id, :pesel, :regon, :phone_number,
35
+ :mailing_company_name, :mailing_street, :mailing_city,
36
+ :mailing_postal_code, :business_activity_code
37
+
38
+ def initialize(data)
39
+ @first_name = data["first_name"]
40
+ @last_name = data["last_name"]
41
+ @company_name = data["company_name"]
42
+ @owner_name = data["owner_name"]
43
+ @owner_surname = data["owner_surname"]
44
+ @street = data["street"]
45
+ @street_name = data["street_name"]
46
+ @street_number = data["street_number"]
47
+ @flat_number = data["flat_number"]
48
+ @city = data["city"]
49
+ @postal_code = data["postal_code"]
50
+ @tax_id = data["tax_id"]
51
+ @pesel = data["pesel"]
52
+ @regon = data["regon"]
53
+ @phone_number = data["phone_number"]
54
+ @mailing_company_name = data["mailing_company_name"]
55
+ @mailing_street = data["mailing_street"]
56
+ @mailing_city = data["mailing_city"]
57
+ @mailing_postal_code = data["mailing_postal_code"]
58
+ @business_activity_code = data["business_activity_code"]
59
+ end
60
+
61
+ def full_address
62
+ [street, city, postal_code].compact.join(", ")
63
+ end
64
+ end
65
+
66
+ # Represents subscription information for an InfaktApiClient user
67
+ class Subscription
68
+ attr_reader :name, :expired_on, :days_until_expiration, :user_type_symbol
69
+
70
+ def initialize(data)
71
+ @name = data["name"]
72
+ @expired_on = data["expired_on"]
73
+ @days_until_expiration = data["days_until_expiration"]
74
+ @user_type_symbol = data["user_type_symbol"]
75
+ end
76
+ end
77
+
78
+ def initialize(attributes)
79
+ @account_data = AccountData.new(attributes["account_data"])
80
+ @company_data = CompanyData.new(attributes["company_data"])
81
+ @current_subscription = Subscription.new(attributes["current_subscription"])
82
+ @accounting_settings = attributes["accounting_settings"]
83
+ @accounting_office_service = attributes["accounting_office_service"]
84
+ @foundation_process = attributes["foundation_process"]
85
+ @extensions = attributes["extentions"]
86
+ end
87
+
88
+ def full_name
89
+ "#{company_data.first_name} #{company_data.last_name}".strip
90
+ end
91
+
92
+ def subscription_active?
93
+ Date.parse(current_subscription.expired_on) > Date.today
94
+ end
95
+
96
+ def days_to_subscription_end
97
+ current_subscription.days_until_expiration
98
+ end
99
+
100
+ def ksef_active?
101
+ extensions.dig("ksef", "active")
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InfaktApiClient
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "json"
5
+
6
+ require "infakt_api_client/version"
7
+ require "infakt_api_client/configuration"
8
+ require "infakt_api_client/client"
9
+ require "infakt_api_client/user"
10
+
11
+ # Module for interacting with the inFakt.pl API
12
+ # @see https://www.infakt.pl/developers/
13
+ module InfaktApiClient
14
+ # Custom error class for InfaktApiClient specific exceptions
15
+ class Error < StandardError; end
16
+
17
+ # Configuration not initialized error
18
+ class ConfigurationError < Error; end
19
+
20
+ class << self
21
+ attr_writer :configuration
22
+
23
+ # @return [Configuration] Current configuration instance
24
+ def configuration
25
+ @configuration ||= Configuration.new
26
+ end
27
+
28
+ # Configures the client through a block
29
+ # @yield [config] Configuration instance
30
+ # @raise [ConfigurationError] if no block is given
31
+ def configure
32
+ yield(configuration)
33
+ rescue LocalJumpError
34
+ raise ConfigurationError, "Configuration block is required"
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infakt_api_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mateusz Palak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ description: Prosty klient Ruby do integracji z API inFakt.pl
42
+ email:
43
+ - mateusz.palak@hotmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - lib/infakt_api_client.rb
50
+ - lib/infakt_api_client/client.rb
51
+ - lib/infakt_api_client/configuration.rb
52
+ - lib/infakt_api_client/user.rb
53
+ - lib/infakt_api_client/version.rb
54
+ homepage: https://github.com/mateuszpalak/infakt_api_client
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 3.2.6
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.4.19
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Klient API dla systemu fakturowego inFakt.pl
77
+ test_files: []