Skip to content

Commit

Permalink
Remove unused methods since now APIs return objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ignacio-chiazzo committed Oct 15, 2024
1 parent 70f0113 commit b39c807
Show file tree
Hide file tree
Showing 27 changed files with 78 additions and 208 deletions.
1 change: 0 additions & 1 deletion lib/whatsapp_sdk/api/business_profile.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require_relative "request"
require_relative "response"
require_relative "../resource/business_profile"

module WhatsappSdk
Expand Down
3 changes: 1 addition & 2 deletions lib/whatsapp_sdk/api/medias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require "faraday/multipart"

require_relative "request"
require_relative "response"
require_relative '../resource/media_types'

module WhatsappSdk
Expand Down Expand Up @@ -102,7 +101,7 @@ def upload(sender_id:, file_path:, type:, headers: {})
multipart: true
)

return Api::Responses::IdResponse.new(response["id"])
Api::Responses::IdResponse.new(response["id"])
end

# Delete a Media by ID.
Expand Down
1 change: 0 additions & 1 deletion lib/whatsapp_sdk/api/messages.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require_relative "request"
require_relative "response"

module WhatsappSdk
module Api
Expand Down
1 change: 0 additions & 1 deletion lib/whatsapp_sdk/api/phone_numbers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require_relative "request"
require_relative "response"

module WhatsappSdk
module Api
Expand Down
27 changes: 0 additions & 27 deletions lib/whatsapp_sdk/api/response.rb

This file was deleted.

17 changes: 0 additions & 17 deletions lib/whatsapp_sdk/api/responses/data_response.rb

This file was deleted.

25 changes: 0 additions & 25 deletions lib/whatsapp_sdk/api/responses/error_response.rb

This file was deleted.

6 changes: 1 addition & 5 deletions lib/whatsapp_sdk/api/responses/generic_error_response.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# frozen_string_literal: true

require_relative "error_response"

module WhatsappSdk
module Api
module Responses
class GenericErrorResponse < ErrorResponse
class GenericErrorResponse
attr_reader :code, :subcode, :message, :type, :data, :fbtrace_id

def initialize(response:)
Expand All @@ -15,8 +13,6 @@ def initialize(response:)
@type = response["type"]
@data = response["data"]
@fbtrace_id = response["fbtrace_id"]

super(response: response)
end

def self.response_error?(response:)
Expand Down
2 changes: 0 additions & 2 deletions lib/whatsapp_sdk/api/responses/http_response_error.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_relative "data_response"

module WhatsappSdk
module Api
module Responses
Expand Down
2 changes: 0 additions & 2 deletions lib/whatsapp_sdk/api/responses/id_response.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_relative "data_response"

module WhatsappSdk
module Api
module Responses
Expand Down
2 changes: 0 additions & 2 deletions lib/whatsapp_sdk/api/responses/pagination_records.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_relative "data_response"

module WhatsappSdk
module Api
module Responses
Expand Down
19 changes: 1 addition & 18 deletions lib/whatsapp_sdk/api/responses/success_response.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
# frozen_string_literal: true

require_relative "data_response"

module WhatsappSdk
module Api
module Responses
class SuccessResponse < DataResponse
def initialize(response:)
@success = response["success"]
super(response)
end

class SuccessResponse
def self.success_response?(response:)
response["success"] == true
end

def self.build_from_response(response:)
return unless response["success"]

new(response: response)
end

def success?
@success
end
end
end
end
Expand Down
3 changes: 0 additions & 3 deletions lib/whatsapp_sdk/api/templates.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# frozen_string_literal: true

require_relative "request"
require_relative "response"
require_relative 'responses/success_response'
require_relative 'responses/generic_error_response'
require_relative "../resource/languages"

module WhatsappSdk
Expand Down
18 changes: 9 additions & 9 deletions lib/whatsapp_sdk/resource/business_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BusinessProfile
].freeze

attr_accessor :about, :address, :description, :email, :messaging_product,
:profile_picture_url, :vertical, :websites
:profile_picture_url, :vertical, :websites

def self.from_hash(hash)
business_profile = BusinessProfile.new
Expand All @@ -26,14 +26,14 @@ def self.from_hash(hash)
end

def ==(other)
self.about == other.about &&
self.address == other.address &&
self.description == other.description &&
self.email == other.email &&
self.messaging_product == other.messaging_product &&
self.profile_picture_url == other.profile_picture_url &&
self.vertical == other.vertical &&
self.websites == other.websites
about == other.about &&
address == other.address &&
description == other.description &&
email == other.email &&
messaging_product == other.messaging_product &&
profile_picture_url == other.profile_picture_url &&
vertical == other.vertical &&
websites == other.websites
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/whatsapp_sdk/resource/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def self.from_hash(hash)
end

