sms_teknik 0.1.0

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: feb4c40e655d9455b5157049e768400b5b844ad7
4
+ data.tar.gz: 754293fe1a24830e0a595fbe6ea123c459ba7f23
5
+ SHA512:
6
+ metadata.gz: e48d328a3c43e1e9907769c627dbb70d8d076e92d83dd6923c117798518383ec46cad5e90d0adf4e24276c7e3ed4cda900a7adf3e7f7695a7864c1dbe65b4edb
7
+ data.tar.gz: ee7b8411fe5b6b2d4349535d914dd40ed46e385c3aea2e07b556f6862074d0ca6a5f96b22fdc7bf120d76e70b64ebff064dee4c97b78e5a04316e5526c70e55b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at alex@aross.se. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sms_teknik.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alexander Ross
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.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # SmsTeknik
2
+
3
+ Need to send an SMS with [SMS Teknik](http://www.smsteknik.se)? Then this is the Gem for you. We only implemented the gateway calls we need for now. But keep in mind that it's open source and you can help us improve the gem and make it more feature complete.
4
+
5
+ This gem is created by [Standout AB](http://standout.se).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sms_teknik'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sms_teknik
22
+
23
+ ## Usage
24
+
25
+ You need to contact [SMS Teknik](http://www.smsteknik.se) to get an account.
26
+
27
+ ### Send a SMS
28
+
29
+ ```ruby
30
+ id = "Your company ID"
31
+ user = "your user name"
32
+ pass = "your password"
33
+ sender = "FOO"
34
+ client = SmsTeknik::Client.new(id: id, user: user, pass: pass)
35
+ sms = SmsTeknik::Message(from: sender, to: ["+700000000"], body: "Hello, World!")
36
+
37
+ client.deliver(sms)
38
+ ```
39
+
40
+ ## Development
41
+
42
+ 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.
43
+
44
+ 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`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sms_teknik. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
49
+
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
54
+
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sms_teknik"
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
data/bin/setup ADDED
@@ -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,56 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+
4
+ module SmsTeknik
5
+ class Client
6
+ attr_accessor :id, :user, :pass
7
+
8
+ def initialize(options = {})
9
+ @id = options[:id]
10
+ @user = options[:user]
11
+ @pass = options[:pass]
12
+ end
13
+
14
+ def deliver(message)
15
+ req = Net::HTTP::Post.new(uri)
16
+ req.add_field "Content-Type", "text/xml"
17
+ req.body = SmsTeknik::XMLTemplates.text_message(
18
+ recipients: message.to,
19
+ message: message.body,
20
+ sender: message.from,
21
+ send_date: Time.now.strftime("%Y-%m-%d"),
22
+ send_time: Time.now.strftime("%H:%M")
23
+ )
24
+
25
+ # Fetch Request
26
+ res = http.request(req)
27
+ SmsTeknik.logger.info "[SmsTeknik] Message sent with status #{res.code} and response \"#{res.body}\""
28
+ return true
29
+ rescue StandardError => e
30
+ SmsTeknik.logger.error "[SmsTeknik] HTTP Request failed (#{e.message})"
31
+ return false
32
+ end
33
+
34
+ def self.endpoint
35
+ @endpoint || "https://api.smsteknik.se"
36
+ end
37
+
38
+ def self.endpoint=(value)
39
+ @endpoint = value
40
+ end
41
+
42
+ private
43
+
44
+ def uri
45
+ params = URI.encode_www_form(id: id, user: user, pass: pass)
46
+ URI("#{self.class.endpoint}/send/xml/?#{params}")
47
+ end
48
+
49
+ def http
50
+ Net::HTTP.new(uri.host, uri.port).tap do |h|
51
+ h.use_ssl = true
52
+ h.verify_mode = OpenSSL::SSL::VERIFY_PEER
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,16 @@
1
+ module SmsTeknik
2
+ class Message
3
+ attr_accessor :from, :to, :body
4
+
5
+ def initialize(attributes = {})
6
+ @from = attributes[:from]
7
+ @to = attributes[:to]
8
+ @body = attributes[:body]
9
+ end
10
+
11
+ def to
12
+ Array(@to)
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ module SmsTeknik
2
+ class Railties < ::Rails::Railtie
3
+ initializer 'Rails logger' do
4
+ SmsTeknik.logger = Rails.logger
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module SmsTeknik
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,54 @@
1
+ module SmsTeknik
2
+ module XMLTemplates
3
+
4
+ def self.text_message(attributes = {})
5
+ recipients = attributes[:recipients]
6
+ message = attributes[:message]
7
+ sender = attributes[:sender]
8
+ send_date = attributes[:send_date]
9
+ send_time = attributes[:send_time]
10
+
11
+ <<-XML
12
+ <?xml version="1.0" ?>
13
+ <sms-teknik>
14
+ <operationtype>0</operationtype>
15
+ <flash>0</flash>
16
+ <multisms>1</multisms>
17
+ <maxmultisms>0</maxmultisms>
18
+ <ttl>0</ttl>
19
+ <customid>1</customid>
20
+ <compresstext>0</compresstext>
21
+ <send_date>#{send_date}</send_date>
22
+ <send_time>#{send_time}</send_time>
23
+ <udh></udh>
24
+ <udmessage><![CDATA[#{message}]]></udmessage>
25
+ <smssender>#{sender}</smssender>
26
+ <deliverystatustype>0</deliverystatustype>
27
+ <deliverystatusaddress></deliverystatusaddress>
28
+ <usereplynumber>0</usereplynumber>
29
+ <usereplyforwardtype>0</usereplyforwardtype>
30
+ <usereplyforwardurl></usereplyforwardurl>
31
+ <usereplycustomid></usereplycustomid>
32
+ <usereplysmp>0</usereplysmp>
33
+ <usee164>0</usee164>
34
+ <items>
35
+ #{recipients_partial(recipients)} </items>
36
+ </sms-teknik>
37
+ XML
38
+ end
39
+
40
+ private
41
+
42
+ def self.recipients_partial(recipients)
43
+ recipients.map { |recipient|
44
+ <<-XML
45
+ <recipient>
46
+ <nr>#{recipient}</nr>
47
+ </recipient>
48
+ XML
49
+ }.join("\n")
50
+ end
51
+
52
+ end
53
+ end
54
+
data/lib/sms_teknik.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "logger"
2
+ require "sms_teknik/version"
3
+ require "sms_teknik/message"
4
+ require "sms_teknik/client"
5
+ require "sms_teknik/xml_templates"
6
+ require 'sms_teknik/railtie' if defined?(Rails)
7
+
8
+ module SmsTeknik
9
+ def self.logger
10
+ @logger ||= Logger.new(STDOUT)
11
+ end
12
+
13
+ def self.logger=(value)
14
+ @logger = value
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sms_teknik/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sms_teknik"
8
+ spec.version = SmsTeknik::VERSION
9
+ spec.authors = ["Standout AB"]
10
+ spec.email = ["kontakt@standout.se"]
11
+
12
+ spec.summary = %q{SMS Gateway client for SMS Teknik}
13
+ spec.description = %q{Need to send an SMS with SMS Teknik? Then this is the
14
+ Gem for you. We only implemented the gateway calls we need for now. But
15
+ keep in mind that it's open source and you can help us improve the gem and
16
+ make it more feature complete.}
17
+ spec.homepage = "https://github.com/standout/sms_teknik"
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.11"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "webmock", "~> 2.1.0"
29
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sms_teknik
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Standout AB
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-21 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.1.0
69
+ description: |-
70
+ Need to send an SMS with SMS Teknik? Then this is the
71
+ Gem for you. We only implemented the gateway calls we need for now. But
72
+ keep in mind that it's open source and you can help us improve the gem and
73
+ make it more feature complete.
74
+ email:
75
+ - kontakt@standout.se
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - .gitignore
81
+ - .rspec
82
+ - .travis.yml
83
+ - CODE_OF_CONDUCT.md
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - lib/sms_teknik.rb
91
+ - lib/sms_teknik/client.rb
92
+ - lib/sms_teknik/message.rb
93
+ - lib/sms_teknik/railtie.rb
94
+ - lib/sms_teknik/version.rb
95
+ - lib/sms_teknik/xml_templates.rb
96
+ - sms_teknik.gemspec
97
+ homepage: https://github.com/standout/sms_teknik
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.0.14
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: SMS Gateway client for SMS Teknik
121
+ test_files: []