textlocal-india 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 85963f9553b1cae985f0b35ccd9b7a26d3fb6d9f
4
+ data.tar.gz: a1642b9e5259d8607a0ee3950499d6019cc38876
5
+ SHA512:
6
+ metadata.gz: 8b747ef753db3157a1a0a21b2829d01117ecd1dbc119633082509ac0dfc266be8578206fe7bd00587feead8fbfe4b8d042ea7d12343c2988dbb5bc6c7d7a96dd
7
+ data.tar.gz: 37e233ecbfb71e6c7bb2ccf358f35b8f018195fdc9e8655837fd1cba0b4883d0aaf76d4244818b79360c46fea2778be0a749661756769ba313397229b9ce0b4c
@@ -0,0 +1,10 @@
1
+ <<<<<<< HEAD
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in textlocal.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Sajan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 sajan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,92 @@
1
+ # textlocal-india
2
+ Unofficial Ruby wrapper for **textlocal.in** API.
3
+
4
+ ## Installation
5
+
6
+ Add:
7
+ `gem 'textlocal-india', :git => 'https://github.com/sajan45/textlocal-india'`
8
+ or `gem 'textlocal-india'` to your `Gemfile`
9
+
10
+ or install from Rubygems:
11
+ Run `gem install textlocal-india`
12
+
13
+ ## Usage
14
+
15
+ Configure the default settings
16
+
17
+ ```
18
+ Textlocal.config do |c|
19
+ c.sender = "MYAPP"
20
+ c.username = "textlocal_username"
21
+ c.api_hash = "textlocal_hash"
22
+ c.test = false
23
+ end
24
+ ```
25
+ In above configuration, set `c.test = true` if you want to use API in test mode. This will not send message, hence no deduction of credit.
26
+
27
+ Alternative to above configuration, you can just set environment variables for Textlocal username and hash and you are ready to go.
28
+
29
+ ```
30
+ TEXTLOCAL_USER_NAME = "textlocal_username"
31
+ TEXTLOCAL_API_HASH = "textlocal_api_hash"
32
+ ```
33
+
34
+ Sending SMS:
35
+ ```
36
+ sms = Textlocal.send_message(message, numbers, options)
37
+ # Textlocal.send_message('hello world', '9853xxxxxx')
38
+ status = sms.response[:status] # can be 'success' or 'failure'
39
+ ```
40
+ or you can create message manually:
41
+ ```
42
+ msg = Textlocal::Message.new
43
+ msg.message = "your order is received successfully"
44
+ msg.numbers = ["9853xxxxxx"]
45
+ msg.send!
46
+ ```
47
+ `message` is a string type argument.
48
+ `numbers` argument can be `string`, `integer` or `array` of `strings` or `integers`
49
+
50
+ All of the below can be valid for numbers argument:
51
+ * '9853xxxxxx'
52
+ * 9853xxxxxx
53
+ * ['9853xxxxxx', '9856xxxxxx']
54
+ * ['8894xxxxxx', 7504xxxxxx]
55
+
56
+ Every individual **Number** should be at least 10 character long, containing all numeric character.
57
+ Below are valid individual numbers irrespective of string or integer:
58
+ * 9876543210
59
+ * 919876543210
60
+ * +919876543210
61
+
62
+ But numbers like *987654321* (less than 10 digit) or *98765abcde* (containing non numeric character) is not valid.
63
+
64
+ #### Options
65
+ The third optional argument for `send_message` method is a Hash object.
66
+ * **sender** : You can override sender by passing a `sender` option.
67
+ `Textlocal.send_message('message', '9538xxxxxx', 'sender' => 'MYAPPS')`
68
+
69
+ ## Development
70
+
71
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
72
+
73
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`.
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sajan45/textlocal.
78
+
79
+ ## TODO
80
+
81
+ * Support for bulk send
82
+ * Support for more options like schedule time
83
+ * Specs for features
84
+
85
+ ## Credits
86
+
87
+ This gem was originally insipired from [txtlocal UK](https://github.com/epigenesys/txtlocal) gem.
88
+
89
+ ## License
90
+
91
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
92
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "textlocal"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require 'textlocal/config'
2
+ require 'textlocal/message'
3
+ require "textlocal/version"
4
+
5
+ module Textlocal
6
+
7
+ class << self
8
+
9
+ def config
10
+ @config ||= Config.new
11
+ if block_given?
12
+ yield @config
13
+ end
14
+ @config
15
+ end
16
+
17
+ def reset_config
18
+ @config = nil
19
+ end
20
+
21
+ def send_message(message, numbers, options={})
22
+ msg = Textlocal::Message.new(message, numbers, options)
23
+ msg.send!
24
+ msg
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,27 @@
1
+ module Textlocal
2
+ class Config
3
+
4
+ # this can be overridden on a per-message basis
5
+ attr_accessor :sender
6
+
7
+ # The username of the Textlocal account to use when accessing the API
8
+ attr_accessor :username
9
+
10
+ # The API hash of the Textlocal account to use when accessing the API
11
+ attr_accessor :api_hash
12
+
13
+ # Access the API in test mode
14
+ attr_accessor :test
15
+
16
+ def initialize
17
+ @test = false
18
+ @username = ENV['TEXTLOCAL_USER_NAME']
19
+ @api_hash = ENV['TEXTLOCAL_API_HASH']
20
+ end
21
+
22
+ def testing?
23
+ !!@test
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,103 @@
1
+ require 'net/https'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'cgi'
5
+
6
+ module Textlocal
7
+ class Message
8
+
9
+ attr_accessor :message
10
+ attr_accessor :numbers
11
+ attr_accessor :sender
12
+
13
+ attr_accessor :response
14
+
15
+ SMS_ENDPOINT = URI.parse("https://api.textlocal.in/send/?")
16
+
17
+ def initialize(message=nil, numbers=nil, options=nil)
18
+ self.message = message if message
19
+ self.numbers = numbers if numbers
20
+ self.options = options if options
21
+ end
22
+
23
+ def message=(message)
24
+ @message = CGI.escape(message)
25
+ end
26
+
27
+ def numbers
28
+ @numbers ||= []
29
+ end
30
+
31
+ def numbers=(numbers)
32
+ @numbers = []
33
+ if numbers.is_a?Array
34
+ numbers.map!(&:to_s)
35
+ else
36
+ numbers = numbers.to_s.split(',')
37
+ end
38
+ numbers.each do |num|
39
+ add_recipient(num)
40
+ end
41
+ end
42
+
43
+ def add_recipient(number)
44
+ number = number.gsub(/\s/, '')
45
+ number = case number
46
+ when /^91\d{10}$/
47
+ number
48
+ when /^(?:\+91)(\d{10})$/
49
+ "91#{$1}"
50
+ when /^(\d{10})$/
51
+ "91#{$1}"
52
+ else
53
+ return
54
+ end
55
+ @numbers << number
56
+ end
57
+
58
+ def sender
59
+ self.sender = Textlocal.config.sender unless @sender
60
+ @sender
61
+ end
62
+
63
+ def sender=(sender)
64
+ @sender = sender.strip.gsub(/[^\w]/, '').to_s[0, 11] if sender
65
+ if @sender && @sender.length < 6
66
+ @sender = nil
67
+ end
68
+ end
69
+
70
+ def options=(options)
71
+ self.sender = options[:sender] if options.has_key?(:sender)
72
+ end
73
+
74
+ def response=(response)
75
+ unless response.body.empty?
76
+ @response = {}
77
+ data = JSON.parse(response.body)
78
+ data.each_pair do |k, v|
79
+ key = k.gsub(/\B[A-Z]+/, '_\0').downcase.to_sym
80
+ @response[key] = v
81
+ end
82
+ end
83
+ end
84
+
85
+ def send!
86
+ http = Net::HTTP.new(SMS_ENDPOINT.host, SMS_ENDPOINT.port)
87
+ http.use_ssl = true
88
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
89
+
90
+ req = Net::HTTP::Post.new(SMS_ENDPOINT.path)
91
+ params = {'username'=> Textlocal.config.username,
92
+ 'hash' => Textlocal.config.api_hash,
93
+ 'numbers' => numbers.join(','),
94
+ 'message' => self.message,
95
+ 'test' => Textlocal.config.testing? ? true : false
96
+ }
97
+ params['sender'] = sender if sender
98
+ req.set_form_data(params)
99
+ result = http.start { |http| http.request(req) }
100
+ self.response = result
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,3 @@
1
+ module Textlocal
2
+ VERSION = "0.1.1"
3
+ 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 'textlocal/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "textlocal-india"
8
+ spec.version = Textlocal::VERSION
9
+ spec.authors = ["sajan"]
10
+ spec.email = ["sajan.sahu@live.com"]
11
+
12
+ spec.summary = %q{Unofficial wrapper for textlocal.in API.}
13
+ spec.homepage = "https://github.com/sajan45/textlocal"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", ">= 1.12"
30
+ spec.add_development_dependency "rake", ">= 10.0"
31
+ spec.add_development_dependency "rspec", ">= 3.0"
32
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: textlocal-india
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - sajan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-18 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - sajan.sahu@live.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/textlocal.rb
73
+ - lib/textlocal/config.rb
74
+ - lib/textlocal/message.rb
75
+ - lib/textlocal/version.rb
76
+ - textlocal.gemspec
77
+ homepage: https://github.com/sajan45/textlocal
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ allowed_push_host: https://rubygems.org
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.5.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Unofficial wrapper for textlocal.in API.
102
+ test_files: []