smsone-sms 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 614845103b591c2c5aff81ec883ff8387c488404
4
+ data.tar.gz: 64bf67853fd74794ee7d734fc7a18ef226a1e7ea
5
+ SHA512:
6
+ metadata.gz: ccaa77dd2bdd027ea3bce749d303417bbef9c17080826611dc832138797b031b99ee3d9333e93bc8359bd407c186a2a558fe9f315b8e821016bb133ae510dc3b
7
+ data.tar.gz: e8f9fe39860e2313ca30b5f12dd1a89336c1657536fdf81b475f41d1af2643556e615a183f1fc0bba5d38c9a3f57540a4ee6c46e50a3a1f5fe76245653b7cf6c
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smsone-sms.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 miclovich
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.
@@ -0,0 +1,31 @@
1
+ # Smsone::Sms
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'smsone-sms'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install smsone-sms
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/smsone-sms/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,108 @@
1
+ # encoding: UTF-8
2
+ require 'net/http'
3
+ require 'uri'
4
+ require "smsone/sms/version"
5
+
6
+ module Smsone
7
+ module Sms
8
+ #################
9
+ # status codes
10
+ success_status_code = 0
11
+ auth_failure_status_code = 1
12
+ insufficient_fund_status_code = 2
13
+ unauthorized_destination_status_code = 3
14
+
15
+ def make_http_call call, options={}
16
+ uri = URI("http://sms.smsone.co.ug:8866/cgi-bin/#{call}")
17
+ http_obj = Net::HTTP.new uri.host, uri.port
18
+ request = Net::HTTP::Post.new uri
19
+
20
+ response = http_obj.start do |http|
21
+ post_data = URI.encode_www_form options[:payload]
22
+ http.request(request, post_data)
23
+ end
24
+ response
25
+ end
26
+
27
+ ###################
28
+ # makes an API call to SMSONE
29
+ def make_http_call call, options={}
30
+ uri = URI("http://sms.smsone.co.ug:8866/cgi-bin/#{call}")
31
+ http_obj = Net::HTTP.new uri.host, uri.port
32
+ request = Net::HTTP::Post.new uri
33
+
34
+ response = http_obj.start do |http|
35
+ post_data = URI.encode_www_form options[:payload]
36
+ http.request(request, post_data)
37
+ end
38
+ response
39
+ end
40
+
41
+ def send_sms username, password, msidn, from_who, text
42
+ # Sends a message through a pre-configured short code
43
+ # Params:
44
+ # +username+:: username to access system
45
+ # +password+:: password to access system
46
+ # +msidn+:: MSIDN refers to the full phone number with country code
47
+ # +from_who+:: keyword or label that identifies who sent SMS
48
+ # +text+:: Text is the actual content or message
49
+
50
+ response = make_http_call 'sendsms',
51
+ :payload => {
52
+ 'mocean-username' => username,
53
+ 'mocean-password' => password,
54
+ 'mocean-to' => msidn,
55
+ 'mocean-from' => from_who,
56
+ 'mocean-text' => text
57
+ }
58
+ response
59
+ end
60
+
61
+ def request_balance username, password
62
+ # Requests the amount of credit or balance left
63
+ # Params:
64
+ # +username+:: username to access the bloody system
65
+ # +password+:: yeah, you need a password to get in
66
+
67
+ response = make_http_call 'requestbalance',
68
+ :payload=>{
69
+ "mocean-username" => username,
70
+ "mocean-password" => password
71
+ }
72
+
73
+ to_ret = {:response => response, :response_hash => nil}
74
+
75
+ if response.body.match /status=0/
76
+ to_ret[:response_hash] ={
77
+ body: response.body,
78
+ success: true,
79
+ error_message: nil,
80
+ api_status_code: 0,
81
+ response_code: response.code
82
+ }
83
+ end
84
+
85
+ if response.body.match /status=1/
86
+ to_ret[:response_hash] = {
87
+ body: response.body,
88
+ success: false,
89
+ error_message: "Authorization failed",
90
+ api_status_code: 1,
91
+ response_code: response.code
92
+ }
93
+ end
94
+
95
+ if response.body.match /status=3/
96
+ to_ret[:response_hash] = {
97
+ body: response.body,
98
+ success: false,
99
+ error_message: "Unauthorized destination status",
100
+ api_status_code: 3,
101
+ response_code: response.code
102
+ }
103
+ end
104
+ to_ret
105
+ end
106
+
107
+ end
108
+ end
@@ -0,0 +1,5 @@
1
+ module Smsone
2
+ module Sms
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smsone/sms/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "smsone-sms"
8
+ spec.version = Smsone::Sms::VERSION
9
+ spec.authors = ["miclovich"]
10
+ spec.email = ["vicmiclovich@gmail.com"]
11
+ spec.summary = %q{Interact with the SMSONE API to send SMS or find out about credit balance}
12
+ spec.description = %q{Well, this abstracts the hard work to get a message out, right!}
13
+ spec.homepage = ""
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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0", '>= 3.0.0'
24
+ spec.add_development_dependency "webmock"
25
+ end
@@ -0,0 +1,57 @@
1
+ require './lib/smsone/sms'
2
+
3
+
4
+ # TODO
5
+ # Test code for the following scenarios
6
+ # - 3 possible errors (out of numerous ones... get MVP out)
7
+ # - complete request balance test code
8
+
9
+ class Messaging; include Smsone::Sms; end
10
+
11
+ describe Messaging do
12
+ describe 'sending out messages' do
13
+ before do
14
+ ResponseObjClass = Struct.new(:username, :password) do
15
+ def code
16
+ '202'
17
+ end
18
+
19
+ def body
20
+ 'status=0&msgid=sms0512064727974228'
21
+ end
22
+
23
+ def response
24
+ nil
25
+ end
26
+ end
27
+
28
+ resp_obj = ResponseObjClass.new 'username', 'password'
29
+ resp = {:response => resp_obj}
30
+
31
+ expect_any_instance_of(Messaging).to receive(:request_balance).and_return(resp)
32
+ end
33
+
34
+ let(:messaging) { Messaging.new }
35
+
36
+ it 'responds to #send_sms' do
37
+ response = messaging.send_sms 'username',
38
+ 'password',
39
+ '256772501811',
40
+ 'ensi',
41
+ 'hi there'
42
+ expect(response.code).to eq "202"
43
+ expect(response.body).to eq 'status=0&msgid=sms0512064727974228'
44
+ end
45
+ end
46
+
47
+ describe 'checking balance of credits' do
48
+
49
+ it 'responds to #request_balance' do
50
+ response = messaging.request_balance 'username', 'password'
51
+ expect(response[:response].code).to eq '202'
52
+ expect(response[:response].body).to eq 'status=0& total_credit_bal=95.000'
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,11 @@
1
+ require 'sms'
2
+ require 'webmock/rspec'
3
+ WebMock.disable_net_connect! allow_localhost: true
4
+
5
+ RSpec.configure do |config|
6
+ config.before(:each) do
7
+ stub_request(:post, /sms.smsone.co.ug/).
8
+ with(headers: {'Accept' => '*/*', 'User-Agent'=> 'Ruby'}).
9
+ to_return(status: 200, body: 'stubbed response', headers: {})
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smsone-sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - miclovich
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.0.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.0.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: webmock
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: Well, this abstracts the hard work to get a message out, right!
76
+ email:
77
+ - vicmiclovich@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - lib/smsone/sms.rb
88
+ - lib/smsone/sms/version.rb
89
+ - smsone-sms.gemspec
90
+ - spec/sms_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: ''
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.1
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Interact with the SMSONE API to send SMS or find out about credit balance
116
+ test_files:
117
+ - spec/sms_spec.rb
118
+ - spec/spec_helper.rb