sofia 0.1.2 → 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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +63 -12
  4. data/lib/sofia/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 720c61ca3d6708e000cde2eab720a283199d02ae5c02e45c9c513da7493c0366
4
- data.tar.gz: 14e66efc3be75d6ec3e12d638b0df237e474212a52930bcb64dd7126b9ecf62c
3
+ metadata.gz: 2c16a0331d44fdc638dc0efc3a30c4f9c4bfdfb7546361e37070b34ba88ed784
4
+ data.tar.gz: 9496ec65c4403845ade1a049fc62453738d65f84363d32dc75f364778a58b6b8
5
5
  SHA512:
6
- metadata.gz: 7c635e0eef70a141af112b4955e031103c1e06d09afefb6ff55a91026f0bfdcc09256d35bf0cb92819cb48edc02d5c5e58620419b0f681d4287c4367d601a17a
7
- data.tar.gz: a8c3cd787e0c7375f55671454f1f577bbdaf25fa3d1ce227940779fc76ba36be2f516b758be7f6dd91e9569a545697293e542ab571e0443731f934b4b32931a9
6
+ metadata.gz: c92bc688a73c1e3e6c0acbaa6c3ee21d0da5f237b82d920155a64976e377d98b8df234dea65f35bf1a98f7c8543ef1c815c36b6474f6278a398d376ea4e36345
7
+ data.tar.gz: 796638bc140e642d0fb3d71598ae9a3e60e3e6dd786ca3589dbb39258f6cee16943b89fc4961d9f6c876b7c4119081a4523d4a801a3b0fe0fd6ba366d3d6652a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.4] - 2026-04-20
4
+
5
+ ### Added
6
+
7
+ - Soren gem updated to 0.1.5
8
+
9
+ ## [0.1.3] - 2026-04-17
10
+
11
+ ### Added
12
+
13
+ - Soren gem updated to 0.1.3
14
+
3
15
  ## [0.1.2] - 2026-04-17
4
16
 
5
17
  ### Added
data/README.md CHANGED
@@ -1,24 +1,75 @@
1
1
  # Sofia
2
2
 
3
- This is a personal project created for self-learning purposes. The goal is to create a simple HTTP client abstraction layer, similar to `Faraday`. At the current moment `Sofia` supports only `NetHTTP` as adapter, and only with `Content-Type: JSON` and default configuration. While basic, at the current moment `Sofia` is implemented into my other project [Shopik](https://github.com/KubaJadrzak/Shopik) and allows to perform HTTP requests correctly. I will add more functionality with time. The goal is to ultimately create my own HTTP client as well.
3
+ A simple HTTP client abstraction layer for Ruby, similar to `Faraday`. Sofia provides an abstraction layer so you can swap the underlying HTTP library without changing your application code.
4
+
5
+ Sofia is currently implemented in my integration with Espago Payment System [Shopik](https://github.com/KubaJadrzak/Shopik) alongside my own HTTP client library [Soren](https://github.com/KubaJadrzak/soren), and everything seems to be working pretty good :P
4
6
 
5
7
  # How it works
6
8
 
7
- In order to perform a request with `Sofia` you need to initialize an instance of `client` class by providing `base_url` and `adapter`. At the current moment the only supported adapter is `NetHTTP` and it will be used by default.
9
+ Initialize a client with a `base_url` and an optional `adapter` (defaults to `:net_http`):
10
+
8
11
  ```rb
9
- @client = Sofia.new(base_url: base_url, adapter: adapter)
12
+ @client = Sofia.new(base_url: base_url, adapter: adapter)
10
13
  ```
11
14
 
12
- You can perform a request via method `send` on the instance of `client` class. You need to provide http request type (for now only `get`, `post`, `put`, `patch`, `delete` are supported) as method argument as well as block of code with configuration, for example:
15
+ Call the desired HTTP method via `send` with a configuration block. The supported methods are `get`, `post`, `put`, `patch`, and `delete`:
16
+
13
17
  ```rb
14
- response = @client.send(method) do |req|
15
- req.path = path
16
- req.headers['Accept'] = 'application/json'
17
- req.headers['Authorization'] = "Basic #{encoded_credentials}"
18
- req.body = body if body
19
- end
18
+ response = @client.send(method) do |req|
19
+ req.path = path
20
+ req.headers['Accept'] = 'application/json'
21
+ req.headers['Authorization'] = "Basic #{encoded_credentials}"
22
+ req.body = body if body
23
+ end
24
+ ```
25
+
26
+ At the current moment Sofia supports only JSON!!!
27
+
28
+ # Errors
29
+
30
+ Response codes in the `400–499` and `500–599` ranges are not raised as errors — inspect `response.status`, `response.client_error?`, or `response.server_error?` yourself.
31
+
32
+ | Error | Cause |
33
+ |---|---|
34
+ | `Sofia::Error::TimeoutError` | Read, write, or connection timeout |
35
+ | `Sofia::Error::ConnectionFailed` | DNS failure, refused connection, network error |
36
+ | `Sofia::Error::SSLError` | TLS handshake failure |
37
+ | `Sofia::Error::ParserError` | Response body is not valid JSON |
38
+
39
+ ## Adapters
40
+
41
+ Sofia supports two adapter: `:net_http` as well as `:soren`. [Soren](https://github.com/KubaJadrzak/soren) is my own simple HTTP client library :P.
42
+
43
+ ```rb
44
+ # Default — Net::HTTP
45
+ client = Sofia.new(base_url: 'https://api.example.com', adapter: :net_http)
46
+
47
+ # Soren
48
+ client = Sofia.new(base_url: 'https://api.example.com', adapter: :soren)
49
+ ```
50
+
51
+ ## Timeouts
52
+
53
+ Timeouts can be configured per client via the `options:` keyword:
54
+
55
+ ```rb
56
+ client = Sofia.new(
57
+ base_url: 'https://api.example.com',
58
+ adapter: :net_http,
59
+ options: {
60
+ read_timeout: 60, # seconds — default 30
61
+ write_timeout: 30, # seconds — default 30
62
+ connection_timeout: 5, # seconds — default 10
63
+ },
64
+ )
20
65
  ```
21
- It is a good practice to rescue errors which can be thrown by `Sofia`. The response codes `400-499` and `500-599` are not errors, instead you need to handle these on your own. This is an example of the entire flow that allows you to make a request based on my [Shopik](https://github.com/KubaJadrzak/Shopik) project where `Sofia` is implement as HTTP client abstraction layer:
66
+
67
+ Both adapters support all three timeout values.
68
+
69
+ ## Example
70
+
71
+ This is an example of the entire flow from my [Shopik](https://github.com/KubaJadrzak/Shopik) project, where both `Sofia` HTTP client abstraction layer and `Soren` HTTP client library are implemented:
72
+
22
73
  ```rb
23
74
  class EspagoClient
24
75
 
@@ -27,7 +78,7 @@ class EspagoClient
27
78
  @user = Rails.application.credentials.dig(:espago, :app_id)
28
79
  @password = Rails.application.credentials.dig(:espago, :password)
29
80
 
30
- @client = Sofia.new(base_url: base_url)
81
+ @client = Sofia.new(base_url: base_url, adapter: :soren)
31
82
  end
32
83
 
33
84
  def send(path, body: nil, method: :get)
data/lib/sofia/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sofia
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sofia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - KubaJadrzak