From 168189975a15ab59ac3d8585fcf2967480fb7677 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Wed, 9 Apr 2025 11:16:39 +0200 Subject: [PATCH 01/27] Added requests management and documentation --- Gemfile | 8 +-- Gemfile.lock | 85 ++++++++++++++++++++++++++++++++ README.md | 8 ++- Rakefile | 6 +-- lib/ohme.rb | 3 +- lib/ohme/client.rb | 85 ++++++++++++++++++++++++++++++++ lib/ohme/configuration.rb | 26 ++++++++++ ohme.gemspec | 32 ++++++------ sig/ohme.rbs | 21 +++++++- spec/ohme/client_spec.rb | 79 ++++++++++++++++++++++++++++++ spec/ohme/configuration_spec.rb | 87 +++++++++++++++++++++++++++++++++ spec/ohme_spec.rb | 6 +-- 12 files changed, 411 insertions(+), 35 deletions(-) create mode 100644 Gemfile.lock create mode 100644 lib/ohme/client.rb create mode 100644 lib/ohme/configuration.rb create mode 100644 spec/ohme/client_spec.rb create mode 100644 spec/ohme/configuration_spec.rb diff --git a/Gemfile b/Gemfile index 6808d3f..8ecdb4d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,12 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' # Specify your gem's dependencies in ohme.gemspec gemspec -gem "rake", "~> 13.0" +gem 'rake', '~> 13.0' -gem "rspec", "~> 3.0" +gem 'rspec', '~> 3.0' -gem "standard", "~> 1.3" +gem 'standard', '~> 1.3' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..7128e1d --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,85 @@ +PATH + remote: . + specs: + ohme (0.1.0) + typhoeus (>= 1.4) + +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.3) + diff-lcs (1.6.1) + ethon (0.16.0) + ffi (>= 1.15.0) + ffi (1.15.5) + json (2.10.2) + language_server-protocol (3.17.0.4) + lint_roller (1.1.0) + parallel (1.26.3) + parser (3.3.7.4) + ast (~> 2.4.1) + racc + prism (1.4.0) + racc (1.8.1) + rainbow (3.1.1) + rake (13.2.1) + regexp_parser (2.10.0) + rexml (3.4.1) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.3) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.2) + rubocop (1.64.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.44.0) + parser (>= 3.3.7.2) + prism (~> 1.4) + rubocop-performance (1.21.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (1.13.0) + standard (1.37.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.64.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.4) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.4.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.21.0) + typhoeus (1.4.0) + ethon (>= 0.9.0) + unicode-display_width (2.6.0) + +PLATFORMS + x86_64-darwin-20 + +DEPENDENCIES + ohme! + rake (~> 13.0) + rspec (~> 3.0) + standard (~> 1.3) + +BUNDLED WITH + 2.3.12 diff --git a/README.md b/README.md index 85bb420..c24df5d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # Ohme -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ohme`. To experiment with that code, run `bin/console` for an interactive prompt. - -TODO: Delete this and the text above, and describe your gem +A Ruby connector for the Ohme API, a tool for integrating with the Ohme CRM platform. This gem simplifies interaction with the Ohme API, allowing developers to easily perform operations such as retrieving data, creating resources, and managing entities within the Ohme ecosystem. ## Installation @@ -26,7 +24,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ohme. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ohme/blob/main/CODE_OF_CONDUCT.md). +Bug reports and pull requests are welcome on GitHub at https://github.com/Treize37/ohme. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Treize37/ohme/blob/main/CODE_OF_CONDUCT.md). ## License @@ -34,4 +32,4 @@ The gem is available as open source under the terms of the [MIT License](https:/ ## Code of Conduct -Everyone interacting in the Ohme project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ohme/blob/main/CODE_OF_CONDUCT.md). +Everyone interacting in the Ohme project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Treize37/ohme/blob/main/CODE_OF_CONDUCT.md). diff --git a/Rakefile b/Rakefile index df40677..7d38ee8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,10 @@ # frozen_string_literal: true -require "bundler/gem_tasks" -require "rspec/core/rake_task" +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -require "standard/rake" +require 'standard/rake' task default: %i[spec standard] diff --git a/lib/ohme.rb b/lib/ohme.rb index 2aaab41..67cdd4c 100644 --- a/lib/ohme.rb +++ b/lib/ohme.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true -require_relative "ohme/version" +require_relative 'ohme/version' +# Ohme API client gem main module. module Ohme class Error < StandardError; end # Your code goes here... diff --git a/lib/ohme/client.rb b/lib/ohme/client.rb new file mode 100644 index 0000000..ca19367 --- /dev/null +++ b/lib/ohme/client.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +require 'typhoeus' +require_relative 'configuration' + +module Ohme + # Client for interacting with the Ohme API + class Client + # Initializes the client with the configuration + # @param api_key [String] The API key for authentication + # @param base_url [String] The base URL for the API + # @param timeout [Integer] The timeout for requests in seconds + # @param domain [String] The domain for the API + # @param version [String] The version of the API + def initialize + Ohme::Configuration.validate! + end + + # Performs a GET request + def get(endpoint, params = {}) + request(:get, endpoint, params: params) + end + + # Performs a POST request + def post(endpoint, body = {}) + request(:post, endpoint, body: body) + end + + # Performs a PUT request + def put(endpoint, body = {}) + request(:put, endpoint, body: body) + end + + # Performs a DELETE request + def delete(endpoint, params = {}) + request(:delete, endpoint, params: params) + end + + private + + # Private: Performs an HTTP request + def request(method, endpoint, options = {}) + response = Typhoeus::Request.new( + build_url(endpoint), + method: method, + headers: build_headers, + params: options[:params], + body: options[:body]&.to_json, + timeout: Ohme::Configuration.timeout + ).run + + handle_response(response) + end + + def build_url(endpoint) + "#{Ohme::Configuration.base_url}#{Ohme::Configuration.version}/#{endpoint}" + end + + # Builds the headers for the request + def build_headers + { + 'client-name' => Ohme::Configuration.domain, + 'client-secret' => Ohme::Configuration.api_key, + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + } + end + + # Handle the API response + def handle_response(response) + p "Timeout: #{response.timed_out?}" + if response.timed_out? + raise 'Request timed out. Please check your network connection or increase the timeout.' + elsif response.success? + # Return nil for DELETE requests with no body + return nil if response.body.nil? || response.body.strip.empty? + + # Parse JSON for other successful responses + JSON.parse(response.body) + else + raise "HTTP request failed: #{response.code} - #{response.body}" + end + end + end +end diff --git a/lib/ohme/configuration.rb b/lib/ohme/configuration.rb new file mode 100644 index 0000000..c7ab184 --- /dev/null +++ b/lib/ohme/configuration.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Ohme + # Configuration of the Ohme API client gem. + module Configuration + class << self + attr_accessor :api_key, :base_url, :timeout, :domain, :version + + # Initializes the configuration with default values. + def configure + @base_url = 'https://api-ohme.oneheart.fr/api/' # Nouvelle URL de base + @version = 'v1' # Version par défaut + @timeout = 30 # Timeout par défaut en secondes + yield self if block_given? + end + + # Validates the configuration values. + def validate! + raise 'API key is missing. Please configure Ohme::Configuration.api_key.' unless @api_key + raise 'Base URL is missing. Please configure Ohme::Configuration.base_url.' unless @base_url + raise 'Domain is missing. Please configure Ohme::Configuration.domain.' unless @domain + raise 'Version is missing. Please configure Ohme::Configuration.version.' unless @version + end + end + end +end diff --git a/ohme.gemspec b/ohme.gemspec index 56a086f..5872ead 100644 --- a/ohme.gemspec +++ b/ohme.gemspec @@ -1,24 +1,24 @@ # frozen_string_literal: true -require_relative "lib/ohme/version" +require_relative 'lib/ohme/version' Gem::Specification.new do |spec| - spec.name = "ohme" + spec.name = 'ohme' spec.version = Ohme::VERSION - spec.authors = ["Fabrice Carrega"] - spec.email = ["fabrice.carrega@treize37.com"] + spec.authors = ['Fabrice Carrega'] + spec.email = ['fabrice.carrega@treize37.com'] - spec.summary = "TODO: Write a short summary, because RubyGems requires one." - spec.description = "TODO: Write a longer description or delete this line." - spec.homepage = "TODO: Put your gem's website or public repo URL here." - spec.license = "MIT" - spec.required_ruby_version = ">= 2.6.0" + spec.summary = 'API client for the Ohme CRM.' + spec.description = 'API client for the Ohme CRM.' + spec.homepage = 'https://github.com/treize37/ohme' + spec.license = 'MIT' + spec.required_ruby_version = '>= 2.6.0' - spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" + spec.metadata['allowed_push_host'] = "TODO: Set to your gem server 'https://example.com'" - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here." - spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = spec.homepage + spec.metadata['changelog_uri'] = 'https://github.com/Treize37/ohme/blob/main/CHANGELOG.md' # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. @@ -27,12 +27,12 @@ Gem::Specification.new do |spec| (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) end end - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] # Uncomment to register a new dependency of your gem - # spec.add_dependency "example-gem", "~> 1.0" + spec.add_dependency 'typhoeus', '>= 1.4' # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html diff --git a/sig/ohme.rbs b/sig/ohme.rbs index 503bae9..191aa1a 100644 --- a/sig/ohme.rbs +++ b/sig/ohme.rbs @@ -1,4 +1,23 @@ module Ohme VERSION: String - # See the writing guide of rbs: https://github.com/ruby/rbs#guides + + module Configuration + def self.configure: () { (config: Configuration) -> void } -> void + def self.validate!: () -> void + + attr_accessor api_key: String? + attr_accessor base_url: String? + attr_accessor timeout: Integer? + attr_accessor domain: String? + attr_accessor version: String? + end + + class Client + def initialize: () -> void + + def get: (String, params: Hash[String, untyped]?) -> Hash[String, untyped]? + def post: (String, body: Hash[String, untyped]?) -> Hash[String, untyped]? + def put: (String, body: Hash[String, untyped]?) -> Hash[String, untyped]? + def delete: (String, params: Hash[String, untyped]?) -> nil + end end diff --git a/spec/ohme/client_spec.rb b/spec/ohme/client_spec.rb new file mode 100644 index 0000000..c0f6e8d --- /dev/null +++ b/spec/ohme/client_spec.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +require 'json' +require 'spec_helper' +require 'typhoeus' +require_relative '../../lib/ohme/client' +require_relative '../../lib/ohme/configuration' + +RSpec.describe Ohme::Client do + before do + # Configure the Ohme::Configuration before each test + Ohme::Configuration.configure do |config| + config.api_key = 'test_api_key' + config.domain = 'test_domain' + end + end + + let(:client) { described_class.new } + + describe '#get' do + it 'sends a GET request to the correct endpoint' do + Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') + .and_return(Typhoeus::Response.new(code: 200, body: '{"success":true}')) + + response = client.get('test_endpoint') + + expect(response).to eq({ 'success' => true }) + end + end + + describe '#post' do + it 'sends a POST request with the correct body' do + Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') + .and_return(Typhoeus::Response.new(code: 201, body: '{"created":true}')) + + response = client.post('test_endpoint', { key: 'value' }) + + expect(response).to eq({ 'created' => true }) + end + end + + describe '#put' do + it 'sends a PUT request with the correct body' do + Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') + .and_return(Typhoeus::Response.new(code: 200, body: '{"updated":true}')) + + response = client.put('test_endpoint', { key: 'updated_value' }) + + expect(response).to eq({ 'updated' => true }) + end + end + + describe '#delete' do + it 'sends a DELETE request to the correct endpoint' do + Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') + .and_return(Typhoeus::Response.new(code: 204, body: '')) + + response = client.delete('test_endpoint') + + expect(response).to eq(nil) + end + end + + describe 'error handling' do + it 'raises an error for a timeout' do + Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') + .and_return(Typhoeus::Response.new(code: 0, return_code: :operation_timedout, return_message: 'Timeout')) + + expect { client.get('test_endpoint') }.to raise_error('Request timed out. Please check your network connection or increase the timeout.') + end + + it 'raises an error for a failed request' do + Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') + .and_return(Typhoeus::Response.new(code: 500, body: 'Internal Server Error')) + + expect { client.get('test_endpoint') }.to raise_error('HTTP request failed: 500 - Internal Server Error') + end + end +end diff --git a/spec/ohme/configuration_spec.rb b/spec/ohme/configuration_spec.rb new file mode 100644 index 0000000..a4d95c6 --- /dev/null +++ b/spec/ohme/configuration_spec.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_relative '../../lib/ohme/configuration' + +RSpec.describe Ohme::Configuration do + before do + # Reset configuration before each test + described_class.configure do |config| + config.api_key = nil + config.base_url = nil + config.domain = nil + config.version = nil + config.timeout = nil + end + end + + describe '.configure' do + it 'allows setting configuration attributes' do + described_class.configure do |config| + config.api_key = 'test_api_key' + config.base_url = 'https://api.example.com' + config.domain = 'test_domain' + config.version = 'v1' + config.timeout = 60 + end + + expect(described_class.api_key).to eq('test_api_key') + expect(described_class.base_url).to eq('https://api.example.com') + expect(described_class.domain).to eq('test_domain') + expect(described_class.version).to eq('v1') + expect(described_class.timeout).to eq(60) + end + end + + describe '.validate!' do + context 'when the configuration is valid' do + it 'does not raise an error' do + described_class.configure do |config| + config.api_key = 'test_api_key' + config.base_url = 'https://api.example.com' + config.domain = 'test_domain' + config.version = 'v1' + end + + expect { described_class.validate! }.not_to raise_error + end + end + + context 'when the API key is missing' do + it 'raises an error' do + described_class.configure do |config| + config.base_url = 'https://api.example.com' + config.domain = 'test_domain' + config.version = 'v1' + end + + expect { described_class.validate! }.to raise_error('API key is missing. Please configure Ohme::Configuration.api_key.') + end + end + + context 'when the base URL is missing' do + it 'raises an error' do + described_class.configure do |config| + config.api_key = 'test_api_key' + config.base_url = nil + config.domain = 'test_domain' + config.version = 'v1' + end + + expect { described_class.validate! }.to raise_error('Base URL is missing. Please configure Ohme::Configuration.base_url.') + end + end + + context 'when the domain is missing' do + it 'raises an error' do + described_class.configure do |config| + config.api_key = 'test_api_key' + config.base_url = 'https://api.example.com' + config.version = nil + end + + expect { described_class.validate! }.to raise_error('Domain is missing. Please configure Ohme::Configuration.domain.') + end + end + end +end diff --git a/spec/ohme_spec.rb b/spec/ohme_spec.rb index 3845426..46713ff 100644 --- a/spec/ohme_spec.rb +++ b/spec/ohme_spec.rb @@ -1,11 +1,7 @@ # frozen_string_literal: true RSpec.describe Ohme do - it "has a version number" do + it 'has a version number' do expect(Ohme::VERSION).not_to be nil end - - it "does something useful" do - expect(false).to eq(true) - end end From 9098038cd8035c433c6616973055f288430f0b7f Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Wed, 9 Apr 2025 11:31:55 +0200 Subject: [PATCH 02/27] Initialized contact API endpoints --- lib/ohme/api/contact.rb | 47 +++++++++++++++++++++++++++++++ sig/ohme.rbs | 14 +++++++++ spec/ohme/api/contact_spec.rb | 53 +++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 lib/ohme/api/contact.rb create mode 100644 spec/ohme/api/contact_spec.rb diff --git a/lib/ohme/api/contact.rb b/lib/ohme/api/contact.rb new file mode 100644 index 0000000..81e522f --- /dev/null +++ b/lib/ohme/api/contact.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Ohme + module API + class Contact + def initialize(client = Ohme::Client.new) + @client = client + end + + # Fetches the list of contacts + # @param params [Hash] Optional query parameters + # @return [Hash] The response from the API + def index(params = {}) + @client.get('contacts', params: params) + end + + # Creates a new contact + # @param body [Hash] The contact data to be sent in the request body + # @return [Hash] The response from the API + def create(body) + @client.post('contacts', body: body) + end + + # Updates a contact by ID + # @param id [String] The ID of the contact to update + # @param body [Hash] The contact data to be updated + # @return [Hash] The response from the API + def update(id, body) + @client.put("contacts/#{id}", body: body) + end + + # Fetches a contact by ID + # @param id [String] The ID of the contact to retrieve + # @return [Hash] The response from the API + def show(id) + @client.get("contacts/#{id}") + end + + # Deletes a contact by ID + # @param id [String] The ID of the contact to delete + # @return [nil] The response from the API + def delete(id) + @client.delete("contacts/#{id}") + end + end + end +end diff --git a/sig/ohme.rbs b/sig/ohme.rbs index 191aa1a..4a3f88f 100644 --- a/sig/ohme.rbs +++ b/sig/ohme.rbs @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Ohme VERSION: String @@ -20,4 +22,16 @@ module Ohme def put: (String, body: Hash[String, untyped]?) -> Hash[String, untyped]? def delete: (String, params: Hash[String, untyped]?) -> nil end + + module API + class Contact + def initialize: (Ohme::Client?) -> void + + def index: (params: Hash[String, untyped]?) -> Hash[String, untyped]? + def create: (body: Hash[String, untyped]) -> Hash[String, untyped]? + def update: (String, body: Hash[String, untyped]) -> Hash[String, untyped]? + def show: (String) -> Hash[String, untyped]? + def delete: (String) -> nil + end + end end diff --git a/spec/ohme/api/contact_spec.rb b/spec/ohme/api/contact_spec.rb new file mode 100644 index 0000000..5574e4a --- /dev/null +++ b/spec/ohme/api/contact_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_relative '../../../lib/ohme/api/contact' + +# rubocop:disable Metrics/BlockLength +RSpec.describe Ohme::API::Contact do + let(:client) { instance_double(Ohme::Client) } + let(:contact_api) { described_class.new(client) } + + describe '#index' do + it 'fetches the list of contacts' do + expect(client).to receive(:get).with('contacts', params: {}).and_return({ 'contacts' => [] }) + response = contact_api.index + expect(response).to eq({ 'contacts' => [] }) + end + end + + describe '#create' do + it 'creates a new contact' do + contact_data = { name: 'John Doe', email: 'john.doe@example.com' } + expect(client).to receive(:post).with('contacts', body: contact_data).and_return({ 'id' => '123' }) + response = contact_api.create(contact_data) + expect(response).to eq({ 'id' => '123' }) + end + end + + describe '#update' do + it 'updates a contact by ID' do + contact_data = { name: 'Jane Doe' } + expect(client).to receive(:put).with('contacts/123', body: contact_data).and_return({ 'id' => '123', 'name' => 'Jane Doe' }) + response = contact_api.update('123', contact_data) + expect(response).to eq({ 'id' => '123', 'name' => 'Jane Doe' }) + end + end + + describe '#show' do + it 'fetches a contact by ID' do + expect(client).to receive(:get).with('contacts/123').and_return({ 'id' => '123', 'name' => 'John Doe' }) + response = contact_api.show('123') + expect(response).to eq({ 'id' => '123', 'name' => 'John Doe' }) + end + end + + describe '#delete' do + it 'deletes a contact by ID' do + expect(client).to receive(:delete).with('contacts/123').and_return(nil) + response = contact_api.delete('123') + expect(response).to be_nil + end + end +end +# rubocop:enable Metrics/BlockLength From 84810deefacabc4c1af02e98f25a1e48402369f7 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Wed, 9 Apr 2025 11:46:53 +0200 Subject: [PATCH 03/27] Changed domain to client name to respect Ohme wording --- lib/ohme/client.rb | 4 ++-- lib/ohme/configuration.rb | 4 ++-- sig/ohme.rbs | 2 +- spec/ohme/client_spec.rb | 2 +- spec/ohme/configuration_spec.rb | 16 ++++++++-------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/ohme/client.rb b/lib/ohme/client.rb index ca19367..ccb20b4 100644 --- a/lib/ohme/client.rb +++ b/lib/ohme/client.rb @@ -10,7 +10,7 @@ class Client # @param api_key [String] The API key for authentication # @param base_url [String] The base URL for the API # @param timeout [Integer] The timeout for requests in seconds - # @param domain [String] The domain for the API + # @param client_name [String] The client_name for the API # @param version [String] The version of the API def initialize Ohme::Configuration.validate! @@ -59,7 +59,7 @@ def build_url(endpoint) # Builds the headers for the request def build_headers { - 'client-name' => Ohme::Configuration.domain, + 'client-name' => Ohme::Configuration.client_name, 'client-secret' => Ohme::Configuration.api_key, 'Content-Type' => 'application/json', 'Accept' => 'application/json' diff --git a/lib/ohme/configuration.rb b/lib/ohme/configuration.rb index c7ab184..048edd5 100644 --- a/lib/ohme/configuration.rb +++ b/lib/ohme/configuration.rb @@ -4,7 +4,7 @@ module Ohme # Configuration of the Ohme API client gem. module Configuration class << self - attr_accessor :api_key, :base_url, :timeout, :domain, :version + attr_accessor :api_key, :base_url, :timeout, :client_name, :version # Initializes the configuration with default values. def configure @@ -18,7 +18,7 @@ def configure def validate! raise 'API key is missing. Please configure Ohme::Configuration.api_key.' unless @api_key raise 'Base URL is missing. Please configure Ohme::Configuration.base_url.' unless @base_url - raise 'Domain is missing. Please configure Ohme::Configuration.domain.' unless @domain + raise 'client_name is missing. Please configure Ohme::Configuration.client_name.' unless @client_name raise 'Version is missing. Please configure Ohme::Configuration.version.' unless @version end end diff --git a/sig/ohme.rbs b/sig/ohme.rbs index 4a3f88f..2bc8e08 100644 --- a/sig/ohme.rbs +++ b/sig/ohme.rbs @@ -10,7 +10,7 @@ module Ohme attr_accessor api_key: String? attr_accessor base_url: String? attr_accessor timeout: Integer? - attr_accessor domain: String? + attr_accessor client_name: String? attr_accessor version: String? end diff --git a/spec/ohme/client_spec.rb b/spec/ohme/client_spec.rb index c0f6e8d..9d64011 100644 --- a/spec/ohme/client_spec.rb +++ b/spec/ohme/client_spec.rb @@ -11,7 +11,7 @@ # Configure the Ohme::Configuration before each test Ohme::Configuration.configure do |config| config.api_key = 'test_api_key' - config.domain = 'test_domain' + config.client_name = 'test_client_name' end end diff --git a/spec/ohme/configuration_spec.rb b/spec/ohme/configuration_spec.rb index a4d95c6..c54a544 100644 --- a/spec/ohme/configuration_spec.rb +++ b/spec/ohme/configuration_spec.rb @@ -9,7 +9,7 @@ described_class.configure do |config| config.api_key = nil config.base_url = nil - config.domain = nil + config.client_name = nil config.version = nil config.timeout = nil end @@ -20,14 +20,14 @@ described_class.configure do |config| config.api_key = 'test_api_key' config.base_url = 'https://api.example.com' - config.domain = 'test_domain' + config.client_name = 'test_client_name' config.version = 'v1' config.timeout = 60 end expect(described_class.api_key).to eq('test_api_key') expect(described_class.base_url).to eq('https://api.example.com') - expect(described_class.domain).to eq('test_domain') + expect(described_class.client_name).to eq('test_client_name') expect(described_class.version).to eq('v1') expect(described_class.timeout).to eq(60) end @@ -39,7 +39,7 @@ described_class.configure do |config| config.api_key = 'test_api_key' config.base_url = 'https://api.example.com' - config.domain = 'test_domain' + config.client_name = 'test_client_name' config.version = 'v1' end @@ -51,7 +51,7 @@ it 'raises an error' do described_class.configure do |config| config.base_url = 'https://api.example.com' - config.domain = 'test_domain' + config.client_name = 'test_client_name' config.version = 'v1' end @@ -64,7 +64,7 @@ described_class.configure do |config| config.api_key = 'test_api_key' config.base_url = nil - config.domain = 'test_domain' + config.client_name = 'test_client_name' config.version = 'v1' end @@ -72,7 +72,7 @@ end end - context 'when the domain is missing' do + context 'when the client_name is missing' do it 'raises an error' do described_class.configure do |config| config.api_key = 'test_api_key' @@ -80,7 +80,7 @@ config.version = nil end - expect { described_class.validate! }.to raise_error('Domain is missing. Please configure Ohme::Configuration.domain.') + expect { described_class.validate! }.to raise_error('client_name is missing. Please configure Ohme::Configuration.client_name.') end end end From 4bc31be3db54ecc92f0c5268d8ff5845867cf7a2 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Wed, 9 Apr 2025 12:59:23 +0200 Subject: [PATCH 04/27] Updated code & version --- Gemfile.lock | 2 +- lib/ohme.rb | 3 +++ lib/ohme/version.rb | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7128e1d..d58d655 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ohme (0.1.0) + ohme (0.1.1) typhoeus (>= 1.4) GEM diff --git a/lib/ohme.rb b/lib/ohme.rb index 67cdd4c..034394b 100644 --- a/lib/ohme.rb +++ b/lib/ohme.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true require_relative 'ohme/version' +require_relative 'ohme/configuration' +require_relative 'ohme/client' +require_relative 'ohme/api/contact' # Ohme API client gem main module. module Ohme diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index b4734fe..d9ab32b 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = "0.1.0" + VERSION = '0.1.1' end From 46239606b96c7aaef928b6c059188dd765fa3898 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Wed, 9 Apr 2025 13:04:29 +0200 Subject: [PATCH 05/27] Renamed api_key to client_secret to match Ohme wording --- Gemfile.lock | 2 +- lib/ohme/client.rb | 4 ++-- lib/ohme/configuration.rb | 4 ++-- lib/ohme/version.rb | 2 +- sig/ohme.rbs | 2 +- spec/ohme/client_spec.rb | 2 +- spec/ohme/configuration_spec.rb | 16 ++++++++-------- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d58d655..c063fd8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ohme (0.1.1) + ohme (0.1.2) typhoeus (>= 1.4) GEM diff --git a/lib/ohme/client.rb b/lib/ohme/client.rb index ccb20b4..12c8358 100644 --- a/lib/ohme/client.rb +++ b/lib/ohme/client.rb @@ -7,7 +7,7 @@ module Ohme # Client for interacting with the Ohme API class Client # Initializes the client with the configuration - # @param api_key [String] The API key for authentication + # @param client_secret [String] The API key for authentication # @param base_url [String] The base URL for the API # @param timeout [Integer] The timeout for requests in seconds # @param client_name [String] The client_name for the API @@ -60,7 +60,7 @@ def build_url(endpoint) def build_headers { 'client-name' => Ohme::Configuration.client_name, - 'client-secret' => Ohme::Configuration.api_key, + 'client-secret' => Ohme::Configuration.client_secret, 'Content-Type' => 'application/json', 'Accept' => 'application/json' } diff --git a/lib/ohme/configuration.rb b/lib/ohme/configuration.rb index 048edd5..eb6d3c8 100644 --- a/lib/ohme/configuration.rb +++ b/lib/ohme/configuration.rb @@ -4,7 +4,7 @@ module Ohme # Configuration of the Ohme API client gem. module Configuration class << self - attr_accessor :api_key, :base_url, :timeout, :client_name, :version + attr_accessor :client_secret, :base_url, :timeout, :client_name, :version # Initializes the configuration with default values. def configure @@ -16,7 +16,7 @@ def configure # Validates the configuration values. def validate! - raise 'API key is missing. Please configure Ohme::Configuration.api_key.' unless @api_key + raise 'client_secret key is missing. Please configure Ohme::Configuration.client_secret.' unless @client_secret raise 'Base URL is missing. Please configure Ohme::Configuration.base_url.' unless @base_url raise 'client_name is missing. Please configure Ohme::Configuration.client_name.' unless @client_name raise 'Version is missing. Please configure Ohme::Configuration.version.' unless @version diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index d9ab32b..f5b6bbf 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = '0.1.1' + VERSION = '0.1.2' end diff --git a/sig/ohme.rbs b/sig/ohme.rbs index 2bc8e08..8a054ca 100644 --- a/sig/ohme.rbs +++ b/sig/ohme.rbs @@ -7,7 +7,7 @@ module Ohme def self.configure: () { (config: Configuration) -> void } -> void def self.validate!: () -> void - attr_accessor api_key: String? + attr_accessor client_secret: String? attr_accessor base_url: String? attr_accessor timeout: Integer? attr_accessor client_name: String? diff --git a/spec/ohme/client_spec.rb b/spec/ohme/client_spec.rb index 9d64011..c787aba 100644 --- a/spec/ohme/client_spec.rb +++ b/spec/ohme/client_spec.rb @@ -10,7 +10,7 @@ before do # Configure the Ohme::Configuration before each test Ohme::Configuration.configure do |config| - config.api_key = 'test_api_key' + config.client_secret = 'test_client_secret' config.client_name = 'test_client_name' end end diff --git a/spec/ohme/configuration_spec.rb b/spec/ohme/configuration_spec.rb index c54a544..7af137d 100644 --- a/spec/ohme/configuration_spec.rb +++ b/spec/ohme/configuration_spec.rb @@ -7,7 +7,7 @@ before do # Reset configuration before each test described_class.configure do |config| - config.api_key = nil + config.client_secret = nil config.base_url = nil config.client_name = nil config.version = nil @@ -18,14 +18,14 @@ describe '.configure' do it 'allows setting configuration attributes' do described_class.configure do |config| - config.api_key = 'test_api_key' + config.client_secret = 'test_client_secret' config.base_url = 'https://api.example.com' config.client_name = 'test_client_name' config.version = 'v1' config.timeout = 60 end - expect(described_class.api_key).to eq('test_api_key') + expect(described_class.client_secret).to eq('test_client_secret') expect(described_class.base_url).to eq('https://api.example.com') expect(described_class.client_name).to eq('test_client_name') expect(described_class.version).to eq('v1') @@ -37,7 +37,7 @@ context 'when the configuration is valid' do it 'does not raise an error' do described_class.configure do |config| - config.api_key = 'test_api_key' + config.client_secret = 'test_client_secret' config.base_url = 'https://api.example.com' config.client_name = 'test_client_name' config.version = 'v1' @@ -47,7 +47,7 @@ end end - context 'when the API key is missing' do + context 'when the client secret is missing' do it 'raises an error' do described_class.configure do |config| config.base_url = 'https://api.example.com' @@ -55,14 +55,14 @@ config.version = 'v1' end - expect { described_class.validate! }.to raise_error('API key is missing. Please configure Ohme::Configuration.api_key.') + expect { described_class.validate! }.to raise_error('client_secret key is missing. Please configure Ohme::Configuration.client_secret.') end end context 'when the base URL is missing' do it 'raises an error' do described_class.configure do |config| - config.api_key = 'test_api_key' + config.client_secret = 'test_client_secret' config.base_url = nil config.client_name = 'test_client_name' config.version = 'v1' @@ -75,7 +75,7 @@ context 'when the client_name is missing' do it 'raises an error' do described_class.configure do |config| - config.api_key = 'test_api_key' + config.client_secret = 'test_client_secret' config.base_url = 'https://api.example.com' config.version = nil end From 963fa4d54cec87a23adab021bdf371866b223d9b Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Wed, 9 Apr 2025 18:00:37 +0200 Subject: [PATCH 06/27] Improved code, specs and bumped version --- Gemfile.lock | 2 +- lib/ohme/client.rb | 18 +++--- lib/ohme/configuration.rb | 43 ++++++++------ lib/ohme/version.rb | 2 +- spec/ohme/client_spec.rb | 9 +-- spec/ohme/configuration_spec.rb | 100 ++++++++++++++------------------ 6 files changed, 84 insertions(+), 90 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c063fd8..ade96bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ohme (0.1.2) + ohme (0.1.3) typhoeus (>= 1.4) GEM diff --git a/lib/ohme/client.rb b/lib/ohme/client.rb index 12c8358..41b864c 100644 --- a/lib/ohme/client.rb +++ b/lib/ohme/client.rb @@ -7,13 +7,9 @@ module Ohme # Client for interacting with the Ohme API class Client # Initializes the client with the configuration - # @param client_secret [String] The API key for authentication - # @param base_url [String] The base URL for the API - # @param timeout [Integer] The timeout for requests in seconds - # @param client_name [String] The client_name for the API - # @param version [String] The version of the API - def initialize - Ohme::Configuration.validate! + def initialize(configuration = Ohme::Configuration.new) + @configuration = configuration + @configuration.validate! end # Performs a GET request @@ -46,21 +42,21 @@ def request(method, endpoint, options = {}) headers: build_headers, params: options[:params], body: options[:body]&.to_json, - timeout: Ohme::Configuration.timeout + timeout: @configuration.timeout ).run handle_response(response) end def build_url(endpoint) - "#{Ohme::Configuration.base_url}#{Ohme::Configuration.version}/#{endpoint}" + "#{@configuration.base_url}#{@configuration.version}/#{endpoint}" end # Builds the headers for the request def build_headers { - 'client-name' => Ohme::Configuration.client_name, - 'client-secret' => Ohme::Configuration.client_secret, + 'client-name' => @configuration.client_name, + 'client-secret' => @configuration.client_secret, 'Content-Type' => 'application/json', 'Accept' => 'application/json' } diff --git a/lib/ohme/configuration.rb b/lib/ohme/configuration.rb index eb6d3c8..364db7d 100644 --- a/lib/ohme/configuration.rb +++ b/lib/ohme/configuration.rb @@ -2,25 +2,34 @@ module Ohme # Configuration of the Ohme API client gem. - module Configuration - class << self - attr_accessor :client_secret, :base_url, :timeout, :client_name, :version + class Configuration + attr_accessor :base_url, :client_name, :client_secret, :timeout, :version - # Initializes the configuration with default values. - def configure - @base_url = 'https://api-ohme.oneheart.fr/api/' # Nouvelle URL de base - @version = 'v1' # Version par défaut - @timeout = 30 # Timeout par défaut en secondes - yield self if block_given? - end + # Initializes the configuration with default values. + def initialize + @base_url = 'https://api-ohme.oneheart.fr/api/' + @version = 'v1' + @timeout = 30 + yield self if block_given? + end + + def configure + yield(self) if block_given? + end + + # Validates the configuration values. + def validate! + error_on('client_name') unless @client_name + error_on('client_secret') unless @client_secret + end + + private - # Validates the configuration values. - def validate! - raise 'client_secret key is missing. Please configure Ohme::Configuration.client_secret.' unless @client_secret - raise 'Base URL is missing. Please configure Ohme::Configuration.base_url.' unless @base_url - raise 'client_name is missing. Please configure Ohme::Configuration.client_name.' unless @client_name - raise 'Version is missing. Please configure Ohme::Configuration.version.' unless @version - end + def error_on(attribute) + raise( + "#{attribute} is missing. " \ + "Please configure Ohme::Configuration.#{attribute}." + ) end end end diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index f5b6bbf..4b805ee 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = '0.1.2' + VERSION = '0.1.3' end diff --git a/spec/ohme/client_spec.rb b/spec/ohme/client_spec.rb index c787aba..79f3931 100644 --- a/spec/ohme/client_spec.rb +++ b/spec/ohme/client_spec.rb @@ -6,16 +6,16 @@ require_relative '../../lib/ohme/client' require_relative '../../lib/ohme/configuration' +# rubocop:disable Metrics/BlockLength RSpec.describe Ohme::Client do - before do - # Configure the Ohme::Configuration before each test - Ohme::Configuration.configure do |config| + let(:configuration) do + Ohme::Configuration.new do |config| config.client_secret = 'test_client_secret' config.client_name = 'test_client_name' end end - let(:client) { described_class.new } + let(:client) { described_class.new(configuration) } describe '#get' do it 'sends a GET request to the correct endpoint' do @@ -77,3 +77,4 @@ end end end +# rubocop:enable Metrics/BlockLength diff --git a/spec/ohme/configuration_spec.rb b/spec/ohme/configuration_spec.rb index 7af137d..4b42cff 100644 --- a/spec/ohme/configuration_spec.rb +++ b/spec/ohme/configuration_spec.rb @@ -3,85 +3,73 @@ require 'spec_helper' require_relative '../../lib/ohme/configuration' +# rubocop:disable Metrics/BlockLength RSpec.describe Ohme::Configuration do - before do - # Reset configuration before each test - described_class.configure do |config| - config.client_secret = nil - config.base_url = nil - config.client_name = nil - config.version = nil - config.timeout = nil - end - end - - describe '.configure' do - it 'allows setting configuration attributes' do - described_class.configure do |config| - config.client_secret = 'test_client_secret' + describe '.new' do + let(:conf) do + described_class.new do |config| config.base_url = 'https://api.example.com' config.client_name = 'test_client_name' - config.version = 'v1' + config.client_secret = 'test_client_secret' config.timeout = 60 + config.version = 'v1' end - - expect(described_class.client_secret).to eq('test_client_secret') - expect(described_class.base_url).to eq('https://api.example.com') - expect(described_class.client_name).to eq('test_client_name') - expect(described_class.version).to eq('v1') - expect(described_class.timeout).to eq(60) end - end - describe '.validate!' do - context 'when the configuration is valid' do - it 'does not raise an error' do - described_class.configure do |config| - config.client_secret = 'test_client_secret' - config.base_url = 'https://api.example.com' - config.client_name = 'test_client_name' - config.version = 'v1' - end + describe 'setting configuration attributes' do + it 'sets the client_secret attribute correctly' do + expect(conf.client_secret).to eq('test_client_secret') + end - expect { described_class.validate! }.not_to raise_error + it 'sets the base_url attribute correctly' do + expect(conf.base_url).to eq('https://api.example.com') + end + + it 'sets the client_name attribute correctly' do + expect(conf.client_name).to eq('test_client_name') + end + + it 'sets the version attribute correctly' do + expect(conf.version).to eq('v1') + end + + it 'sets the timeout attribute correctly' do + expect(conf.timeout).to eq(60) end end + end - context 'when the client secret is missing' do - it 'raises an error' do - described_class.configure do |config| - config.base_url = 'https://api.example.com' - config.client_name = 'test_client_name' - config.version = 'v1' - end + describe '#validate!' do + let(:conf) { described_class.new } + + context 'when all required attributes are set' do + it 'does not raise an error' do + conf.client_name = 'test_client_name' + conf.client_secret = 'test_client_secret' - expect { described_class.validate! }.to raise_error('client_secret key is missing. Please configure Ohme::Configuration.client_secret.') + expect { conf.validate! }.not_to raise_error end end - context 'when the base URL is missing' do + context 'when client_name is missing' do it 'raises an error' do - described_class.configure do |config| - config.client_secret = 'test_client_secret' - config.base_url = nil - config.client_name = 'test_client_name' - config.version = 'v1' - end + error_message = 'client_name is missing. ' \ + 'Please configure Ohme::Configuration.client_name.' + conf.client_secret = 'test_client_secret' - expect { described_class.validate! }.to raise_error('Base URL is missing. Please configure Ohme::Configuration.base_url.') + expect { conf.validate! }.to raise_error(error_message) end end - context 'when the client_name is missing' do + context 'when client_secret is missing' do it 'raises an error' do - described_class.configure do |config| - config.client_secret = 'test_client_secret' - config.base_url = 'https://api.example.com' - config.version = nil - end + error_message = 'client_secret is missing. ' \ + 'Please configure Ohme::Configuration.client_secret.' + conf.client_name = 'test_client_name' - expect { described_class.validate! }.to raise_error('client_name is missing. Please configure Ohme::Configuration.client_name.') + expect { conf.validate! }.to raise_error(error_message) end end end end +# rubocop:enable Metrics/BlockLength From edd8ab61c295cef3d7387fef1695769c3ef45f1c Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Mon, 12 May 2025 12:43:27 +0200 Subject: [PATCH 07/27] Added payment code + specifications --- Gemfile.lock | 2 +- lib/ohme/api/payment.rb | 47 ++++++++++++++++++++++++++++++++ lib/ohme/version.rb | 2 +- spec/ohme/api/payment_spec.rb | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 lib/ohme/api/payment.rb create mode 100644 spec/ohme/api/payment_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index ade96bd..92c15e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ohme (0.1.3) + ohme (0.1.4) typhoeus (>= 1.4) GEM diff --git a/lib/ohme/api/payment.rb b/lib/ohme/api/payment.rb new file mode 100644 index 0000000..c5815ec --- /dev/null +++ b/lib/ohme/api/payment.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Ohme + module API + class Payment + def initialize(client = Ohme::Client.new) + @client = client + end + + # Fetches the list of payments + # @param params [Hash] Optional query parameters + # @return [Hash] The response from the API + def index(params = {}) + @client.get('payments', params: params) + end + + # Creates a new payment + # @param body [Hash] The payment data to be sent in the request body + # @return [Hash] The response from the API + def create(body) + @client.post('payments', body: body) + end + + # Updates a payment by ID + # @param id [String] The ID of the payment to update + # @param body [Hash] The payment data to be updated + # @return [Hash] The response from the API + def update(id, body) + @client.put("payments/#{id}", body: body) + end + + # Fetches a payment by ID + # @param id [String] The ID of the payment to retrieve + # @return [Hash] The response from the API + def show(id) + @client.get("payments/#{id}") + end + + # Deletes a payment by ID + # @param id [String] The ID of the payment to delete + # @return [nil] The response from the API + def delete(id) + @client.delete("payments/#{id}") + end + end + end +end diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index 4b805ee..99673c5 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = '0.1.3' + VERSION = '0.1.4' end diff --git a/spec/ohme/api/payment_spec.rb b/spec/ohme/api/payment_spec.rb new file mode 100644 index 0000000..3fdcd08 --- /dev/null +++ b/spec/ohme/api/payment_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_relative '../../../lib/ohme/api/payment' + +RSpec.describe Ohme::API::Payment do + let(:client) { instance_double(Ohme::Client) } + let(:payment_api) { described_class.new(client) } + + describe '#index' do + it 'fetches the list of payments' do + expect(client).to receive(:get).with('payments', params: {}).and_return({ 'payments' => [] }) + response = payment_api.index + expect(response).to eq({ 'payments' => [] }) + end + end + + describe '#create' do + it 'creates a new payment' do + payment_data = { amount: 100, currency: 'USD' } + expect(client).to receive(:post).with('payments', body: payment_data).and_return({ 'id' => '123' }) + response = payment_api.create(payment_data) + expect(response).to eq({ 'id' => '123' }) + end + end + + describe '#update' do + it 'updates a payment by ID' do + payment_data = { amount: 150 } + expect(client).to receive(:put).with('payments/123', body: payment_data).and_return({ 'id' => '123', 'amount' => 150 }) + response = payment_api.update('123', payment_data) + expect(response).to eq({ 'id' => '123', 'amount' => 150 }) + end + end + + describe '#show' do + it 'fetches a payment by ID' do + expect(client).to receive(:get).with('payments/123').and_return({ 'id' => '123', 'amount' => 100 }) + response = payment_api.show('123') + expect(response).to eq({ 'id' => '123', 'amount' => 100 }) + end + end + + describe '#delete' do + it 'deletes a payment by ID' do + expect(client).to receive(:delete).with('payments/123').and_return(nil) + response = payment_api.delete('123') + expect(response).to be_nil + end + end +end From c8663f0bd2a22b705da26a5849930ebc687f46e7 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Wed, 14 May 2025 17:48:10 +0200 Subject: [PATCH 08/27] Removed timeout log --- Gemfile.lock | 2 +- lib/ohme/client.rb | 1 - lib/ohme/version.rb | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 92c15e1..2c3e482 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ohme (0.1.4) + ohme (0.1.5) typhoeus (>= 1.4) GEM diff --git a/lib/ohme/client.rb b/lib/ohme/client.rb index 41b864c..b117e54 100644 --- a/lib/ohme/client.rb +++ b/lib/ohme/client.rb @@ -64,7 +64,6 @@ def build_headers # Handle the API response def handle_response(response) - p "Timeout: #{response.timed_out?}" if response.timed_out? raise 'Request timed out. Please check your network connection or increase the timeout.' elsif response.success? diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index 99673c5..fab8e0b 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = '0.1.4' + VERSION = '0.1.5' end From 90e90e0dc5f209a9b52226e1bc2a25ecb65aaf2a Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Mon, 19 May 2025 11:56:33 +0200 Subject: [PATCH 09/27] Corrected lib requirements --- Gemfile.lock | 2 +- lib/ohme.rb | 1 + lib/ohme/version.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2c3e482..f8acf33 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ohme (0.1.5) + ohme (0.1.6) typhoeus (>= 1.4) GEM diff --git a/lib/ohme.rb b/lib/ohme.rb index 034394b..37685be 100644 --- a/lib/ohme.rb +++ b/lib/ohme.rb @@ -4,6 +4,7 @@ require_relative 'ohme/configuration' require_relative 'ohme/client' require_relative 'ohme/api/contact' +require_relative 'ohme/api/payment' # Ohme API client gem main module. module Ohme diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index fab8e0b..b338378 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = '0.1.5' + VERSION = '0.1.6' end From 1d09e56c1f25d2326d4cd640b3430d725fb47d4e Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Tue, 20 May 2025 11:12:05 +0200 Subject: [PATCH 10/27] Corrected request --- Gemfile.lock | 2 +- lib/ohme/client.rb | 2 +- lib/ohme/version.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f8acf33..d93ab1b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ohme (0.1.6) + ohme (0.1.7) typhoeus (>= 1.4) GEM diff --git a/lib/ohme/client.rb b/lib/ohme/client.rb index b117e54..5390f57 100644 --- a/lib/ohme/client.rb +++ b/lib/ohme/client.rb @@ -41,7 +41,7 @@ def request(method, endpoint, options = {}) method: method, headers: build_headers, params: options[:params], - body: options[:body]&.to_json, + body: options[:body], timeout: @configuration.timeout ).run diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index b338378..2a4dc9f 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = '0.1.6' + VERSION = '0.1.7' end From c8f37465cae5e79082a1eb96f8c5adbfb1d62afd Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Tue, 20 May 2025 12:22:56 +0200 Subject: [PATCH 11/27] Rollback on serialized body --- lib/ohme/client.rb | 2 +- lib/ohme/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ohme/client.rb b/lib/ohme/client.rb index 5390f57..b117e54 100644 --- a/lib/ohme/client.rb +++ b/lib/ohme/client.rb @@ -41,7 +41,7 @@ def request(method, endpoint, options = {}) method: method, headers: build_headers, params: options[:params], - body: options[:body], + body: options[:body]&.to_json, timeout: @configuration.timeout ).run diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index 2a4dc9f..ab56917 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = '0.1.7' + VERSION = '0.1.8 end From fe7503d95f55079f6a0af1c1be00b1b3ea326dbe Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Tue, 20 May 2025 12:24:46 +0200 Subject: [PATCH 12/27] Corrected typo --- Gemfile.lock | 2 +- lib/ohme/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d93ab1b..1790afd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ohme (0.1.7) + ohme (0.1.8) typhoeus (>= 1.4) GEM diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index ab56917..a921a7f 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = '0.1.8 + VERSION = '0.1.8' end From f1c651ccbfc602e468c1604927f1816504b23229 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Tue, 20 May 2025 12:41:22 +0200 Subject: [PATCH 13/27] Corrected client calls --- Gemfile.lock | 2 +- lib/ohme/api/contact.rb | 6 +++--- lib/ohme/version.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1790afd..8a05017 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ohme (0.1.8) + ohme (0.1.9) typhoeus (>= 1.4) GEM diff --git a/lib/ohme/api/contact.rb b/lib/ohme/api/contact.rb index 81e522f..c12ee9d 100644 --- a/lib/ohme/api/contact.rb +++ b/lib/ohme/api/contact.rb @@ -11,14 +11,14 @@ def initialize(client = Ohme::Client.new) # @param params [Hash] Optional query parameters # @return [Hash] The response from the API def index(params = {}) - @client.get('contacts', params: params) + @client.get('contacts', params) end # Creates a new contact # @param body [Hash] The contact data to be sent in the request body # @return [Hash] The response from the API def create(body) - @client.post('contacts', body: body) + @client.post('contacts', body) end # Updates a contact by ID @@ -26,7 +26,7 @@ def create(body) # @param body [Hash] The contact data to be updated # @return [Hash] The response from the API def update(id, body) - @client.put("contacts/#{id}", body: body) + @client.put("contacts/#{id}", body) end # Fetches a contact by ID diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index a921a7f..24becc7 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = '0.1.8' + VERSION = '0.1.9' end From 537b4b3be6c633bd5e2e4308d351c24a453ceb14 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Tue, 20 May 2025 15:25:50 +0200 Subject: [PATCH 14/27] Corrected payment api --- Gemfile.lock | 2 +- lib/ohme/api/payment.rb | 6 +++--- lib/ohme/version.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8a05017..51d600c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ohme (0.1.9) + ohme (0.1.10) typhoeus (>= 1.4) GEM diff --git a/lib/ohme/api/payment.rb b/lib/ohme/api/payment.rb index c5815ec..64229aa 100644 --- a/lib/ohme/api/payment.rb +++ b/lib/ohme/api/payment.rb @@ -11,14 +11,14 @@ def initialize(client = Ohme::Client.new) # @param params [Hash] Optional query parameters # @return [Hash] The response from the API def index(params = {}) - @client.get('payments', params: params) + @client.get('payments', params) end # Creates a new payment # @param body [Hash] The payment data to be sent in the request body # @return [Hash] The response from the API def create(body) - @client.post('payments', body: body) + @client.post('payments', body) end # Updates a payment by ID @@ -26,7 +26,7 @@ def create(body) # @param body [Hash] The payment data to be updated # @return [Hash] The response from the API def update(id, body) - @client.put("payments/#{id}", body: body) + @client.put("payments/#{id}", body) end # Fetches a payment by ID diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index 24becc7..921ca9e 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = '0.1.9' + VERSION = '0.1.10' end From 704c713d42d1dd491d3c2e8937a9b349973f0dca Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Tue, 24 Jun 2025 17:25:54 +0200 Subject: [PATCH 15/27] Corrected specs --- spec/ohme/api/contact_spec.rb | 6 +++--- spec/ohme/api/payment_spec.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/ohme/api/contact_spec.rb b/spec/ohme/api/contact_spec.rb index 5574e4a..9f68091 100644 --- a/spec/ohme/api/contact_spec.rb +++ b/spec/ohme/api/contact_spec.rb @@ -10,7 +10,7 @@ describe '#index' do it 'fetches the list of contacts' do - expect(client).to receive(:get).with('contacts', params: {}).and_return({ 'contacts' => [] }) + expect(client).to receive(:get).with('contacts', {}).and_return({ 'contacts' => [] }) response = contact_api.index expect(response).to eq({ 'contacts' => [] }) end @@ -19,7 +19,7 @@ describe '#create' do it 'creates a new contact' do contact_data = { name: 'John Doe', email: 'john.doe@example.com' } - expect(client).to receive(:post).with('contacts', body: contact_data).and_return({ 'id' => '123' }) + expect(client).to receive(:post).with('contacts', contact_data).and_return({ 'id' => '123' }) response = contact_api.create(contact_data) expect(response).to eq({ 'id' => '123' }) end @@ -28,7 +28,7 @@ describe '#update' do it 'updates a contact by ID' do contact_data = { name: 'Jane Doe' } - expect(client).to receive(:put).with('contacts/123', body: contact_data).and_return({ 'id' => '123', 'name' => 'Jane Doe' }) + expect(client).to receive(:put).with('contacts/123', contact_data).and_return({ 'id' => '123', 'name' => 'Jane Doe' }) response = contact_api.update('123', contact_data) expect(response).to eq({ 'id' => '123', 'name' => 'Jane Doe' }) end diff --git a/spec/ohme/api/payment_spec.rb b/spec/ohme/api/payment_spec.rb index 3fdcd08..1aa6394 100644 --- a/spec/ohme/api/payment_spec.rb +++ b/spec/ohme/api/payment_spec.rb @@ -9,7 +9,7 @@ describe '#index' do it 'fetches the list of payments' do - expect(client).to receive(:get).with('payments', params: {}).and_return({ 'payments' => [] }) + expect(client).to receive(:get).with('payments', {}).and_return({ 'payments' => [] }) response = payment_api.index expect(response).to eq({ 'payments' => [] }) end @@ -18,7 +18,7 @@ describe '#create' do it 'creates a new payment' do payment_data = { amount: 100, currency: 'USD' } - expect(client).to receive(:post).with('payments', body: payment_data).and_return({ 'id' => '123' }) + expect(client).to receive(:post).with('payments', payment_data).and_return({ 'id' => '123' }) response = payment_api.create(payment_data) expect(response).to eq({ 'id' => '123' }) end @@ -27,7 +27,7 @@ describe '#update' do it 'updates a payment by ID' do payment_data = { amount: 150 } - expect(client).to receive(:put).with('payments/123', body: payment_data).and_return({ 'id' => '123', 'amount' => 150 }) + expect(client).to receive(:put).with('payments/123', payment_data).and_return({ 'id' => '123', 'amount' => 150 }) response = payment_api.update('123', payment_data) expect(response).to eq({ 'id' => '123', 'amount' => 150 }) end From 573e47e5efd1356463357b33f2cebd2b4b556dc8 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Tue, 24 Jun 2025 17:28:05 +0200 Subject: [PATCH 16/27] Bump ohme to 0.2.0 --- lib/ohme/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index 921ca9e..1dbd82e 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = '0.1.10' + VERSION = '0.2.0' end From 09adf851a82131395c832d4f417150dce4486eb9 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Tue, 24 Jun 2025 17:43:20 +0200 Subject: [PATCH 17/27] Added documentation --- .gitignore | 3 +++ Gemfile.lock | 2 +- lib/ohme/api/contact.rb | 13 +++++++++++++ lib/ohme/api/payment.rb | 8 ++++++++ lib/ohme/client.rb | 37 +++++++++++++++++++++++++++++++++++-- lib/ohme/configuration.rb | 13 +++++++++++++ 6 files changed, 73 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index b04a8c8..6cdb52a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ # rspec failure tracking .rspec_status + +# Qlty +.qlty/ diff --git a/Gemfile.lock b/Gemfile.lock index 51d600c..cfd31ba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ohme (0.1.10) + ohme (0.2.0) typhoeus (>= 1.4) GEM diff --git a/lib/ohme/api/contact.rb b/lib/ohme/api/contact.rb index c12ee9d..e5325f2 100644 --- a/lib/ohme/api/contact.rb +++ b/lib/ohme/api/contact.rb @@ -2,12 +2,21 @@ module Ohme module API + # The Contact class provides methods to interact with the Ohme API's + # contacts endpoint. + # It allows you to list, create, read, update, and delete contacts. class Contact + # Initializes a new Contact instance with a client. + # + # @param client [Ohme::Client] An instance of the Ohme client to + # make API requests + # @return [Ohme::API::Contact] A new instance of the Contact class def initialize(client = Ohme::Client.new) @client = client end # Fetches the list of contacts + # # @param params [Hash] Optional query parameters # @return [Hash] The response from the API def index(params = {}) @@ -15,6 +24,7 @@ def index(params = {}) end # Creates a new contact + # # @param body [Hash] The contact data to be sent in the request body # @return [Hash] The response from the API def create(body) @@ -22,6 +32,7 @@ def create(body) end # Updates a contact by ID + # # @param id [String] The ID of the contact to update # @param body [Hash] The contact data to be updated # @return [Hash] The response from the API @@ -30,6 +41,7 @@ def update(id, body) end # Fetches a contact by ID + # # @param id [String] The ID of the contact to retrieve # @return [Hash] The response from the API def show(id) @@ -37,6 +49,7 @@ def show(id) end # Deletes a contact by ID + # # @param id [String] The ID of the contact to delete # @return [nil] The response from the API def delete(id) diff --git a/lib/ohme/api/payment.rb b/lib/ohme/api/payment.rb index 64229aa..f412f48 100644 --- a/lib/ohme/api/payment.rb +++ b/lib/ohme/api/payment.rb @@ -2,12 +2,16 @@ module Ohme module API + # The Payment class provides methods to interact with the Ohme API's + # payments endpoint. + # It allows you to list, create, read, update, and delete payments. class Payment def initialize(client = Ohme::Client.new) @client = client end # Fetches the list of payments + # # @param params [Hash] Optional query parameters # @return [Hash] The response from the API def index(params = {}) @@ -15,6 +19,7 @@ def index(params = {}) end # Creates a new payment + # # @param body [Hash] The payment data to be sent in the request body # @return [Hash] The response from the API def create(body) @@ -22,6 +27,7 @@ def create(body) end # Updates a payment by ID + # # @param id [String] The ID of the payment to update # @param body [Hash] The payment data to be updated # @return [Hash] The response from the API @@ -30,6 +36,7 @@ def update(id, body) end # Fetches a payment by ID + # # @param id [String] The ID of the payment to retrieve # @return [Hash] The response from the API def show(id) @@ -37,6 +44,7 @@ def show(id) end # Deletes a payment by ID + # # @param id [String] The ID of the payment to delete # @return [nil] The response from the API def delete(id) diff --git a/lib/ohme/client.rb b/lib/ohme/client.rb index b117e54..037d23c 100644 --- a/lib/ohme/client.rb +++ b/lib/ohme/client.rb @@ -7,27 +7,46 @@ module Ohme # Client for interacting with the Ohme API class Client # Initializes the client with the configuration + # + # @param configuration [Ohme::Configuration] The configuration object + # @return [Ohme::Client] A new instance of the Ohme client def initialize(configuration = Ohme::Configuration.new) @configuration = configuration @configuration.validate! end # Performs a GET request + # + # @param endpoint [String] The API endpoint to request + # @param params [Hash] Optional query parameters + # @return [Hash] The response from the API def get(endpoint, params = {}) request(:get, endpoint, params: params) end # Performs a POST request + # + # @param endpoint [String] The API endpoint to request + # @param body [Hash] The request body to send + # @return [Hash] The response from the API def post(endpoint, body = {}) request(:post, endpoint, body: body) end # Performs a PUT request + # + # @param endpoint [String] The API endpoint to request + # @param body [Hash] The request body to send + # @return [Hash] The response from the API def put(endpoint, body = {}) request(:put, endpoint, body: body) end # Performs a DELETE request + # + # @param endpoint [String] The API endpoint to request + # @param params [Hash] Optional query parameters + # @return [nil] The response from the API (nil for DELETE requests) def delete(endpoint, params = {}) request(:delete, endpoint, params: params) end @@ -35,6 +54,11 @@ def delete(endpoint, params = {}) private # Private: Performs an HTTP request + # + # @param method [Symbol] The HTTP method (get, post, put, delete) + # @param endpoint [String] The API endpoint to request + # @param options [Hash] Optional parameters for the request + # @return [Hash, nil] The parsed response from the API or nil for DELETE def request(method, endpoint, options = {}) response = Typhoeus::Request.new( build_url(endpoint), @@ -48,11 +72,17 @@ def request(method, endpoint, options = {}) handle_response(response) end + # Private: Builds the full URL for the API request + # + # @param endpoint [String] The API endpoint to request + # @return [String] The full URL for the request def build_url(endpoint) "#{@configuration.base_url}#{@configuration.version}/#{endpoint}" end - # Builds the headers for the request + # Private: Builds the headers for the request + # + # @return [Hash] The headers to be sent with the request def build_headers { 'client-name' => @configuration.client_name, @@ -62,7 +92,10 @@ def build_headers } end - # Handle the API response + # Private: Handles the API response + # + # @param response [Typhoeus::Response] The response from the API + # @return [Hash, nil] The parsed response or nil for DELETE requests def handle_response(response) if response.timed_out? raise 'Request timed out. Please check your network connection or increase the timeout.' diff --git a/lib/ohme/configuration.rb b/lib/ohme/configuration.rb index 364db7d..6897ab9 100644 --- a/lib/ohme/configuration.rb +++ b/lib/ohme/configuration.rb @@ -6,6 +6,9 @@ class Configuration attr_accessor :base_url, :client_name, :client_secret, :timeout, :version # Initializes the configuration with default values. + # + # @yield [config] Optional block to configure the client + # @return [Ohme::Configuration] A new instance of the configuration def initialize @base_url = 'https://api-ohme.oneheart.fr/api/' @version = 'v1' @@ -13,11 +16,17 @@ def initialize yield self if block_given? end + # Configures the Ohme API client with a block. + # + # @yield [config] A block to configure the client + # @return [Ohme::Configuration] The current configuration instance def configure yield(self) if block_given? end # Validates the configuration values. + # + # @raise [RuntimeError] if required values are missing def validate! error_on('client_name') unless @client_name error_on('client_secret') unless @client_secret @@ -25,6 +34,10 @@ def validate! private + # Private: Raises an error if a required configuration attribute is missing. + # + # @param attribute [String] The name of the missing attribute + # @raise [RuntimeError] if the attribute is missing def error_on(attribute) raise( "#{attribute} is missing. " \ From ff93c148a0735976c5fbac3e24de1a2feecec8ab Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Tue, 24 Jun 2025 17:53:34 +0200 Subject: [PATCH 18/27] Corrected formatting issues --- Gemfile | 8 ++-- README.md | 6 +-- Rakefile | 6 +-- lib/ohme.rb | 10 ++--- lib/ohme/api/contact.rb | 4 +- lib/ohme/api/payment.rb | 4 +- lib/ohme/client.rb | 14 +++--- lib/ohme/configuration.rb | 8 ++-- lib/ohme/version.rb | 2 +- ohme.gemspec | 32 ++++++------- spec/ohme/api/contact_spec.rb | 53 +++++++++++----------- spec/ohme/api/payment_spec.rb | 52 ++++++++++----------- spec/ohme/client_spec.rb | 80 +++++++++++++++++---------------- spec/ohme/configuration_spec.rb | 64 +++++++++++++------------- spec/ohme_spec.rb | 2 +- 15 files changed, 174 insertions(+), 171 deletions(-) diff --git a/Gemfile b/Gemfile index 8ecdb4d..6808d3f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,12 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in ohme.gemspec gemspec -gem 'rake', '~> 13.0' +gem "rake", "~> 13.0" -gem 'rspec', '~> 3.0' +gem "rspec", "~> 3.0" -gem 'standard', '~> 1.3' +gem "standard", "~> 1.3" diff --git a/README.md b/README.md index c24df5d..d6f416d 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ A Ruby connector for the Ohme API, a tool for integrating with the Ohme CRM plat Install the gem and add to the application's Gemfile by executing: - $ bundle add ohme + bundle add ohme If bundler is not being used to manage dependencies, install the gem by executing: - $ gem install ohme + gem install ohme ## Usage @@ -24,7 +24,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/Treize37/ohme. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Treize37/ohme/blob/main/CODE_OF_CONDUCT.md). +Bug reports and pull requests are welcome on GitHub at . This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Treize37/ohme/blob/main/CODE_OF_CONDUCT.md). ## License diff --git a/Rakefile b/Rakefile index 7d38ee8..df40677 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' +require "bundler/gem_tasks" +require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) -require 'standard/rake' +require "standard/rake" task default: %i[spec standard] diff --git a/lib/ohme.rb b/lib/ohme.rb index 37685be..d3735db 100644 --- a/lib/ohme.rb +++ b/lib/ohme.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require_relative 'ohme/version' -require_relative 'ohme/configuration' -require_relative 'ohme/client' -require_relative 'ohme/api/contact' -require_relative 'ohme/api/payment' +require_relative "ohme/version" +require_relative "ohme/configuration" +require_relative "ohme/client" +require_relative "ohme/api/contact" +require_relative "ohme/api/payment" # Ohme API client gem main module. module Ohme diff --git a/lib/ohme/api/contact.rb b/lib/ohme/api/contact.rb index e5325f2..97f74f9 100644 --- a/lib/ohme/api/contact.rb +++ b/lib/ohme/api/contact.rb @@ -20,7 +20,7 @@ def initialize(client = Ohme::Client.new) # @param params [Hash] Optional query parameters # @return [Hash] The response from the API def index(params = {}) - @client.get('contacts', params) + @client.get("contacts", params) end # Creates a new contact @@ -28,7 +28,7 @@ def index(params = {}) # @param body [Hash] The contact data to be sent in the request body # @return [Hash] The response from the API def create(body) - @client.post('contacts', body) + @client.post("contacts", body) end # Updates a contact by ID diff --git a/lib/ohme/api/payment.rb b/lib/ohme/api/payment.rb index f412f48..b9a96fd 100644 --- a/lib/ohme/api/payment.rb +++ b/lib/ohme/api/payment.rb @@ -15,7 +15,7 @@ def initialize(client = Ohme::Client.new) # @param params [Hash] Optional query parameters # @return [Hash] The response from the API def index(params = {}) - @client.get('payments', params) + @client.get("payments", params) end # Creates a new payment @@ -23,7 +23,7 @@ def index(params = {}) # @param body [Hash] The payment data to be sent in the request body # @return [Hash] The response from the API def create(body) - @client.post('payments', body) + @client.post("payments", body) end # Updates a payment by ID diff --git a/lib/ohme/client.rb b/lib/ohme/client.rb index 037d23c..d0708a0 100644 --- a/lib/ohme/client.rb +++ b/lib/ohme/client.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'typhoeus' -require_relative 'configuration' +require "typhoeus" +require_relative "configuration" module Ohme # Client for interacting with the Ohme API @@ -85,10 +85,10 @@ def build_url(endpoint) # @return [Hash] The headers to be sent with the request def build_headers { - 'client-name' => @configuration.client_name, - 'client-secret' => @configuration.client_secret, - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + "client-name" => @configuration.client_name, + "client-secret" => @configuration.client_secret, + "Content-Type" => "application/json", + "Accept" => "application/json" } end @@ -98,7 +98,7 @@ def build_headers # @return [Hash, nil] The parsed response or nil for DELETE requests def handle_response(response) if response.timed_out? - raise 'Request timed out. Please check your network connection or increase the timeout.' + raise "Request timed out. Please check your network connection or increase the timeout." elsif response.success? # Return nil for DELETE requests with no body return nil if response.body.nil? || response.body.strip.empty? diff --git a/lib/ohme/configuration.rb b/lib/ohme/configuration.rb index 6897ab9..f5cfa52 100644 --- a/lib/ohme/configuration.rb +++ b/lib/ohme/configuration.rb @@ -10,8 +10,8 @@ class Configuration # @yield [config] Optional block to configure the client # @return [Ohme::Configuration] A new instance of the configuration def initialize - @base_url = 'https://api-ohme.oneheart.fr/api/' - @version = 'v1' + @base_url = "https://api-ohme.oneheart.fr/api/" + @version = "v1" @timeout = 30 yield self if block_given? end @@ -28,8 +28,8 @@ def configure # # @raise [RuntimeError] if required values are missing def validate! - error_on('client_name') unless @client_name - error_on('client_secret') unless @client_secret + error_on("client_name") unless @client_name + error_on("client_secret") unless @client_secret end private diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index 1dbd82e..2d2de49 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = '0.2.0' + VERSION = "0.2.0" end diff --git a/ohme.gemspec b/ohme.gemspec index 5872ead..deccf6f 100644 --- a/ohme.gemspec +++ b/ohme.gemspec @@ -1,24 +1,24 @@ # frozen_string_literal: true -require_relative 'lib/ohme/version' +require_relative "lib/ohme/version" Gem::Specification.new do |spec| - spec.name = 'ohme' + spec.name = "ohme" spec.version = Ohme::VERSION - spec.authors = ['Fabrice Carrega'] - spec.email = ['fabrice.carrega@treize37.com'] + spec.authors = ["Fabrice Carrega"] + spec.email = ["fabrice.carrega@treize37.com"] - spec.summary = 'API client for the Ohme CRM.' - spec.description = 'API client for the Ohme CRM.' - spec.homepage = 'https://github.com/treize37/ohme' - spec.license = 'MIT' - spec.required_ruby_version = '>= 2.6.0' + spec.summary = "API client for the Ohme CRM." + spec.description = "API client for the Ohme CRM." + spec.homepage = "https://github.com/treize37/ohme" + spec.license = "MIT" + spec.required_ruby_version = ">= 2.6.0" - spec.metadata['allowed_push_host'] = "TODO: Set to your gem server 'https://example.com'" + spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" - spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = spec.homepage - spec.metadata['changelog_uri'] = 'https://github.com/Treize37/ohme/blob/main/CHANGELOG.md' + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = spec.homepage + spec.metadata["changelog_uri"] = "https://github.com/Treize37/ohme/blob/main/CHANGELOG.md" # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. @@ -27,12 +27,12 @@ Gem::Specification.new do |spec| (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) end end - spec.bindir = 'exe' + spec.bindir = "exe" spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } - spec.require_paths = ['lib'] + spec.require_paths = ["lib"] # Uncomment to register a new dependency of your gem - spec.add_dependency 'typhoeus', '>= 1.4' + spec.add_dependency "typhoeus", ">= 1.4" # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html diff --git a/spec/ohme/api/contact_spec.rb b/spec/ohme/api/contact_spec.rb index 9f68091..1d55f95 100644 --- a/spec/ohme/api/contact_spec.rb +++ b/spec/ohme/api/contact_spec.rb @@ -1,51 +1,52 @@ # frozen_string_literal: true -require 'spec_helper' -require_relative '../../../lib/ohme/api/contact' +require "spec_helper" +require_relative "../../../lib/ohme/api/contact" # rubocop:disable Metrics/BlockLength RSpec.describe Ohme::API::Contact do let(:client) { instance_double(Ohme::Client) } let(:contact_api) { described_class.new(client) } - describe '#index' do - it 'fetches the list of contacts' do - expect(client).to receive(:get).with('contacts', {}).and_return({ 'contacts' => [] }) + describe "#index" do + it "fetches the list of contacts" do + expect(client).to receive(:get).with("contacts", {}).and_return({"contacts" => []}) response = contact_api.index - expect(response).to eq({ 'contacts' => [] }) + expect(response).to eq({"contacts" => []}) end end - describe '#create' do - it 'creates a new contact' do - contact_data = { name: 'John Doe', email: 'john.doe@example.com' } - expect(client).to receive(:post).with('contacts', contact_data).and_return({ 'id' => '123' }) + describe "#create" do + it "creates a new contact" do + contact_data = {name: "John Doe", email: "john.doe@example.com"} + expect(client).to receive(:post).with("contacts", contact_data).and_return({"id" => "123"}) response = contact_api.create(contact_data) - expect(response).to eq({ 'id' => '123' }) + expect(response).to eq({"id" => "123"}) end end - describe '#update' do - it 'updates a contact by ID' do - contact_data = { name: 'Jane Doe' } - expect(client).to receive(:put).with('contacts/123', contact_data).and_return({ 'id' => '123', 'name' => 'Jane Doe' }) - response = contact_api.update('123', contact_data) - expect(response).to eq({ 'id' => '123', 'name' => 'Jane Doe' }) + describe "#update" do + it "updates a contact by ID" do + contact_data = {name: "Jane Doe"} + expect(client).to receive(:put).with("contacts/123", + contact_data).and_return({"id" => "123", "name" => "Jane Doe"}) + response = contact_api.update("123", contact_data) + expect(response).to eq({"id" => "123", "name" => "Jane Doe"}) end end - describe '#show' do - it 'fetches a contact by ID' do - expect(client).to receive(:get).with('contacts/123').and_return({ 'id' => '123', 'name' => 'John Doe' }) - response = contact_api.show('123') - expect(response).to eq({ 'id' => '123', 'name' => 'John Doe' }) + describe "#show" do + it "fetches a contact by ID" do + expect(client).to receive(:get).with("contacts/123").and_return({"id" => "123", "name" => "John Doe"}) + response = contact_api.show("123") + expect(response).to eq({"id" => "123", "name" => "John Doe"}) end end - describe '#delete' do - it 'deletes a contact by ID' do - expect(client).to receive(:delete).with('contacts/123').and_return(nil) - response = contact_api.delete('123') + describe "#delete" do + it "deletes a contact by ID" do + expect(client).to receive(:delete).with("contacts/123").and_return(nil) + response = contact_api.delete("123") expect(response).to be_nil end end diff --git a/spec/ohme/api/payment_spec.rb b/spec/ohme/api/payment_spec.rb index 1aa6394..400f434 100644 --- a/spec/ohme/api/payment_spec.rb +++ b/spec/ohme/api/payment_spec.rb @@ -1,50 +1,50 @@ # frozen_string_literal: true -require 'spec_helper' -require_relative '../../../lib/ohme/api/payment' +require "spec_helper" +require_relative "../../../lib/ohme/api/payment" RSpec.describe Ohme::API::Payment do let(:client) { instance_double(Ohme::Client) } let(:payment_api) { described_class.new(client) } - describe '#index' do - it 'fetches the list of payments' do - expect(client).to receive(:get).with('payments', {}).and_return({ 'payments' => [] }) + describe "#index" do + it "fetches the list of payments" do + expect(client).to receive(:get).with("payments", {}).and_return({"payments" => []}) response = payment_api.index - expect(response).to eq({ 'payments' => [] }) + expect(response).to eq({"payments" => []}) end end - describe '#create' do - it 'creates a new payment' do - payment_data = { amount: 100, currency: 'USD' } - expect(client).to receive(:post).with('payments', payment_data).and_return({ 'id' => '123' }) + describe "#create" do + it "creates a new payment" do + payment_data = {amount: 100, currency: "USD"} + expect(client).to receive(:post).with("payments", payment_data).and_return({"id" => "123"}) response = payment_api.create(payment_data) - expect(response).to eq({ 'id' => '123' }) + expect(response).to eq({"id" => "123"}) end end - describe '#update' do - it 'updates a payment by ID' do - payment_data = { amount: 150 } - expect(client).to receive(:put).with('payments/123', payment_data).and_return({ 'id' => '123', 'amount' => 150 }) - response = payment_api.update('123', payment_data) - expect(response).to eq({ 'id' => '123', 'amount' => 150 }) + describe "#update" do + it "updates a payment by ID" do + payment_data = {amount: 150} + expect(client).to receive(:put).with("payments/123", payment_data).and_return({"id" => "123", "amount" => 150}) + response = payment_api.update("123", payment_data) + expect(response).to eq({"id" => "123", "amount" => 150}) end end - describe '#show' do - it 'fetches a payment by ID' do - expect(client).to receive(:get).with('payments/123').and_return({ 'id' => '123', 'amount' => 100 }) - response = payment_api.show('123') - expect(response).to eq({ 'id' => '123', 'amount' => 100 }) + describe "#show" do + it "fetches a payment by ID" do + expect(client).to receive(:get).with("payments/123").and_return({"id" => "123", "amount" => 100}) + response = payment_api.show("123") + expect(response).to eq({"id" => "123", "amount" => 100}) end end - describe '#delete' do - it 'deletes a payment by ID' do - expect(client).to receive(:delete).with('payments/123').and_return(nil) - response = payment_api.delete('123') + describe "#delete" do + it "deletes a payment by ID" do + expect(client).to receive(:delete).with("payments/123").and_return(nil) + response = payment_api.delete("123") expect(response).to be_nil end end diff --git a/spec/ohme/client_spec.rb b/spec/ohme/client_spec.rb index 79f3931..1fdc0e7 100644 --- a/spec/ohme/client_spec.rb +++ b/spec/ohme/client_spec.rb @@ -1,79 +1,81 @@ # frozen_string_literal: true -require 'json' -require 'spec_helper' -require 'typhoeus' -require_relative '../../lib/ohme/client' -require_relative '../../lib/ohme/configuration' +require "json" +require "spec_helper" +require "typhoeus" +require_relative "../../lib/ohme/client" +require_relative "../../lib/ohme/configuration" # rubocop:disable Metrics/BlockLength RSpec.describe Ohme::Client do let(:configuration) do Ohme::Configuration.new do |config| - config.client_secret = 'test_client_secret' - config.client_name = 'test_client_name' + config.client_secret = "test_client_secret" + config.client_name = "test_client_name" end end let(:client) { described_class.new(configuration) } - describe '#get' do - it 'sends a GET request to the correct endpoint' do - Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') - .and_return(Typhoeus::Response.new(code: 200, body: '{"success":true}')) + describe "#get" do + it "sends a GET request to the correct endpoint" do + Typhoeus.stub("https://api-ohme.oneheart.fr/api/v1/test_endpoint") + .and_return(Typhoeus::Response.new(code: 200, body: '{"success":true}')) - response = client.get('test_endpoint') + response = client.get("test_endpoint") - expect(response).to eq({ 'success' => true }) + expect(response).to eq({"success" => true}) end end - describe '#post' do - it 'sends a POST request with the correct body' do - Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') - .and_return(Typhoeus::Response.new(code: 201, body: '{"created":true}')) + describe "#post" do + it "sends a POST request with the correct body" do + Typhoeus.stub("https://api-ohme.oneheart.fr/api/v1/test_endpoint") + .and_return(Typhoeus::Response.new(code: 201, body: '{"created":true}')) - response = client.post('test_endpoint', { key: 'value' }) + response = client.post("test_endpoint", {key: "value"}) - expect(response).to eq({ 'created' => true }) + expect(response).to eq({"created" => true}) end end - describe '#put' do - it 'sends a PUT request with the correct body' do - Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') - .and_return(Typhoeus::Response.new(code: 200, body: '{"updated":true}')) + describe "#put" do + it "sends a PUT request with the correct body" do + Typhoeus.stub("https://api-ohme.oneheart.fr/api/v1/test_endpoint") + .and_return(Typhoeus::Response.new(code: 200, body: '{"updated":true}')) - response = client.put('test_endpoint', { key: 'updated_value' }) + response = client.put("test_endpoint", {key: "updated_value"}) - expect(response).to eq({ 'updated' => true }) + expect(response).to eq({"updated" => true}) end end - describe '#delete' do - it 'sends a DELETE request to the correct endpoint' do - Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') - .and_return(Typhoeus::Response.new(code: 204, body: '')) + describe "#delete" do + it "sends a DELETE request to the correct endpoint" do + Typhoeus.stub("https://api-ohme.oneheart.fr/api/v1/test_endpoint") + .and_return(Typhoeus::Response.new(code: 204, body: "")) - response = client.delete('test_endpoint') + response = client.delete("test_endpoint") expect(response).to eq(nil) end end - describe 'error handling' do - it 'raises an error for a timeout' do - Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') - .and_return(Typhoeus::Response.new(code: 0, return_code: :operation_timedout, return_message: 'Timeout')) + describe "error handling" do + it "raises an error for a timeout" do + Typhoeus.stub("https://api-ohme.oneheart.fr/api/v1/test_endpoint") + .and_return(Typhoeus::Response.new(code: 0, return_code: :operation_timedout, return_message: "Timeout")) - expect { client.get('test_endpoint') }.to raise_error('Request timed out. Please check your network connection or increase the timeout.') + expect { + client.get("test_endpoint") + }.to raise_error("Request timed out. Please check your network connection or increase the timeout.") end - it 'raises an error for a failed request' do - Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') - .and_return(Typhoeus::Response.new(code: 500, body: 'Internal Server Error')) + it "raises an error for a failed request" do + Typhoeus.stub("https://api-ohme.oneheart.fr/api/v1/test_endpoint") + .and_return(Typhoeus::Response.new(code: 500, body: "Internal Server Error")) - expect { client.get('test_endpoint') }.to raise_error('HTTP request failed: 500 - Internal Server Error') + expect { client.get("test_endpoint") }.to raise_error("HTTP request failed: 500 - Internal Server Error") end end end diff --git a/spec/ohme/configuration_spec.rb b/spec/ohme/configuration_spec.rb index 4b42cff..78c92bb 100644 --- a/spec/ohme/configuration_spec.rb +++ b/spec/ohme/configuration_spec.rb @@ -1,71 +1,71 @@ # frozen_string_literal: true -require 'spec_helper' -require_relative '../../lib/ohme/configuration' +require "spec_helper" +require_relative "../../lib/ohme/configuration" # rubocop:disable Metrics/BlockLength RSpec.describe Ohme::Configuration do - describe '.new' do + describe ".new" do let(:conf) do described_class.new do |config| - config.base_url = 'https://api.example.com' - config.client_name = 'test_client_name' - config.client_secret = 'test_client_secret' + config.base_url = "https://api.example.com" + config.client_name = "test_client_name" + config.client_secret = "test_client_secret" config.timeout = 60 - config.version = 'v1' + config.version = "v1" end end - describe 'setting configuration attributes' do - it 'sets the client_secret attribute correctly' do - expect(conf.client_secret).to eq('test_client_secret') + describe "setting configuration attributes" do + it "sets the client_secret attribute correctly" do + expect(conf.client_secret).to eq("test_client_secret") end - it 'sets the base_url attribute correctly' do - expect(conf.base_url).to eq('https://api.example.com') + it "sets the base_url attribute correctly" do + expect(conf.base_url).to eq("https://api.example.com") end - it 'sets the client_name attribute correctly' do - expect(conf.client_name).to eq('test_client_name') + it "sets the client_name attribute correctly" do + expect(conf.client_name).to eq("test_client_name") end - it 'sets the version attribute correctly' do - expect(conf.version).to eq('v1') + it "sets the version attribute correctly" do + expect(conf.version).to eq("v1") end - it 'sets the timeout attribute correctly' do + it "sets the timeout attribute correctly" do expect(conf.timeout).to eq(60) end end end - describe '#validate!' do + describe "#validate!" do let(:conf) { described_class.new } - context 'when all required attributes are set' do - it 'does not raise an error' do - conf.client_name = 'test_client_name' - conf.client_secret = 'test_client_secret' + context "when all required attributes are set" do + it "does not raise an error" do + conf.client_name = "test_client_name" + conf.client_secret = "test_client_secret" expect { conf.validate! }.not_to raise_error end end - context 'when client_name is missing' do - it 'raises an error' do - error_message = 'client_name is missing. ' \ - 'Please configure Ohme::Configuration.client_name.' - conf.client_secret = 'test_client_secret' + context "when client_name is missing" do + it "raises an error" do + error_message = "client_name is missing. " \ + "Please configure Ohme::Configuration.client_name." + conf.client_secret = "test_client_secret" expect { conf.validate! }.to raise_error(error_message) end end - context 'when client_secret is missing' do - it 'raises an error' do - error_message = 'client_secret is missing. ' \ - 'Please configure Ohme::Configuration.client_secret.' - conf.client_name = 'test_client_name' + context "when client_secret is missing" do + it "raises an error" do + error_message = "client_secret is missing. " \ + "Please configure Ohme::Configuration.client_secret." + conf.client_name = "test_client_name" expect { conf.validate! }.to raise_error(error_message) end diff --git a/spec/ohme_spec.rb b/spec/ohme_spec.rb index 46713ff..f458e8c 100644 --- a/spec/ohme_spec.rb +++ b/spec/ohme_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Ohme do - it 'has a version number' do + it "has a version number" do expect(Ohme::VERSION).not_to be nil end end From a46edb9cbd28025c0573b6d79c2a9d9464ee10ab Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Tue, 24 Jun 2025 18:00:45 +0200 Subject: [PATCH 19/27] Added platform to Gemfile.lock --- Gemfile.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile.lock b/Gemfile.lock index cfd31ba..aefd129 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -74,6 +74,7 @@ GEM PLATFORMS x86_64-darwin-20 + x86_64-linux DEPENDENCIES ohme! From 7e1c7ad0152e4cfc5422b879301dc9e073b74f54 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Wed, 25 Jun 2025 10:46:03 +0200 Subject: [PATCH 20/27] Code Climate --- lib/ohme.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ohme.rb b/lib/ohme.rb index d3735db..37685be 100644 --- a/lib/ohme.rb +++ b/lib/ohme.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require_relative "ohme/version" -require_relative "ohme/configuration" -require_relative "ohme/client" -require_relative "ohme/api/contact" -require_relative "ohme/api/payment" +require_relative 'ohme/version' +require_relative 'ohme/configuration' +require_relative 'ohme/client' +require_relative 'ohme/api/contact' +require_relative 'ohme/api/payment' # Ohme API client gem main module. module Ohme From 70e43b1c04815cde463c7b9e094395092de1ddaf Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Thu, 26 Jun 2025 11:57:33 +0200 Subject: [PATCH 21/27] Commited Qlty files --- .gitignore | 3 -- .qlty/.gitignore | 7 +++ .qlty/configs/.yamllint.yaml | 8 +++ .qlty/qlty.toml | 101 +++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 .qlty/.gitignore create mode 100644 .qlty/configs/.yamllint.yaml create mode 100644 .qlty/qlty.toml diff --git a/.gitignore b/.gitignore index 6cdb52a..b04a8c8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,3 @@ # rspec failure tracking .rspec_status - -# Qlty -.qlty/ diff --git a/.qlty/.gitignore b/.qlty/.gitignore new file mode 100644 index 0000000..3036618 --- /dev/null +++ b/.qlty/.gitignore @@ -0,0 +1,7 @@ +* +!configs +!configs/** +!hooks +!hooks/** +!qlty.toml +!.gitignore diff --git a/.qlty/configs/.yamllint.yaml b/.qlty/configs/.yamllint.yaml new file mode 100644 index 0000000..d22fa77 --- /dev/null +++ b/.qlty/configs/.yamllint.yaml @@ -0,0 +1,8 @@ +rules: + document-start: disable + quoted-strings: + required: only-when-needed + extra-allowed: ["{|}"] + key-duplicates: {} + octal-values: + forbid-implicit-octal: true diff --git a/.qlty/qlty.toml b/.qlty/qlty.toml new file mode 100644 index 0000000..1d845d8 --- /dev/null +++ b/.qlty/qlty.toml @@ -0,0 +1,101 @@ +# This file was automatically generated by `qlty init`. +# You can modify it to suit your needs. +# We recommend you to commit this file to your repository. +# +# This configuration is used by both Qlty CLI and Qlty Cloud. +# +# Qlty CLI -- Code quality toolkit for developers +# Qlty Cloud -- Fully automated Code Health Platform +# +# Try Qlty Cloud: https://qlty.sh +# +# For a guide to configuration, visit https://qlty.sh/d/config +# Or for a full reference, visit https://qlty.sh/d/qlty-toml +config_version = "0" + +exclude_patterns = [ + "*_min.*", + "*-min.*", + "*.min.*", + "**/.yarn/**", + "**/*.d.ts", + "**/assets/**", + "**/bower_components/**", + "**/build/**", + "**/cache/**", + "**/config/**", + "**/db/**", + "**/deps/**", + "**/dist/**", + "**/extern/**", + "**/external/**", + "**/generated/**", + "**/Godeps/**", + "**/gradlew/**", + "**/mvnw/**", + "**/node_modules/**", + "**/protos/**", + "**/seed/**", + "**/target/**", + "**/templates/**", + "**/testdata/**", + "**/vendor/**", +] + +test_patterns = [ + "**/test/**", + "**/spec/**", + "**/*.test.*", + "**/*.spec.*", + "**/*_test.*", + "**/*_spec.*", + "**/test_*.*", + "**/spec_*.*", +] + +[smells] +mode = "comment" + +[[source]] +name = "default" +default = true + + +[[plugin]] +name = "actionlint" + +[[plugin]] +name = "checkov" + +[[plugin]] +name = "markdownlint" +mode = "comment" + +[[plugin]] +name = "osv-scanner" + +[[plugin]] +name = "prettier" + +[[plugin]] +name = "ripgrep" +mode = "comment" + +[[plugin]] +name = "rubocop" + +[[plugin]] +name = "standardrb" + +[[plugin]] +name = "trivy" +drivers = [ + "config", + "fs-vuln", +] + +[[plugin]] +name = "trufflehog" + +[[plugin]] +name = "yamllint" From 5e5a8764cd4e02f21dcc9229ca1000de0e78c31c Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Thu, 26 Jun 2025 12:34:48 +0200 Subject: [PATCH 22/27] Quality configuration and correction --- .qlty/configs/.standard.yml | 5 ++ .standard.yml | 3 -- lib/ohme/api/contact.rb | 4 +- lib/ohme/api/payment.rb | 4 +- lib/ohme/client.rb | 14 +++--- lib/ohme/configuration.rb | 8 ++-- lib/ohme/version.rb | 2 +- ohme.gemspec | 34 +++++++------- spec/ohme/api/contact_spec.rb | 54 +++++++++++----------- spec/ohme/api/payment_spec.rb | 54 +++++++++++----------- spec/ohme/client_spec.rb | 82 ++++++++++++++++----------------- spec/ohme/configuration_spec.rb | 64 ++++++++++++------------- 12 files changed, 166 insertions(+), 162 deletions(-) create mode 100644 .qlty/configs/.standard.yml delete mode 100644 .standard.yml diff --git a/.qlty/configs/.standard.yml b/.qlty/configs/.standard.yml new file mode 100644 index 0000000..7cbd2f0 --- /dev/null +++ b/.qlty/configs/.standard.yml @@ -0,0 +1,5 @@ +ignore: + - "**/*": + - Style/StringLiterals # Use single quotes for strings + - Layout/MultilineMethodCallIndentation # Indentation of multiline method calls + - Layout/SpaceInsideHashLiteralBraces # Allow space inside hash literal braces diff --git a/.standard.yml b/.standard.yml deleted file mode 100644 index 3a0787a..0000000 --- a/.standard.yml +++ /dev/null @@ -1,3 +0,0 @@ -# For available configuration options, see: -# https://github.com/testdouble/standard -ruby_version: 2.6 diff --git a/lib/ohme/api/contact.rb b/lib/ohme/api/contact.rb index 97f74f9..e5325f2 100644 --- a/lib/ohme/api/contact.rb +++ b/lib/ohme/api/contact.rb @@ -20,7 +20,7 @@ def initialize(client = Ohme::Client.new) # @param params [Hash] Optional query parameters # @return [Hash] The response from the API def index(params = {}) - @client.get("contacts", params) + @client.get('contacts', params) end # Creates a new contact @@ -28,7 +28,7 @@ def index(params = {}) # @param body [Hash] The contact data to be sent in the request body # @return [Hash] The response from the API def create(body) - @client.post("contacts", body) + @client.post('contacts', body) end # Updates a contact by ID diff --git a/lib/ohme/api/payment.rb b/lib/ohme/api/payment.rb index b9a96fd..f412f48 100644 --- a/lib/ohme/api/payment.rb +++ b/lib/ohme/api/payment.rb @@ -15,7 +15,7 @@ def initialize(client = Ohme::Client.new) # @param params [Hash] Optional query parameters # @return [Hash] The response from the API def index(params = {}) - @client.get("payments", params) + @client.get('payments', params) end # Creates a new payment @@ -23,7 +23,7 @@ def index(params = {}) # @param body [Hash] The payment data to be sent in the request body # @return [Hash] The response from the API def create(body) - @client.post("payments", body) + @client.post('payments', body) end # Updates a payment by ID diff --git a/lib/ohme/client.rb b/lib/ohme/client.rb index d0708a0..037d23c 100644 --- a/lib/ohme/client.rb +++ b/lib/ohme/client.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require "typhoeus" -require_relative "configuration" +require 'typhoeus' +require_relative 'configuration' module Ohme # Client for interacting with the Ohme API @@ -85,10 +85,10 @@ def build_url(endpoint) # @return [Hash] The headers to be sent with the request def build_headers { - "client-name" => @configuration.client_name, - "client-secret" => @configuration.client_secret, - "Content-Type" => "application/json", - "Accept" => "application/json" + 'client-name' => @configuration.client_name, + 'client-secret' => @configuration.client_secret, + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' } end @@ -98,7 +98,7 @@ def build_headers # @return [Hash, nil] The parsed response or nil for DELETE requests def handle_response(response) if response.timed_out? - raise "Request timed out. Please check your network connection or increase the timeout." + raise 'Request timed out. Please check your network connection or increase the timeout.' elsif response.success? # Return nil for DELETE requests with no body return nil if response.body.nil? || response.body.strip.empty? diff --git a/lib/ohme/configuration.rb b/lib/ohme/configuration.rb index f5cfa52..6897ab9 100644 --- a/lib/ohme/configuration.rb +++ b/lib/ohme/configuration.rb @@ -10,8 +10,8 @@ class Configuration # @yield [config] Optional block to configure the client # @return [Ohme::Configuration] A new instance of the configuration def initialize - @base_url = "https://api-ohme.oneheart.fr/api/" - @version = "v1" + @base_url = 'https://api-ohme.oneheart.fr/api/' + @version = 'v1' @timeout = 30 yield self if block_given? end @@ -28,8 +28,8 @@ def configure # # @raise [RuntimeError] if required values are missing def validate! - error_on("client_name") unless @client_name - error_on("client_secret") unless @client_secret + error_on('client_name') unless @client_name + error_on('client_secret') unless @client_secret end private diff --git a/lib/ohme/version.rb b/lib/ohme/version.rb index 2d2de49..1dbd82e 100644 --- a/lib/ohme/version.rb +++ b/lib/ohme/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ohme - VERSION = "0.2.0" + VERSION = '0.2.0' end diff --git a/ohme.gemspec b/ohme.gemspec index deccf6f..aa05e5b 100644 --- a/ohme.gemspec +++ b/ohme.gemspec @@ -1,38 +1,38 @@ # frozen_string_literal: true -require_relative "lib/ohme/version" +require_relative 'lib/ohme/version' Gem::Specification.new do |spec| - spec.name = "ohme" + spec.name = 'ohme' spec.version = Ohme::VERSION - spec.authors = ["Fabrice Carrega"] - spec.email = ["fabrice.carrega@treize37.com"] + spec.authors = ['Fabrice Carrega'] + spec.email = ['fabrice.carrega@treize37.com'] - spec.summary = "API client for the Ohme CRM." - spec.description = "API client for the Ohme CRM." - spec.homepage = "https://github.com/treize37/ohme" - spec.license = "MIT" - spec.required_ruby_version = ">= 2.6.0" + spec.summary = 'API client for the Ohme CRM.' + spec.description = 'API client for the Ohme CRM.' + spec.homepage = 'https://github.com/treize37/ohme' + spec.license = 'MIT' + spec.required_ruby_version = '>= 2.6.0' - spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" + spec.metadata['allowed_push_host'] = "TODO: Set to your gem server 'https://example.com'" - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = spec.homepage - spec.metadata["changelog_uri"] = "https://github.com/Treize37/ohme/blob/main/CHANGELOG.md" + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = spec.homepage + spec.metadata['changelog_uri'] = 'https://github.com/Treize37/ohme/blob/main/CHANGELOG.md' # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(__dir__) do - `git ls-files -z`.split("\x0").reject do |f| + `git ls-files -z`.split('\x0').reject do |f| (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) end end - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] # Uncomment to register a new dependency of your gem - spec.add_dependency "typhoeus", ">= 1.4" + spec.add_dependency 'typhoeus', '>= 1.4' # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html diff --git a/spec/ohme/api/contact_spec.rb b/spec/ohme/api/contact_spec.rb index 1d55f95..fab86c4 100644 --- a/spec/ohme/api/contact_spec.rb +++ b/spec/ohme/api/contact_spec.rb @@ -1,52 +1,52 @@ # frozen_string_literal: true -require "spec_helper" -require_relative "../../../lib/ohme/api/contact" +require 'spec_helper' +require_relative '../../../lib/ohme/api/contact' # rubocop:disable Metrics/BlockLength RSpec.describe Ohme::API::Contact do let(:client) { instance_double(Ohme::Client) } let(:contact_api) { described_class.new(client) } - describe "#index" do - it "fetches the list of contacts" do - expect(client).to receive(:get).with("contacts", {}).and_return({"contacts" => []}) + describe '#index' do + it 'fetches the list of contacts' do + expect(client).to receive(:get).with('contacts', {}).and_return({ 'contacts' => [] }) response = contact_api.index - expect(response).to eq({"contacts" => []}) + expect(response).to eq({ 'contacts' => [] }) end end - describe "#create" do - it "creates a new contact" do - contact_data = {name: "John Doe", email: "john.doe@example.com"} - expect(client).to receive(:post).with("contacts", contact_data).and_return({"id" => "123"}) + describe '#create' do + it 'creates a new contact' do + contact_data = { name: 'John Doe', email: 'john.doe@example.com' } + expect(client).to receive(:post).with('contacts', contact_data).and_return({ 'id' => '123' }) response = contact_api.create(contact_data) - expect(response).to eq({"id" => "123"}) + expect(response).to eq({ 'id' => '123' }) end end - describe "#update" do - it "updates a contact by ID" do - contact_data = {name: "Jane Doe"} - expect(client).to receive(:put).with("contacts/123", - contact_data).and_return({"id" => "123", "name" => "Jane Doe"}) - response = contact_api.update("123", contact_data) - expect(response).to eq({"id" => "123", "name" => "Jane Doe"}) + describe '#update' do + it 'updates a contact by ID' do + contact_data = { name: 'Jane Doe' } + expect(client).to receive(:put).with('contacts/123', contact_data) + .and_return({ 'id' => '123', 'name' => 'Jane Doe' }) + response = contact_api.update('123', contact_data) + expect(response).to eq({ 'id' => '123', 'name' => 'Jane Doe' }) end end - describe "#show" do - it "fetches a contact by ID" do - expect(client).to receive(:get).with("contacts/123").and_return({"id" => "123", "name" => "John Doe"}) - response = contact_api.show("123") - expect(response).to eq({"id" => "123", "name" => "John Doe"}) + describe '#show' do + it 'fetches a contact by ID' do + expect(client).to receive(:get).with('contacts/123').and_return({ 'id' => '123', 'name' => 'John Doe' }) + response = contact_api.show('123') + expect(response).to eq({ 'id' => '123', 'name' => 'John Doe' }) end end - describe "#delete" do - it "deletes a contact by ID" do - expect(client).to receive(:delete).with("contacts/123").and_return(nil) - response = contact_api.delete("123") + describe '#delete' do + it 'deletes a contact by ID' do + expect(client).to receive(:delete).with('contacts/123').and_return(nil) + response = contact_api.delete('123') expect(response).to be_nil end end diff --git a/spec/ohme/api/payment_spec.rb b/spec/ohme/api/payment_spec.rb index 400f434..5afdb83 100644 --- a/spec/ohme/api/payment_spec.rb +++ b/spec/ohme/api/payment_spec.rb @@ -1,51 +1,53 @@ # frozen_string_literal: true -require "spec_helper" -require_relative "../../../lib/ohme/api/payment" +require 'spec_helper' +require_relative '../../../lib/ohme/api/payment' +# rubocop:disable Metrics/BlockLength RSpec.describe Ohme::API::Payment do let(:client) { instance_double(Ohme::Client) } let(:payment_api) { described_class.new(client) } - describe "#index" do - it "fetches the list of payments" do - expect(client).to receive(:get).with("payments", {}).and_return({"payments" => []}) + describe '#index' do + it 'fetches the list of payments' do + expect(client).to receive(:get).with('payments', {}).and_return({ 'payments' => [] }) response = payment_api.index - expect(response).to eq({"payments" => []}) + expect(response).to eq({ 'payments' => [] }) end end - describe "#create" do - it "creates a new payment" do - payment_data = {amount: 100, currency: "USD"} - expect(client).to receive(:post).with("payments", payment_data).and_return({"id" => "123"}) + describe '#create' do + it 'creates a new payment' do + payment_data = { amount: 100, currency: 'USD' } + expect(client).to receive(:post).with('payments', payment_data).and_return({ 'id' => '123' }) response = payment_api.create(payment_data) - expect(response).to eq({"id" => "123"}) + expect(response).to eq({ 'id' => '123' }) end end - describe "#update" do - it "updates a payment by ID" do - payment_data = {amount: 150} - expect(client).to receive(:put).with("payments/123", payment_data).and_return({"id" => "123", "amount" => 150}) - response = payment_api.update("123", payment_data) - expect(response).to eq({"id" => "123", "amount" => 150}) + describe '#update' do + it 'updates a payment by ID' do + payment_data = { amount: 150 } + expect(client).to receive(:put).with('payments/123', payment_data).and_return({ 'id' => '123', 'amount' => 150 }) + response = payment_api.update('123', payment_data) + expect(response).to eq({ 'id' => '123', 'amount' => 150 }) end end - describe "#show" do - it "fetches a payment by ID" do - expect(client).to receive(:get).with("payments/123").and_return({"id" => "123", "amount" => 100}) - response = payment_api.show("123") - expect(response).to eq({"id" => "123", "amount" => 100}) + describe '#show' do + it 'fetches a payment by ID' do + expect(client).to receive(:get).with('payments/123').and_return({ 'id' => '123', 'amount' => 100 }) + response = payment_api.show('123') + expect(response).to eq({ 'id' => '123', 'amount' => 100 }) end end - describe "#delete" do - it "deletes a payment by ID" do - expect(client).to receive(:delete).with("payments/123").and_return(nil) - response = payment_api.delete("123") + describe '#delete' do + it 'deletes a payment by ID' do + expect(client).to receive(:delete).with('payments/123').and_return(nil) + response = payment_api.delete('123') expect(response).to be_nil end end end +# rubocop:enable Metrics/BlockLength diff --git a/spec/ohme/client_spec.rb b/spec/ohme/client_spec.rb index 1fdc0e7..234ba87 100644 --- a/spec/ohme/client_spec.rb +++ b/spec/ohme/client_spec.rb @@ -1,81 +1,81 @@ # frozen_string_literal: true -require "json" -require "spec_helper" -require "typhoeus" -require_relative "../../lib/ohme/client" -require_relative "../../lib/ohme/configuration" +require 'json' +require 'spec_helper' +require 'typhoeus' +require_relative '../../lib/ohme/client' +require_relative '../../lib/ohme/configuration' # rubocop:disable Metrics/BlockLength RSpec.describe Ohme::Client do let(:configuration) do Ohme::Configuration.new do |config| - config.client_secret = "test_client_secret" - config.client_name = "test_client_name" + config.client_secret = 'test_client_secret' + config.client_name = 'test_client_name' end end let(:client) { described_class.new(configuration) } - describe "#get" do - it "sends a GET request to the correct endpoint" do - Typhoeus.stub("https://api-ohme.oneheart.fr/api/v1/test_endpoint") - .and_return(Typhoeus::Response.new(code: 200, body: '{"success":true}')) + describe '#get' do + it 'sends a GET request to the correct endpoint' do + Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') + .and_return(Typhoeus::Response.new(code: 200, body: "{ 'success':true }")) - response = client.get("test_endpoint") + response = client.get('test_endpoint') - expect(response).to eq({"success" => true}) + expect(response).to eq({ 'success' => true }) end end - describe "#post" do - it "sends a POST request with the correct body" do - Typhoeus.stub("https://api-ohme.oneheart.fr/api/v1/test_endpoint") - .and_return(Typhoeus::Response.new(code: 201, body: '{"created":true}')) + describe '#post' do + it 'sends a POST request with the correct body' do + Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') + .and_return(Typhoeus::Response.new(code: 201, body: "{ 'created':true }")) - response = client.post("test_endpoint", {key: "value"}) + response = client.post('test_endpoint', { key: 'value' }) - expect(response).to eq({"created" => true}) + expect(response).to eq({ 'created' => true }) end end - describe "#put" do - it "sends a PUT request with the correct body" do - Typhoeus.stub("https://api-ohme.oneheart.fr/api/v1/test_endpoint") - .and_return(Typhoeus::Response.new(code: 200, body: '{"updated":true}')) + describe '#put' do + it 'sends a PUT request with the correct body' do + Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') + .and_return(Typhoeus::Response.new(code: 200, body: "{ 'updated':true }")) - response = client.put("test_endpoint", {key: "updated_value"}) + response = client.put('test_endpoint', { key: 'updated_value' }) - expect(response).to eq({"updated" => true}) + expect(response).to eq({ 'updated' => true }) end end - describe "#delete" do - it "sends a DELETE request to the correct endpoint" do - Typhoeus.stub("https://api-ohme.oneheart.fr/api/v1/test_endpoint") - .and_return(Typhoeus::Response.new(code: 204, body: "")) + describe '#delete' do + it 'sends a DELETE request to the correct endpoint' do + Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') + .and_return(Typhoeus::Response.new(code: 204, body: '')) - response = client.delete("test_endpoint") + response = client.delete('test_endpoint') expect(response).to eq(nil) end end - describe "error handling" do - it "raises an error for a timeout" do - Typhoeus.stub("https://api-ohme.oneheart.fr/api/v1/test_endpoint") - .and_return(Typhoeus::Response.new(code: 0, return_code: :operation_timedout, return_message: "Timeout")) + describe 'error handling' do + it 'raises an error for a timeout' do + error_message = 'Request timed out. Please check your network connection or increase the timeout.' + Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') + .and_return(Typhoeus::Response.new(code: 0, return_code: :operation_timedout, return_message: 'Timeout')) - expect { - client.get("test_endpoint") - }.to raise_error("Request timed out. Please check your network connection or increase the timeout.") + expect { client.get('test_endpoint') }.to raise_error(error_message) end - it "raises an error for a failed request" do - Typhoeus.stub("https://api-ohme.oneheart.fr/api/v1/test_endpoint") - .and_return(Typhoeus::Response.new(code: 500, body: "Internal Server Error")) + it 'raises an error for a failed request' do + error_message = 'HTTP request failed: 500 - Internal Server Error' + Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') + .and_return(Typhoeus::Response.new(code: 500, body: 'Internal Server Error')) - expect { client.get("test_endpoint") }.to raise_error("HTTP request failed: 500 - Internal Server Error") + expect { client.get('test_endpoint') }.to raise_error(error_message) end end end diff --git a/spec/ohme/configuration_spec.rb b/spec/ohme/configuration_spec.rb index 78c92bb..4b42cff 100644 --- a/spec/ohme/configuration_spec.rb +++ b/spec/ohme/configuration_spec.rb @@ -1,71 +1,71 @@ # frozen_string_literal: true -require "spec_helper" -require_relative "../../lib/ohme/configuration" +require 'spec_helper' +require_relative '../../lib/ohme/configuration' # rubocop:disable Metrics/BlockLength RSpec.describe Ohme::Configuration do - describe ".new" do + describe '.new' do let(:conf) do described_class.new do |config| - config.base_url = "https://api.example.com" - config.client_name = "test_client_name" - config.client_secret = "test_client_secret" + config.base_url = 'https://api.example.com' + config.client_name = 'test_client_name' + config.client_secret = 'test_client_secret' config.timeout = 60 - config.version = "v1" + config.version = 'v1' end end - describe "setting configuration attributes" do - it "sets the client_secret attribute correctly" do - expect(conf.client_secret).to eq("test_client_secret") + describe 'setting configuration attributes' do + it 'sets the client_secret attribute correctly' do + expect(conf.client_secret).to eq('test_client_secret') end - it "sets the base_url attribute correctly" do - expect(conf.base_url).to eq("https://api.example.com") + it 'sets the base_url attribute correctly' do + expect(conf.base_url).to eq('https://api.example.com') end - it "sets the client_name attribute correctly" do - expect(conf.client_name).to eq("test_client_name") + it 'sets the client_name attribute correctly' do + expect(conf.client_name).to eq('test_client_name') end - it "sets the version attribute correctly" do - expect(conf.version).to eq("v1") + it 'sets the version attribute correctly' do + expect(conf.version).to eq('v1') end - it "sets the timeout attribute correctly" do + it 'sets the timeout attribute correctly' do expect(conf.timeout).to eq(60) end end end - describe "#validate!" do + describe '#validate!' do let(:conf) { described_class.new } - context "when all required attributes are set" do - it "does not raise an error" do - conf.client_name = "test_client_name" - conf.client_secret = "test_client_secret" + context 'when all required attributes are set' do + it 'does not raise an error' do + conf.client_name = 'test_client_name' + conf.client_secret = 'test_client_secret' expect { conf.validate! }.not_to raise_error end end - context "when client_name is missing" do - it "raises an error" do - error_message = "client_name is missing. " \ - "Please configure Ohme::Configuration.client_name." - conf.client_secret = "test_client_secret" + context 'when client_name is missing' do + it 'raises an error' do + error_message = 'client_name is missing. ' \ + 'Please configure Ohme::Configuration.client_name.' + conf.client_secret = 'test_client_secret' expect { conf.validate! }.to raise_error(error_message) end end - context "when client_secret is missing" do - it "raises an error" do - error_message = "client_secret is missing. " \ - "Please configure Ohme::Configuration.client_secret." - conf.client_name = "test_client_name" + context 'when client_secret is missing' do + it 'raises an error' do + error_message = 'client_secret is missing. ' \ + 'Please configure Ohme::Configuration.client_secret.' + conf.client_name = 'test_client_name' expect { conf.validate! }.to raise_error(error_message) end From e1aee5273aa680559d71cdc14b1b081e7df59ad4 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Thu, 26 Jun 2025 12:42:53 +0200 Subject: [PATCH 23/27] Corrected specs --- spec/ohme/client_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/ohme/client_spec.rb b/spec/ohme/client_spec.rb index 234ba87..89d550b 100644 --- a/spec/ohme/client_spec.rb +++ b/spec/ohme/client_spec.rb @@ -20,7 +20,7 @@ describe '#get' do it 'sends a GET request to the correct endpoint' do Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') - .and_return(Typhoeus::Response.new(code: 200, body: "{ 'success':true }")) + .and_return(Typhoeus::Response.new(code: 200, body: '{ "success": true }')) response = client.get('test_endpoint') @@ -31,7 +31,7 @@ describe '#post' do it 'sends a POST request with the correct body' do Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') - .and_return(Typhoeus::Response.new(code: 201, body: "{ 'created':true }")) + .and_return(Typhoeus::Response.new(code: 201, body: '{ "created": true }')) response = client.post('test_endpoint', { key: 'value' }) @@ -42,7 +42,7 @@ describe '#put' do it 'sends a PUT request with the correct body' do Typhoeus.stub('https://api-ohme.oneheart.fr/api/v1/test_endpoint') - .and_return(Typhoeus::Response.new(code: 200, body: "{ 'updated':true }")) + .and_return(Typhoeus::Response.new(code: 200, body: '{ "updated": true }')) response = client.put('test_endpoint', { key: 'updated_value' }) From 1f0b2ee5b0b0ed4cf9bfe45d48baae4085b23442 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Fri, 27 Jun 2025 10:50:32 +0200 Subject: [PATCH 24/27] Corrected syntax --- spec/ohme_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/ohme_spec.rb b/spec/ohme_spec.rb index f458e8c..46713ff 100644 --- a/spec/ohme_spec.rb +++ b/spec/ohme_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Ohme do - it "has a version number" do + it 'has a version number' do expect(Ohme::VERSION).not_to be nil end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2e0998b..5c8f6a2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,7 @@ RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = ".rspec_status" + config.example_status_persistence_file_path = '.rspec_status' # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! From e3b849ecab03dfb70aea432ab714f8dec728607f Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Fri, 27 Jun 2025 10:52:05 +0200 Subject: [PATCH 25/27] Added gem host --- ohme.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohme.gemspec b/ohme.gemspec index aa05e5b..9b3a922 100644 --- a/ohme.gemspec +++ b/ohme.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |spec| spec.license = 'MIT' spec.required_ruby_version = '>= 2.6.0' - spec.metadata['allowed_push_host'] = "TODO: Set to your gem server 'https://example.com'" + spec.metadata['allowed_push_host'] = 'https://rubygems.org' spec.metadata['homepage_uri'] = spec.homepage spec.metadata['source_code_uri'] = spec.homepage From c76f1847c84c883a7c446f7b3f561a3a5bd19dc6 Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Fri, 27 Jun 2025 10:58:15 +0200 Subject: [PATCH 26/27] Changed actions and added documentation --- CHANGELOG.md | 5 +++++ Rakefile | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd8c893..6ff971a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## [Unreleased] +## [0.2.0] - 2025-06-27 + +- Added contacts and payment API calls +- Improved configuration and specifications + ## [0.1.0] - 2024-12-12 - Initial release diff --git a/Rakefile b/Rakefile index df40677..d38c45d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,10 @@ # frozen_string_literal: true -require "bundler/gem_tasks" -require "rspec/core/rake_task" +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -require "standard/rake" +require 'standard/rake' -task default: %i[spec standard] +task default: %i[spec] From 09ae49a9c3315b49cd510a3af39e7426381959da Mon Sep 17 00:00:00 2001 From: Fabrice Carrega Date: Fri, 27 Jun 2025 11:15:10 +0200 Subject: [PATCH 27/27] Modified README.md --- README.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6f416d..dab91fb 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,33 @@ If bundler is not being used to manage dependencies, install the gem by executin ## Usage -TODO: Write usage instructions here +### Configuration Initialization + +First, configure the Ohme client with your credentials and settings: + +```ruby +require 'ohme' +require 'json' + +config = Ohme::Configuration.new do |c| + c.client_name = 'your_client_name' + c.client_secret = 'your_client_secret' +end +``` + +Then, initialize the client using your configuration: + +```ruby +client = Ohme::Client.new(config) +``` + +You can now use the API endpoints. For example, to list contacts: + +```ruby +contact_api = Ohme::API::Contact.new(client) +contacts = contact_api.index +puts contacts +``` ## Development