cloud-waba-ruby-client 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89437f3bd0c514a2d35343a46891931087d376c76de5de276cb3e90de87ced84
4
- data.tar.gz: 2d9e434046bc4e996746b2e43547433159a39e8430b197966e3871985a12e1c5
3
+ metadata.gz: add418afadc7db2c4e164bc742a67bb82b5b372d7bf84f956fbc8d7c2d948930
4
+ data.tar.gz: c210daa37769103a78c3f290d75e5af35cc92104b1f2b1b6f21918d24a2e8cac
5
5
  SHA512:
6
- metadata.gz: fa1590c643341ad725aa7b40a7f3bb5c1279ef48214982f305b174cd13616fc4546f7b9cec6ae265b32c0c94492bea6015bb89649cd6e20d9cc8f746cded445c
7
- data.tar.gz: f7308f3c128cbe5c3777cf02b1e5f4ee808e1bc127ae3b8aa26ad44a77ae370231f1c3f5428405b41c7cbf0478a4d6baa0b5e292b59cd0beca3601fc8f5ff326
6
+ metadata.gz: f1c12beadeedf7f0fa3b8268b9b8d548ebb362c11e1626b88a4b7de3ef28f55a131c89dbb2d1c3f894e68c8485177fa7b490927ddb82cc87ba5475b4b17465d2
7
+ data.tar.gz: 43de35076e075ceb5eb08307b975f78326d6a7ab97bc89bf8ce07498319be284ec777548e6ec6023b36178f8166c463c91639ba7c71dc7e474d8e0b60fb3c268
data/.byebug_history ADDED
@@ -0,0 +1,15 @@
1
+ c
2
+ phone_number_id
3
+ c
4
+ C
5
+ c
6
+ client.config
7
+ client.config.methods
8
+ client.config.keys
9
+ ENV["CLOUD_API_ACCESS_TOKEN"]
10
+ ENV
11
+ client.config.access_token
12
+ client.config
13
+ c
14
+ client.config
15
+ client
data/Gemfile CHANGED
@@ -1,2 +1,6 @@
1
1
  source "https://rubygems.org"
2
- gemspec
2
+ gemspec
3
+
4
+ group :test do
5
+ gem 'byebug', '~> 9.0', '>= 9.0.5'
6
+ end
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloud-waba-ruby-client (0.0.0)
4
+ cloud-waba-ruby-client (0.0.2)
5
5
  dotenv (~> 2.8.0)
6
- http (~> 4.0.0)
6
+ http (~> 4.4.1)
7
7
  sorbet-runtime (~> 0.5.1)
8
8
 
9
9
  GEM
@@ -18,17 +18,23 @@ GEM
18
18
  domain_name (0.5.20190701)
19
19
  unf (>= 0.0.5, < 1.0.0)
20
20
  dotenv (2.8.1)
21
+ ffi (1.15.5)
22
+ ffi-compiler (1.0.1)
23
+ ffi (>= 1.0.0)
24
+ rake
21
25
  hashdiff (1.0.1)
22
- http (4.0.5)
26
+ http (4.4.1)
23
27
  addressable (~> 2.3)
24
28
  http-cookie (~> 1.0)
25
- http-form_data (~> 2.0)
26
- http_parser.rb (~> 0.6.0)
29
+ http-form_data (~> 2.2)
30
+ http-parser (~> 1.2.0)
27
31
  http-cookie (1.0.5)
28
32
  domain_name (~> 0.5)
29
33
  http-form_data (2.3.0)
30
- http_parser.rb (0.6.0)
34
+ http-parser (1.2.3)
35
+ ffi-compiler (>= 1.0, < 2.0)
31
36
  public_suffix (4.0.7)
37
+ rake (13.0.6)
32
38
  rexml (3.2.6)
33
39
  rspec (3.4.0)
34
40
  rspec-core (~> 3.4.0)
@@ -62,8 +68,7 @@ DEPENDENCIES
62
68
  byebug (~> 9.0, >= 9.0.5)
63
69
  cloud-waba-ruby-client!
64
70
  rspec (~> 3.4.0)
65
- sorbet
66
- sorbet-runtime
71
+ sorbet (~> 0.5.1)
67
72
  webmock (~> 3.17.0)
68
73
 
69
74
  BUNDLED WITH
