tiny-rest-client 0.1.0 → 0.2.1

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: bbbf391dfae3b7c9331328d57465ee906873ada7424306f2338c33802a46f1d4
4
- data.tar.gz: 300105bfe2e54479fb613cb977188b6eea7e80eafd56442a0f2ac9a85387fe9d
3
+ metadata.gz: f09282185efbece684932d3948209e72499ec8c4031addb174aebbcfd63b1fe9
4
+ data.tar.gz: b0def93e35f743ce5527d84f3bd6252b25162f98416fed14cfa1281c3fa9c092
5
5
  SHA512:
6
- metadata.gz: ba5ff7eb795d3b30c97c96da58f5831a504a411730ae30f171debceac4d2254226929a100b6b264521c3c450f8028e71a768f8a54edc8c63bcd064404eb2b760
7
- data.tar.gz: 1ced9f35ca6a4df30e55039dae8d1927143c95de9460bcc157e3e40d43e1c421814ddd33d27b84202d3718f1b761ab736773ace5adb27cd970247fe67f203013
6
+ metadata.gz: 4a652a084126647ff8db999ac13e0179f054637e26ada3000a1e0088658e073151639e5f764bb5081f7c7a2212b4a12d5369e45f3d45d4329bd0982774edf30b
7
+ data.tar.gz: 6bde4f84e45822efcf26fe96964907d84987435ea9934bdfe7e3d5cbd0e0d71065a87bc82e095e970ff93e80d5a63a0ee1c06d451c08b4eaf493aecf682b03a6
data/CHANGELOG.md CHANGED
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.2.1] - 2026-03-03
9
+
10
+ ### Fixed
11
+ - Ensure the gem can be required without `require:` option in Gemfile
12
+ - Add `lib/tiny-rest-client.rb` loader file for RubyGems auto-require compatibility
13
+
14
+ ## [0.2.0] - 2026-03-03
15
+
16
+ ### Added
17
+ - Rails generator `tiny_rest_client:client` for scaffolding API client classes
18
+ - Supports nested client names (e.g. `api/v1/stripe`)
19
+ - Optional base URL argument
20
+ - Configurable root namespace via `--namespace`
21
+ - Automatically generates properly namespaced client classes under `app/`
22
+
8
23
  ## [0.1.0] - 2026-02-22
9
24
 
10
25
  ### Added
@@ -19,5 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
34
  - Full Minitest suite (classic + spec style examples)
20
35
  - Basic README documentation
21
36
 
22
- [Unreleased]: https://github.com/Dabrovsky/tiny_rest_client/compare/v0.1.0...HEAD
37
+ [Unreleased]: https://github.com/Dabrovsky/tiny_rest_client/compare/v0.2.1...HEAD
38
+ [0.2.1]: https://github.com/Dabrovsky/tiny_rest_client/compare/v0.2.0...v0.2.1
39
+ [0.2.0]: https://github.com/Dabrovsky/tiny_rest_client/compare/v0.1.0...v0.2.0
23
40
  [0.1.0]: https://github.com/Dabrovsky/tiny_rest_client/releases/tag/v0.1.0
data/README.md CHANGED
@@ -19,6 +19,7 @@ A minimal, opinionated HTTP client wrapper for Rails, built on top of Typhoeus.
19
19
 
