softers-sms 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDUxODYzZDhjYjAyNTQyZmRjZmI0NThhMjJiOGUzYzkwMTA1NDQ3OA==
5
+ data.tar.gz: !binary |-
6
+ ZjYxYjM3Y2Y2NDE5NjdiNTg1NTI0YzM4NGM3MzVmNzFjMTEzNDBhMQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTkxMDkzOTVhMWNkNmQxYTNiMTVlNGI0ZWMyNzBiODUyZDY1YjQxNzQ1ZjM1
10
+ NTFkNWM3MmNiN2RkYmZkNjMwYThhNTgwZjQ0OGNmZGQ2M2NiNTZiZDVjMTE5
11
+ N2IxZDU4OTNhNWI3NTcyZTEzMTFiMTUxNTJjZDNlMWQ2ZjRlZmY=
12
+ data.tar.gz: !binary |-
13
+ YWNiNTQ2OGZiZDExODVkMzI1OWIwNzlmYTE4ZDdlODU4ZDk3YTQ1YzY1ZDU1
14
+ ZWJiYmNlMDQ0OTZlOWMzNzFiMjU0Y2Y5MmE3YmJkNzMwYWJmNzUzMGUyMGI1
15
+ NmUxZjgxZjNhNjNjZjQ2OGIwNGI5NGI5NDlkZDdmZTEwYzkwODQ=
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ .idea/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
5
+ - "2.0.0"
6
+ - jruby-19mode # JRuby in 1.9 mode
7
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'rake'
7
+ gem 'minitest'
8
+ gem 'mocha'
9
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Lauri Nevala
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,38 @@
1
+ A Ruby wrapper for the [Softers](http://www.softers.net/) SMS API
2
+ =======================================================
3
+ [![Build Status](https://travis-ci.org/nevalla/softers-sms.png?branch=master)](https://travis-ci.org/nevalla/softers-sms)
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'softers-sms'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install softers-sms
17
+
18
+ ## Usage
19
+
20
+ Construct a client object with your Softers API credentials:
21
+
22
+ @client = SoftersSms::Client.new('...username...', '...password...')
23
+ @client.send_message({to_phone: '+3585551144', message: 'Hey!'})
24
+
25
+
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
34
+
35
+
36
+ ## Credits
37
+
38
+ This gem is influenced by [Nexmo](https://github.com/timcraft/nexmo) gem, originally by Tim Craft
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'lib/softers'
6
+ t.test_files = FileList['spec/*_spec.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,59 @@
1
+ require 'net/http'
2
+ require 'net/https' if RUBY_VERSION == '1.8.7'
3
+ require 'json'
4
+ require 'uri'
5
+
6
+ module SoftersSms
7
+
8
+ class Client
9
+ def initialize(username, password)
10
+ @username, @password = username, password
11
+
12
+ @headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
13
+
14
+ @http = Net::HTTP.new('www.softers.net', Net::HTTP.https_default_port)
15
+ @http.use_ssl = true
16
+ end
17
+
18
+ attr_accessor :username, :password, :http, :headers
19
+
20
+ def send_message(data)
21
+ data[:message] = data[:message].encode('ISO-8859-1')
22
+ response = @http.post('/messaging/smsclient.php?type=send', encode(data), headers)
23
+ if response.body.strip == "200 OK"
24
+ Success.new(true)
25
+ else
26
+ Failure.new(Error.new("#{response.body}"))
27
+ end
28
+
29
+ end
30
+
31
+ def encode(data)
32
+ URI.encode_www_form data.merge(:username => @username, :password => @password)
33
+ end
34
+
35
+ end
36
+
37
+ class Success < Struct.new(:success)
38
+ def success?
39
+ true
40
+ end
41
+
42
+ def failure?
43
+ false
44
+ end
45
+ end
46
+
47
+ class Failure < Struct.new(:error)
48
+ def success?
49
+ false
50
+ end
51
+
52
+ def failure?
53
+ true
54
+ end
55
+ end
56
+
57
+ class Error < StandardError
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module SoftersSms
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/softers-sms/version', __FILE__)
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "softers-sms"
8
+ gem.version = SoftersSms::VERSION
9
+ gem.authors = ["Lauri Nevala"]
10
+ gem.email = ["lauri.nevala@gmail.com"]
11
+ gem.description = "A Ruby wrapper for the Softers SMS API"
12
+ gem.summary = "see description"
13
+ gem.homepage = "https://github.com/nevalla/softers"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.add_dependency('json', ['~> 1.5'])
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,61 @@
1
+ require 'minitest/autorun'
2
+ require 'mocha/setup'
3
+
4
+ require_relative '../lib/softers-sms'
5
+
6
+ describe SoftersSms::Client do
7
+ before do
8
+ @client = SoftersSms::Client.new('key', 'secret')
9
+ end
10
+
11
+ describe 'http method' do
12
+ it 'should return a Net::HTTP object that uses SSL' do
13
+ @client.http.must_be_instance_of(Net::HTTP)
14
+ @client.http.use_ssl?.must_equal(true)
15
+ end
16
+ end
17
+
18
+ describe 'headers method' do
19
+ it 'should return a hash' do
20
+ @client.headers.must_be_kind_of(Hash)
21
+ end
22
+ end
23
+
24
+ describe 'send_message method' do
25
+ before do
26
+ @headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
27
+ end
28
+
29
+ it 'should make the correct http call return a successful response body equals 200 OK' do
30
+
31
+ # Stub out post request
32
+ http_response = stub(:code => "200", :body => '200 OK')
33
+
34
+
35
+ data = 'to_phone=number&message=Hey%21&username=key&password=secret'
36
+
37
+ @client.http.expects(:post).with('/messaging/smsclient.php?type=send', data, @headers).returns(http_response)
38
+
39
+ response = @client.send_message({to_phone: 'number', message: 'Hey!'})
40
+
41
+ response.success?.must_equal(true)
42
+ end
43
+
44
+ it 'should return failure response if response body does not equal 200 OK' do
45
+
46
+ # Stub out post request
47
+ http_response = stub(:code => "200", :body => '404 Not found\r\nUnable to find user information')
48
+
49
+ data = 'to_phone=number&message=Hey%21&username=key&password=secret'
50
+
51
+ @client.http.expects(:post).with('/messaging/smsclient.php?type=send', data, @headers).returns(http_response)
52
+
53
+ response = @client.send_message({to_phone: 'number', message: 'Hey!'})
54
+
55
+ response.success?.must_equal(false)
56
+ response.failure?.must_equal(true)
57
+ response.error.to_s.must_equal('404 Not found\r\nUnable to find user information')
58
+
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: softers-sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Lauri Nevala
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-25 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: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ description: A Ruby wrapper for the Softers SMS API
28
+ email:
29
+ - lauri.nevala@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - .travis.yml
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - lib/softers-sms.rb
41
+ - lib/softers-sms/version.rb
42
+ - softers-sms.gemspec
43
+ - spec/softers-sms_spec.rb
44
+ homepage: https://github.com/nevalla/softers
45
+ licenses: []
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.1.10
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: see description
67
+ test_files:
68
+ - spec/softers-sms_spec.rb