sms160 0.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: b57490205bf183b33800307918d3cab00acb0702
4
+ data.tar.gz: c41529c0161b11ae9f5964ba4c4bf83fb87505b2
5
+ SHA512:
6
+ metadata.gz: d0c4b443d5634ba09a2d2280f0fd58eabc820ebf622e51563106c4e167fd676eaa61ed0b07b0c35d5e380339c25b34e41160a08b3a8306af93a19cc2ad1e0fb6
7
+ data.tar.gz: 08a58f34ad280171bcc0c7e38cc1da590b3f0e16df67d8219abb7bb4b1e616a81e949bbba2ffbeae1c922e15a416855f5725c6e93b29c6f79a1727fec75ded41
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sms160.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Mark Chavez
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,29 @@
1
+ # Sms160
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sms160'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sms160
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/sms160/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/sms160 ADDED
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env ruby
2
+ require "rest_client"
3
+ require "sms160"
data/lib/sms160.rb ADDED
@@ -0,0 +1,68 @@
1
+ require "sms160/version"
2
+ require "sms160/constants"
3
+ require "active_support/core_ext"
4
+ require "open-uri"
5
+ require "rest_client"
6
+
7
+ module Sms160
8
+ class Message
9
+ attr_accessor :to, :body, :reply_to
10
+ attr_accessor :username, :password
11
+
12
+ def initialize(attr = {})
13
+ attr.each do |k, v|
14
+ self.send("#{k}=", v)
15
+ end
16
+ end
17
+
18
+ def credit_balance
19
+ response = RestClient.get(BALANCE_ENDPOINT, params: fetch_credentials)
20
+ Hash.from_xml(response)["string"]
21
+ end
22
+
23
+ def send_message
24
+ raise "Incomplete Parameters ERROR" unless to and body and reply_to
25
+
26
+ options = fetch_credentials.merge!(mobileNumber: to, messageText: body, sms2way: reply_to)
27
+ response = RestClient.post(SEND_MESSAGE_ENDPOINT, options)
28
+
29
+ if response.code.to_i == 200
30
+ response = Hash.from_xml(response)["string"]
31
+
32
+ if response.include?("ERR") or API_ERROR.include?(response)
33
+ false
34
+ else
35
+ response
36
+ end
37
+ else
38
+ false
39
+ end
40
+ end
41
+
42
+ def bulk_send!
43
+ raise "Incomplete PARAMETERS errors" unless to and body and reply_to
44
+
45
+ options = fetch_credentials.merge!(messageText: body, sms2way: reply_to)
46
+
47
+ to.each do |recipient|
48
+ options.merge!("mobileNumber[#{recipient.object_id}]" => recipient)
49
+ end
50
+
51
+ response = RestClient.post(SEND_MESSAGE_ENDPOINT, options)
52
+ result = Hash.from_xml(response)["string"]["result"]["status"] rescue nil
53
+
54
+ result
55
+ end
56
+
57
+ def message_status(message_id)
58
+ response = RestClient.get(MESSAGE_STATUS_ENDPOINT, params: fetch_credentials.merge!(messageId: message_id))
59
+ Hash.from_xml(response)["string"]
60
+ end
61
+
62
+ private
63
+
64
+ def fetch_credentials
65
+ { username: username, password: password }
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ module Sms160
2
+ BASE_URI = "http://www.160.com.au/api/sms.asmx"
3
+ BALANCE_ENDPOINT = "#{BASE_URI}/api/sms.asmx/GetCreditBalance"
4
+ SEND_MESSAGE_ENDPOINT = "#{BASE_URI}/api/sms.asmx/SendMessage"
5
+ MESSAGE_STATUS_ENDPOINT = "#{BASE_URI}/api/sms.asmx/GetMessageStatus"
6
+
7
+ API_ERROR = [
8
+ "Error with message",
9
+ "Error delivering message",
10
+ "Routing error",
11
+ "User cancelled message delivery"
12
+ ]
13
+
14
+ API_PENDING = [
15
+ "Awaiting Result",
16
+ "Sending message.."
17
+ ]
18
+
19
+ API_SUCCESS = [
20
+ "Delivered to carrier",
21
+ "Delivered to handset",
22
+ "OK"
23
+ ]
24
+ end
@@ -0,0 +1,3 @@
1
+ module Sms160
2
+ VERSION = "0.0.1"
3
+ end
data/sms160.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sms160/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sms160"
8
+ spec.version = Sms160::VERSION
9
+ spec.authors = ["Mark Chavez"]
10
+ spec.email = ["markchav3z@gmail.com"]
11
+ spec.summary = %q{API wrapper for 160}
12
+ spec.description = %q{--- cool ---}
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.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+ spec.add_dependency "activesupport"
26
+ spec.add_dependency "rest_client"
27
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+ require "net/http"
3
+
4
+ describe Sms160 do
5
+ describe "accessors" do
6
+ it "can set the recipient of the message" do
7
+ sms = Sms160::Message.new(to: "+639182390239")
8
+ expect(sms.to).to eq "+639182390239"
9
+ end
10
+
11
+ it "can set the body of the message" do
12
+ sms = Sms160::Message.new(body: "hello world!")
13
+ expect(sms.body).to eq "hello world!"
14
+ end
15
+
16
+ it "can set the reply to of the message" do
17
+ sms = Sms160::Message.new(reply_to: "+639182390239")
18
+ expect(sms.reply_to).to eq "+639182390239"
19
+ end
20
+
21
+ it "can set the username and password" do
22
+ sms = Sms160::Message.new(username: "mark", password: "12345")
23
+ expect(sms.username).to eq "mark"
24
+ expect(sms.password).to eq "12345"
25
+ end
26
+ end
27
+
28
+ it "gets the credit balance" do
29
+ stub_request(:get, "#{Sms160::BALANCE_ENDPOINT}?username=username&password=password").
30
+ to_return(:status => 200, :body => "<?xml version='1.0' encoding='utf-8'?><string xmlns='www.160.com.au/api'>4621.00</string>", :headers => {})
31
+
32
+ sms = Sms160::Message.new(username: "username", password: "password")
33
+ expect(sms.credit_balance).to eq "4621.00"
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ require "bundler/setup"
2
+ require "webmock/rspec"
3
+
4
+ Bundler.setup
5
+ WebMock.disable_net_connect!(allow_localhost: true)
6
+
7
+ require "sms160"
8
+
9
+ RSpec.configure do |config|
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sms160
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mark Chavez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-30 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
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: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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: rest_client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: "--- cool ---"
98
+ email:
99
+ - markchav3z@gmail.com
100
+ executables:
101
+ - sms160
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/sms160
112
+ - lib/sms160.rb
113
+ - lib/sms160/constants.rb
114
+ - lib/sms160/version.rb
115
+ - sms160.gemspec
116
+ - spec/lib/sms160_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: ''
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.1
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: API wrapper for 160
142
+ test_files:
143
+ - spec/lib/sms160_spec.rb
144
+ - spec/spec_helper.rb