def ==(other)
self.id == other.id &&
self.file_size == other.file_size &&
self.messaging_product == other.messaging_product &&
self.mime_type == other.mime_type &&
self.sha256 == other.sha256 &&
self.url == other.url
id == other.id &&
file_size == other.file_size &&
messaging_product == other.messaging_product &&
mime_type == other.mime_type &&
sha256 == other.sha256 &&
url == other.url
end
end
end
Expand Down
39 changes: 20 additions & 19 deletions lib/whatsapp_sdk/resource/phone_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
module WhatsappSdk
module Resource
class PhoneNumber

attr_accessor :id, :verified_name, :display_phone_number, :quality_rating, :is_pin_enabled,
:is_official_business_account, :account_mode, :certificate, :code_verification_status,
:eligibility_for_api_business_global_search, :name_status, :new_name_status, :status,
:search_visibility, :messaging_limit_tier # , :phone, :wa_id, :type
:is_official_business_account, :account_mode, :certificate, :code_verification_status,
:eligibility_for_api_business_global_search, :name_status, :new_name_status, :status,
:search_visibility, :messaging_limit_tier # , :phone, :wa_id, :type

def self.from_hash(hash)
phone_number = PhoneNumber.new
Expand All @@ -30,23 +29,25 @@ def self.from_hash(hash)
phone_number
end

# rubocop:disable Metrics/PerceivedComplexity
def ==(other)
self.id == other.id &&
self.verified_name == other.verified_name &&
self.display_phone_number == other.display_phone_number &&
self.quality_rating == other.quality_rating &&
self.is_pin_enabled == other.is_pin_enabled &&
self.is_official_business_account == other.is_official_business_account &&
self.account_mode == other.account_mode &&
self.certificate == other.certificate &&
self.code_verification_status == other.code_verification_status &&
self.eligibility_for_api_business_global_search == other.eligibility_for_api_business_global_search &&
self.name_status == other.name_status &&
self.new_name_status == other.new_name_status &&
self.status == other.status &&
self.search_visibility == other.search_visibility &&
self.messaging_limit_tier == other.messaging_limit_tier
id == other.id &&
verified_name == other.verified_name &&
display_phone_number == other.display_phone_number &&
quality_rating == other.quality_rating &&
is_pin_enabled == other.is_pin_enabled &&
is_official_business_account == other.is_official_business_account &&
account_mode == other.account_mode &&
certificate == other.certificate &&
code_verification_status == other.code_verification_status &&
eligibility_for_api_business_global_search == other.eligibility_for_api_business_global_search &&
name_status == other.name_status &&
new_name_status == other.new_name_status &&
status == other.status &&
search_visibility == other.search_visibility &&
messaging_limit_tier == other.messaging_limit_tier
end
# rubocop:enable Metrics/PerceivedComplexity
end
end
end
12 changes: 6 additions & 6 deletions lib/whatsapp_sdk/resource/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ def self.from_hash(hash)
end

def ==(other)
self.id == other.id &&
self.status == other.status &&
self.category == other.category &&
self.language == other.language &&
self.name == other.name &&
self.components_json == other.components_json
id == other.id &&
status == other.status &&
category == other.category &&
language == other.language &&
name == other.name &&
components_json == other.components_json
end
end
end
Expand Down
19 changes: 0 additions & 19 deletions test/api_response_helper.rb

This file was deleted.

4 changes: 3 additions & 1 deletion test/errors_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def assert_unsupported_request_error(http_method, response, object_id, fb_trace_
)
end

def assert_unsupported_request_error_v2(http_method, object_id, fb_trace_id, error_info, type = "GraphMethodException")
def assert_unsupported_request_error_v2(
http_method, object_id, fb_trace_id, error_info, type = "GraphMethodException"
)
assert_error_info(
{
code: 100,
Expand Down
1 change: 0 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
require "pry-nav"
require "webmock/minitest"
require "errors_helper"
require "api_response_helper"
require 'vcr'

VCR.configure do |config|
Expand Down
5 changes: 2 additions & 3 deletions test/whatsapp/api/business_profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

require 'api/business_profile'
require 'api/client'
require 'api_response_helper'

module WhatsappSdk
module Api
class BusinessProfileTest < Minitest::Test
include(ErrorsHelper)
include(ApiResponseHelper)

def setup
client = Client.new(ENV.fetch('WHATSAPP_ACCESS_TOKEN', nil))
Expand Down Expand Up @@ -72,7 +71,7 @@ def test_update_with_success_response
websites: ["https://www.google.com"],
vertical: "EDU"
}
assert_equal(true, @business_profile_api.update(phone_number_id: 107_878_721_936_019, params: params))
assert(@business_profile_api.update(phone_number_id: 107_878_721_936_019, params: params))
end
end

Expand Down
Loading

0 comments on commit b39c807

Please sign in to comment.