direct7 0.0.11 → 0.0.13

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: a9afbbf171b7e12d3472ed39168510562aaf97618d1df01346b8806f730267bb
4
- data.tar.gz: ebc9d5a1820c9a691810c59ab09e223ddb622497365f9586c6212e9a0858b64a
3
+ metadata.gz: f8c128191bac6a5abb2d2dfed05e504a36df201d394d44fb05dde354bc4e3e16
4
+ data.tar.gz: 0bd62c9782fa39cceebc1110bd68b68dc000d37e0548c11788fc882c48b2c0b0
5
5
  SHA512:
6
- metadata.gz: e6cb412caf09c09dffe941834a789ad32722fef46708b8e77d717d73992d054af8df4f3200e7fbf42707aee935866f0c579ff804982c31a3d89fc3431de173a8
7
- data.tar.gz: d8bb0be38deb0c6e9dfba4a3b674114670f0ccb6873b992f5aa74178b415ef7ecd3a2b99762bf36c83f8efe6ebb271eeaf0568a2c01407af9d242eceb94885ad
6
+ metadata.gz: 34016259c47fa36daf4e3829897fb7a3a5cb38f1e4f82222d02d1eec093d36db4e10ec038276dfe238132b08bd62bb241eaf99def9fa020cebd038d9392f7f39
7
+ data.tar.gz: 75564fd228ff33d129220c29961e20fc9e963d760c918b0331fc002218fc66122ae1172221238c0cbdd8f98f09f0e3c7eb395d6dd35bcdb0efc8af4beccde941
Binary file
Binary file
@@ -1,7 +1,10 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <module type="PYTHON_MODULE" version="4">
3
3
  <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$" />
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/vendor/bundle/ruby/2.7.0/doc" />
6
+ <excludeFolder url="file://$MODULE_DIR$/vendor/bundle/ruby/3.0.0/doc" />
7
+ </content>
5
8
  <orderEntry type="inheritedJdk" />
6
9
  <orderEntry type="sourceFolder" forTests="false" />
7
10
  </component>
data/README.md CHANGED
@@ -8,7 +8,7 @@ The SDK is available on RubyGems and can be installed using two methods:
8
8
  Add this line to your application's Gemfile:
9
9
 
10
10
  ```bash
11
- gem 'direct7', '~> 0.0.11'
11
+ gem 'direct7', '~> 0.0.13'
12
12
  ```
13
13
 
14
14
  And then execute:
@@ -35,7 +35,12 @@ require 'direct7'
35
35
 
36
36
  client = Direct7::Client.new('Your API token')
37
37
 
38
- client.sms.send_message( recipients =['+91999999XXXX'], content ='Greetings from D7 API', originator ='SignOTP', report_url ='https://the_url_to_recieve_delivery_report.com', unicode =true)
38
+ client.sms.send_message(
39
+ originator='SignOTP',
40
+ report_url='https://the_url_to_recieve_delivery_report.com',
41
+ schedule_time=nil,
42
+ { recipients: ['+919999XXXXXX'], content: 'Greetings from D7 API', unicode: false }
43
+ )
39
44
  ```
40
45
 
41
46
  ### Send SMS (Unicode)
@@ -45,7 +50,12 @@ require 'direct7'
45
50
 
46
51
  client = Direct7::Client.new('Your API token')
47
52
 
48
- client.sms.send_message(recipients = ["+97150900XXXX","+97845900XXX"], content = "مرحبا بالعالم!", originator = "SignOTP", report_url = "https://the_url_to_recieve_delivery_report.com", unicode = True)
53
+ client.sms.send_message(
54
+ originator='SignOTP',
55
+ report_url='https://the_url_to_recieve_delivery_report.com',
56
+ schedule_time=nil,
57
+ { recipients: ['+919999XXXXXX'], content: "مرحبا بالعالم!", unicode: true }
58
+ )
49
59
  ```
50
60
 
51
61
  ### Get Request Status
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.0.13
Binary file
Binary file
data/direct7.gemspec CHANGED
@@ -4,7 +4,7 @@ require "direct7/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "direct7"
7
- spec.version = "0.0.11"
7
+ spec.version = "0.0.13"
8
8
  spec.authors = ["Direct7 Networks"]
9
9
  spec.email = ["support@d7networks.com"]
10
10
  spec.summary = "Ruby SDK for Direct7 Platform REST API"
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/d7networks/direct7-ruby-sdk.git"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files`.split("\n")
16
+ spec.files = `git ls-files`.split("\n")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ["lib"]
19
19
 
data/lib/direct7/sms.rb CHANGED
@@ -8,23 +8,28 @@ module Direct7
8
8
  @client = client
9
9
  end
10
10
 
