valuefirst 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/valuefirst.rb +22 -0
- data/lib/valuefirst/config.rb +23 -0
- data/lib/valuefirst/constants.rb +37 -0
- data/lib/valuefirst/valuefirst.rb +84 -0
- data/lib/valuefirst/version.rb +3 -0
- data/lib/valuefirst/xml_payload/batchtext.rb +35 -0
- data/lib/valuefirst/xml_payload/batchunicode.rb +37 -0
- data/lib/valuefirst/xml_payload/multicast_message.rb +30 -0
- data/lib/valuefirst/xml_payload/multicast_unicode.rb +31 -0
- data/lib/valuefirst/xml_payload/request_credit.rb +17 -0
- data/lib/valuefirst/xml_payload/status_request.rb +26 -0
- data/lib/valuefirst/xml_payload/text_message.rb +28 -0
- data/lib/valuefirst/xml_payload/unicode_message.rb +30 -0
- data/lib/valuefirst/xml_payload/xml_generator.rb +30 -0
- data/valuefirst.gemspec +35 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 733fc4129fe2cbc62264decde44fb8e53c439817aa3b0e2ff06cf861b53cadee
|
4
|
+
data.tar.gz: e174a47b298ca3abeca8d9f8b9dd66ec9d52e1d512938734c623edc6fa41cae2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d025849c164f38d2e3bea0c9579e43509989da9d1d2bfa4a288e08c351a0d34f9a37794f0e7b2ae296c24a8cb471f9f724b0a1bd260f47f8fc60c0180fee6699
|
7
|
+
data.tar.gz: f64bba48017c498dfb3110fd685e5a88af495946a2c9e4e135cbb650334e349dab6d13a62a05b6fd4f4087b3e01c5f4adce65ea11b29134dbe55bfa532363dd8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 spidergears
|
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,39 @@
|
|
1
|
+
# Valuefirst [![Build Status](https://travis-ci.org/spidergears/valuefirst.svg?branch=master)](https://travis-ci.org/spidergears/valuefirst) [![Coverage Status](https://coveralls.io/repos/spidergears/valuefirst/badge.svg?branch=master)](https://coveralls.io/r/spidergears/valuefirst?branch=master)
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/valuefirst`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'valuefirst'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install valuefirst
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/valuefirst/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "valuefirst"
|
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
data/lib/valuefirst.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'yaml'
|
3
|
+
require "net/http"
|
4
|
+
require 'csv'
|
5
|
+
#gems
|
6
|
+
require 'happymapper'
|
7
|
+
require 'pry'
|
8
|
+
require 'pry-nav'
|
9
|
+
require 'xml'
|
10
|
+
|
11
|
+
require "valuefirst/version"
|
12
|
+
require "valuefirst/constants"
|
13
|
+
require "valuefirst/valuefirst.rb"
|
14
|
+
require "valuefirst/xml_payload/xml_generator.rb"
|
15
|
+
require "valuefirst/xml_payload/request_credit.rb"
|
16
|
+
require "valuefirst/xml_payload/batchtext.rb"
|
17
|
+
require "valuefirst/xml_payload/text_message.rb"
|
18
|
+
require "valuefirst/xml_payload/multicast_message.rb"
|
19
|
+
require "valuefirst/xml_payload/unicode_message.rb"
|
20
|
+
require "valuefirst/xml_payload/batchunicode.rb"
|
21
|
+
require "valuefirst/xml_payload/multicast_unicode.rb"
|
22
|
+
require "valuefirst/xml_payload/status_request.rb"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Valuefirst
|
2
|
+
class Config
|
3
|
+
attr_accessor :username, :password, :default_sender, :url, :version
|
4
|
+
|
5
|
+
def initialize(opts = {})
|
6
|
+
@username = opts[:username]
|
7
|
+
@password = opts[:password]
|
8
|
+
@default_sender = opts[:default_sender]
|
9
|
+
@url = opts[:url] || "http://api.myvaluefirst.com/psms/servlet/psms.Eservice2"
|
10
|
+
@version = opts[:version] || '1.2'
|
11
|
+
end
|
12
|
+
|
13
|
+
def validate
|
14
|
+
errors = []
|
15
|
+
errors << "Invalid username" if @username.nil? || @username.empty?
|
16
|
+
errors << "Invalid password" if @password.nil? || @password.empty?
|
17
|
+
errors << "API version not supported" unless @version == '1.2'
|
18
|
+
unless errors.empty?
|
19
|
+
raise ArgumentError, "#{errors.join(', ')}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Valuefirst
|
2
|
+
module Constants
|
3
|
+
|
4
|
+
VALID_ACTIONS = %w(send status credits)
|
5
|
+
|
6
|
+
ERROR_CODES = {
|
7
|
+
'52992'=> 'Username / Password incorrect',
|
8
|
+
'57089'=> 'Contract expired',
|
9
|
+
'57090'=> 'User Credit expired',
|
10
|
+
'57091'=> 'User disabled',
|
11
|
+
'65380'=> 'Service is temporarily unavailable',
|
12
|
+
'65535'=> 'The specified message does not conform to DTD',
|
13
|
+
'28673'=> 'Destination number not numeric',
|
14
|
+
'28674'=> 'Destination number empty',
|
15
|
+
'28675'=> 'Sender address empty',
|
16
|
+
'28676'=> 'SMS over 160 character, Non-compliant message',
|
17
|
+
'28677'=> 'UDH is invalid',
|
18
|
+
'28678'=> 'Coding is invalid',
|
19
|
+
'28679'=> 'SMS text is empty',
|
20
|
+
'28680'=> 'Invalid sender ID',
|
21
|
+
'28681'=> 'Invalid message, Duplicate message, Submit failed',
|
22
|
+
'28682'=> 'Invalid Receiver ID',
|
23
|
+
'28683'=> 'Invalid Date time for message Schedule',
|
24
|
+
'8448'=> 'Message delivered successfully',
|
25
|
+
'8449'=> 'Message failed',
|
26
|
+
'8450'=> 'Message ID is invalid',
|
27
|
+
'13568'=> 'Command Completed Successfully',
|
28
|
+
'13569'=> 'Cannot update/delete schedule since it has already been processed',
|
29
|
+
'13570'=> 'Cannot update schedule since the new date-time parameter is incorrect',
|
30
|
+
'13571'=> 'Invalid SMS ID/GUID',
|
31
|
+
'13572'=> 'Invalid Status type for schedule search query. The status strings can be PROCESSED, PENDING and ERROR',
|
32
|
+
'13573'=> 'Invalid date time parameter for schedule search query',
|
33
|
+
'13574'=> 'Invalid GUID for GUID search query',
|
34
|
+
'13575'=> 'Invalid command action'
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require_relative 'config.rb'
|
2
|
+
require_relative 'valuefirst.rb'
|
3
|
+
|
4
|
+
module Valuefirst
|
5
|
+
|
6
|
+
class Valuefirst
|
7
|
+
include Constants
|
8
|
+
attr_reader :config
|
9
|
+
|
10
|
+
def initialize(opts = {}, &block)
|
11
|
+
@config = Config.new(opts)
|
12
|
+
yield(@config) if block_given?
|
13
|
+
@config.validate
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.error_desc error_code
|
17
|
+
ERROR_CODES.fetch(error_code.to_s, "Description not available")
|
18
|
+
end
|
19
|
+
|
20
|
+
def credit_request
|
21
|
+
payload = XmlPayload::RequestCredit.requestcredit @config
|
22
|
+
call_api payload, "credits"
|
23
|
+
end
|
24
|
+
|
25
|
+
def status_request guid_seq_hash
|
26
|
+
payload = XmlPayload::StatusRequest.statusrequest @config, guid_seq_hash
|
27
|
+
call_api payload, "status"
|
28
|
+
end
|
29
|
+
|
30
|
+
def send_message message_content, phone_number, sender_id = nil
|
31
|
+
payload = XmlPayload::TextMessage.textmessage @config, message_content, phone_number, sender_id
|
32
|
+
call_api payload, "send"
|
33
|
+
end
|
34
|
+
|
35
|
+
def bulksend_message file_path
|
36
|
+
raise ArgumentError, "File does not exist." unless File.exists? file_path.to_s
|
37
|
+
raise ArgumentError, "File is not readable." unless File.readable? file_path.to_s
|
38
|
+
payload = XmlPayload::Batchtext.batchtext @config, file_path
|
39
|
+
call_api payload, "send"
|
40
|
+
end
|
41
|
+
|
42
|
+
def multicast_message message_content, phone_number_array, sender_id = nil
|
43
|
+
payload = XmlPayload::MulticastMessage.multicastmessage @config, message_content, phone_number_array, sender_id
|
44
|
+
call_api payload, "send"
|
45
|
+
end
|
46
|
+
|
47
|
+
def send_unicode message_content, phone_number, sender_id = nil
|
48
|
+
payload = XmlPayload::UnicodeMessage.unicodemessage @config, message_content, phone_number, sender_id
|
49
|
+
call_api payload, "send"
|
50
|
+
end
|
51
|
+
|
52
|
+
def bulksend_unicode file_path
|
53
|
+
raise ArgumentError, "File does not exist." unless File.exists? file_path.to_s
|
54
|
+
raise ArgumentError, "File is not readable." unless File.readable? file_path.to_s
|
55
|
+
payload = XmlPayload::Batchunicode.batchunicode @config, file_path
|
56
|
+
call_api payload, "send"
|
57
|
+
end
|
58
|
+
|
59
|
+
def multicast_unicode message_content, phone_number_array, sender_id = nil
|
60
|
+
payload = XmlPayload::MulticastUnicode.multicastunicode @config, message_content, phone_number_array, sender_id
|
61
|
+
call_api payload, "send"
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def call_api payload, action
|
67
|
+
raise ArgumentError, "Invalid action" unless VALID_ACTIONS.include? action
|
68
|
+
params = {data: payload, action: action}
|
69
|
+
api_reponse = Net::HTTP.post_form(
|
70
|
+
URI.parse(@config.url),
|
71
|
+
params
|
72
|
+
)
|
73
|
+
|
74
|
+
case api_reponse
|
75
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
76
|
+
return HappyMapper.parse(api_reponse.body.downcase)
|
77
|
+
else
|
78
|
+
return api_reponse
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module XmlPayload
|
2
|
+
|
3
|
+
class Batchtext
|
4
|
+
|
5
|
+
CSV_CONFIG = {headers: true}
|
6
|
+
|
7
|
+
def self.batchtext vfirst_config, file_path
|
8
|
+
doc = XmlPayload::XmlGenerator.new_doc
|
9
|
+
message_tag = XmlPayload::XmlGenerator.create_node("MESSAGE", attributes: {"VER" => XmlPayload::VERSION})
|
10
|
+
doc.root = message_tag
|
11
|
+
user_tag = XmlPayload::XmlGenerator.user_tag vfirst_config
|
12
|
+
doc.root << user_tag
|
13
|
+
|
14
|
+
CSV.foreach(file_path.to_s, CSV_CONFIG) do |message_record|
|
15
|
+
sms_tag = XmlPayload::XmlGenerator.create_node("SMS", attributes: { "UDH" => "0",
|
16
|
+
"CODING" => "1",
|
17
|
+
"TEXT" => message_record["message_content"].to_s,
|
18
|
+
"PROPERTY" => "0",
|
19
|
+
"ID" => "1",
|
20
|
+
})
|
21
|
+
|
22
|
+
address_tag = XmlPayload::XmlGenerator.create_node("ADDRESS", attributes: { "FROM" => message_record["sender"] || vfirst_config.default_sender.to_s,
|
23
|
+
"TO" => message_record["phone_number"].to_s,
|
24
|
+
"SEQ" => "",
|
25
|
+
"TAG" => "",
|
26
|
+
})
|
27
|
+
|
28
|
+
sms_tag << address_tag
|
29
|
+
doc.root << sms_tag
|
30
|
+
end
|
31
|
+
doc
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module XmlPayload
|
2
|
+
|
3
|
+
class Batchunicode
|
4
|
+
|
5
|
+
CSV_CONFIG = {headers: true}
|
6
|
+
|
7
|
+
def self.batchunicode vfirst_config, file_path
|
8
|
+
doc = XmlPayload::XmlGenerator.new_doc
|
9
|
+
message_tag = XmlPayload::XmlGenerator.create_node("MESSAGE", attributes: {"VER" => XmlPayload::VERSION})
|
10
|
+
doc.root = message_tag
|
11
|
+
user_tag = XmlPayload::XmlGenerator.user_tag vfirst_config
|
12
|
+
doc.root << user_tag
|
13
|
+
|
14
|
+
CSV.foreach(file_path.to_s, CSV_CONFIG) do |message_record|
|
15
|
+
message_content = message_record["message_content"].to_s
|
16
|
+
sms_tag = XmlPayload::XmlGenerator.create_node("SMS", attributes: { "UDH" => "0",
|
17
|
+
"CODING" => "2",
|
18
|
+
"TEXT" => message_content.
|
19
|
+
unpack('U'*message_content.length).collect { |x| x.to_s 16 }.join,
|
20
|
+
"PROPERTY" => "0",
|
21
|
+
"ID" => "1",
|
22
|
+
})
|
23
|
+
|
24
|
+
address_tag = XmlPayload::XmlGenerator.create_node("ADDRESS", attributes: { "FROM" => message_record["sender"] || vfirst_config.default_sender.to_s,
|
25
|
+
"TO" => message_record["phone_number"].to_s,
|
26
|
+
"SEQ" => "",
|
27
|
+
"TAG" => "",
|
28
|
+
})
|
29
|
+
|
30
|
+
sms_tag << address_tag
|
31
|
+
doc.root << sms_tag
|
32
|
+
end
|
33
|
+
doc
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module XmlPayload
|
2
|
+
class MulticastMessage
|
3
|
+
def self.multicastmessage(vfirst_config, message_content, phone_number_array, sender_id = nil)
|
4
|
+
doc = XmlPayload::XmlGenerator.new_doc
|
5
|
+
message_tag = XmlPayload::XmlGenerator.create_node("MESSAGE", attributes: {"VER" => XmlPayload::VERSION})
|
6
|
+
doc.root = message_tag
|
7
|
+
user_tag = XmlPayload::XmlGenerator.user_tag vfirst_config
|
8
|
+
doc.root << user_tag
|
9
|
+
|
10
|
+
sms_tag = XmlPayload::XmlGenerator.create_node("SMS", attributes: { "UDH" => "0",
|
11
|
+
"CODING" => "1",
|
12
|
+
"TEXT" => message_content.to_s,
|
13
|
+
"PROPERTY" => "0",
|
14
|
+
"ID" => "1",
|
15
|
+
})
|
16
|
+
phone_number_array.each do |phone_number|
|
17
|
+
address_tag = XmlPayload::XmlGenerator.create_node("ADDRESS", attributes: { "FROM" => sender_id.to_s || vfirst_config.default_sender.to_s,
|
18
|
+
"TO" => phone_number.to_s,
|
19
|
+
"SEQ" => "",
|
20
|
+
"TAG" => "",
|
21
|
+
})
|
22
|
+
|
23
|
+
sms_tag << address_tag
|
24
|
+
doc.root << sms_tag
|
25
|
+
end
|
26
|
+
|
27
|
+
doc
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module XmlPayload
|
2
|
+
class MulticastUnicode
|
3
|
+
def self.multicastunicode(vfirst_config, message_content, phone_number_array, sender_id = nil)
|
4
|
+
doc = XmlPayload::XmlGenerator.new_doc
|
5
|
+
message_tag = XmlPayload::XmlGenerator.create_node("MESSAGE", attributes: {"VER" => XmlPayload::VERSION})
|
6
|
+
doc.root = message_tag
|
7
|
+
user_tag = XmlPayload::XmlGenerator.user_tag vfirst_config
|
8
|
+
doc.root << user_tag
|
9
|
+
|
10
|
+
sms_tag = XmlPayload::XmlGenerator.create_node("SMS", attributes: { "UDH" => "0",
|
11
|
+
"CODING" => "2",
|
12
|
+
"TEXT" => message_content.
|
13
|
+
unpack('U'*message_content.length).collect { |x| x.to_s 16 }.join,
|
14
|
+
"PROPERTY" => "0",
|
15
|
+
"ID" => "1",
|
16
|
+
})
|
17
|
+
phone_number_array.each do |phone_number|
|
18
|
+
address_tag = XmlPayload::XmlGenerator.create_node("ADDRESS", attributes: { "FROM" => sender_id.to_s || vfirst_config.default_sender.to_s,
|
19
|
+
"TO" => phone_number.to_s,
|
20
|
+
"SEQ" => "",
|
21
|
+
"TAG" => "",
|
22
|
+
})
|
23
|
+
|
24
|
+
sms_tag << address_tag
|
25
|
+
doc.root << sms_tag
|
26
|
+
end
|
27
|
+
|
28
|
+
doc
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'xml_generator.rb'
|
2
|
+
|
3
|
+
module XmlPayload
|
4
|
+
|
5
|
+
VERSION = "1.2"
|
6
|
+
|
7
|
+
class RequestCredit
|
8
|
+
def self.requestcredit vfirst_config
|
9
|
+
doc = XmlPayload::XmlGenerator.new_doc
|
10
|
+
#doc_type = XmlGenerator.create_node("!DOCTYPE", )
|
11
|
+
requestcredit_tag = XmlPayload::XmlGenerator.create_node("REQUESTCREDIT", attributes: {"USERNAME" => vfirst_config.username.to_s, "PASSWORD" => vfirst_config.password.to_s})
|
12
|
+
doc.root = requestcredit_tag
|
13
|
+
doc
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module XmlPayload
|
2
|
+
class StatusRequest
|
3
|
+
def self.statusrequest vfirst_config, guid_seq_hash
|
4
|
+
doc = XmlPayload::XmlGenerator.new_doc
|
5
|
+
message_tag = XmlPayload::XmlGenerator.create_node("STATUSREQUEST", attributes: {"VER" => XmlPayload::VERSION})
|
6
|
+
doc.root = message_tag
|
7
|
+
user_tag = XmlPayload::XmlGenerator.user_tag vfirst_config
|
8
|
+
doc.root << user_tag
|
9
|
+
|
10
|
+
guid_seq_hash.each do |guid, seq_list|
|
11
|
+
doc.root << guid_tag(guid, seq_list)
|
12
|
+
end
|
13
|
+
doc
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.guid_tag guid, seq_list
|
17
|
+
guid_tag = XmlPayload::XmlGenerator.create_node("GUID", attributes: {"GUID" => guid })
|
18
|
+
if !seq_list.empty?
|
19
|
+
seq_list.each do |seq|
|
20
|
+
guid_tag << XmlPayload::XmlGenerator.create_node("STATUS", attributes: {"SEQ" => seq.to_s})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
guid_tag
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module XmlPayload
|
2
|
+
class TextMessage
|
3
|
+
def self.textmessage(vfirst_config, message_content, phone_number, sender_id = nil)
|
4
|
+
doc = XmlPayload::XmlGenerator.new_doc
|
5
|
+
message_tag = XmlPayload::XmlGenerator.create_node("MESSAGE", attributes: {"VER" => XmlPayload::VERSION})
|
6
|
+
doc.root = message_tag
|
7
|
+
user_tag = XmlPayload::XmlGenerator.user_tag vfirst_config
|
8
|
+
doc.root << user_tag
|
9
|
+
|
10
|
+
sms_tag = XmlPayload::XmlGenerator.create_node("SMS", attributes: { "UDH" => "0",
|
11
|
+
"CODING" => "1",
|
12
|
+
"TEXT" => message_content.to_s,
|
13
|
+
"PROPERTY" => "0",
|
14
|
+
"ID" => "1",
|
15
|
+
})
|
16
|
+
|
17
|
+
address_tag = XmlPayload::XmlGenerator.create_node("ADDRESS", attributes: { "FROM" => sender_id || vfirst_config.default_sender.to_s,
|
18
|
+
"TO" => phone_number.to_s,
|
19
|
+
"SEQ" => "",
|
20
|
+
"TAG" => "",
|
21
|
+
})
|
22
|
+
|
23
|
+
sms_tag << address_tag
|
24
|
+
doc.root << sms_tag
|
25
|
+
doc
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module XmlPayload
|
2
|
+
class UnicodeMessage
|
3
|
+
def self.unicodemessage(vfirst_config, message_content, phone_number, sender_id = nil)
|
4
|
+
doc = XmlPayload::XmlGenerator.new_doc
|
5
|
+
message_tag = XmlPayload::XmlGenerator.create_node("MESSAGE", attributes: {"VER" => XmlPayload::VERSION})
|
6
|
+
doc.root = message_tag
|
7
|
+
user_tag = XmlPayload::XmlGenerator.user_tag vfirst_config
|
8
|
+
doc.root << user_tag
|
9
|
+
|
10
|
+
sms_tag = XmlPayload::XmlGenerator.create_node("SMS", attributes: { "UDH" => "0",
|
11
|
+
"CODING" => "2",
|
12
|
+
#16-bit unicode string
|
13
|
+
"TEXT" => message_content.
|
14
|
+
unpack('U'*message_content.length).collect { |x| x.to_s 16 }.join,
|
15
|
+
"PROPERTY" => "0",
|
16
|
+
"ID" => "1",
|
17
|
+
})
|
18
|
+
|
19
|
+
address_tag = XmlPayload::XmlGenerator.create_node("ADDRESS", attributes: { "FROM" => sender_id || vfirst_config.default_sender.to_s,
|
20
|
+
"TO" => phone_number.to_s,
|
21
|
+
"SEQ" => "",
|
22
|
+
"TAG" => "",
|
23
|
+
})
|
24
|
+
|
25
|
+
sms_tag << address_tag
|
26
|
+
doc.root << sms_tag
|
27
|
+
doc
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module XmlPayload
|
2
|
+
|
3
|
+
class XmlGenerator
|
4
|
+
def self.new_doc
|
5
|
+
doc = XML::Document.new
|
6
|
+
doc.encoding = XML::Encoding::ISO_8859_1
|
7
|
+
doc
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.add_attributes( node, attributes )
|
11
|
+
attributes.each do |name, value|
|
12
|
+
XML::Attr.new( node, name, value )
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.create_node( name, options = {} )
|
17
|
+
node = XML::Node.new( name )
|
18
|
+
|
19
|
+
attributes = options.delete( :attributes ) unless options.empty?
|
20
|
+
add_attributes( node, attributes ) if attributes
|
21
|
+
|
22
|
+
node
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.user_tag vfirst_config
|
26
|
+
XmlPayload::XmlGenerator.create_node("USER", attributes: {"USERNAME" => vfirst_config.username.to_s, "PASSWORD" => vfirst_config.password.to_s})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/valuefirst.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'valuefirst/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "valuefirst"
|
8
|
+
spec.version = Valuefirst::VERSION
|
9
|
+
spec.authors = ["spidergears"]
|
10
|
+
spec.email = ["findspidergears@gmail.com"]
|
11
|
+
|
12
|
+
if spec.respond_to?(:metadata)
|
13
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
14
|
+
end
|
15
|
+
|
16
|
+
spec.summary = "Ruby gem to communicate with valuefirst sms service provider."
|
17
|
+
spec.description = "Ruby gem to communicate with valuefirst sms service provider."
|
18
|
+
spec.homepage = "http://github.com/spidergears/valuefirst"
|
19
|
+
spec.license = "MIT"
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "nokogiri-happymapper", "~> 0.4"
|
27
|
+
spec.add_dependency "libxml-ruby", "~> 2.0"
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec-rails", "~> 3.2"
|
32
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
33
|
+
spec.add_development_dependency "pry-nav", "~> 0.2.4"
|
34
|
+
spec.add_development_dependency "coveralls", "~> 0.8"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: valuefirst
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- spidergears
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri-happymapper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: libxml-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-nav
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.2.4
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.2.4
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: coveralls
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.8'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.8'
|
125
|
+
description: Ruby gem to communicate with valuefirst sms service provider.
|
126
|
+
email:
|
127
|
+
- findspidergears@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CODE_OF_CONDUCT.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- lib/valuefirst.rb
|
143
|
+
- lib/valuefirst/config.rb
|
144
|
+
- lib/valuefirst/constants.rb
|
145
|
+
- lib/valuefirst/valuefirst.rb
|
146
|
+
- lib/valuefirst/version.rb
|
147
|
+
- lib/valuefirst/xml_payload/batchtext.rb
|
148
|
+
- lib/valuefirst/xml_payload/batchunicode.rb
|
149
|
+
- lib/valuefirst/xml_payload/multicast_message.rb
|
150
|
+
- lib/valuefirst/xml_payload/multicast_unicode.rb
|
151
|
+
- lib/valuefirst/xml_payload/request_credit.rb
|
152
|
+
- lib/valuefirst/xml_payload/status_request.rb
|
153
|
+
- lib/valuefirst/xml_payload/text_message.rb
|
154
|
+
- lib/valuefirst/xml_payload/unicode_message.rb
|
155
|
+
- lib/valuefirst/xml_payload/xml_generator.rb
|
156
|
+
- valuefirst.gemspec
|
157
|
+
homepage: http://github.com/spidergears/valuefirst
|
158
|
+
licenses:
|
159
|
+
- MIT
|
160
|
+
metadata:
|
161
|
+
allowed_push_host: https://rubygems.org
|
162
|
+
post_install_message:
|
163
|
+
rdoc_options: []
|
164
|
+
require_paths:
|
165
|
+
- lib
|
166
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
requirements: []
|
177
|
+
rubyforge_project:
|
178
|
+
rubygems_version: 2.7.3
|
179
|
+
signing_key:
|
180
|
+
specification_version: 4
|
181
|
+
summary: Ruby gem to communicate with valuefirst sms service provider.
|
182
|
+
test_files: []
|