isms-ruby 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4fe1b7f6c03bd3fb17bfb4b466644c86a769e2c5
4
+ data.tar.gz: 62724a048a34d6aba997144d4bd7c83ef7b2e45e
5
+ SHA512:
6
+ metadata.gz: 3cb7cc7595fbc2646b6cedc3b4130c169904dee5784bf3a64b82f9af476fda98d246a21b31080bc6667a91fde15fe7d580a3a7304674ff3f0d2e1077be1ef02a
7
+ data.tar.gz: d16acea19b2ebfb7a2ae270b4a2cd3403fd9f2f17c974888d9eb8d035d9d615bf3a1e14e8693b1c36f160a8e7b114a4003d784a5f79e075bdc4075dd838a9ba4
data/.gitignore ADDED
@@ -0,0 +1,16 @@
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
+
16
+ .idea/workspace.xml
data/.idea/.name ADDED
@@ -0,0 +1 @@
1
+ isms-ruby
data/.idea/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
4
+ </project>
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="gem" name="Ruby Gem">
5
+ <configuration>
6
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
7
+ <option name="GEM_APP_TEST_PATH" value="" />
8
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
9
+ </configuration>
10
+ </facet>
11
+ </component>
12
+ <component name="NewModuleRootManager">
13
+ <content url="file://$MODULE_DIR$" />
14
+ <orderEntry type="inheritedJdk" />
15
+ <orderEntry type="sourceFolder" forTests="false" />
16
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.7.1.pre.3, rbenv: 2.1.2) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, rbenv: 2.1.2) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="faraday (v0.9.1, rbenv: 2.1.2) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="multipart-post (v2.0.0, rbenv: 2.1.2) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.4.2, rbenv: 2.1.2) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.2.0, rbenv: 2.1.2) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.2.1, rbenv: 2.1.2) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.2.0, rbenv: 2.1.2) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.2.1, rbenv: 2.1.2) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.2.2, rbenv: 2.1.2) [gem]" level="application" />
26
+ </component>
27
+ </module>
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 2.1.2" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/isms-ruby.iml" filepath="$PROJECT_DIR$/.idea/isms-ruby.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,5 @@
1
+ <component name="DependencyValidationManager">
2
+ <state>
3
+ <option name="SKIP_IMPORT_STATEMENTS" value="false" />
4
+ </state>
5
+ </component>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="" />
5
+ </component>
6
+ </project>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in isms-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jonathan ES Lin
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,57 @@
1
+ ## isms-ruby
2
+
3
+ A wrapper gem for iSMS (Malaysia) API.
4
+
5
+ Check [www.isms.com.my](www.isms.com.my) for API documentation.
6
+
7
+ Currently only supports sending SMS.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'isms-ruby'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install isms-ruby
24
+
25
+ ## Usage
26
+
27
+ In an initializer file, configure as follows:
28
+
29
+ require 'isms'
30
+
31
+ ISMS.configure do |config|
32
+ config.username = ENV['ISMS_USERNAME'] || 'username'
33
+ config.password = ENV['ISMS_PASSWORD'] || 'password'
34
+ config.protocol = 'https'
35
+ end
36
+
37
+ Then, initialize a client and send an SMS as follows:
38
+
39
+ client = ISMS::Client.new
40
+ response = client.send_sms('Hello world!', '60121231234')
41
+
42
+ # => { code: 200, description: 'SUCCESS' }
43
+ # => { code: -1001, description: 'AUTHENTICATION FAILED' } etc.
44
+
45
+ Check out other response codes at [http://isms.com.my/response_result.php](http://isms.com.my/response_result.php)
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it ( https://github.com/ernsheong/isms-ruby/fork )
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create a new Pull Request
54
+
55
+ To run the specs:
56
+
57
+ $ bundle exec rspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/isms-ruby.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'isms/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "isms-ruby"
8
+ spec.version = ISMS::VERSION
9
+ spec.authors = ["Jonathan ES Lin"]
10
+ spec.email = ["ernsheong@gmail.com"]
11
+ spec.summary = %q{An API wrapper gem for iSMS.}
12
+ spec.description = %q{A gem to interface with iSMS's API (www.isms.com.my) for SMS sending.}
13
+ spec.homepage = "https://github.com/ernsheong/isms-ruby"
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 "faraday", "~> 0.9.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.2.0"
26
+ end
data/lib/isms.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'isms/version'
2
+ require 'isms/configuration'
3
+ require 'isms/client'
4
+
5
+ module ISMS
6
+ extend Configuration
7
+ end
@@ -0,0 +1,56 @@
1
+ require 'isms/configuration'
2
+ require 'faraday'
3
+
4
+ module ISMS
5
+ class Client
6
+ SEND_SMS_URL = '/isms_send.php'
7
+
8
+ def initialize
9
+ # Check for username and password
10
+ raise RuntimeError, "Username and password not provided!" unless ISMS.username && ISMS.password
11
+ end
12
+
13
+ #
14
+ # Returns Hash of :code and :description
15
+ # code has the error code number
16
+ # description is the error description
17
+ # http://www.isms.com.my/sms_api.php#SendSMS_Response
18
+ #
19
+ def send_sms(message_body, phone_no, type = 1)
20
+ request_body = {}
21
+ request_body[:un] = ISMS.username
22
+ request_body[:pwd] = ISMS.password
23
+ request_body[:dstno] = phone_no
24
+ request_body[:msg] = message_body
25
+ request_body[:type] = type
26
+
27
+ faraday_response = connection.post do |request|
28
+ request.url SEND_SMS_URL
29
+ request.body = request_body
30
+ end
31
+
32
+ parse_response(faraday_response.body)
33
+ end
34
+
35
+ private
36
+
37
+ def connection
38
+ @connection ||= Faraday.new(url: ISMS.endpoint_url_with_protocol)
39
+ end
40
+
41
+ def parse_response(body)
42
+ if body && body.index('=')
43
+ result_array = body.split('=')
44
+ {
45
+ code: result_array.first.strip.to_i,
46
+ description: result_array.last.strip
47
+ }
48
+ else
49
+ {
50
+ code: 200,
51
+ description: 'SUCCESS'
52
+ }
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,32 @@
1
+ require 'isms/version'
2
+
3
+ module ISMS
4
+ module Configuration
5
+ DEFAULT_PROTOCOL = 'http'
6
+ DEFAULT_ENDPOINT = 'www.isms.com.my'
7
+ DEFAULT_USERNAME = nil
8
+ DEFAULT_PASSWORD = nil
9
+
10
+ attr_accessor :username, :password, :protocol, :endpoint
11
+
12
+ # When extended, call reset to set variable values to defaults
13
+ def self.extended(mod)
14
+ mod.reset
15
+ end
16
+
17
+ def reset
18
+ self.username = DEFAULT_USERNAME
19
+ self.password = DEFAULT_PASSWORD
20
+ self.protocol = DEFAULT_PROTOCOL
21
+ self.endpoint = DEFAULT_ENDPOINT
22
+ end
23
+
24
+ def endpoint_url_with_protocol
25
+ "#{protocol}://#{endpoint}"
26
+ end
27
+
28
+ def configure
29
+ yield self
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module ISMS
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,82 @@
1
+ require 'isms'
2
+
3
+ describe ISMS::Client do
4
+ let(:request_stubs) { Faraday::Adapter::Test::Stubs.new }
5
+ let(:test_connection) do
6
+ Faraday.new do |builder|
7
+ builder.adapter :test, request_stubs
8
+ end
9
+ end
10
+ let(:client) { ISMS::Client.new }
11
+
12
+ describe ".initialize" do
13
+ it "complains when API key is not configured" do
14
+ expect { ISMS::Client.new }.to raise_error(RuntimeError)
15
+ end
16
+
17
+ context "with API key" do
18
+ before do
19
+ allow(ISMS).to receive(:password).and_return("1234567890")
20
+ allow(ISMS).to receive(:username).and_return("username")
21
+ end
22
+
23
+ it "should not complain if password and username is given" do
24
+ expect { ISMS::Client.new }.not_to raise_error
25
+ end
26
+ end
27
+ end
28
+
29
+ describe ".send_sms" do
30
+ let(:send_sms_url) { '/isms_send.php' }
31
+ before do
32
+ allow(ISMS).to receive(:password).and_return("1234567890")
33
+ allow(ISMS).to receive(:username).and_return("username")
34
+ end
35
+
36
+ context 'successful send' do
37
+ let(:success_response) { "200 = SUCCESS" }
38
+
39
+ context "returns 200 = SUCCESS" do
40
+ before do
41
+ allow(client).to receive(:connection).and_return(test_connection)
42
+ request_stubs.post(send_sms_url) { |env| [ 200, {}, success_response ] }
43
+ end
44
+
45
+ it 'sends successfully' do
46
+ result = client.send_sms('Hi there!', '60121231234')
47
+ expect(result[:code]).to eq(200)
48
+ expect(result[:description]).to eq('SUCCESS')
49
+ end
50
+ end
51
+
52
+ context "returns blank" do
53
+ before do
54
+ allow(client).to receive(:connection).and_return(test_connection)
55
+ request_stubs.post(send_sms_url) { |env| [ 200, {}, '' ] }
56
+ end
57
+
58
+ it 'sends successfully' do
59
+ result = client.send_sms('Hi there!', '60121231234')
60
+ expect(result[:code]).to eq(200)
61
+ expect(result[:description]).to eq('SUCCESS')
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'unsuccessful send' do
67
+ let(:failure_response) { "-1001 = AUTHENTICATION FAILED" }
68
+
69
+ before do
70
+ allow(client).to receive(:connection).and_return(test_connection)
71
+ request_stubs.post(send_sms_url) { |env| [ 200, {}, failure_response ] }
72
+ end
73
+
74
+ it 'sends successfully' do
75
+ result = client.send_sms('Hi there!', '60121231234')
76
+ expect(result[:code]).to eq(-1001)
77
+ expect(result[:description]).to eq('AUTHENTICATION FAILED')
78
+ end
79
+ end
80
+ end
81
+ end
82
+
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: isms-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan ES Lin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.0
69
+ description: A gem to interface with iSMS's API (www.isms.com.my) for SMS sending.
70
+ email:
71
+ - ernsheong@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".idea/.name"
78
+ - ".idea/.rakeTasks"
79
+ - ".idea/encodings.xml"
80
+ - ".idea/isms-ruby.iml"
81
+ - ".idea/misc.xml"
82
+ - ".idea/modules.xml"
83
+ - ".idea/scopes/scope_settings.xml"
84
+ - ".idea/vcs.xml"
85
+ - Gemfile
86
+ - LICENSE.txt
87
+ - README.md
88
+ - Rakefile
89
+ - isms-ruby.gemspec
90
+ - lib/isms.rb
91
+ - lib/isms/client.rb
92
+ - lib/isms/configuration.rb
93
+ - lib/isms/version.rb
94
+ - spec/client_spec.rb
95
+ homepage: https://github.com/ernsheong/isms-ruby
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.2
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: An API wrapper gem for iSMS.
119
+ test_files:
120
+ - spec/client_spec.rb