11
- def send_message(recipients, content, originator, report_url = nil, unicode = false)
12
- message = {
13
- 'channel' => 'sms',
14
- 'content' => content,
15
- 'msg_type' => 'text',
16
- 'data_coding' => unicode ? 'unicode' : 'text',
17
- 'recipients' => recipients
18
- };
11
+ def send_message(originator, report_url, schedule_time, *args)
12
+ messages = []
13
+ args.each do |message|
14
+ messages << {
15
+ 'channel' => 'sms',
16
+ 'recipients' => message[:recipients] || [],
17
+ 'content' => message[:content] || '',
18
+ 'msg_type' => 'text',
19
+ 'data_coding' => message[:unicode] ? 'unicode' : 'text'
20
+ }
21
+ end
19
22
  message_globals = {
20
23
  'originator' => originator,
21
24
  'report_url' => report_url,
25
+ 'schedule_time' => schedule_time
22
26
  };
23
- response = @client.post(@client.host, '/messages/v1/send', true, params= {
24
- 'messages' => [message],
25
- 'message_globals' => message_globals
26
- })
27
- # puts "Message sent successfully."
27
+ payload = {
28
+ 'messages' => messages,
29
+ 'message_globals' => message_globals
30
+ }
31
+ response = @client.post(@client.host, '/messages/v1/send', true, params=payload)
32
+ puts "Message sent successfully."
28
33
  response
29
34
  end
30
35
 
@@ -10,12 +10,7 @@ module Direct7
10
10
  @log = Logger.new(STDOUT) # You can customize the log destination as needed
11
11
  end
12
12
 
