clicksend 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.txt +6 -0
- data/Manifest.txt +13 -0
- data/README.md +118 -0
- data/Rakefile +25 -0
- data/bin/clicksend +3 -0
- data/lib/click_send.rb +10 -0
- data/lib/click_send/rest/account_balance.rb +28 -0
- data/lib/click_send/rest/client.rb +74 -0
- data/lib/click_send/rest/delivery_report.rb +16 -0
- data/lib/click_send/rest/resource.rb +68 -0
- data/lib/click_send/rest/sms.rb +83 -0
- data/lib/click_send/version.rb +7 -0
- data/lib/clicksend.rb +4 -0
- data/spec/rest/account_balance_spec.rb +20 -0
- data/spec/rest/client_spec.rb +28 -0
- data/spec/rest/delivery_report_spec.rb +13 -0
- data/spec/rest/resource_spec.rb +32 -0
- data/spec/rest/sms_spec.rb +52 -0
- data/spec/spec_helper.rb +7 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ee581a67fee18feee3bcdb03816a584fdc3bb44c
|
4
|
+
data.tar.gz: f132a30f3ff3cdc22e7d9de662bd66d957939152
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0bd5851b81765959ccaaa01b9a3b4043acb84d0f2334cb3418f6ea5aa83c4861f1d91b7f91e27fe2589072b8844434b6030dcc45debf52f83c2c63a0ef7d811e
|
7
|
+
data.tar.gz: c9ba94f90dd4cd9d7f6e4c64a2f649a2c639b157fd9a2ae31515963ac3c1607af5af34589c652348c00885e87d6fe91bb7cded24a75e44b46ae0dbd730b72f40
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.md
|
4
|
+
Rakefile
|
5
|
+
bin/clicksend
|
6
|
+
lib/clicksend.rb
|
7
|
+
lib/click_send.rb
|
8
|
+
lib/click_send/version.rb
|
9
|
+
lib/click_send/rest/account_balance.rb
|
10
|
+
lib/click_send/rest/client.rb
|
11
|
+
lib/click_send/rest/delivery_report.rb
|
12
|
+
lib/click_send/rest/resource.rb
|
13
|
+
lib/click_send/rest/sms.rb
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# clicksend
|
2
|
+
|
3
|
+
ClickSend is a ruby gem that provides a clicksend class to check credit and send SMS text messages to single or multiple recipients.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
To install using [Bundler][bundler] grab the latest stable version:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'clicksend', '~> 0.0.3'
|
11
|
+
```
|
12
|
+
|
13
|
+
As a Gem from gemcutter
|
14
|
+
|
15
|
+
```
|
16
|
+
% gem install clicksend
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You will require an account with https://my.clicksend.com for the username and secret key - They offer a free trial so you can try before buying.
|
22
|
+
|
23
|
+
## Getting Started With REST
|
24
|
+
|
25
|
+
### Setup Work
|
26
|
+
|
27
|
+
```
|
28
|
+
require 'rubygems' # not necessary with ruby 1.9 but included for completeness
|
29
|
+
require 'clicksend'
|
30
|
+
|
31
|
+
# put your own credentials here
|
32
|
+
username = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # Your ClickSend username.
|
33
|
+
api_key = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # Your Secure Unique API key.
|
34
|
+
|
35
|
+
# set up a client to talk to the ClickSend REST API
|
36
|
+
@client = ClickSend::REST::Client.new(:username => username, :api_key => api_key)
|
37
|
+
|
38
|
+
# secure socket layer is enable
|
39
|
+
# set false to disable secure socket layer
|
40
|
+
@client = ClickSend::REST::Client.new(:username => username, :api_key => api_key, :use_ssl => false)
|
41
|
+
```
|
42
|
+
|
43
|
+
### Send an SMS
|
44
|
+
|
45
|
+
Send SMS message from given number.
|
46
|
+
|
47
|
+
```
|
48
|
+
@client.messages.send(:to => '+919999999999', :message => 'hello world')
|
49
|
+
```
|
50
|
+
|
51
|
+
#### Parameters
|
52
|
+
|
53
|
+
| Parameter | Required | Type | Description |
|
54
|
+
| --------- | -------- | ---- | ----------- |
|
55
|
+
| to | Yes | String | Recipient Mobile Number in international format (with leading + and country code). Separate multiple recipients with a comma (,) where applicable. Maximum 1000 recipients.<br>For example:<br>+614XXXXXXXX (Australia)<br>+1XXXXXXXXXX (US)<br> +65XXXXXXXXX (Singapore)<br>+44XXXXXXXXXX (UK) |
|
56
|
+
| message | Yes | String | The message to be sent. Maximum 960 characters. |
|
57
|
+
| senderid | No | String | custom sender ID:<br>-Alphanumeric e.g. "MyCompany". 11 characters max. No spaces. The recipient will not be able to reply to the message.<br>-Numeric e.g. +61411111111. You can enter your own mobile number in international format to make messages appear to come from your mobile number. Replies will be sent directly to your mobile.<br>-Leave blank for two-way SMS. Replies will be directed back to the original sender. |
|
58
|
+
| schedule | No | String | Allows you to schedule message delivery. Must be in unix format.<br>For example: 1348742950.<br>Leave blank for instant delivery. |
|
59
|
+
| customstring | No | String | A custom string that will be passed back with replies and delivery reports. Maximum 50 characters. |
|
60
|
+
| return | No | String | Redirect to a URL after delivering the message(s). |
|
61
|
+
| messagetype | No | String | For non-English characters use messagetype=Unicode.<br>Leave blank for a standard English message. |
|
62
|
+
|
63
|
+
#### Example
|
64
|
+
|
65
|
+
```
|
66
|
+
# replies will be sent directly to given senderid
|
67
|
+
@client.messages.send(:to => '+919999999999', :message => 'hello world', :senderid => '+918888888888')
|
68
|
+
```
|
69
|
+
|
70
|
+
```
|
71
|
+
# Deliver message 5 minutes from now
|
72
|
+
@client.messages.send(:to => '+919999999999', :message => 'hello world', :schedule => Time.now + 300)
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
### Receive
|
77
|
+
|
78
|
+
Poll ClickSend API for replies to messages. Make sure 'Poll our server' settings is selected under 'SMS Reply Report Settings' before using this.
|
79
|
+
|
80
|
+
```
|
81
|
+
@client.messages.receive
|
82
|
+
```
|
83
|
+
|
84
|
+
### Delivery Reports
|
85
|
+
|
86
|
+
Direct method to get delivery reports for sent messages using ClickSend API.
|
87
|
+
|
88
|
+
```
|
89
|
+
@client.delivery_report
|
90
|
+
```
|
91
|
+
|
92
|
+
### Account Balance
|
93
|
+
|
94
|
+
Direct method to get account balance using ClickSend API.
|
95
|
+
|
96
|
+
```
|
97
|
+
@client.account_balance
|
98
|
+
```
|
99
|
+
|
100
|
+
#### Parameters
|
101
|
+
|
102
|
+
| Parameter | Required | Type | Description |
|
103
|
+
| --------- | -------- | ---- | ----------- |
|
104
|
+
| country | No | String | A 2-letter country code (ISO 3166-1 Alpha-2 code).<br>e.g. "AU" = Australia.<br>If provided, the response will show the account balance and the number of SMS messages you can send to the country specified (credit).<br>If the country isn't provided, the response will only show the account balance. |
|
105
|
+
|
106
|
+
#### Example
|
107
|
+
|
108
|
+
```
|
109
|
+
# This will show the account balance and the number of SMS messages you can send to the country specified
|
110
|
+
@client.account_balance('IN')
|
111
|
+
```
|
112
|
+
|
113
|
+
## Copyright
|
114
|
+
|
115
|
+
Copyright (c) 2014 https://prayantr.com - MIT License. See LICENSE.txt for further details.
|
116
|
+
|
117
|
+
|
118
|
+
[bundler]: http://bundler.io
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "hoe"
|
5
|
+
require "./lib/click_send/version"
|
6
|
+
|
7
|
+
# Hoe.plugin :compiler
|
8
|
+
# Hoe.plugin :gem_prelude_sucks
|
9
|
+
# Hoe.plugin :inline
|
10
|
+
# Hoe.plugin :racc
|
11
|
+
# Hoe.plugin :rcov
|
12
|
+
# Hoe.plugin :rdoc
|
13
|
+
Hoe.plugin :gemspec
|
14
|
+
|
15
|
+
Hoe.spec "clicksend" do
|
16
|
+
developer("Amit Solanki", "amit@prayantr.com")
|
17
|
+
developer("Braj Pratap Singh", "braj@prayantr.com")
|
18
|
+
|
19
|
+
self.name = "clicksend"
|
20
|
+
self.version = "0.0.3"
|
21
|
+
self.urls = ["http://github.com/prayantr/clicksend"]
|
22
|
+
license "MIT" # this should match the license in the README
|
23
|
+
end
|
24
|
+
|
25
|
+
# vim: syntax=ruby
|
data/bin/clicksend
ADDED
data/lib/click_send.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'click_send/version'
|
2
|
+
require 'click_send/rest/resource'
|
3
|
+
require 'click_send/rest/account_balance'
|
4
|
+
require 'click_send/rest/delivery_report'
|
5
|
+
require 'click_send/rest/sms'
|
6
|
+
require 'click_send/rest/client'
|
7
|
+
|
8
|
+
module ClickSend
|
9
|
+
class ClickSendError < StandardError; end # :nodoc:
|
10
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ClickSend
|
2
|
+
module REST
|
3
|
+
##
|
4
|
+
# A class to wrap account balance related functionality within the ClickSend API.
|
5
|
+
class AccountBalance < Resource
|
6
|
+
|
7
|
+
##
|
8
|
+
# Get account balance details from ClickSend API.
|
9
|
+
# The following keys are optional:
|
10
|
+
#
|
11
|
+
# === <tt>:country => 'AU'</tt>
|
12
|
+
#
|
13
|
+
# A 2-letter country code (ISO 3166-1 Alpha-2 code).
|
14
|
+
#
|
15
|
+
# e.g. "AU" = Australia.
|
16
|
+
#
|
17
|
+
# If provided, the response will show the account balance and the number of SMS messages you can send to the country specified (credit).
|
18
|
+
#
|
19
|
+
# If the country isn't provided, the response will only show the account balance.
|
20
|
+
def all(opts={})
|
21
|
+
params = {method: 'rest'}
|
22
|
+
params.merge!(country: opts[:country]) if opts[:country]
|
23
|
+
perform_request(:post, '/rest/v2/balance.json', params)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module ClickSend
|
2
|
+
module REST # :nodoc:
|
3
|
+
##
|
4
|
+
# The ClickSend::REST::Client class stores information related to authentication
|
5
|
+
# such as username and api key.
|
6
|
+
#
|
7
|
+
# Instantiate a client like this:
|
8
|
+
#
|
9
|
+
# @client = ClickSend::REST::Client.new(:username => username, :api_key => api_key)
|
10
|
+
#
|
11
|
+
# You can configure opts[:use_ssl] to talk to clicksend api via non secure layer. By default
|
12
|
+
# this is set as true, you would need to explicitly set this parameter to false if you need to.
|
13
|
+
#
|
14
|
+
# @client = ClickSend::REST::Client.new(:username => username, :api_key => api_key, :use_ssl => false)
|
15
|
+
#
|
16
|
+
# Once you have a client object you can use it to communicate with clicksend api.
|
17
|
+
#
|
18
|
+
# @client.messages.send(:to => '+919999999999', :message => 'Hello from ClickSend')
|
19
|
+
#
|
20
|
+
class Client
|
21
|
+
attr_reader :connection, :site_url, :messages
|
22
|
+
|
23
|
+
attr_accessor :username, :api_key
|
24
|
+
|
25
|
+
##
|
26
|
+
# Instantiate a new Faraday client to talk to ClickSend. The +opts+ parameter is a
|
27
|
+
# hash of connection configuration options. the following keys are
|
28
|
+
# supported:
|
29
|
+
#
|
30
|
+
# === <tt>:username => 'username'</tt>
|
31
|
+
#
|
32
|
+
# The username provided by clicksend. In case you don't have one, signup on clicksend.com to get it.
|
33
|
+
#
|
34
|
+
# === <tt>:api_key => 'password'</tt>
|
35
|
+
#
|
36
|
+
# The api_key provided by clicksend. You can find this under Manage API Users in Account Settings.
|
37
|
+
#
|
38
|
+
# === <tt>:use_ssl => false</tt>
|
39
|
+
# Define if you need a secure or a non secure connection. Defaults to secure, need to override if one needs
|
40
|
+
# to connect via a non-secure connection.
|
41
|
+
#
|
42
|
+
def initialize(opts={})
|
43
|
+
opts.merge!(use_ssl: true)
|
44
|
+
|
45
|
+
@username, @api_key = opts[:username], opts[:api_key]
|
46
|
+
@host = 'api.clicksend.com'
|
47
|
+
|
48
|
+
@site_url = (opts[:use_ssl] ? 'https://' : 'http://') + @host
|
49
|
+
|
50
|
+
@connection = Faraday.new(:url => @site_url)
|
51
|
+
@connection.basic_auth username, api_key
|
52
|
+
@messages = ClickSend::REST::Sms.new(@connection)
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Direct method to get delivery reports for sent messages using ClickSend API.
|
57
|
+
def delivery_report
|
58
|
+
@delivery_report = ClickSend::REST::DeliveryReport.new(@connection)
|
59
|
+
@delivery_report.all
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Direct method to get account balance using ClickSend API.
|
64
|
+
def account_balance(opts={})
|
65
|
+
@account_balance = ClickSend::REST::AccountBalance.new(@connection)
|
66
|
+
@account_balance.all(opts)
|
67
|
+
end
|
68
|
+
|
69
|
+
def inspect # :nodoc:
|
70
|
+
"#<ClickSend::REST::Client:0x007fc3eb08df48 @api_key=#{@api_key}, @username=#{@username}, @host=#{@host}, @site_url=#{@site_url}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ClickSend
|
2
|
+
module REST
|
3
|
+
##
|
4
|
+
# A class to wrap delivery report related functionality within the ClickSend API.
|
5
|
+
class DeliveryReport < Resource
|
6
|
+
|
7
|
+
##
|
8
|
+
# Poll ClickSend API for delivery reports for sent messages. Make sure 'Poll our server'
|
9
|
+
# settings is selected under 'SMS Delivery Report Settings' before using this.
|
10
|
+
def all
|
11
|
+
perform_request(:post, '/rest/v2/delivery.json')
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module ClickSend
|
2
|
+
module REST
|
3
|
+
##
|
4
|
+
# A base class to wrap all basic methods to interact with ClickSend API.
|
5
|
+
# All other resource classes within this library inherit from this class.
|
6
|
+
class Resource
|
7
|
+
|
8
|
+
attr_accessor :connection
|
9
|
+
|
10
|
+
##
|
11
|
+
# Instantiate a new resource object.
|
12
|
+
def initialize(connection)
|
13
|
+
@connection = connection
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def get(url)
|
19
|
+
raise "To be Implemented"
|
20
|
+
end
|
21
|
+
|
22
|
+
def post(url, params)
|
23
|
+
@connection.post(url, params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def put(url, params)
|
27
|
+
raise "To be Implemented"
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(url)
|
31
|
+
raise "To be Implemented"
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Define #get, #post, #put and #delete helper methods for sending HTTP
|
36
|
+
# requests to ClickSend. Each method returns a hash obtained from parsing
|
37
|
+
# the JSON object in the response body.
|
38
|
+
def perform_request(method, url, params={})
|
39
|
+
begin
|
40
|
+
response = case method
|
41
|
+
when :get
|
42
|
+
get(url)
|
43
|
+
when :post
|
44
|
+
post(url, params)
|
45
|
+
when :put
|
46
|
+
put(url, params)
|
47
|
+
when :delete
|
48
|
+
delete(url)
|
49
|
+
end
|
50
|
+
parse_response(response)
|
51
|
+
rescue Exception => e
|
52
|
+
raise ClickSendError, e.message
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Parse JSON object returned from ClickSend API and raise error if response
|
58
|
+
# fails or is not as expected.
|
59
|
+
def parse_response(response)
|
60
|
+
begin
|
61
|
+
body = MultiJson.load(response.body)
|
62
|
+
rescue Exception => e
|
63
|
+
raise ClickSendError, e.message
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module ClickSend
|
2
|
+
module REST
|
3
|
+
##
|
4
|
+
# A class to wrap all messaging related functionality within the ClickSend API.
|
5
|
+
class Sms < Resource
|
6
|
+
|
7
|
+
##
|
8
|
+
# Send messages using ClickSend API. The +params+ parameter is a
|
9
|
+
# hash of options. The following keys are mandatory:
|
10
|
+
#
|
11
|
+
# === <tt>:to => '+614XXXXXXXX'</tt>
|
12
|
+
#
|
13
|
+
# Recipient Mobile Number in international format (with leading + and country code). Separate multiple recipients with a comma (,) where applicable. Maximum 1000 recipients.
|
14
|
+
#
|
15
|
+
# For example:
|
16
|
+
#
|
17
|
+
# +614XXXXXXXX (Australia)
|
18
|
+
#
|
19
|
+
# +1XXXXXXXXXX (US)
|
20
|
+
#
|
21
|
+
# +65XXXXXXXXX (Singapore)
|
22
|
+
#
|
23
|
+
# +44XXXXXXXXXX (UK)
|
24
|
+
#
|
25
|
+
# === <tt>:message => 'Hello'</tt>
|
26
|
+
#
|
27
|
+
# The message to be sent. Maximum 960 characters.
|
28
|
+
#
|
29
|
+
#
|
30
|
+
#
|
31
|
+
# The following keys are optional and can be used:
|
32
|
+
#
|
33
|
+
# === <tt>:senderid => '+61411111111'</tt>
|
34
|
+
#
|
35
|
+
# custom sender ID:
|
36
|
+
#
|
37
|
+
# -Alphanumeric e.g. "MyCompany". 11 characters max. No spaces. The recipient will not be able to reply to the message.
|
38
|
+
#
|
39
|
+
# -Numeric e.g. +61411111111. You can enter your own mobile number in international format to make messages appear to come from your mobile number. Replies will be sent directly to your mobile.
|
40
|
+
#
|
41
|
+
# -Leave blank for two-way SMS. Replies will be directed back to the original sender.
|
42
|
+
#
|
43
|
+
# === <tt>:schedule => '1348742950'</tt>
|
44
|
+
# Allows you to schedule message delivery. Must be in unix format.
|
45
|
+
#
|
46
|
+
# For example: 1348742950.
|
47
|
+
#
|
48
|
+
# Leave blank for instant delivery.
|
49
|
+
#
|
50
|
+
# === <tt>:customstring => 'From ClickSend'</tt>
|
51
|
+
#
|
52
|
+
# A custom string that will be passed back with replies and delivery reports. Maximum 50 characters.
|
53
|
+
#
|
54
|
+
# === <tt>:return => 'http://mydomain.com/callback'</tt>
|
55
|
+
#
|
56
|
+
# Redirect to a URL after delivering the message(s).
|
57
|
+
#
|
58
|
+
# === <tt>:messagetype => 'Unicode'</tt>
|
59
|
+
#
|
60
|
+
# For non-English characters use messagetype=Unicode.
|
61
|
+
#
|
62
|
+
# Leave blank for a standard English message.
|
63
|
+
def send(params={})
|
64
|
+
params.reject!{|key, value| ![:to, :message, :senderid, :schedule, :customstring, :return, :messagetype].include?(key)}
|
65
|
+
raise ClickSendError, 'Recipient Mobile Number is mandatory' if params[:to].nil? || params[:to].empty?
|
66
|
+
raise ClickSendError, 'Message is mandatory' if params[:message].nil? || params[:message].empty?
|
67
|
+
params[:schedule]=params[:schedule].to_i if !(params[:schedule].nil?)
|
68
|
+
|
69
|
+
params.merge!(method: 'rest')
|
70
|
+
|
71
|
+
perform_request(:post, '/rest/v2/send.json', params)
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Poll ClickSend API for replies to messages. Make sure 'Poll our server'
|
76
|
+
# settings is selected under 'SMS Reply Report Settings' before using this.
|
77
|
+
def receive
|
78
|
+
perform_request(:post, '/rest/v2/reply.json')
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/clicksend.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ClickSend::REST::AccountBalance do
|
4
|
+
before :each do
|
5
|
+
@client = ClickSend::REST::Client.new(username: 'user', api_key: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
|
6
|
+
@account_balance = ClickSend::REST::AccountBalance.new(@client.connection)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should not raise error" do
|
10
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/balance.json").to_return(:status => 200, :body => "{}", :headers => {})
|
11
|
+
expect {@account_balance.all}.not_to raise_error
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not raise error if account balance respond with country code" do
|
15
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/balance.json").to_return(:status => 200, :body => "{}", :headers => {})
|
16
|
+
expect {@account_balance.all(:country=>'IN')}.not_to raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ClickSend::REST::Client do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@client = ClickSend::REST::Client.new(username: 'user', api_key: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should raise an error if API end point does not respond' do
|
10
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/balance.json").to_raise(TimeoutError)
|
11
|
+
expect { @client.account_balance }.to raise_error(ClickSend::ClickSendError)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should raise an error if API end point does not respond' do
|
15
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/delivery.json").to_raise(TimeoutError)
|
16
|
+
expect { @client.delivery_report }.to raise_error(ClickSend::ClickSendError)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should not raise error on inspecting client object' do
|
20
|
+
expect {@client.inspect}.not_to raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should set up a new client instance with the given sid and token' do
|
24
|
+
expect(@client.username).to eq('user')
|
25
|
+
expect(@client.api_key).to eq('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ClickSend::REST::DeliveryReport do
|
4
|
+
before :each do
|
5
|
+
@client = ClickSend::REST::Client.new(username: 'user', api_key: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should not raise error" do
|
9
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/delivery.json").to_return(:status => 200, :body => "{}", :headers => {})
|
10
|
+
@delivery_report = ClickSend::REST::DeliveryReport.new(@client.connection)
|
11
|
+
expect {@delivery_report.all}.not_to raise_error
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ClickSend::REST::Resource do
|
4
|
+
before :each do
|
5
|
+
@client = ClickSend::REST::Client.new(username: 'user', api_key: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
|
6
|
+
@resource = ClickSend::REST::Resource.new(@client.connection)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should raise an error" do
|
10
|
+
expect {@resource.send(:perform_request, :get, '/rest/v2/delivery.json')}.to raise_error('To be Implemented')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should raise an error" do
|
14
|
+
expect {@resource.send(:perform_request, :put, '/rest/v2/send.json', {:to=>'+919999999999', :message=>'Hello World'})}.to raise_error('To be Implemented')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise an error" do
|
18
|
+
expect {@resource.send(:perform_request, :delete, '/rest/v2/delivery.json')}.to raise_error('To be Implemented')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not raise error" do
|
22
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/send.json").with(body: {to: '+919999999999', message: 'Hello World'}).to_return(status: 200, body: '{"recipientcount":1,"messages":[{"to":"+919999999999","messageid":"EB2FE08D-4202-6D82-4007-74FFBCEB4D49","result":"0000","errortext":"Success"}]}')
|
23
|
+
expect {@resource.send(:perform_request, :post, '/rest/v2/send.json', {:to=>'+919999999999', :message=>'Hello World'})}.not_to raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not raise error" do
|
27
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/balance.json").to_return(:status => 200, :body => "{}", :headers => {})
|
28
|
+
#expect {@resource.send(:parse_response, /\#\<Faraday::Response:0x89d3b38\>/)}.not_to raise_error
|
29
|
+
expect {@resource.send(:parse_response, '')}.to raise_error(ClickSend::ClickSendError)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ClickSend::REST::Sms do
|
4
|
+
before do
|
5
|
+
@client = ClickSend::REST::Client.new(username: 'user', api_key: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should raise an error if provided recipient mobile number is invalid' do
|
9
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/send.json").to_raise('Recipient mobile number should be provided')
|
10
|
+
@messages = @client.messages
|
11
|
+
expect {@messages.send(message: 'hello')}.to raise_error(ClickSend::ClickSendError)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should raise an error if message is not provided' do
|
15
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/send.json").to_raise('Message should be provided')
|
16
|
+
@messages = @client.messages
|
17
|
+
expect {@messages.send(to: '+919999999999')}.to raise_error(ClickSend::ClickSendError)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should raise an error if provided recipient mobile number is empty' do
|
21
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/send.json").to_raise('Recipient mobile number should not be empty')
|
22
|
+
@messages = @client.messages
|
23
|
+
expect {@messages.send(to: '', message: 'hello')}.to raise_error(ClickSend::ClickSendError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should raise an error if message is empty' do
|
27
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/send.json").to_raise('Message should not be empty')
|
28
|
+
@messages = @client.messages
|
29
|
+
expect {@messages.send(to: '+919999999999', message: '')}.to raise_error(ClickSend::ClickSendError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should not raise an error' do
|
33
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/send.json").to_return(status: 200, body: '{"recipientcount":1,"messages":[{"to":"+919999999999","messageid":"EB2FE08D-4202-6D82-4007-74FFBCEB4D49","result":"0000","errortext":"Success"}]}')
|
34
|
+
@messages = @client.messages
|
35
|
+
expect {@messages.send(to: '+919999999999', message: 'Hello World')}.not_to raise_error
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should not raise an error' do
|
39
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/reply.json").to_return(status: 200, body: '{}')
|
40
|
+
@messages = @client.messages
|
41
|
+
expect {@messages.receive}.not_to raise_error
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should ignore extra parameters passed to api other than defined in the api" do
|
45
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/send.json").with(body: {to: '+919999999999', method: 'rest', message: 'Hello World', priority: 'high'}).to_return(status: 200, body: '{"recipientcount":1,"messages":[{"to":"+919999999999","messageid":"EB2FE08D-4202-6D82-4007-74FFBCEB4D49","result":"0000","errortext":"Success"}]}')
|
46
|
+
@messages = @client.messages
|
47
|
+
expect {@messages.send(to: '+919999999999', message: 'Hello World', priority: 'high')}.to raise_error(ClickSend::ClickSendError)
|
48
|
+
|
49
|
+
stub_request(:post, "https://user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@api.clicksend.com/rest/v2/send.json").with(body: {to: '+919999999999', method: 'rest', message: 'Hello World'}).to_return(status: 200, body: '{"recipientcount":1,"messages":[{"to":"+919999999999","messageid":"EB2FE08D-4202-6D82-4007-74FFBCEB4D49","result":"0000","errortext":"Success"}]}')
|
50
|
+
expect {@messages.send(to: '+919999999999', message: 'Hello World')}.not_to raise_error
|
51
|
+
end
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clicksend
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Amit Solanki
|
8
|
+
- Braj Pratap Singh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.9'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.9'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: multi_json
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.10'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.10'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rdoc
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '4.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '4.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: webmock
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.18'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.18'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: simplecov
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ~>
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0.8'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ~>
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0.8'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: hoe
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ~>
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '3.12'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '3.12'
|
112
|
+
description: Rubygem to interact with ClickSend api
|
113
|
+
email:
|
114
|
+
- amit@prayantr.com
|
115
|
+
- braj@prayantr.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files:
|
119
|
+
- History.txt
|
120
|
+
- Manifest.txt
|
121
|
+
- README.md
|
122
|
+
files:
|
123
|
+
- History.txt
|
124
|
+
- Manifest.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/clicksend
|
128
|
+
- lib/click_send.rb
|
129
|
+
- lib/click_send/rest/account_balance.rb
|
130
|
+
- lib/click_send/rest/client.rb
|
131
|
+
- lib/click_send/rest/delivery_report.rb
|
132
|
+
- lib/click_send/rest/resource.rb
|
133
|
+
- lib/click_send/rest/sms.rb
|
134
|
+
- lib/click_send/version.rb
|
135
|
+
- lib/clicksend.rb
|
136
|
+
- spec/rest/account_balance_spec.rb
|
137
|
+
- spec/rest/client_spec.rb
|
138
|
+
- spec/rest/delivery_report_spec.rb
|
139
|
+
- spec/rest/resource_spec.rb
|
140
|
+
- spec/rest/sms_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
homepage: http://github.com/prayantr/clicksend
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options:
|
148
|
+
- --main
|
149
|
+
- README.md
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
requirements: []
|
163
|
+
rubyforge_project:
|
164
|
+
rubygems_version: 2.4.1
|
165
|
+
signing_key:
|
166
|
+
specification_version: 4
|
167
|
+
summary: Rubygem to interact with ClickSend RESTful api to send sms via clicksend.com
|
168
|
+
test_files:
|
169
|
+
- spec/rest/account_balance_spec.rb
|
170
|
+
- spec/rest/client_spec.rb
|
171
|
+
- spec/rest/delivery_report_spec.rb
|
172
|
+
- spec/rest/resource_spec.rb
|
173
|
+
- spec/rest/sms_spec.rb
|
174
|
+
- spec/spec_helper.rb
|
175
|
+
has_rdoc:
|