data/README.md CHANGED
@@ -23,12 +23,36 @@ gem install cloud-waba-ruby-client
23
23
  ```
24
24
 
25
25
  ## Setup
26
- 1. Make sure you have
26
+ 1. Make sure you have:
27
27
  - Meta business app
28
28
  - WhatsApp Business account
29
29
  - A phone number added to your WhatsApp business account
30
30
  - Meta developer app
31
- 2. Add following environment variables to your `.env` file:
31
+ ### Initiating clients using parameters
32
+ ```ruby
33
+ require "cloud_waba/client"
34
+ client_1 = CloudWaba::Client.new(
35
+ app_id: param_app_id_1,
36
+ app_secret: param_app_secret_1,
37
+ phone_number_id: param_phone_number_id_1,
38
+ business_account_id: param_business_account_id_1,
39
+ access_token: param_access_token_1,
40
+ api_version: param_api_version_1
41
+ )
42
+
43
+ client_2 = CloudWaba::Client.new(
44
+ app_id: param_app_id_2,
45
+ app_secret: param_app_secret_2,
46
+ phone_number_id: param_phone_number_id_2,
47
+ business_account_id: param_business_account_id_2,
48
+ access_token: param_access_token_2,
49
+ api_version: param_api_version_2
50
+ )
51
+
52
+ # Do somethingn with the clients
53
+ ```
54
+ ### Initiating client using Env variables
55
+ Add following environment variables to your `.env` file:
32
56
  ```shell
33
57
  WA_BASE_URL=https://graph.facebook.com
34
58
  CLOUD_API_VERSION=v16.0
@@ -39,7 +63,10 @@ gem install cloud-waba-ruby-client
39
63
  CLOUD_API_ACCESS_TOKEN=
40
64
  ```
41
65
  Fill credentials for your meta developer app, business account and phone number ids.
42
-
66
+ ```ruby
67
+ require "cloud_waba/client"
68
+ client = CloudWaba::Client.new # If no params provided, configuration will fallback to env variables
69
+ ```
43
70
  ## Usage
44
71
  ### Sending template message
45
72
  ```ruby
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cloud-waba-ruby-client"
3
- s.version = "0.0.2"
3
+ s.version = "0.0.3"
4
4
  s.summary = "Cloud Waba Client for Ruby."
5
5
  s.description = "A simple API wrapper for Cloud Whatsapp Business API"
6
6
  s.authors = ["Ahmed Bassell"]
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage =
11
11
  "https://rubygems.org/gems/cloud_waba"
12
12
  s.license = "MIT"
13
+ s.required_ruby_version = '>= 2.5.3'
13
14
 
14
15
  # Runtime dependencies
15
16
  s.add_dependency 'dotenv', '~>2.8.0' # env variable
@@ -18,7 +19,6 @@ Gem::Specification.new do |s|
18
19
  # Development dependencies
19
20
  s.add_development_dependency "rspec", '~>3.4.0' # testing
20
21
  s.add_development_dependency 'webmock', '~>3.17.0'
21
- s.add_development_dependency 'byebug', '~> 9.0', '>= 9.0.5'
22
22
  s.add_development_dependency 'sorbet', '~> 0.5.1'
23
23
  s.add_runtime_dependency 'sorbet-runtime', '~>0.5.1'
24
24
  end
@@ -47,8 +47,34 @@ module CloudWaba
47
47
  extend ::T::Sig
48
48
  extend ::T::Helpers
49
49
 
50
- def initialize
51
- @config = ::CloudWaba::Utils.import_config
50
+ attr_reader :config
51
+
52
+ sig do
53
+ params(
54
+ app_id: ::T.nilable(::String),
55
+ app_secret: ::T.nilable(::String),
56
+ phone_number_id: ::T.nilable(::String),
57
+ business_account_id: ::T.nilable(::String),
58
+ access_token: ::T.nilable(::String),
59
+ api_version: ::T.nilable(::String)
60
+ ).void
61
+ end
62
+ def initialize(
63
+ app_id: nil,
64
+ app_secret: nil,
65
+ phone_number_id: nil,
66
+ business_account_id: nil,
67
+ access_token: nil,
68
+ api_version: nil
69
+ )
70
+ @config = ::CloudWaba::Utils.import_config(
71
+ app_id: app_id,
72
+ app_secret: app_secret,
73
+ phone_number_id: phone_number_id,
74
+ business_account_id: business_account_id,
75
+ access_token: access_token,
76
+ api_version: api_version
77
+ )
52
78
  end
53
79
 
54
80
  def messages
@@ -6,30 +6,37 @@ module CloudWaba
6
6
  extend ::T::Sig
7
7
  extend ::T::Helpers
8
8
 
9
- sig { returns(::CloudWaba::Models::Config) }
10
- def self.import_config
9
+ sig do
10
+ params(
11
+ app_id: ::T.nilable(::String),
12
+ app_secret: ::T.nilable(::String),
13
+ phone_number_id: ::T.nilable(::String),
14
+ business_account_id: ::T.nilable(::String),
15
+ access_token: ::T.nilable(::String),
16
+ api_version: ::T.nilable(::String)
17
+ ).returns(::CloudWaba::Models::Config)
18
+ end
19
+ def self.import_config(app_id:, app_secret:, phone_number_id:, business_account_id:, access_token:, api_version:)
11
20
  Dotenv.load
