steam_fi 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: 958b4b84c5a4e2e65facedc3b8fa607d3bb98aac
4
+ data.tar.gz: 3d8dea1b4eec8bac87ea155a1fbfe084a19a5651
5
+ SHA512:
6
+ metadata.gz: 81870bff0f0c41095e0faf79c75bd5ec815d0b1862f9b7c24ff6b0f9117ae58d21ed79f03f9099340aa3f134506ccd5d5ec17866cf51b9f8a5c69a9e3f5f9eeb
7
+ data.tar.gz: d7436984354f36d363da82e21925a1862fdba0c170992587c14d7891b911d40a5e9f68b02578199c231a30ea0e3b5d698954f62bf740247928f2602757ca6cf4
data/.gitignore ADDED
@@ -0,0 +1,14 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in steam_fi.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Laurynas Butkus
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # SteamFi
2
+
3
+ steam.fi SMS gateway client
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'steam_fi'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install steam_fi
20
+
21
+ ## Usage
22
+
23
+ Add configuration to the initializer: `config/initializers/steam_fi.rb`
24
+
25
+ ```ruby
26
+ SteamFi::API.setup(
27
+ :username => 'someuser',
28
+ :password => 'somepassword'
29
+ )
30
+ ```
31
+
32
+ Send SMS:
33
+
34
+ ```ruby
35
+ SteamFi::API.send_sms('1234PHONE', 'Hello world')
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( https://github.com/[my-github-username]/steam_fi/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,69 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module SteamFi
5
+ class API
6
+ # Default configuration
7
+ @@config = {
8
+ :sms_url => 'https://pipe.steam.fi/contentbroker/api/sendsms',
9
+ :username => nil,
10
+ :password => nil
11
+ }
12
+
13
+ cattr_accessor :logger
14
+
15
+ # Logger
16
+ @@logger = Logger.new File.join(RAILS_ROOT, '/log/', "steam_fi_#{RAILS_ENV}.log")
17
+
18
+ # Set configuration parameters
19
+ def self.setup(options)
20
+ @@config.merge!(options)
21
+ end
22
+
23
+ # Send SMS message
24
+ def self.send_sms(msisdn, message, params = {})
25
+ params.merge! :msisdn => msisdn, :msg => message
26
+ self.request @@config[:sms_url], params
27
+ end
28
+
29
+ protected
30
+
31
+ # Send request
32
+ def self.request(url, params = {})
33
+ # add username & password
34
+ params.merge! :l => @@config[:username], :p => @@config[:password]
35
+
36
+ @@logger.info "#{Time.now} REQUEST\n#{url}\n#{params.to_yaml}"
37
+
38
+ begin
39
+ # build & send request
40
+ uri = URI.parse(url)
41
+ req = Net::HTTP::Post.new(uri.path)
42
+
43
+ req.set_form_data(params)
44
+ req.initialize_http_header({
45
+ 'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'
46
+ })
47
+
48
+ http = Net::HTTP.new(uri.host, uri.port)
49
+ http.use_ssl = (uri.port == 443)
50
+ res = http.request(req)
51
+ rescue Exception => e
52
+ self.handle_error e
53
+ end
54
+
55
+ case res
56
+ when Net::HTTPSuccess
57
+ @@logger.info "#{Time.now} RESPONSE\n#{res.body}"
58
+ res.body
59
+ else
60
+ self.handle_error SteamFi::SteamException.new(res.inspect)
61
+ end
62
+ end
63
+
64
+ def self.handle_error(e)
65
+ @@logger.error "#{Time.now} ERROR\n#{e.message}"
66
+ raise SteamFi::SteamException.new(e.message)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,4 @@
1
+ module SteamFi
2
+ class SteamException < Exception
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module SteamFi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/steam_fi.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'steam_fi/version'
2
+ require 'steam_fi/steam_exception'
3
+ require 'steam_fi/api'
data/steam_fi.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'steam_fi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "steam_fi"
8
+ spec.version = SteamFi::VERSION
9
+ spec.authors = ["Laurynas Butkus"]
10
+ spec.email = ["laurynas.butkus@gmail.com"]
11
+ spec.summary = %q{steam.fi SMS gateway client}
12
+ spec.homepage = "https://github.com/laurynas/steam_fi"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class SteamFiTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steam_fi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Laurynas Butkus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-10 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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
+ description:
42
+ email:
43
+ - laurynas.butkus@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/steam_fi.rb
54
+ - lib/steam_fi/api.rb
55
+ - lib/steam_fi/steam_exception.rb
56
+ - lib/steam_fi/version.rb
57
+ - steam_fi.gemspec
58
+ - test/steam_fi_test.rb
59
+ - test/test_helper.rb
60
+ homepage: https://github.com/laurynas/steam_fi
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.2
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: steam.fi SMS gateway client
84
+ test_files:
85
+ - test/steam_fi_test.rb
86
+ - test/test_helper.rb
87
+ has_rdoc: