whatsapp_sdk 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f68cc009fe9fd27e79ac8e7f1a128204c66a565f055bce04bf4338f63ccb4f63
4
- data.tar.gz: 49c4b5891624196c2557166cce8587e645a12e16716ccbc216c19f048cf2ab41
3
+ metadata.gz: 3dabd5d87a1a3988caaafc2a090c9b85bcea77cc764132a169227a5ca1c4b409
4
+ data.tar.gz: 1ac41750e5e737fbf9a606e013015d796b68c328e3950241cad051c8eef6d674
5
5
  SHA512:
6
- metadata.gz: 91204e0864c369777ff18f63c95f846acbcfa6248ed52fa0db6d05f43784be704e124edffcc73f4d3e0d565269b1784058ede119bdd862d067f75a49550d67df
7
- data.tar.gz: 606a0b4ab9601388c2c737e47306cbc2432ef763efd82a869dd92be7d23d8fc2a6877573f1db5119b20ff8135523469a47ed02e2f75f857f33b238b6e7e23be5
6
+ metadata.gz: 183f8600f1e74a46b4a38f290c806f479a0e52a20ec7c6d836b2fe3ac8038e4c91620e83d8780810907a2395555169aa8911fd5385299adcd3830a3492bea9a7
7
+ data.tar.gz: ce2cb90d04e06dc62d0294bcd395b3cf6cdffb2e60c24a8671539825de486299b11647eab9cf875007f290b8a35af350aadb7a985cad4bad2bcc415d85955cd3
data/.rubocop.yml CHANGED
@@ -1,3 +1,7 @@
1
+ require:
2
+ - rubocop-minitest
3
+ - rubocop-performance
4
+
1
5
  AllCops:
2
6
  NewCops: enable
3
7
 
@@ -28,3 +32,6 @@ Metrics/AbcSize:
28
32
  # Wait until https://github.com/rubocop/rubocop/issues/8761 is fixed
29
33
  Gemspec/RequiredRubyVersion:
30
34
  Enabled: false
35
+
36
+ Minitest/MultipleAssertions:
37
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Unreleased
2
2
 
3
+ # v 0.3.0
4
+ - Allow Apps to have a singleton global authentication client.
5
+
3
6
  # v 0.2.0
4
7
  - Added Media API
5
8
  - Update Facebook API to v14
data/Gemfile CHANGED
@@ -4,19 +4,21 @@ source "https://rubygems.org"
4
4
 
5
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
- # Specify your gem's dependencies in whatsapp_sdk.gemspec
8
7
  gem("faraday")
9
8
  gem("faraday-multipart")
10
9
  gem("oj")
10
+ gem("rake", ">= 12.3.3")
11
11
 
12
12
  group(:test) do
13
13
  gem('mocha')
14
+ gem('rubocop', require: false)
15
+ gem('rubocop-minitest', require: false)
16
+ gem('rubocop-performance', require: false)
14
17
  end
15
18
 
16
19
  group(:development) do
17
20
  gem('pry')
18
21
  gem('pry-nav')
19
- gem('rubocop', require: false)
20
22
  end
21
23
 
22
24
  gemspec
data/Gemfile.lock CHANGED
@@ -18,10 +18,10 @@ GEM
18
18
  multipart-post (~> 2)
19
19
  faraday-net_http (2.0.3)
20
20
  method_source (1.0.0)
21
- minitest (5.15.0)
21
+ minitest (5.16.1)
22
22
  mocha (1.14.0)
23
- multipart-post (2.2.2)
24
- oj (3.13.13)
23
+ multipart-post (2.2.3)
24
+ oj (3.13.14)
25
25
  parallel (1.22.1)
26
26
  parser (3.1.2.0)
27
27
  ast (~> 2.4.1)
@@ -31,10 +31,10 @@ GEM
31
31
  pry-nav (1.0.0)
32
32
  pry (>= 0.9.10, < 0.15)
33
33
  rainbow (3.1.1)
34
- rake (10.5.0)
34
+ rake (13.0.6)
35
35
  regexp_parser (2.5.0)
36
36
  rexml (3.2.5)
37
- rubocop (1.30.0)
37
+ rubocop (1.30.1)
38
38
  parallel (~> 1.10)
39
39
  parser (>= 3.1.0.0)
40
40
  rainbow (>= 2.2.2, < 4.0)
@@ -45,9 +45,14 @@ GEM
45
45
  unicode-display_width (>= 1.4.0, < 3.0)
46
46
  rubocop-ast (1.18.0)
47
47
  parser (>= 3.1.1.0)
48
+ rubocop-minitest (0.20.1)
49
+ rubocop (>= 0.90, < 2.0)
50
+ rubocop-performance (1.14.2)
51
+ rubocop (>= 1.7.0, < 2.0)
52
+ rubocop-ast (>= 0.4.0)
48
53
  ruby-progressbar (1.11.0)
49
54
  ruby2_keywords (0.0.5)
50
- unicode-display_width (2.1.0)
55
+ unicode-display_width (2.2.0)
51
56
 
52
57
  PLATFORMS
53
58
  x86_64-darwin-21
@@ -61,8 +66,10 @@ DEPENDENCIES
61
66
  oj
62
67
  pry
63
68
  pry-nav
64
- rake (~> 10.0)
69
+ rake (>= 12.3.3)
65
70
  rubocop
71
+ rubocop-minitest
72
+ rubocop-performance
66
73
  whatsapp_sdk!
67
74
 
68
75
  BUNDLED WITH
data/README.md CHANGED
@@ -1,8 +1,15 @@
1
1
  # Ruby Whatsapp SDK