12
21
  validate_config!
13
22
 
14
23
  base_url = ENV.fetch("WA_BASE_URL", "https://graph.facebook.com")
15
- app_id = ENV.fetch("M4D_APP_ID", "")
16
- app_secret = ENV.fetch("M4D_APP_SECRET", "")
17
- phone_number_id = ENV.fetch("WA_PHONE_NUMBER_ID", "")
18
- business_account_id = ENV.fetch("WA_BUSINESS_ACCOUNT_ID", "")
19
- access_token = ENV.fetch("CLOUD_API_ACCESS_TOKEN", "")
20
- api_version = ENV.fetch("CLOUD_API_VERSION", "v16.0")
24
+ app_id = app_id || ENV.fetch("M4D_APP_ID", "")
25
+ app_secret = app_secret || ENV.fetch("M4D_APP_SECRET", "")
26
+ phone_number_id = phone_number_id || ENV.fetch("WA_PHONE_NUMBER_ID", "")
27
+ business_account_id = business_account_id || ENV.fetch("WA_BUSINESS_ACCOUNT_ID", "")
28
+ access_token = access_token || ENV.fetch("CLOUD_API_ACCESS_TOKEN", "")
29
+ api_version = api_version || ENV.fetch("CLOUD_API_VERSION", "v16.0")
21
30
 