13
- def send_whatsapp_freeform_message(originator, recipient, message_type, message_text= nil, first_name= nil,
14
- last_name= nil, display_name= nil, phone= nil,
15
- email= nil, url= nil, latitude= nil, longitude= nil,
16
- location_name= nil, location_address= nil,
17
- attachment_type= nil, attachment_url= nil,
18
- attachment_caption= nil)
13
+ def send_whatsapp_freeform_message(originator, recipient, message_type, body=nil, first_name=nil, last_name=nil, formatted_name=nil, phones=nil, emails=nil, urls=nil, latitude=nil, longitude=nil, name=nil, address=nil, type=nil, url=nil, caption=nil)
19
14
  message = {
20
15
  'originator' => originator,
21
16
  'recipients' => [{'recipient' => recipient}],
@@ -26,40 +21,44 @@ module Direct7
26
21
 
27
22
  case message_type
28
23
  when 'CONTACTS'
29
- message['content']['contact'] = {
30
- 'first_name' => first_name,
31
- 'last_name' => last_name,
32
- 'display_name' => display_name,
33
- 'phone' => phone,
34
- 'email' => email,
35
- 'url' => url
36
- }
24
+ message['content']['contacts'] = [{
25
+ 'name' => {
26
+ 'first_name' => first_name,
27
+ 'last_name' => last_name,
28
+ 'formatted_name' => formatted_name,
29
+ },
30
+ 'phones' => (phones.map { |phone| { 'phone' => phone } } if phones),
31
+ 'emails' => (emails.map { |email| { 'email' => email } } if emails),
32
+ 'urls' => (urls.map { |url| { 'url' => url } } if urls),
33
+ }]
37
34
  when 'LOCATION'
38
35
  message['content']['location'] = {
39
36
  'latitude' => latitude,
40
37
  'longitude' => longitude,
41
- 'name' => location_name,
42
- 'address' => location_address
38
+ 'name' => name,
39
+ 'address' => address,
43
40
  }
44
41
  when 'ATTACHMENT'
45
42
  message['content']['attachment'] = {
46
- 'attachment_type' => attachment_type,
47
- 'attachment_url' => attachment_url,
48
- 'attachment_caption' => attachment_caption
43
+ 'type' => type,
44
+ 'url' => url,
45
+ 'caption' => caption,
49
46
  }
50
47
  when 'TEXT'
51
- message['content']['message_text'] = message_text
48
+ message['content']['text'] = {
49
+ 'body' => body,
50
+ }
52
51
  end
53
- puts message
54
- response = @client.post(@client.host, '/whatsapp/v1/send', true, params= { 'messages' => [message] })
52
+
53
+ response = @client.post(@client.host, '/whatsapp/v2/send', params: { 'messages' => [message] })
55
54
  @log.info('Message sent successfully.')
56
55
  response
57
56
  end
58
57
 
59
58
  def send_whatsapp_templated_message(originator, recipient, template_id,
60
- body_parameter_values, media_type= nil, media_url= nil,
61
- latitude= nil, longitude= nil, location_name= nil,
62
- location_address= nil)
59
+ body_parameter_values, media_type=nil, media_url=nil,
60
+ latitude=nil, longitude=nil, location_name=nil,
61
+ location_address=nil,lto_expiration_time_ms=nil, coupon_code=nil, quick_replies= nil, actions= nil, carousel_cards=nil)
63
62
  message = {
64
63
  'originator' => originator,
65
64
  'recipients' => [{'recipient' => recipient}],
@@ -87,8 +86,44 @@ module Direct7
87
86
  message['content']['template']['media'] = { 'media_type' => media_type, 'media_url' => media_url }
88
87
  end
89
88
  end
90
-
91
- response = @client.post(@client.host, '/whatsapp/v1/send', true, params= { 'messages' => [message] })
89
+
90
+ if lto_expiration_time_ms
91
+ message['content']['template']['limited_time_offer'] = {
92
+ 'expiration_time_ms' => 'lto_expiration_time_ms',
93
+ }
94
+ end
95
+
96
+ if coupon_code
97
+ message['content']['template']['buttons'] = {
98
+ 'coupon_code' => [
99
+ {
100
+ "index"=> 0,
101
+ "type"=> "copy_code",
102
+ "coupon_code"=> coupon_code
103
+ }
104
+ ]
105
+ }
106
+ end
107
+
108
+ if quick_replies
109
+ message['content']['template']['buttons'] = {
110
+ 'quick_replies' => actquick_repliesions,
111
+ }
112
+ end
113
+
114
+ if actions
115
+ message['content']['template']['buttons'] = {
116
+ 'actions' => actions,
117
+ }
118
+ end
119
+
120
+ if carousel_cards
121
+ message['content']['template']['carousel'] = {
122
+ 'cards' => carousel_cards,
123
+ }
124
+ end
125
+
126
+ response = @client.post(@client.host, '/whatsapp/v2/send', true, params: { 'messages' => [message] })
92
127
  @log.info('Message sent successfully.')
93
128
  response
94
129
  end
data/test/test.rb CHANGED
@@ -1,20 +1,19 @@
1
- require './lib/direct7/client'
2
- require './lib/direct7/errors/errors'
1
+ require '../lib/direct7/client'
2
+ require '../lib/direct7/errors/errors'
3
3
  require 'test/unit'
4
4
  require_relative '../lib/direct7/client'
5
5
 
6
6
  class TestSERVICES < Test::Unit::TestCase
7
7
  def setup
8
- @client = Direct7::Client.new('Your API token')
8
+ @client = Direct7::Client.new('Your API Token')
9
9
  end
10
10
 
11
11
  def test_send_message
12
12
  response1 = @client.sms.send_message(
13
- recipients =['+91999999XXXX'],
14
- content ='Greetings from D7 API',
15
- originator ='SignOTP',
16
- report_url ='https://the_url_to_recieve_delivery_report.com',
17
- unicode =true
13
+ originator='SignOTP',
14
+ report_url='https://the_url_to_recieve_delivery_report.com',
15
+ schedule_time=nil,
16
+ { recipients: ['+991999999XXXX'], content: 'Greetings from D7 API', unicode: false }
18
17
  )
19
18
  puts response1
20
19
  response2 = @client.sms.get_status(request_id= '001a1a4e-0221-4cb7-a524-a2a5b337cbe8')
@@ -59,9 +58,31 @@ class TestSERVICES < Test::Unit::TestCase
59
58
  response = @client.whatsapp.send_whatsapp_freeform_message(
60
59
  originator= "91906154XXXX",
61
60
  recipient= "+91999999XXXX",
62
- message_type="CONTACTS", first_name="Amal", last_name="Anu", display_name="Amal Anu", phone="91906152XXXX", email = "amal@gmail.com"
61
+ message_type="CONTACTS", first_name="Amal", last_name="Anu", formatted_name="Amal Anu", phones=["91906152XXXX"], emails = ["amal@gmail.com"]
63
62
  )
64
63
  response = @client.whatsapp.get_status(request_id="81eca535-8131-4866-be18-b3d933604069")
65
64
  puts response
66
65
  end
66
+
67
+ def test_send_whatsapp_freeform_message_text
68
+ response = @client.whatsapp.send_whatsapp_freeform_message(
69
+ originator= "+XXXXXXXXXXXX",
70
+ recipient= "XXXXXXXXXXX",
71
+ message_type= "TEXT",
72
+ body= "Hi",
73
+ )
74
+ puts response
75
+ end
76
+
77
+ def test_send_whatsapp_freeform_message_attachment
78
+ response = @client.whatsapp.send_whatsapp_freeform_message(
79
+ originator= "+XXXXXXXXXXXX",
80
+ recipient= "XXXXXXXXXXX",
81
+ message_type= "ATTACHMENT",
82
+ type= "image",
83
+ url= "https=//upload.wikimedia.org",
84
+ caption= "Tet"
85
+ )
86
+ puts response
87
+ end
67
88
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: direct7
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Direct7 Networks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-07 00:00:00.000000000 Z
11
+ date: 2024-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -105,6 +105,8 @@ extra_rdoc_files:
105
105
  - README.md
106
106
  files:
107
107
  - ".bundle/config"
108
+ - ".direct7.gemspec.swo"
109
+ - ".direct7.gemspec.swp"
108
110
  - ".gitignore"
109
111
  - ".idea/.gitignore"
110
112
  - ".idea/direct7-ruby-sdk.iml"
@@ -125,7 +127,8 @@ files:
125
127
  - Rakefile
126
128
  - VERSION
127
129
  - direct7-0.0.10.gem
128
- - direct7-0.0.9.gem
130
+ - direct7-0.0.11.gem
131
+ - direct7-0.0.12.gem
129
132
  - direct7.gemspec
130
133
  - doc/Direct7.html
131
134
  - doc/Direct7/AuthenticationError.html
data/direct7-0.0.9.gem DELETED
Binary file