voice_com 0.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in voice_com.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Tmpv
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # VoiceCom
2
+
3
+ TODO: Write a gem description
4
+
5
+ This is a simple API for working with the bulgarian VoiceCom AD service.
6
+
7
+ At this moment only usable with Rails.
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'voice_com'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install voice_com
20
+
21
+ ## Usage
22
+
23
+ After installing the gem. You have to create a configuration config/voicecom_config.yml.
24
+
25
+ A template is give in the gem's repository in templates/voicecom_config.yml.
26
+
27
+ ## Request
28
+
29
+ Creating a request object:
30
+
31
+ request = VoiceCom::Request.new request_attr
32
+
33
+ Attribute accepted by a request object:
34
+
35
+ smsid* : Unique id of the sms **message
36
+
37
+ phone* : Phone number of the receiver
38
+
39
+ text* : The sort text message of the request
40
+
41
+ op : Mobile operator, if none given it will be determined by the phone number
42
+
43
+ priority : 1 - height priority / 2 - lower priority
44
+
45
+ validity : Sets the short message validity period, default 24 hours
46
+
47
+ ** VoiceCom gem builds in an ActiveRecord instance method, with gives an unique sms id,
48
+ created from the records 'database id column' and prefixed with the uppercase letter in the ActiveRecord Class name.
49
+
50
+ The config file accepts and an addition value(sms_uniq_id_column). If given the 'uniq_sms_id' return the value in this column.
51
+
52
+ Sending the message:
53
+
54
+ request.send_message
55
+
56
+ The method returns a response string, check VoiceCom documentation for more details.
57
+
58
+ Creating a response object:
59
+
60
+ response = VoiceCom::Response.new response_attr
61
+
62
+ Attributes for creating a response object:
63
+ :sid, :dlr, :answer, :to, :from, :ts, :smsID, :voicecom_id
64
+
65
+ For more information see VoiceCom documentation.
66
+
67
+
68
+
69
+ ## Response
70
+
71
+
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ module VoiceCom
2
+ module ModelHelpers
3
+ def uniq_sms_id
4
+
5
+ if uniq_column_id
6
+ send(uniq_column_id)
7
+ else
8
+ self.class.name.gsub(/[a-z]/, "").downcase + id.to_s
9
+ end
10
+
11
+ end
12
+
13
+ def uniq_column_id
14
+ #custome column for the uniq sms id, given in the config file
15
+ #when non given uses the first 2 upcase letter of the model + 'id' column in the database
16
+
17
+ VoiceCom.config["sms_uniq_id_column"]
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ module VoiceCom
2
+ class Railtie < Rails::Railtie
3
+ initializer "voice_com.model_helpers" do
4
+ ActiveRecord::Base.send :include, ModelHelpers
5
+ end
6
+
7
+ initializer "voice_com.config_initialize" do
8
+ VoiceCom.config = YAML.load_file Rails.root.join('config', 'voicecom_config.yml').to_s
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,45 @@
1
+ require 'net/http'
2
+
3
+ module VoiceCom
4
+ class Request
5
+
6
+ attr_accessor :smsid, :phone, :text, :op, :priority, :validity
7
+
8
+ def initialize(args = {})
9
+
10
+ @main_url = VoiceCom.config["service_url"]
11
+ @sid = VoiceCom.config["sid"]
12
+
13
+ args.each {|k,v| instance_variable_set("@#{k}", v) unless k.blank?}
14
+ yield self if block_given?
15
+ validate!
16
+ end
17
+
18
+ def send_message
19
+ build_uri
20
+ responce = Net::HTTP.get URI(@request_uri)
21
+ end
22
+
23
+ def build_uri
24
+ url_string = "http://#{@main_url}?serviceID=#{@sid}&id=#{smsid}&msisdn=#{phone}&msg=#{text}"
25
+ # url_string = "http://#{@main_url}?sid=#{@sid}&id=#{smsid}&msisdn=#{phone}&text=#{text}"
26
+ url_str = addition_attr_to_uri url_string
27
+
28
+ @request_uri = URI.encode url_str
29
+ end
30
+
31
+
32
+ private
33
+
34
+ def addition_attr_to_uri(str)
35
+ str + "&" + ["op", "priority", "validity"].select{|x| instance_variable_get("@#{x}")}.map{|x| "#{x}" + "=" + instance_variable_get("@#{x}")}.join("&")
36
+ end
37
+
38
+ def validate!
39
+ [:smsid, :phone, :text].each do |sym|
40
+ raise ArgumentError, "Required attribute #{sym}" if send(sym).blank?
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,42 @@
1
+ module VoiceCom
2
+ class Response
3
+
4
+ attr_accessor :sid, :dlr, :answer, :to, :from, :ts, :smsID, :voicecom_id
5
+ attr_reader :answer_hash
6
+
7
+ def initialize(args = {})
8
+ args.each {|k,v| instance_variable_set("@#{k}", v)}
9
+ yield self if block_given?
10
+ validate!
11
+ parse_answer
12
+ end
13
+
14
+ def sms_id
15
+ @dlr
16
+ end
17
+
18
+ def parse_answer
19
+ @answer_hash = get_answer
20
+ end
21
+
22
+ def get_answer
23
+ Hash[@answer.split("+").map{|x| x.split(":")}]
24
+ end
25
+
26
+
27
+ def success?
28
+
29
+ #in que to be implemented
30
+ true
31
+
32
+ end
33
+
34
+ private
35
+
36
+ def validate!
37
+ [:sid, :dlr, :answer, :to, :from, :ts, :smsID, :voicecom_id].each do |x|
38
+ raise ArgumentError, "Request attribute #{x}" if instance_variable_get("@#{x}").blank?
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,12 @@
1
+ development:
2
+ service_url: url/given/by/the/service/provider
3
+ sid: ID/given/by/the/service/provider
4
+ sms_uniq_id_column: this is an optional configuration/see uniq_sms_id method for more details
5
+ production:
6
+ service_url: url/given/by/the/service/provider
7
+ sid: ID/given/by/the/service/provider
8
+ sms_uniq_id_column: this is an optional configuration/see uniq_sms_id method for more details
9
+ test:
10
+ service_url: url/given/by/the/service/provider
11
+ sid: ID/given/by/the/service/provider
12
+ sms_uniq_id_column: this is an optional configuration/see uniq_sms_id method for more details
@@ -0,0 +1,3 @@
1
+ module VoiceCom
2
+ VERSION = "0.0.1.1"
3
+ end
data/lib/voice_com.rb ADDED
@@ -0,0 +1,23 @@
1
+ require "voice_com/version"
2
+ require "voice_com/request"
3
+ require "voice_com/response"
4
+ require "voice_com/model_helpers"
5
+
6
+ require 'voice_com/railtie' if defined? Rails
7
+
8
+ module VoiceCom
9
+ class << self
10
+
11
+ def config=(conf)
12
+ @@config = conf
13
+ end
14
+
15
+ def config
16
+ @@config[Rails.env]
17
+ end
18
+
19
+ def uri_query_string_to_hash(uri)
20
+ Hash[uri.query.split('&').map{|x| URI.decode(x).split('=')}].symbolize_keys
21
+ end
22
+ end
23
+ end
data/voice_com.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'voice_com/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "voice_com"
8
+ spec.version = VoiceCom::VERSION
9
+ spec.authors = ["Toma"]
10
+ spec.email = ["t0ma.popov.90@gmail.com"]
11
+ spec.description = %q{API for sending sms-s}
12
+ spec.summary = %q{Simple API for working with the VoiceCom sms sending service}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: voice_com
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Toma
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: API for sending sms-s
47
+ email:
48
+ - t0ma.popov.90@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - lib/voice_com.rb
59
+ - lib/voice_com/model_helpers.rb
60
+ - lib/voice_com/railtie.rb
61
+ - lib/voice_com/request.rb
62
+ - lib/voice_com/response.rb
63
+ - lib/voice_com/templates/voicecom_config.yml
64
+ - lib/voice_com/version.rb
65
+ - voice_com.gemspec
66
+ homepage: ''
67
+ licenses:
68
+ - MIT
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ segments:
80
+ - 0
81
+ hash: -137348665721630467
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ segments:
89
+ - 0
90
+ hash: -137348665721630467
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.25
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Simple API for working with the VoiceCom sms sending service
97
+ test_files: []