Skip to content

Commit

Permalink
Merge pull request #148 from ignacio-chiazzo/remove-sorbet
Browse files Browse the repository at this point in the history
🔥 🔥 🔥 🔥  Remove sorbet dependency
  • Loading branch information
ignacio-chiazzo authored Sep 4, 2024
2 parents c7fc40c + 97eafff commit 2913238
Show file tree
Hide file tree
Showing 90 changed files with 386 additions and 8,176 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require:
- rubocop-minitest
- rubocop-performance
- rubocop-sorbet

AllCops:
NewCops: enable
Expand Down Expand Up @@ -53,6 +52,4 @@ Gemspec/RequiredRubyVersion:
Minitest/MultipleAssertions:
Enabled: false

Style/AccessorGrouping: # disabled so that we can use sorbet signatures for each attr
Enabled: false

4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ group(:test) do
gem('rubocop', require: false)
gem('rubocop-minitest', require: false)
gem('rubocop-performance', require: false)
gem('rubocop-sorbet', require: false)
gem('webmock')
end

group(:development) do
gem('pry')
gem('pry-nav')
gem('sorbet')
gem('spoom')
gem('tapioca', require: false)
end

gemspec
19 changes: 0 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ PATH
whatsapp_sdk (0.12.1)
faraday (~> 2)
faraday-multipart (~> 1)
sorbet-runtime (~> 0.5)
zeitwerk (~> 2)