2
+ [![Gem Version](https://badge.fury.io/rb/whatsapp_sdk.svg)](https://badge.fury.io/rb/whatsapp_sdk)
3
+ [![CircleCI](https://circleci.com/gh/circleci/circleci-docs.svg?style=svg)](https://circleci.com/gh/ignacio-chiazzo/ruby_whatsapp_sdk)
4
+ <a href="https://codeclimate.com/github/ignacio-chiazzo/ruby_whatsapp_sdk/maintainability"><img src="https://api.codeclimate.com/v1/badges/169cce95450272e4ad7d/maintainability" /></a>
2
5
 
3
6
  The SDK provides a set of operations and classes to use the Whatsapp API.
4
7
  Send stickers, messages, audio, videos, locations or just ask for the phone numbers through this library in a few steps!
5
8
 
9
+
10
+ https://user-images.githubusercontent.com/11672878/173238826-6fc0a6f8-d0ee-4eae-8947-7dfd3b8b3446.mov
11
+
12
+
6
13
  ## Installation
7
14
 
8
15
  Add this line to your application's Gemfile:
@@ -21,12 +28,22 @@ Or install it yourself as:
21
28
 
22
29
  ## Quick Start
23
30
 
24
- There are two primary resources, `Messages` and `PhoneNumbers`. The first one allows clients to send any kind of message (text, audio, location, video, image, etc.), and the latter will enable clients to query the phone numbers associated.
31
+ There are three primary resources, `Messages`, `Media` and `PhoneNumbers`. The first one allows clients to send any kind of message (text, audio, location, video, image, etc.), and the latter will enable clients to query the phone numbers associated.
25
32
 
26
- To use `Messages` or `PhoneNumbers` you need to create a `Client` instance by passing the `access_token` like this:
33
+ To use `Messages`, `Media` or `PhoneNumbers` you need to initialize the `Client` that contain auth information. There are two ways to do it
34
+
35
+ 1) Using an initializer
36
+
37
+ ```ruby
38
+ WhatsappSdk.configure do |config|
39
+ config.access_token = ACCESS_TOKEN
40
+ end
41
+ ```
42
+ OR creating an instance and pass it to the Messages or PhoneNumbers instance like this:
27
43
 
28
44
  ```ruby
29
45
  client = WhatsappSdk::Api::Client.new("<ACCESS TOKEN>") # replace this with a valid access token
46
+ messages_api = WhatsappSdk::Api::Messages.new(client)
30
47
  ```
31
48
 
32
49
  Each API operation returns a `WhatsappSdk::Api::Response` that contains `data` and `error` and a couple of helpful functions such as `ok?` and `error?`. There are three types of response `WhatsappSdk::Api::MessageDataResponse`, `WhatsappSdk::Api::PhoneNumberDataResponse` and `WhatsappSdk::Api::PhoneNumbersDataResponse`. Each of them contains different attributes.
@@ -35,12 +52,13 @@ Each API operation returns a `WhatsappSdk::Api::Response` that contains `data` a
35
52
  First, create the client and then create an instance `WhatsappSdk::Api::Messages` that requires a client as a param like this:
36
53
 
37
54
  ```ruby
38
- client = WhatsappSdk::Api::Client.new("<ACCESS TOKEN>") # replace this with a valid access_token
39
- messages_api = WhatsappSdk::Api::Messages.new(client)
40
- phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new(client)
41
- medias_api = WhatsappSdk::Api::Medias.new(client)
55
+ messages_api = WhatsappSdk::Api::Messages.new
56
+ phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
57
+ medias_api = WhatsappSdk::Api::Medias.new
42
58
  ```
43
59
 
60
+ Note: Remember to initialize the client first!
61
+
44
62
  ### Phone numbers API
45
63
  Get the list of phone numbers registered
46
64
  ```ruby
@@ -82,11 +100,19 @@ medias_api.delete(media_id: MEDIA_ID)
82
100
  messages_api.send_text(sender_id: 1234, recipient_number: "112345678", message: "hola")
83
101
  ```
84
102
 
103
+ **Read a message**
104
+ ```ruby
105
+ messages_api.read_message(sender_id: 1234, message_id: "wamid.HBgLMTM0M12345678910=")
106
+ ```
107
+
108
+ Note: To get the `message_id` you can set up [Webhooks](https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/components) that will listen and fire an event when a message is received.
109
+
110
+
85
111
  **Send a location message**
86
112
 
87
113
  ```ruby
88
114
  messages_api.send_location(
89
- sender_id: 123123, recipient_number: "56789",
115
+ sender_id: 123123, recipient_number: "56789",
90
116
  longitude: 45.4215, latitude: 75.6972, name: "nacho", address: "141 cooper street"
91
117
  )
92
118
  ```
@@ -94,12 +120,12 @@ messages_api.send_location(
94
120
  **Send an image message**
95
121
  It could use a link or an image_id.
96
122
  ```ruby
97
- # with a link
123
+ # with a link
98
124
  messages_api.send_image(
99
125
  sender_id: 123123, recipient_number: "56789", link: "image_link", caption: "Ignacio Chiazzo Profile"
100
126
  )
101
127
 
102
- # with an image id
128
+ # with an image id
103
129
  messages_api.send_image(
104
130
  sender_id: 123123, recipient_number: "56789", image_id: "1234", caption: "Ignacio Chiazzo Profile"
105
131
  )
@@ -108,22 +134,22 @@ messages_api.send_image(
108
134
  **Send an audio message**
109
135
  It could use a link or an audio_id.
110
136
  ```ruby
111
- # with a link
137
+ # with a link
112
138
  messages_api.send_audio(sender_id: 123123, recipient_number: "56789", link: "audio_link")
113
139
 
114
- # with an audio id
140
+ # with an audio id
115
141
  messages_api.send_audio(sender_id: 123123, recipient_number: "56789", audio_id: "1234")
116
142
  ```
117
143
 
118
144
  **Send a document message**
119
145
  It could use a link or a document_id.
120
146
  ```ruby
121
- # with a link
147
+ # with a link
122
148
  messages_api.send_document(
123
149
  sender_id: 123123, recipient_number: "56789", link: "document_link", caption: "Ignacio Chiazzo"
124
150
  )
125
151
 
126
- # with a document id
152
+ # with a document id
127
153
  messages_api.send_document(
128
154
  sender_id: 123123, recipient_number: "56789", document_id: "1234", caption: "Ignacio Chiazzo"
129
155
  )
@@ -132,7 +158,7 @@ messages_api.send_document(
132
158
  **Send a sticker message**
133
159
  It could use a link or a sticker_id.
134
160
  ```ruby
135
- # with a link
161
+ # with a link
136
162
  messages_api.send_sticker(sender_id: 123123, recipient_number: "56789", link: "link")
137
163
 
138
164
  # with a sticker_id
@@ -228,7 +254,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
228
254
 
229
255
  ## Contributing
230
256
 
231
- Bug reports and pull requests are welcome on GitHub at [https://github.com/ignacio-chiazzo/whatsapp_sdk](https://github.com/ignacio-chiazzo/whatsapp_sdk) This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
257
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk) This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
232
258
 
233
259
  ## License
234
260
 
data/example.rb CHANGED
@@ -11,7 +11,7 @@ gemfile(true) do
11
11
 
12
12
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
13
13
 
14
- gem "whatsapp_sdk", github: "ignacio-chiazzo/whatsapp_sdk", branch: "main"
14
+ gem "whatsapp_sdk"
15
15
  gem "pry"
16
16
  gem "pry-nav"
17
17
  end
@@ -28,6 +28,11 @@ RECIPIENT_NUMBER = "<TODO replace>"
28
28
  BUSINESS_ID = "<TODO replace>"
29
29
  IMAGE_LINK = "<TODO replace>"
30
30
 
31
+ ################# Initialize Client #################
32
+ WhatsappSdk.configure do |config|
33
+ config.access_token = ACCESS_TOKEN
34
+ end
35
+
31
36
  ################# HELPERS ########################
32
37
  def print_message_sent(message_response)
33
38
  if message_response.ok?
@@ -38,10 +43,9 @@ def print_message_sent(message_response)
38
43
  end
39
44
  ##################################################
40
45
 
41
- client = WhatsappSdk::Api::Client.new(ACCESS_TOKEN)
42
- medias_api = WhatsappSdk::Api::Medias.new(client)
43
- messages_api = WhatsappSdk::Api::Messages.new(client)
44
- phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new(client)
46
+ medias_api = WhatsappSdk::Api::Medias.new
47
+ messages_api = WhatsappSdk::Api::Messages.new
48
+ phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
45
49
 
46
50
  ############################## Phone Numbers API ##############################
47
51
  phone_numbers_api.registered_number(SENDER_ID)
@@ -77,6 +81,9 @@ location_sent = messages_api.send_location(
77
81
  )
78
82
  print_message_sent(location_sent)
79
83
 
84
+ ######### READ A MESSAGE
85
+ # messages_api.read_message(sender_id: SENDER_ID, message_id: msg_id)
86
+
80
87
  ######### SEND AN IMAGE
81
88
  # Send an image with a link
82
89
  image_sent = messages_api.send_image(
@@ -91,28 +98,28 @@ messages_api.send_image(
91
98
 
92
99
  ######### SEND AUDIOS
93
100
  ## with a link
94
- # messages_api.send_audio(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "audio_link")
101
+ messages_api.send_audio(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "audio_link")
95
102
 
96
103
  ## with an audio id
97
- # messages_api.send_audio(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, audio_id: "1234")
104
+ messages_api.send_audio(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, audio_id: "1234")
98
105
 
99
106
  ######### SEND DOCUMENTS
100
107
  ## with a link
101
- # messages_api.send_document(
102
- # sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "document_link", caption: "Ignacio Chiazzo"
103
- # )
108
+ messages_api.send_document(
109
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "document_link", caption: "Ignacio Chiazzo"
110
+ )
104
111
 
105
112
  ## with a document id
106
- # messages_api.send_document(
107
- # sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, document_id: "1234", caption: "Ignacio Chiazzo"
108
- # )
113
+ messages_api.send_document(
114
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, document_id: "1234", caption: "Ignacio Chiazzo"
115
+ )
109
116
 
110
117
  ######### SEND STICKERS
111
118
  ## with a link
112
- # messages_api.send_sticker(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "link")
119
+ messages_api.send_sticker(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "link")
113
120
 
114
121
  ## with a sticker_id
115
- # messages_api.send_sticker(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, sticker_id: "1234")
122
+ messages_api.send_sticker(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, sticker_id: "1234")
116
123
 
117
124
  ######### SEND A TEMPLATE
118
125
  # Note: The template must have been created previously.
@@ -122,49 +129,49 @@ response_with_object = messages_api.send_template(sender_id: SENDER_ID, recipien
122
129
  name: "hello_world", language: "en_US", components: [])
123
130
  puts response_with_object
124
131
 
125
- # Send a template with components. Remember to create the template first.
126
- # header_component = WhatsappSdk::Resource::Component.new(
127
- # type: WhatsappSdk::Resource::Component::Type::HEADER
128
- # )
132
+ # Send a template with components.Remember to create the template first.
133
+ header_component = WhatsappSdk::Resource::Component.new(
134
+ type: WhatsappSdk::Resource::Component::Type::HEADER
135
+ )
129
136
 
130
- # image = WhatsappSdk::Resource::Media.new(type: "image", link: "http(s)://URL", caption: "caption")
131
- # document = WhatsappSdk::Resource::Media.new(type: "document", link: "http(s)://URL", filename: "txt.rb")
132
- # video = WhatsappSdk::Resource::Media.new(type: "video", id: 123)
137
+ image = WhatsappSdk::Resource::Media.new(type: "image", link: "http(s)://URL", caption: "caption")
138
+ document = WhatsappSdk::Resource::Media.new(type: "document", link: "http(s)://URL", filename: "txt.rb")
139
+ video = WhatsappSdk::Resource::Media.new(type: "video", id: 123)
133
140
 
134
- # parameter_image = WhatsappSdk::Resource::ParameterObject.new(
135
- # type: "image",
136
- # image: image
137
- # )
141
+ parameter_image = WhatsappSdk::Resource::ParameterObject.new(
142
+ type: "image",
143
+ image: image
144
+ )
138
145
 
139
- # parameter_document = WhatsappSdk::Resource::ParameterObject.new(
140
- # type: "document",
141
- # document: document
142
- # )
146
+ parameter_document = WhatsappSdk::Resource::ParameterObject.new(
147
+ type: "document",
148
+ document: document
149
+ )
143
150
 
144
- # parameter_video = WhatsappSdk::Resource::ParameterObject.new(
145
- # type: "video",
146
- # video: video
147
- # )
151
+ parameter_video = WhatsappSdk::Resource::ParameterObject.new(
152
+ type: "video",
153
+ video: video
154
+ )
148
155
 
149
- # parameter_text = WhatsappSdk::Resource::ParameterObject.new(
150
- # type: "text",
151
- # text: "I am a text"
152
- # )
156
+ parameter_text = WhatsappSdk::Resource::ParameterObject.new(
157
+ type: "text",
158
+ text: "I am a text"
159
+ )
153
160
 
154
- # header_component.add_parameter(parameter_text)
155
- # header_component.add_parameter(parameter_image)
156
- # header_component.add_parameter(parameter_video)
157
- # header_component.add_parameter(parameter_document)
158
- # header_component.to_json
161
+ header_component.add_parameter(parameter_text)
162
+ header_component.add_parameter(parameter_image)
163
+ header_component.add_parameter(parameter_video)
164
+ header_component.add_parameter(parameter_document)
165
+ header_component.to_json
159
166
 
160
- # body_component = WhatsappSdk::Resource::Component.new(
161
- # type: WhatsappSdk::Resource::Component::Type::BODY
162
- # )
163
- # body_component.add_parameter(parameter_text)
164
- # body_component.add_parameter(parameter_image)
165
- # body_component.add_parameter(parameter_video)
166
- # body_component.add_parameter(parameter_document)
167
- # body_component.to_json
167
+ body_component = WhatsappSdk::Resource::Component.new(
168
+ type: WhatsappSdk::Resource::Component::Type::BODY
169
+ )
170
+ body_component.add_parameter(parameter_text)
171
+ body_component.add_parameter(parameter_image)
172
+ body_component.add_parameter(parameter_video)
173
+ body_component.add_parameter(parameter_document)
174
+ body_component.to_json
168
175
 
169
176
  # button_component_1 = WhatsappSdk::Resource::Component.new(
170
177
  # type: WhatsappSdk::Resource::Component::Type::BUTTON,
@@ -180,21 +187,21 @@ puts response_with_object
180
187
  # parameters: [WhatsappSdk::Resource::ButtonParameter.new(type: "payload", payload: "payload")]
181
188
  # )
182
189
 
183
- # # Send a template with component_json
184
- # response_with_json = messages_api.send_template(
185
- # sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, name: "hello_world", language: "en_US",
186
- # components_json: [
187
- # {
188
- # "type" => "header",
189
- # "parameters" => [
190
- # {
191
- # "type" => "image",
192
- # "image" => {
193
- # "link" => "https://www.google.com/imgres?imgurl=https%3A%2F%2Fqph.cf2.quoracdn.net%2Fmain-qimg-6d977408fdd90a09a1fee7ba9e2f777c-lq&imgrefurl=https%3A%2F%2Fwww.quora.com%2FHow-can-I-find-my-WhatsApp-ID&tbnid=lDAx1vzXwqCakM&vet=12ahUKEwjKupLviJX4AhVrrHIEHQpGD9MQMygAegUIARC9AQ..i&docid=s-DNQVCrZmhJYM&w=602&h=339&q=example%20whatsapp%20image%20id&ved=2ahUKEwjKupLviJX4AhVrrHIEHQpGD9MQMygAegUIARC9AQ"
194
- # }
195
- # }
196
- # ]
197
- # }
198
- # ]
199
- # )
200
- # puts response_with_json
190
+ # Send a template with component_json
191
+ response_with_json = messages_api.send_template(
192
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, name: "hello_world", language: "en_US",
193
+ components_json: [
194
+ {
195
+ "type" => "header",
196
+ "parameters" => [
197
+ {
198
+ "type" => "image",
199
+ "image" => {
200
+ "link" => "https://www.google.com/imgres?imgurl=https%3A%2F%2Fqph.cf2.quoracdn.net%2Fmain-qimg-6d977408fdd90a09a1fee7ba9e2f777c-lq&imgrefurl=https%3A%2F%2Fwww.quora.com%2FHow-can-I-find-my-WhatsApp-ID&tbnid=lDAx1vzXwqCakM&vet=12ahUKEwjKupLviJX4AhVrrHIEHQpGD9MQMygAegUIARC9AQ..i&docid=s-DNQVCrZmhJYM&w=602&h=339&q=example%20whatsapp%20image%20id&ved=2ahUKEwjKupLviJX4AhVrrHIEHQpGD9MQMygAegUIARC9AQ"
201
+ }
202
+ }
203
+ ]
204
+ }
205
+ ]
206
+ )
207
+ puts response_with_json
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WhatsappSdk
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -6,7 +6,7 @@ module WhatsappSdk
6
6
  API_VERSION = "v13.0"
7
7
  API_CLIENT = "https://graph.facebook.com/#{API_VERSION}/"
8
8
 
9
- def initialize(client)
9
+ def initialize(client = WhatsappSdk.configuration.client)
10
10
  @client = client
11
11
  end
12
12
 
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WhatsappSdk
4
+ # This module allows client instantiating the client as a singleton like the following example:
5
+ # WhatsappSdk.configure do |config|
6
+ # config.access_token = ACCESS_TOKEN
7
+ # end
8
+ #
9
+ # The gem have access to the client through WhatsappSdk.configuration.client
10
+
11
+ class << self
12
+ def configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def configure
17
+ yield(configuration)
18
+ end
19
+ end
20
+
21
+ class Configuration
22
+ attr_accessor :access_token
23
+
24
+ def initialize(access_token = nil)
25
+ @access_token = access_token
26
+ end
27
+
28
+ def client
29
+ return unless access_token
30
+
31
+ WhatsappSdk::Api::Client.new(access_token)
32
+ end
33
+ end
34
+ end
data/lib/whatsapp_sdk.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Configuration
4
+ require_relative "whatsapp_sdk/configuration"
5
+
3
6
  # APIs
4
7
  require_relative "whatsapp_sdk/api/phone_numbers"
5
8
  require_relative "whatsapp_sdk/api/messages"
data/whatsapp_sdk.gemspec CHANGED
@@ -9,10 +9,12 @@ Gem::Specification.new do |spec|
9
9
  spec.version = WhatsappSdk::VERSION
10
10
  spec.authors = ["ignacio-chiazzo"]
11
11
  spec.email = ["ignaciochiazzo@gmail.com"]
12
-
13
- spec.summary = "Use the Whatsapp SDK to comunicate with Whatsapp API"
14
- spec.description = "Ruby Whatsapp SDK. Use the Whatsapp API through this library"
15
- spec.homepage = "https://github.com/ignacio-chiazzo/whatsapp_sdk"
12
+ spec.summary = "Use the Ruby Whatsapp SDK to comunicate with Whatsapp API using the Cloud API"
13
+ spec.description = <<-DESCRIPTION
14
+ Use the Ruby Whatsapp SDK to comunicate with Whatsapp API using the Cloud API.
15
+ Create bots to send and receive messages using the Whatsapp SDK in a few minutes.
16
+ DESCRIPTION
17
+ spec.homepage = "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk"
16
18
  spec.license = "MIT"
17
19
  spec.required_ruby_version = '>= 1.8.6'
18
20
 
@@ -20,8 +22,8 @@ Gem::Specification.new do |spec|
20
22
  # to allow pushing to a single host or delete this section to allow pushing to any host.
21
23
  if spec.respond_to?(:metadata)
22
24
  spec.metadata["homepage_uri"] = spec.homepage
23
- spec.metadata["source_code_uri"] = "https://github.com/ignacio-chiazzo/whatsapp_sdk"
24
- spec.metadata["changelog_uri"] = "https://github.com/ignacio-chiazzo/whatsapp_sdk/blob/main/CHANGELOG.md"
25
+ spec.metadata["source_code_uri"] = "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk"
26
+ spec.metadata["changelog_uri"] = "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/CHANGELOG.md"
25
27
  else
26
28
  raise "RubyGems 2.0 or newer is required to protect against " \
27
29
  "public gem pushes."
@@ -38,7 +40,7 @@ Gem::Specification.new do |spec|
38
40
 
39
41
  spec.add_development_dependency "bundler", "~> 2.3"
40
42
  spec.add_development_dependency "minitest", "~> 5.0"
41
- spec.add_development_dependency "rake", "~> 10.0"
43
+ spec.add_development_dependency "rake", "~> 12.3.3"
42
44
 
43
45
  spec.add_dependency("faraday", "~> 2.3.0")
44
46
  spec.add_dependency("faraday-multipart", "~> 1.0.4")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whatsapp_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ignacio-chiazzo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-11 00:00:00.000000000 Z
11
+ date: 2022-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: 12.3.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: 12.3.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: faraday
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +94,9 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 3.13.13
97
- description: Ruby Whatsapp SDK. Use the Whatsapp API through this library
97
+ description: |2
98
+ Use the Ruby Whatsapp SDK to comunicate with Whatsapp API using the Cloud API.
99
+ Create bots to send and receive messages using the Whatsapp SDK in a few minutes.
98
100
  email:
99
101
  - ignaciochiazzo@gmail.com
100
102
  executables: []
@@ -134,6 +136,7 @@ files:
134
136
  - lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb
135
137
  - lib/whatsapp_sdk/api/responses/read_message_data_response.rb
136
138
  - lib/whatsapp_sdk/api/responses/success_response.rb
139
+ - lib/whatsapp_sdk/configuration.rb
137
140
  - lib/whatsapp_sdk/error.rb
138
141
  - lib/whatsapp_sdk/resource/address.rb
139
142
  - lib/whatsapp_sdk/resource/button_parameter.rb
@@ -152,13 +155,13 @@ files:
152
155
  - lib/whatsapp_sdk/resource/url.rb
153
156
  - tmp/whatsapp.png
154
157
  - whatsapp_sdk.gemspec
155
- homepage: https://github.com/ignacio-chiazzo/whatsapp_sdk
158
+ homepage: https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk
156
159
  licenses:
157
160
  - MIT
158
161
  metadata:
159
- homepage_uri: https://github.com/ignacio-chiazzo/whatsapp_sdk
160
- source_code_uri: https://github.com/ignacio-chiazzo/whatsapp_sdk
161
- changelog_uri: https://github.com/ignacio-chiazzo/whatsapp_sdk/blob/main/CHANGELOG.md
162
+ homepage_uri: https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk
163
+ source_code_uri: https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk
164
+ changelog_uri: https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/CHANGELOG.md
162
165
  rubygems_mfa_required: 'true'
163
166
  post_install_message:
164
167
  rdoc_options: []
@@ -178,5 +181,6 @@ requirements: []
178
181
  rubygems_version: 3.2.3
179
182
  signing_key:
180
183
  specification_version: 4
181
- summary: Use the Whatsapp SDK to comunicate with Whatsapp API
184
+ summary: Use the Ruby Whatsapp SDK to comunicate with Whatsapp API using the Cloud
185
+ API
182
186
  test_files: []