22
- config = ::CloudWaba::Models::Config.new(
31
+ ::CloudWaba::Models::Config.new(
23
32
  base_url: base_url,
24
33
  app_id: app_id,
25
34
  app_secret: app_secret,
26
35
  phone_number_id: phone_number_id,
27
36
  business_account_id: business_account_id,
28
37
  api_version: api_version,
29
- access_token: access_token,
38
+ access_token: access_token
30
39
  )
31
-
32
- config
33
40
  end
34
41
 
35
42
  private
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::CloudWaba::Client do
4
+ let(:env_access_token) { ENV["CLOUD_API_ACCESS_TOKEN"] }
5
+ let(:env_api_version) { ENV["CLOUD_API_VERSION"] }
6
+ let(:env_app_id) { ENV["M4D_APP_ID"] }
7
+ let(:env_app_secret) { ENV["M4D_APP_SECRET"] }
8
+ let(:env_base_url) { ENV["WA_BASE_URL"] }
9
+ let(:env_business_account_id) { ENV["WA_BUSINESS_ACCOUNT_ID"] }
10
+ let(:env_phone_number_id) { ENV["WA_PHONE_NUMBER_ID"] }
11
+
12
+ let(:param_access_token) { "CLOUD_API_ACCESS_TOKEN_PARAM_VALUE" }
13
+ let(:param_api_version) { "CLOUD_API_VERSION_PARAM_VALUE" }
14
+ let(:param_app_id) { "M4D_APP_ID_PARAM_VALUE" }
15
+ let(:param_app_secret) { "M4D_APP_SECRET_PARAM_VALUE" }
16
+ let(:param_business_account_id) { "WA_BUSINESS_ACCOUNT_ID_PARAM_VALUE" }
17
+ let(:param_phone_number_id) { "WA_PHONE_NUMBER_ID_PARAM_VALUE" }
18
+
19
+ before do
20
+ # Set env variables for testing
21
+ ENV["CLOUD_API_ACCESS_TOKEN"] = "CLOUD_API_ACCESS_TOKEN_VALUE"
22
+ ENV["CLOUD_API_VERSION"] = "CLOUD_API_VERSION_VALUE"
23
+ ENV["M4D_APP_ID"] = "M4D_APP_ID_VALUE"
24
+ ENV["M4D_APP_SECRET"] = "M4D_APP_SECRET_VALUE"
25
+ ENV["WA_BASE_URL"] = "WA_BASE_URL_VALUE"
26
+ ENV["WA_BUSINESS_ACCOUNT_ID"] = "WA_BUSINESS_ACCOUNT_ID_VALUE"
27
+ ENV["WA_PHONE_NUMBER_ID"] = "WA_PHONE_NUMBER_ID_VALUE"
28
+ end
29
+
30
+ context "When init new client instance using env variables" do
31
+ it "Should read configuration from environment variables" do
32
+ client = described_class.new
33
+
34
+ expect(client.config.access_token).to eq(env_access_token)
35
+ expect(client.config.api_version).to eq(env_api_version)
36
+ expect(client.config.app_id).to eq(env_app_id)
37
+ expect(client.config.app_secret).to eq(env_app_secret)
38
+ expect(client.config.base_url).to eq(env_base_url)
39
+ expect(client.config.business_account_id).to eq(env_business_account_id)
40
+ expect(client.config.phone_number_id).to eq(env_phone_number_id)
41
+ end
42
+ end
43
+
44
+ context "When init new client instance using params" do
45
+ it "Should read configuration from parameters if provided" do
46
+ client = described_class.new(
47
+ app_id: param_app_id,
48
+ app_secret: param_app_secret,
49
+ phone_number_id: param_phone_number_id,
50
+ business_account_id: param_business_account_id,
51
+ access_token: param_access_token,
52
+ api_version: param_api_version
53
+ )
54
+
55
+ expect(client.config.access_token).to eq(param_access_token)
56
+ expect(client.config.access_token).not_to eq(env_access_token)
57
+
58
+ expect(client.config.api_version).to eq(param_api_version)
59
+ expect(client.config.api_version).not_to eq(env_api_version)
60
+
61
+ expect(client.config.app_id).to eq(param_app_id)
62
+ expect(client.config.app_id).not_to eq(env_app_id)
63
+
64
+ expect(client.config.app_secret).to eq(param_app_secret)
65
+ expect(client.config.app_secret).not_to eq(env_app_secret)
66
+
67
+ expect(client.config.business_account_id).to eq(param_business_account_id)
68
+ expect(client.config.business_account_id).not_to eq(env_business_account_id)
69
+
70
+ expect(client.config.phone_number_id).to eq(param_phone_number_id)
71
+ expect(client.config.phone_number_id).not_to eq(env_phone_number_id)
72
+ end
73
+ end
74
+
75
+ context "When multiple clients co-exist" do
76
+ it "Should have different configurations per client" do
77
+ client_1 = described_class.new
78
+ client_2 = described_class.new(
79
+ app_id: param_app_id,
80
+ app_secret: param_app_secret,
81
+ phone_number_id: param_phone_number_id,
82
+ business_account_id: param_business_account_id,
83
+ access_token: param_access_token,
84
+ api_version: param_api_version
85
+ )
86
+
87
+ expect(client_1).not_to eq(client_2)
88
+ expect(client_1.config.access_token).not_to eq(client_2.config.access_token)
89
+ expect(client_1.config.api_version).not_to eq(client_2.config.api_version)
90
+ expect(client_1.config.app_id).not_to eq(client_2.config.app_id)
91
+ expect(client_1.config.app_secret).not_to eq(client_2.config.app_secret)
92
+ expect(client_1.config.business_account_id).not_to eq(client_2.config.business_account_id)
93
+ expect(client_1.config.phone_number_id).not_to eq(client_2.config.phone_number_id)
94
+ end
95
+ end
96
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require 'bundler/setup'
2
2
  require 'dotenv/load'
3
+ require 'byebug'
3
4
 
4
5
  Bundler.setup
5
6
 
6
- require 'cloud_waba' # and any other gems you need
7
+ require 'cloud_waba/client' # and any other gems you need
7
8
 
8
9
  RSpec.configure do |config|
9
10
  # some (optional) config here
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud-waba-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmed Bassell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-04 00:00:00.000000000 Z
11
+ date: 2023-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -66,26 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.17.0
69
- - !ruby/object:Gem::Dependency
70
- name: byebug
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '9.0'
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: 9.0.5
79
- type: :development
80
- prerelease: false
81
- version_requirements: !ruby/object:Gem::Requirement
82
- requirements:
83
- - - "~>"
84
- - !ruby/object:Gem::Version
85
- version: '9.0'
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: 9.0.5
89
69
  - !ruby/object:Gem::Dependency
90
70
  name: sorbet
91
71
  requirement: !ruby/object:Gem::Requirement
@@ -120,6 +100,7 @@ executables: []
120
100
  extensions: []
121
101
  extra_rdoc_files: []
122
102
  files:
103
+ - ".byebug_history"
123
104
  - ".env.example"
124
105
  - ".gitignore"
125
106
  - ".rspec"
@@ -162,7 +143,7 @@ files:
162
143
  - lib/cloud_waba/models/templates/message_template.rb
163
144
  - lib/cloud_waba/models/templates/response.rb
164
145
  - lib/cloud_waba/utils.rb
165
- - spec/cloud_waba_spec.rb
146
+ - spec/cloud_waba/client_spec.rb
166
147
  - spec/spec_helper.rb
167
148
  homepage: https://rubygems.org/gems/cloud_waba
168
149
  licenses:
@@ -176,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
157
  requirements:
177
158
  - - ">="
178
159
  - !ruby/object:Gem::Version
179
- version: '0'
160
+ version: 2.5.3
180
161
  required_rubygems_version: !ruby/object:Gem::Requirement
181
162
  requirements:
182
163
  - - ">="
@@ -1,4 +0,0 @@
1
- require 'spec_helper'
2
- describe CloudWaba do
3
- pending "write it"
4
- end