GEM
Expand Down Expand Up @@ -58,22 +57,8 @@ GEM
rubocop-performance (1.14.2)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-sorbet (0.7.0)
rubocop (>= 0.90.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
sorbet (0.5.10346)
sorbet-static (= 0.5.10346)
sorbet-runtime (0.5.10346)
sorbet-static (0.5.10346-universal-darwin-19)
sorbet-static (0.5.10346-universal-darwin-21)
sorbet-static (0.5.10346-x86_64-linux)
spoom (1.1.12)
sorbet (>= 0.5.9204)
sorbet-runtime (>= 0.5.9204)
thor (>= 0.19.2)
tapioca (0.0.1)
thor (1.2.1)
unicode-display_width (2.2.0)
webmock (3.18.1)
addressable (>= 2.8.0)
Expand All @@ -97,10 +82,6 @@ DEPENDENCIES
rubocop
rubocop-minitest
rubocop-performance
rubocop-sorbet
sorbet
spoom
tapioca
webmock
whatsapp_sdk!

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ interactive_footer = WhatsappSdk::Resource::InteractiveFooter.new(
)

interactive_action = WhatsappSdk::Resource::InteractiveAction.new(
type: WhatsappSdk::Resource::InteractiveAction::Type::ListMessage
type: WhatsappSdk::Resource::InteractiveAction::Type::LIST_MESSAGE
)

interactive_action.button = "I am the button CTA"
Expand Down Expand Up @@ -509,7 +509,7 @@ interactive_footer = WhatsappSdk::Resource::InteractiveFooter.new(
)

interactive_action = WhatsappSdk::Resource::InteractiveAction.new(
type: WhatsappSdk::Resource::InteractiveAction::Type::ReplyButton
type: WhatsappSdk::REPLY_BUTTON
)

interactive_reply_button_1 = WhatsappSdk::Resource::InteractiveActionReplyButton.new(
Expand Down
4 changes: 0 additions & 4 deletions lib/whatsapp_sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
require "zeitwerk"
require "faraday"
require "faraday/multipart"
require "sorbet-runtime"

loader = Zeitwerk::Loader.for_gem
loader.setup

module WhatsappSdk
class << self
extend T::Sig

sig { returns(Configuration) }
def configuration
@configuration ||= Configuration.new
end
Expand Down
7 changes: 2 additions & 5 deletions lib/whatsapp_sdk/api/api_configuration.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# typed: strict
# frozen_string_literal: true

module WhatsappSdk
module Api
module ApiConfiguration
extend T::Sig

DEFAULT_API_VERSION = T.let("v19.0", String)
API_URL = T.let("https://graph.facebook.com", String)
DEFAULT_API_VERSION = "v19.0"
API_URL = "https://graph.facebook.com"
end
end
end
12 changes: 0 additions & 12 deletions lib/whatsapp_sdk/api/business_profile.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# typed: strict
# frozen_string_literal: true

require_relative "request"
Expand All @@ -11,12 +10,8 @@ class BusinessProfile < Request
DEFAULT_FIELDS = 'about,address,description,email,profile_picture_url,websites,vertical'

class InvalidVertical < StandardError
extend T::Sig

sig { returns(String) }
attr_accessor :message

sig { params(vertical: String).void }
def initialize(vertical:)
@message = "invalid vertical #{vertical}. See the supported types in the official documentation " \
"https://developers.facebook.com/docs/whatsapp/cloud-api/reference/business-profiles"
Expand All @@ -28,7 +23,6 @@ def initialize(vertical:)
#
# @param phone_number_id [Integer] Phone Number Id.
# @return [Api::Response] Response object.
sig { params(phone_number_id: Integer, fields: T.nilable(T::Array[String])).returns(Api::Response) }
def details(phone_number_id, fields: nil)
fields = if fields
fields.join(',')
Expand All @@ -52,11 +46,6 @@ def details(phone_number_id, fields: nil)
# @param phone_number_id [Integer] Phone Number Id.
# @param params [Hash] Params to update.
# @return [Api::Response] Response object.
sig do
params(
phone_number_id: Integer, params: T::Hash[T.untyped, T.untyped]
).returns(Api::Response)
end
def update(phone_number_id:, params:)
# this is a required field
params[:messaging_product] = 'whatsapp'
Expand All @@ -76,7 +65,6 @@ def update(phone_number_id:, params:)

private

sig { params(params: T::Hash[T.untyped, T.untyped]).returns(T::Boolean) }
def valid_vertical?(params)
return true unless params[:vertical]

Expand Down
50 changes: 7 additions & 43 deletions lib/whatsapp_sdk/api/client.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# typed: strict
# frozen_string_literal: true

require "faraday"
Expand All @@ -7,26 +6,13 @@
module WhatsappSdk
module Api
class Client
extend T::Sig

API_VERSIONS = T.let(
[
'v19.0', 'v18.0', 'v17.0', 'v16.0', 'v15.0', 'v14.0', 'v13.0', 'v12.0',
'v11.0', 'v10.0', 'v9.0', 'v8.0', 'v7.0', 'v6.0', 'v5.0', 'v4.0', 'v3.3',
'v3.2', 'v3.1', 'v3.0', 'v2.12', 'v2.11', 'v2.10', 'v2.9', 'v2.8', 'v2.7',
'v2.6', 'v2.5', 'v2.4', 'v2.3', 'v2.2', 'v2.1'
].freeze,
T::Array[String]
)
API_VERSIONS = [
'v19.0', 'v18.0', 'v17.0', 'v16.0', 'v15.0', 'v14.0', 'v13.0', 'v12.0',
'v11.0', 'v10.0', 'v9.0', 'v8.0', 'v7.0', 'v6.0', 'v5.0', 'v4.0', 'v3.3',
'v3.2', 'v3.1', 'v3.0', 'v2.12', 'v2.11', 'v2.10', 'v2.9', 'v2.8', 'v2.7',
'v2.6', 'v2.5', 'v2.4', 'v2.3', 'v2.2', 'v2.1'
].freeze

sig do
params(
access_token: String,
api_version: String,
logger: T.nilable(T.any(Logger, T.class_of(Logger))),
logger_options: Hash
).void
end
def initialize(
access_token,
api_version = ApiConfiguration::DEFAULT_API_VERSION,
Expand All @@ -41,20 +27,10 @@ def initialize(
@api_version = api_version
end

sig do
params(
endpoint: String,
full_url: T.nilable(String),
http_method: String,
params: T::Hash[T.untyped, T.untyped],
headers: T::Hash[T.untyped, T.untyped],
multipart: T::Boolean
).returns(T.nilable(T::Hash[T.untyped, T.untyped]))
end
def send_request(endpoint: "", full_url: nil, http_method: "post", params: {}, headers: {}, multipart: false)
url = full_url || "#{ApiConfiguration::API_URL}/#{@api_version}/"

faraday_request = T.unsafe(faraday(url: url, multipart: multipart))
faraday_request = faraday(url: url, multipart: multipart)

response = faraday_request.public_send(http_method, endpoint, request_params(params, headers), headers)

Expand All @@ -63,10 +39,6 @@ def send_request(endpoint: "", full_url: nil, http_method: "post", params: {}, h
JSON.parse(response.body)
end

sig do
params(url: String, content_type_header: String, file_path: T.nilable(String))
.returns(Net::HTTPResponse)
end
def download_file(url:, content_type_header:, file_path: nil)
uri = URI.parse(url)
request = Net::HTTP::Get.new(uri)
Expand All @@ -85,19 +57,12 @@ def download_file(url:, content_type_header:, file_path: nil)

private

sig do
params(
params: T::Hash[T.untyped, T.untyped],
headers: T::Hash[T.untyped, T.untyped]
).returns(T.any(T::Hash[T.untyped, T.untyped], String))
end
def request_params(params, headers)
return params.to_json if params.is_a?(Hash) && headers['Content-Type'] == 'application/json'

params
end

sig { params(url: String, multipart: T::Boolean).returns(Faraday::Connection) }
def faraday(url:, multipart: false)
::Faraday.new(url) do |client|
client.request(:multipart) if multipart
Expand All @@ -108,7 +73,6 @@ def faraday(url:, multipart: false)
end
end

sig { params(api_version: String).void }
def validate_api_version(api_version)
raise ArgumentError, "Invalid API version: #{api_version}" unless API_VERSIONS.include?(api_version)
end
Expand Down
20 changes: 0 additions & 20 deletions lib/whatsapp_sdk/api/medias.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# typed: strict
# frozen_string_literal: true

require "faraday"
Expand All @@ -14,12 +13,8 @@ module WhatsappSdk
module Api
class Medias < Request
class FileNotFoundError < StandardError
extend T::Sig

sig { returns(String) }
attr_reader :file_path

sig { params(file_path: String).void }
def initialize(file_path:)
@file_path = file_path

Expand All @@ -29,12 +24,8 @@ def initialize(file_path:)
end

class InvalidMediaTypeError < StandardError
extend T::Sig

sig { returns(String) }
attr_reader :media_type

sig { params(media_type: String).void }
def initialize(media_type:)
@media_type = media_type
message = "Invalid Media Type #{media_type}. See the supported types in the official documentation " \
Expand All @@ -47,7 +38,6 @@ def initialize(media_type:)
#
# @param media_id [String] Media Id.
# @return [Api::Response] Response object.
sig { params(media_id: String).returns(Api::Response) }
def media(media_id:)
response = send_request(
http_method: "get",
Expand All @@ -68,7 +58,6 @@ def media(media_id:)
# documentation https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#supported-media-types,
# but note that the API may allow more depending on the client.
# @return [Api::Response] Response object.
sig { params(url: String, file_path: String, media_type: String).returns(Api::Response) }
def download(url:, file_path:, media_type:)
# Allow download of unsupported media types, since Cloud API may decide to let it through.
# https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/discussions/127
Expand Down Expand Up @@ -97,14 +86,6 @@ def download(url:, file_path:, media_type:)
# see the official documentation https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#supported-media-types.
#
# @return [Api::Response] Response object.
sig do
params(
sender_id: Integer,
file_path: String,
type: String,
headers: T::Hash[String, String]
).returns(Api::Response)
end
def upload(sender_id:, file_path:, type:, headers: {})
raise FileNotFoundError.new(file_path: file_path) unless File.file?(file_path)

Expand Down Expand Up @@ -132,7 +113,6 @@ def upload(sender_id:, file_path:, type:, headers: {})
#
# @param media_id [String] Media Id.
# @return [Api::Response] Response object.
sig { params(media_id: String).returns(Api::Response) }
def delete(media_id:)
response = send_request(
http_method: "delete",
Expand Down
Loading

0 comments on commit 2913238

Please sign in to comment.