gupshup-sdk 1.0.1 → 1.0.2

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: 93d703cc1208e0cedb7f376e4e4cbdedbc4f3cd53cf2f03d85760fc8dc92cc73
4
- data.tar.gz: 6cbc279e6dbf738e87e5ce2fd9821736fb0cac8f89b27bb6a1258373aefb046e
3
+ metadata.gz: dc41ddee089f971ee94c84684ad0f93873b35126bbc6fb432b1bf14150be7128
4
+ data.tar.gz: 33b4dfe76ad935a8a65cfbe8a02131c111ffb52e1cab54780c81a49d1d018a8a
5
5
  SHA512:
6
- metadata.gz: f980615ac97ee9364a10eb9d1958097f6590b1d2758dcd9dd4adbc30f640f5c4de79253b8cf6f946e6208d8a8e927881c3c32c18c8ec25b4560726d8dab417cc
7
- data.tar.gz: 430bbdcdb00f36b75ca190f54c84d041a1d5533644bd8b8fce841940803441822b9695282fee828ca2a2d329f0b0c7c66e0d674413e3bdb5b11219acb3ca95da
6
+ metadata.gz: 8d9fdbba95c387721a230cf882a06700eb426f2b90b2308aed5ae801ce01e8a926facdd7b79578720d9400088304bdf032f416e955f3cefd919879f8e4802253
7
+ data.tar.gz: e38b4501c966b50353a9d8ed4c68efa8b6bb33f6ae07a51f0623c22f4c69cb4cc42509f132b215e8e3fdc79e78c12bb2ce88d099baa5eae700fb17064d29212a
data/lib/gupshup.rb CHANGED
@@ -2,11 +2,11 @@
2
2
  module Gupshup
3
3
  class Client
4
4
  # Init
5
- # @gupshup = Gupshup::Client.new("APIKEY HERE")
5
+ # @gupshup = Gupshup::Client.new("APIKEY HERE","APPNAME")
6
6
  #
7
7
  #
8
8
  # Example:
9
- # >> response=@gupshup.sendWhatsApp(from:"917834811114",to:"94778845700",body:"This is to remind you that {{1}} is due by {{2}}.",appName:"Shoutouttest")
9
+ # >> response=@gupshup.sendWhatsAppText(from:"917834811114",to:"94778845700",body:"This is to remind you that {{1}} is due by {{2}}.")
10
10
  # {:code=>200, :body=>{"status"=>"submitted", "messageId"=>"45c63e36-2e30-4116-aa85-66a3de6f35fa"}}
11
11
  #
12
12
  # Arguments:
@@ -14,17 +14,34 @@ module Gupshup
14
14
  # from: (String) sender ID
15
15
  # to: (Array) receivers phone numbers
16
16
  # body: (String) message body
17
- # appName: (String) Gupshup app name
18
- attr_reader :apikey
19
- def initialize(apikey)
17
+
18
+ attr_reader :apikey,:appName
19
+ def initialize(apikey,appName)
20
20
  @apikey=apikey
21
+ @appName=appName
21
22
  end
22
23
 
23
24
 
24
- def sendWhatsApp(from:,to:,body:,appName:)
25
-
26
- return WhatspApp.send(self.apikey,from,to,body,appName)
25
+ def sendWhatsAppText(from:,to:,body:)
26
+ params={
27
+ "isHSM":"true",
28
+ "type": "text",
29
+ "text": body
30
+ }
31
+ return WhatspApp.send(self.apikey,from,to,JSON.generate(params),self.appName)
32
+ end
33
+
34
+ def sendWhatsAppImage(from:,to:,imageUrl:,previewUrl: nil,caption: nil, filename: nil)
35
+ params={
36
+ "type": "image",
37
+ "originalUrl": imageUrl
38
+ }
39
+ params[:previewUrl]=previewUrl|| imageUrl
40
+ params[:caption]=caption if caption!=nil
41
+ params[:filename]=filename if filename!=nil
42
+ return WhatspApp.send(self.apikey,from,to,JSON.generate(params),self.appName)
27
43
  end
28
44
  end
29
45
  end
30
- require 'gupshup/whatsapp'
46
+ require 'gupshup/whatsapp'
47
+ require 'uri'
@@ -1,15 +1,41 @@
1
1
  class Gupshup::RestClient
2
- def self.post(apikey:,body:,url:)
3
- response = HTTP.headers(:apikey=>apikey).post(url,
4
- :form => body
5
- )
6
- puts response.to_s
7
- return {:code=>response.code,:body=>response.code==200?JSON.parse(response.to_s):response.to_s}
8
-
2
+
3
+ def self.post(apikey:,body:,url:)
4
+
5
+
6
+ url = URI(url)
7
+
8
+ http = Net::HTTP.new(url.host, url.port)
9
+ http.use_ssl = true
10
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
11
+
12
+ request = Net::HTTP::Post.new(url)
13
+ request["content-type"] = 'application/x-www-form-urlencoded'
14
+ request["cache-control"] = 'no-cache'
15
+ request["apikey"]=apikey
16
+ request.set_form_data(body)
17
+ # request.body='channel=whatsapp&message=%7B%22type%22:%22image%22,%22previewUrl%22:%22https://www.buildquickbots.com/whatsapp/media/sample/jpg/sample01.jpg%22,%22originalUrl%22:%22https://www.buildquickbots.com/whatsapp/media/sample/jpg/sample01.jpg%22,%22caption%22:%22%22,%22filename%22:%22Sample.jpeg%22%7D&source=917834811114&destination=94766171818&src.name=Shoutouttest'
18
+ begin
19
+ response = http.request(request)
20
+ case response
21
+ when Net::HTTPSuccess then
22
+ return {code:200,response:response.read_body}
23
+ else
24
+ return {code:response.value,response:response.read_body}
25
+ end
26
+
27
+
28
+ rescue StandardError
29
+ return {code:response.code, response:response.read_body}
9
30
 
10
31
  end
11
32
 
12
33
  end
13
34
 
35
+
36
+ end
37
+
38
+
39
+ require 'uri'
40
+ require 'net/http'
14
41
  require "json"
15
- require "http"
@@ -4,11 +4,11 @@ class Gupshup::WhatspApp
4
4
 
5
5
  return Gupshup::RestClient.post(
6
6
  body:{
7
- 'source' => from,
8
- 'channel':'whatsapp',
9
- 'message' => body,
10
- 'destination' => to,
11
- 'src.name'=>appName
7
+ "source" => from,
8
+ "channel"=> "whatsapp",
9
+ "message" => body,
10
+ "destination" => to,
11
+ "src.name"=> appName
12
12
  },
13
13
  url:"https://api.gupshup.io/sm/api/v1/msg",
14
14
  apikey:apikey
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gupshup-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ShoutOUT Labs
@@ -9,21 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2021-06-30 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: http
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '5.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '5.0'
12
+ dependencies: []
27
13
  description: Gupshup API integration
28
14
  email: support@getshoutout.com
29
15
  executables: []