20
20
  - [Installation](#installation)
21
21
  - [Basic Usage](#basic-usage)
22
+ - [Rails Generator](#rails-generator)
22
23
  - [Configuration](#configuration)
23
24
  - [Authorization](#authorization)
24
25
  - [Making Requests](#making-requests)
@@ -31,7 +32,7 @@ A minimal, opinionated HTTP client wrapper for Rails, built on top of Typhoeus.
31
32
  Add this line to your Gemfile:
32
33
 
33
34
  ```bash
34
- gem "tiny-rest-client"
35
+ gem "tiny-rest-client", require: "tiny_rest_client"
35
36
  ```
36
37
 
37
38
  Or install it manually:
@@ -87,6 +88,38 @@ client.update_todo(status: "finished")
87
88
  client.destroy_todo(1)
88
89
  ```
89
90
 
91
+ ## Rails Generator
92
+
93
+ The gem includes a built-in Rails generator to quickly scaffold new API clients.
94
+
95
+ ```bash
96
+ rails generate tiny_rest_client:client NAME [URL] [options]
97
+ ```
98
+
99
+ ### Available options
100
+
101
+ | Option | Default | Description | Example Usage |
102
+ |-----------------|---------------|-------------------------------------------------------------|----------------------|
103
+ | NAME | (required) | Client name (supports nesting like `api/v1/stripe`) | `rails g ... api/v1/stripe` |
104
+ | URL | (none) | Base API URL | `rails g ... stripe https://api.stripe.com` |
105
+ | --namespace | `clients` | Root folder under `app/` (e.g. `app/services/...`) | `--namespace=services` |
106
+
107
+ ### Basic usage
108
+
109
+ ```bash
110
+ # Basic client
111
+ rails generate tiny_rest_client:client stripe
112
+
113
+ # Custom base URL
114
+ rails generate tiny_rest_client:client stripe https://api.stripe.com/v1
115
+
116
+ # Nested namespace (creates app/clients/api/v1/payment_client.rb)
117
+ rails generate tiny_rest_client:client api/v1/payment https://api.example.com/v1
118
+
119
+ # Custom namespace (creates app/custom/stripe_client.rb)
120
+ rails generate tiny_rest_client:client stripe https://api.example.com/v1 --namespace=custom
121
+ ```
122
+
90
123
  ## Configuration
91
124
 
92
125
  You can configure client setup at the class level:
@@ -176,7 +209,7 @@ MyClient.new(auth: { basic_auth: { user: "name", password: "secret" } })
176
209
 
177
210
  ## Making Requests
178
211
 
179
- The standard HTTP methods are available directly on every client instance automatically include any headers and/or authorization configuration you defined.
212
+ The standard HTTP methods are available directly on every client instance automatically include any headers or authorization configuration you defined.
180
213
 
181
214
  ```ruby
182
215
  get("/users", page: 1, per_page: 10) # GET request with query parameters
@@ -206,7 +239,7 @@ helpers:
206
239
  ```ruby
207
240
  response.success? # true if code 200–299
208
241
  response.failure? # opposite
209
- response.code # HTTP status code (Integer)
242
+ response.code # HTTP status code
210
243
  response.status # Typhoeus return_code symbol
211
244
  response.body # auto-parsed JSON hash or raw string
212
245
  response.headers # hash of response headers
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TinyRestClient
4
+ module Generators
5
+ class ClientGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ argument :name, type: :string, required: true, banner: "NAME"
9
+ argument :api_path, type: :string, required: false, default: "your_api_path", banner: "URL"
10
+
11
+ class_option :namespace, type: :string, default: "clients", desc: "Namespace (default clients)"
12
+
13
+ desc "Generates a TinyRestClient subclass"
14
+
15
+ def create_client_file
16
+ client_path = "app/#{namespace.downcase}/#{name.downcase}_client.rb"
17
+ template "client.rb.tt", client_path
18
+ end
19
+
20
+ def create_test_files
21
+ return if options[:skip_tests]
22
+
23
+ framework = options[:test_framework] || detect_test_framework
24
+
25
+ case framework
26
+ when "rspec"
27
+ client_test_path = "spec/#{namespace.downcase}/#{name.downcase}_client_spec.rb"
28
+ template "client_spec.rb.tt", client_test_path
29
+ when "minitest"
30
+ client_test_path = "test/#{namespace.downcase}/#{name.downcase}_client_test.rb"
31
+ template "client_test.rb.tt", client_test_path
32
+ else
33
+ say "Unknown test framework: #{framework}", :yellow
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def detect_test_framework
40
+ if defined?(RSpec) || File.exist?(File.join(destination_root, "spec"))
41
+ "rspec"
42
+ else
43
+ "minitest"
44
+ end
45
+ end
46
+
47
+ def module_names
48
+ name.split("/").map(&:capitalize).join("::")
49
+ end
50
+
51
+ def class_name
52
+ "#{module_names}Client"
53
+ end
54
+
55
+ def namespace
56
+ options[:namespace].split("/").first
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,18 @@
1
+ class <%= class_name %> < TinyRestClient::Core
2
+ api_path "<%= api_path %>"
3
+
4
+ # Define authorization type (optionally)
5
+ # authorization :bearer (:api_key or :basic_auth)
6
+ #
7
+ # Include headers (optionally)
8
+ # header "Content-Type", "application/json"
9
+
10
+ # Define helper methods
11
+ # def fetch_todos
12
+ # get("/todos")
13
+ # end
14
+ #
15
+ # def fetch_todo(id)
16
+ # get("/todos/#{id}")
17
+ # end
18
+ end
@@ -0,0 +1,19 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe <%= class_name %>, type: :client do
4
+ subject(:client) { described_class.new }
5
+
6
+ describe "#initialize" do
7
+ it "sets the api path" do
8
+ expect(client.api_path).to eq("<%= api_path %>")
9
+ end
10
+ end
11
+
12
+ describe "inheritance" do
13
+ it "inherits from TinyRestClient::Core" do
14
+ expect(client).to be_a(TinyRestClient::Core)
15
+ end
16
+ end
17
+
18
+ # Add your client-specific tests below
19
+ end
@@ -0,0 +1,19 @@
1
+ require "test_helper"
2
+
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
4
+ attr_reader :client
5
+
6
+ setup do
7
+ @client = <%= class_name %>.new
8
+ end
9
+
10
+ test "initializes with api path" do
11
+ assert_equal "<%= api_path %>", client.api_path
12
+ end
13
+
14
+ test "inherits from TinyRestClient::Core" do
15
+ assert_kind_of TinyRestClient::Core, client
16
+ end
17
+
18
+ # Add your client-specific tests below
19
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "#{File.dirname(__FILE__)}/tiny_rest_client"
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require "rails/generators"
5
+
6
+ module TinyRestClient
7
+ class Railtie < ::Rails::Railtie
8
+ initializer "tiny_rest_client.load_generators" do
9
+ require "generators/tiny_rest_client/client_generator"
10
+ end
11
+ end
12
+ end
@@ -6,14 +6,14 @@ class Response
6
6
  attr_reader :code, :status, :body, :headers
7
7
 
8
8
  def initialize(code: nil, status: nil, body: nil, headers: nil)
9
- @code = code
9
+ @code = code&.to_i
10
10
  @status = status
11
11
  @headers = headers
12
12
  @body = parse_body(body)
13
13
  end
14
14
 
15
15
  def success?
16
- code.to_i.between?(200, 299)
16
+ code.between?(200, 299)
17
17
  end
18
18
 
19
19
  def failure?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TinyRestClient
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -12,6 +12,8 @@ require "tiny_rest_client/request"
12
12
  require "tiny_rest_client/response"
13
13
  require "tiny_rest_client/version"
14
14
 
15
+ require "tiny_rest_client/railtie" if defined?(Rails)
16
+
15
17
  module TinyRestClient
16
18
  class Core
17
19
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny-rest-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dabrovski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-28 00:00:00.000000000 Z
11
+ date: 2026-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -35,10 +35,13 @@ files:
35
35
  - CHANGELOG.md
36
36
  - LICENSE
37
37
  - README.md
38
- - Rakefile
39
- - bin/console
40
- - bin/setup
38
+ - lib/generators/tiny_rest_client/client_generator.rb
39
+ - lib/generators/tiny_rest_client/templates/client.rb.tt
40
+ - lib/generators/tiny_rest_client/templates/client_spec.rb.tt
41
+ - lib/generators/tiny_rest_client/templates/client_test.rb.tt
42
+ - lib/tiny-rest-client.rb
41
43
  - lib/tiny_rest_client.rb
44
+ - lib/tiny_rest_client/railtie.rb
42
45
  - lib/tiny_rest_client/request.rb
43
46
  - lib/tiny_rest_client/response.rb
44
47
  - lib/tiny_rest_client/strategies/auth/api_key.rb
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "minitest/test_task"
5
-
6
- Minitest::TestTask.create
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[test rubocop]
data/bin/console DELETED
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "tiny_rest_client"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- require "irb"
11
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here