africas_talking 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.travis.yml +15 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +82 -0
- data/Rakefile +40 -0
- data/africas_talking.gemspec +32 -0
- data/lib/africas_talking/africas_talking_gateway_error.rb +2 -0
- data/lib/africas_talking/base.rb +42 -0
- data/lib/africas_talking/message.rb +92 -0
- data/lib/africas_talking/sms_message.rb +14 -0
- data/lib/africas_talking/status_report.rb +11 -0
- data/lib/africas_talking/version.rb +3 -0
- data/lib/africas_talking.rb +10 -0
- data/lib/generators/africas_talking/template_generator.rb +17 -0
- data/lib/generators/africas_talking/templates/README.md +1 -0
- data/lib/generators/africas_talking/templates/africas_talking_config.yml.erb +15 -0
- data/test/helper.rb +28 -0
- data/test/mocks/failed_status_report.json +5 -0
- data/test/mocks/success_status_report.json +3 -0
- data/test/test_africas_talking.rb +28 -0
- metadata +210 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4722fe942f4373d4ecc6288ac2c901ae7afe48b7
|
4
|
+
data.tar.gz: 38ad1e6863e51a4ef655b99b6313dc3aeeff5ce8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85860100e4df575bb327d1b9dfec5d7dd8c7331b08c424957554b455b3b49954fab44a686978f9721ef77c97e4226cd7ee14848209e7727c4b72b316c1e27d11
|
7
|
+
data.tar.gz: d37beab5f552bbe610bd1bd1a9138e00148079db3c59096bf33fa1212e3eeed6d061ca47b6bad4a13fb01e5a4210ebb9935b057e872831b4fee58e35fc4b851f
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1.2
|
4
|
+
- 2.1.1
|
5
|
+
- 2.1.0
|
6
|
+
- 2.0.0
|
7
|
+
env:
|
8
|
+
- africas_talking_apikey="aDax7clbar5yaaAfS1Gqvw"
|
9
|
+
- africas_talking_username="5yaaAfS"
|
10
|
+
global:
|
11
|
+
- BASE_URI='https://api.africastalking.com'
|
12
|
+
# URLS:
|
13
|
+
# - sms_url='/version1/messaging' subscription_url='/version1/subscription' userdata_url='/version1/user' airtime_url='/version1/airtime' voice_url='https://voice.africastalking.com'
|
14
|
+
|
15
|
+
# script: bundle exec rspec spec
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Kariuki Gathitu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#Africas Talking.
|
2
|
+
A fast lightweight and minimalist wrapper around the Africas Talking api
|
3
|
+
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/chalchuck/africas-talking.svg?branch=master)](https://travis-ci.org/chalchuck/africas-talking)
|
6
|
+
[![Dependency Status](https://gemnasium.com/chalchuck/africas-talking.svg)](https://gemnasium.com/chalchuck/africas-talking)
|
7
|
+
[![Code Climate](https://codeclimate.com/github/chalchuck/africas-talking/badges/gpa.svg)](https://codeclimate.com/github/chalchuck/africas-talking)
|
8
|
+
[![Test Coverage](https://codeclimate.com/github/chalchuck/africas-talking/badges/coverage.svg)](https://codeclimate.com/github/chalchuck/africas-talking/coverage)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'africas_talking'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install africas_talking
|
23
|
+
|
24
|
+
|
25
|
+
##Setup
|
26
|
+
|
27
|
+
Obtain a Client ID and Secret
|
28
|
+
---
|
29
|
+
1. Go to Africas Talking website. (https://account.africastalking.com/register)
|
30
|
+
2. In the sidebar on the left, select Settings > Api Key
|
31
|
+
3. If you haven't generated your key already, generate a new api key credentials by clicking Generate My Api Key
|
32
|
+
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
###Sending a message
|
36
|
+
```ruby
|
37
|
+
AfricasTalking::Message.new.deliver(recipients, message, username)
|
38
|
+
```
|
39
|
+
Recipients:
|
40
|
+
This are the numbers that you want to send to,
|
41
|
+
If you want to send to many people delimit the numbers using commas(',')
|
42
|
+
for example: "0700000000, 0710000000, 0720000000"
|
43
|
+
|
44
|
+
Message:
|
45
|
+
This is the message content
|
46
|
+
A message is by default 160 characters
|
47
|
+
If your message is 161-320 it will be sent as two messages and so on
|
48
|
+
|
49
|
+
Username:
|
50
|
+
This is your username on AfricasTalking.com
|
51
|
+
[If you do not have one signup and use it to send messages]
|
52
|
+
|
53
|
+
###Sending message using sender id or shortcode parameter
|
54
|
+
```ruby
|
55
|
+
AfricasTalking::Message.new.deliver_with_shortcode(recipients, message, from, username)
|
56
|
+
```
|
57
|
+
Specify your AfricasTalking shortCode or sender id, sender = "shortCode or senderId"
|
58
|
+
|
59
|
+
###Enqueue messages
|
60
|
+
```ruby
|
61
|
+
AfricasTalking::Message.new.enqueue_messages(options)
|
62
|
+
```
|
63
|
+
Enqueue flag is used to queue messages incase you are sending a high volume.
|
64
|
+
|
65
|
+
sender = nil # sender = "shortCode or sender id"
|
66
|
+
bulkSMSMode = 1 # This should always be 1 for bulk messages
|
67
|
+
The default value for enqueue is 0.
|
68
|
+
|
69
|
+
So as to send/enqueue a message, build a hash with the following options:
|
70
|
+
{recipients: "", message: "", sender: "", enqueue: "", bulkSMSMode: "", username: ""}
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
1. Fork it ( https://github.com/[my-github-username]/africas_talking/fork )
|
79
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
80
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
81
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
82
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# require "bundler/gem_tasks"
|
2
|
+
# require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
# RSpec::Core::RakeTask.new(:spec)
|
5
|
+
# task :default => :spec
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'bundler'
|
14
|
+
begin
|
15
|
+
Bundler.setup(:default, :development)
|
16
|
+
rescue Bundler::BundlerError => e
|
17
|
+
$stderr.puts e.message
|
18
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
19
|
+
exit e.status_code
|
20
|
+
end
|
21
|
+
require 'rake'
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
task :default => :test
|
31
|
+
|
32
|
+
require 'rdoc/task'
|
33
|
+
Rake::RDocTask.new do |rdoc|
|
34
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
35
|
+
|
36
|
+
rdoc.rdoc_dir = 'rdoc'
|
37
|
+
rdoc.title = "africas_talking #{version}"
|
38
|
+
rdoc.rdoc_files.include('README*')
|
39
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'africas_talking/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "africas_talking"
|
8
|
+
spec.version = AfricasTalking::VERSION
|
9
|
+
spec.authors = ["Charles Chuck"]
|
10
|
+
spec.email = ["chalcchuck@gmail.com"]
|
11
|
+
spec.summary = %q{Africa's Talking ruby API wrapper.}
|
12
|
+
spec.description = %q{Africa's Talking ruby API wrapper.}
|
13
|
+
spec.homepage = "https://bitbucket.org/chalchuck/africas-talking"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'json'
|
22
|
+
spec.add_runtime_dependency 'typhoeus'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'pry'
|
28
|
+
spec.add_development_dependency 'minitest'
|
29
|
+
spec.add_development_dependency 'minitest-reporters'
|
30
|
+
spec.add_development_dependency 'shoulda-context'
|
31
|
+
spec.add_development_dependency 'mocha'
|
32
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class AfricasTalking::Base
|
2
|
+
|
3
|
+
BASE_URI='https://api.africastalking.com'
|
4
|
+
|
5
|
+
def prepare_recipients(recipients)
|
6
|
+
recipients_array = []
|
7
|
+
recipients.split(',').each { |recip| recipients_array << recip.strip.gsub(/^0/,'254') }
|
8
|
+
recipients_array.join(', ')
|
9
|
+
end
|
10
|
+
|
11
|
+
def post(url, json_body=nil)
|
12
|
+
Typhoeus.post("#{BASE_URI}#{url}", body: json_body, headers: headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(url)
|
16
|
+
Typhoeus.post("#{BASE_URI}#{url}", headers: headers)
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_api_errors(response)
|
20
|
+
reports = parse_api_response(response)["SMSMessageData"]["Recipients"]
|
21
|
+
return reports.collect {|entry| AfricasTalking::StatusReport.new(entry["number"], entry["status"], entry["cost"])}
|
22
|
+
# return parsed_api_errors
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_messages_array(response)
|
26
|
+
parsed_response = parse_api_response(response)["SMSMessageData"]["Messages"]
|
27
|
+
parsed_response.collect { |msg| AfricasTalking::SMSMessage.new(msg["id"], msg["text"], msg["from"] , msg["to"], msg["linkId"], msg["date"])}
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_api_response(response)
|
31
|
+
JSON.parse(response.body)
|
32
|
+
end
|
33
|
+
|
34
|
+
def api_error_messages(response)
|
35
|
+
AfricasTalking::AfricasTalkingGatewayError#, parse_api_response(response)["SMSMessageData"]["Message"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def headers
|
39
|
+
{'Accept' => "application/json", 'apiKey'=> 'c6ec656ed9bceb689289ccaa6e38d7f6c1b0718a1237b4c13391d1efc1108bfb'}
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
class AfricasTalking::Message < AfricasTalking::Base
|
2
|
+
|
3
|
+
#POST
|
4
|
+
#/version1/messaging
|
5
|
+
#----------------------------------------------------------------------------
|
6
|
+
# Specify the numbers that you want to send to in a comma-separated list
|
7
|
+
# Please ensure you include the country code (+254 for Kenya in this case)
|
8
|
+
# to = "+254711XXXYYY,+254733YYYZZZ";
|
9
|
+
# And of course we want our recipients to know what we really do
|
10
|
+
def deliver(recipients, message, username)
|
11
|
+
response = post('/version1/messaging', {username: username, message: message, to: prepare_recipients(recipients)})
|
12
|
+
process_api_response(response)
|
13
|
+
end
|
14
|
+
|
15
|
+
#POST
|
16
|
+
#/version1/messaging
|
17
|
+
#----------------------------------------------------------------------------
|
18
|
+
# Specify your AfricasTalking shortCode or sender id
|
19
|
+
# sender = "shortCode or senderId"
|
20
|
+
|
21
|
+
def deliver_with_shortcode(recipients, message, from, username)
|
22
|
+
response = post('/version1/messaging', {username: username, message: message, to: recipients, from: from})
|
23
|
+
process_api_response(response)
|
24
|
+
end
|
25
|
+
|
26
|
+
#POST
|
27
|
+
#/version1/messaging
|
28
|
+
#----------------------------------------------------------------------------
|
29
|
+
# sender = nil #
|
30
|
+
# bulkSMSMode # This should always be 1 for bulk messages
|
31
|
+
# # enqueue flag is used to queue messages incase you are sending a high volume.
|
32
|
+
# # The default value is 0.
|
33
|
+
# opts={enqueue: 1, bulkSMSMode: 1, sender: "shortCode/senderId"}
|
34
|
+
# gateway = AfricasTalkingGateway.new(username, apikey)
|
35
|
+
# reports = gateway.sendMessage(to, message, sender, bulkSMSMode, enqueue)
|
36
|
+
|
37
|
+
def enqueue_messages(opts)
|
38
|
+
body={
|
39
|
+
to: opts.fetch(:recipients), message: opts.fetch(:message, ""), sender: opts.fetch(:sender, nil),
|
40
|
+
enqueue: opts.fetch(:enqueue,1), bulkSMSMode: opts.fetch(:bulkSMSMode, 1), username: opts.fetch(:username)}
|
41
|
+
response = post('/version1/messaging', body)
|
42
|
+
process_api_response(response)
|
43
|
+
end
|
44
|
+
|
45
|
+
#POST
|
46
|
+
#/version1/messaging#premium_messages
|
47
|
+
#----------------------------------------------------------------------------
|
48
|
+
#
|
49
|
+
#########Required fields to deliver a premium message through the API########
|
50
|
+
#############################################################################
|
51
|
+
# To send a premium message, build a HASH (as shown below) with the following attributes keeping in mind the defaults.
|
52
|
+
# 1.Specify your premium shortCode and keyword
|
53
|
+
# 2.Set keyword as None where not used (Mostly for onDemand services)
|
54
|
+
# 3.Set the bulkSMSMode flag to 0 so that the subscriber gets charged
|
55
|
+
# 4.Set the enqueue flag to 0 so that your message will not be queued or to 1 for many messages
|
56
|
+
# 5.Incase of an onDemand service, specify the link id. else set it to nil
|
57
|
+
# 6.linkId is received from the message sent by subscriber to your onDemand service
|
58
|
+
# 7.Specify retryDurationInHours: The numbers of hours our API should retry to send the message incase it doesn't go through.
|
59
|
+
# opts={recipients: "0710335602", message: "Hey there testing something awesome", bulkSMSMode: 0, shortCode:"XXXXX", enqueue: 0, keyword: nil, linkId: "messageLinkId"}
|
60
|
+
|
61
|
+
def deliver_premium_messages(opts)
|
62
|
+
body={
|
63
|
+
to: opts.fetch(:recipients), message: opts.fetch(:message),
|
64
|
+
keyword: opts.fetch(:keyword, nil), enqueue: opts.fetch(:enqueue, 0), username: opts.fetch(:username),
|
65
|
+
linkId: opts.fetch(:linkId, nil), retryDurationInHours: opts.fetch(:retryDurationInHours, 1)}
|
66
|
+
response = post('/version1/messaging', body)
|
67
|
+
process_api_response(response)
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
#GET
|
72
|
+
#/?username=#{ENV['africas_talking_username']}&lastReceivedId=#{last_received_id}
|
73
|
+
# The gateway will return 10 messages at a time back to you, starting with
|
74
|
+
# what you currently believe is the lastReceivedId. Specify 0 for the first
|
75
|
+
# time you access the gateway, and the ID of the last message we sent you
|
76
|
+
# on subsequent results
|
77
|
+
|
78
|
+
def fetch_messages(username, last_received_id=0)
|
79
|
+
response = get("/version1/messaging?username=#{username}&lastReceivedId=#{last_received_id}")
|
80
|
+
return build_messages_array(response) if response.options[:response_code] == 200
|
81
|
+
raise api_error_messages(response)
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def process_api_response(response)
|
87
|
+
return parse_api_response(response) if response.options[:response_code] == 200
|
88
|
+
return parse_api_errors(response) if response.options[:response_code] == 201
|
89
|
+
raise api_error_messages(response)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module AfricasTalking
|
2
|
+
require "africas_talking/version"
|
3
|
+
require 'typhoeus'
|
4
|
+
require 'json'
|
5
|
+
require 'africas_talking/base'
|
6
|
+
require 'africas_talking/message'
|
7
|
+
require "africas_talking/sms_message"
|
8
|
+
require "africas_talking/status_report"
|
9
|
+
require "africas_talking/africas_talking_gateway_error"
|
10
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AfricasTalking
|
2
|
+
module Generators
|
3
|
+
class TemplateGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
desc "Create local africas_talking.yml template file for customizations"
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
arguement :templates_path, type: :string,
|
8
|
+
default: "config/",
|
9
|
+
banner: "path to templates"
|
10
|
+
|
11
|
+
def copy_templates
|
12
|
+
copy_file "africas_talking_config.yml.erb", "#{templates_path}/africas_talking.yml"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
To create a local ``
|
@@ -0,0 +1,15 @@
|
|
1
|
+
development:
|
2
|
+
africas_talking_username: "mtotomzuri"
|
3
|
+
africas_talking_apikey: "EO4GM2GOGXWPGZ"
|
4
|
+
|
5
|
+
test:
|
6
|
+
africas_talking_username: "mtotomzuri"
|
7
|
+
africas_talking_apikey: "EO4GM2GOGXWPGZ"
|
8
|
+
|
9
|
+
staging:
|
10
|
+
africas_talking_username: "mtotomzuri"
|
11
|
+
africas_talking_apikey: "EO4GM2GOGXWPGZ"
|
12
|
+
|
13
|
+
produciton:
|
14
|
+
africas_talking_username: "mtotomzuri"
|
15
|
+
africas_talking_apikey: "EO4GM2GOGXWPGZ"
|
data/test/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# require "codeclimate-test-reporter"
|
2
|
+
# CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler'
|
6
|
+
begin
|
7
|
+
Bundler.setup(:default, :development)
|
8
|
+
rescue Bundler::BundlerError => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
11
|
+
exit e.status_code
|
12
|
+
end
|
13
|
+
|
14
|
+
require "minitest/autorun"
|
15
|
+
require 'minitest/reporters'
|
16
|
+
require 'shoulda/context'
|
17
|
+
require 'mocha/setup'
|
18
|
+
# require 'faraday'
|
19
|
+
|
20
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
21
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
22
|
+
require 'africas_talking'
|
23
|
+
|
24
|
+
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
25
|
+
|
26
|
+
class Minitest::Test
|
27
|
+
@@mock_path = File.expand_path(File.join(File.dirname(__FILE__), 'mocks'))
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestAfricasTalking < Minitest::Test
|
4
|
+
include AfricasTalking
|
5
|
+
|
6
|
+
|
7
|
+
context "When connected" do
|
8
|
+
setup do
|
9
|
+
@client_mock = setup_mock_client
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def get_mock_body(name)
|
16
|
+
File.open(@@mock_path + '/' + name).read
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup_mock_client
|
20
|
+
# client = mock('Farady::Response')
|
21
|
+
client.stubs(:finish).returns('')
|
22
|
+
client.stubs(:status).returns(200)
|
23
|
+
client.stubs(:headers).returns({"Accept"=>"application/json"})
|
24
|
+
client.stubs(:body).returns(get_mock_body('.json'))
|
25
|
+
Faraday::Response.stubs(:new).returns(:client)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: africas_talking
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charles Chuck
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: typhoeus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest-reporters
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: shoulda-context
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: mocha
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: Africa's Talking ruby API wrapper.
|
154
|
+
email:
|
155
|
+
- chalcchuck@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".gitignore"
|
161
|
+
- ".rspec"
|
162
|
+
- ".travis.yml"
|
163
|
+
- Gemfile
|
164
|
+
- LICENSE.txt
|
165
|
+
- README.md
|
166
|
+
- Rakefile
|
167
|
+
- africas_talking.gemspec
|
168
|
+
- lib/africas_talking.rb
|
169
|
+
- lib/africas_talking/africas_talking_gateway_error.rb
|
170
|
+
- lib/africas_talking/base.rb
|
171
|
+
- lib/africas_talking/message.rb
|
172
|
+
- lib/africas_talking/sms_message.rb
|
173
|
+
- lib/africas_talking/status_report.rb
|
174
|
+
- lib/africas_talking/version.rb
|
175
|
+
- lib/generators/africas_talking/template_generator.rb
|
176
|
+
- lib/generators/africas_talking/templates/README.md
|
177
|
+
- lib/generators/africas_talking/templates/africas_talking_config.yml.erb
|
178
|
+
- test/helper.rb
|
179
|
+
- test/mocks/failed_status_report.json
|
180
|
+
- test/mocks/success_status_report.json
|
181
|
+
- test/test_africas_talking.rb
|
182
|
+
homepage: https://bitbucket.org/chalchuck/africas-talking
|
183
|
+
licenses:
|
184
|
+
- MIT
|
185
|
+
metadata: {}
|
186
|
+
post_install_message:
|
187
|
+
rdoc_options: []
|
188
|
+
require_paths:
|
189
|
+
- lib
|
190
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
|
+
requirements:
|
197
|
+
- - ">="
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: '0'
|
200
|
+
requirements: []
|
201
|
+
rubyforge_project:
|
202
|
+
rubygems_version: 2.2.2
|
203
|
+
signing_key:
|
204
|
+
specification_version: 4
|
205
|
+
summary: Africa's Talking ruby API wrapper.
|
206
|
+
test_files:
|
207
|
+
- test/helper.rb
|
208
|
+
- test/mocks/failed_status_report.json
|
209
|
+
- test/mocks/success_status_report.json
|
210
|
+
- test/test_africas_talking.rb
|