text_veloper 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a91e7c873564c581099299de34b2e93d49ee34b8
4
+ data.tar.gz: c19c93b5b8b9be5eb0fafce5f543e3ba7ee38dec
5
+ SHA512:
6
+ metadata.gz: bdcb8c45a43c511b930abc4e80216e45261faa4bb6b555f52dcd1faa6b6dc1a42ee3700ed5a00b8c77fd034b0bb42ee127aa14b42010798916ffd53d08f1d949
7
+ data.tar.gz: 0891c90ab4bd6d7cf092d80552168f0ceb61688efd1dd9dbc7cc05a0672ce30f64c99f37d350b6db5fa67f59803a9e523889f3a847763e177295aafb036ef4f7
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
18
+ .idea/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in text_veloper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Gerardo Barcia Palacios
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # TextVeloper
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'text_veloper'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install text_veloper
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
File without changes
@@ -0,0 +1,11 @@
1
+ module TextVeloper
2
+ module Generators
3
+ class InitializerGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def generate_initializer
7
+ copy_file "text_veloper.rb", "config/initializers/text_veloper.rb"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # For configure the tokens for textveloper gem
2
+ TextVeloper::ApiSelector.api.setup do |config|
3
+ config.token_account = "Your token account here"
4
+ config.sub_token = "Your sub token account here"
5
+ end
@@ -0,0 +1,39 @@
1
+ require 'singleton'
2
+
3
+ module TextVeloper
4
+
5
+ URL_BASE = 'http://api.textveloper.com/'
6
+
7
+ def url_base_for concat_param
8
+ URL_BASE + concat_param.to_s + "/"
9
+ end
10
+
11
+ class TextVeloperError < StandardError
12
+
13
+ attr_accessor :exception
14
+
15
+ def initialize message, exception
16
+ @exception = exception
17
+ super(message)
18
+ end
19
+
20
+ end
21
+
22
+ class ApiSelector
23
+
24
+ class << self
25
+ undef_method :new
26
+
27
+ def api
28
+ TextVeloper::Api.instance
29
+ end
30
+
31
+ def account_manager
32
+ TextVeloper::AccountManager.instance
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,3 @@
1
+ module TextVeloper
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,109 @@
1
+ require "text_veloper/version"
2
+ require 'text_veloper/util'
3
+ require 'rest_client'
4
+ require 'singleton'
5
+
6
+ module TextVeloper
7
+
8
+ class Api
9
+ include TextVeloper
10
+ include Singleton
11
+
12
+ attr_accessor :token_account, :sub_token
13
+
14
+ def initialize
15
+ @base_request_data = {
16
+ cuenta_token: "",
17
+ subcuenta_token: ""
18
+ }
19
+ end
20
+
21
+ def config_tokens_account token_account, sub_token
22
+ @base_request_data[:cuenta_token] = token_account
23
+ @base_request_data[:subcuenta_token] = sub_token
24
+ self
25
+ end
26
+
27
+ def send_message(message, phones = [])
28
+ response = {}
29
+ phones_arg = phones
30
+ phones = phones_arg.is_a?(Array) ? phones_arg : [phones_arg]
31
+ phones.each do |phone|
32
+ response = RestClient.post url_base_for('enviar'), @base_request_data.merge({telefono: phone, mensaje: message})
33
+ end
34
+ rescue => e
35
+ raise TextVeloperError.new "Problem with send message", e
36
+ ensure
37
+ return response
38
+ end
39
+
40
+ def points_query
41
+ response = RestClient.post url_base_for('historial-transferencias'), @base_request_data
42
+ rescue => e
43
+ raise TextVeloperError.new "Problem with points query", e
44
+ ensure
45
+ return response
46
+ end
47
+
48
+ def messages_records
49
+ response = RestClient.post url_base_for('historial-envios'), @base_request_data
50
+ rescue => e
51
+ raise TextVeloperError.new "Problem with message records", e
52
+ ensure
53
+ return response
54
+ end
55
+
56
+ def setup
57
+ yield self
58
+ @base_request_data = {cuenta_token: @token_account, subcuenta_token: @sub_token}
59
+ TextVeloper::ApiSelector.account_manager.token = @token_account
60
+ TextVeloper::ApiSelector.account_manager.payload = {cuenta_token: @token_account}
61
+ end
62
+
63
+ end
64
+
65
+ class AccountManager
66
+ include TextVeloper
67
+ include Singleton
68
+
69
+ attr_accessor :token, :payload, :memorizing, :sub_accounts
70
+
71
+ def initialize
72
+ @payload = {cuenta_token: ""}
73
+ @memorizing = true
74
+ @sub_accounts = {}
75
+ end
76
+
77
+ def config_token_account token_account, sub_account_record = true
78
+ @token = token_account
79
+ @payload = {cuenta_token: @token}
80
+ @memorizing = sub_account_record
81
+ @sub_accounts = {}
82
+ self
83
+ end
84
+
85
+ def sub_account_api sub_token
86
+ return TextVeloper::Api.instance.config_tokens_account @token, sub_token unless @memorizing
87
+ @sub_accounts[sub_token] = TextVeloper::Api.instance.config_tokens_account @token, sub_token unless @sub_accounts.keys.include? sub_token
88
+ @sub_accounts[sub_token]
89
+ end
90
+
91
+ def balance
92
+ response = RestClient.post url_base_for('saldo-cuenta'), @payload
93
+ rescue => e
94
+ raise TextVeloperError.new "Problem with balance", e
95
+ ensure
96
+ return response
97
+ end
98
+
99
+ def purchase_history
100
+ response = RestClient.post url_base_for('historial-compras'), @payload
101
+ rescue => e
102
+ raise TextVeloperError.new "Problem with purchase history", e
103
+ ensure
104
+ return response
105
+ end
106
+
107
+ end
108
+
109
+ end
@@ -0,0 +1,97 @@
1
+ require_relative "test_helper"
2
+
3
+ class TvAppTest < Test::Unit::TestCase
4
+
5
+ TOKEN_TEST = "Your token account here"
6
+
7
+ SUB_TOKEN_TEST = "your sub_token account here"
8
+
9
+ PHONE_NUMBERS = %W(TODO puts your array of test phone numbers)
10
+
11
+ TEXT_MESSAGE = "Message for tests sms"
12
+
13
+ SUCCESS_TV_MESSAGE = "exitosa"
14
+
15
+ SUCCESS_SEND_MESSAGE = "MENSAJE_ENVIADO"
16
+
17
+
18
+ def test_config
19
+ TextVeloper::ApiSelector.api.setup do |config|
20
+ config.token_account = TOKEN_TEST
21
+ config.sub_token = SUB_TOKEN_TEST
22
+ end
23
+ assert_equal TOKEN_TEST, TextVeloper::ApiSelector.api.token_account
24
+ assert_equal SUB_TOKEN_TEST, TextVeloper::ApiSelector.api.sub_token
25
+ assert_equal TOKEN_TEST, TextVeloper::ApiSelector.account_manager.token
26
+ end
27
+
28
+
29
+ def test_single_message_send
30
+ text_veloper = TextVeloper::ApiSelector.api
31
+ text_veloper.config_tokens_account TOKEN_TEST, SUB_TOKEN_TEST
32
+ response = text_veloper.send_message(TEXT_MESSAGE, PHONE_NUMBERS.first)
33
+ response = JSON.parse(response)
34
+ assert_equal SUCCESS_TV_MESSAGE, response["transaccion"]
35
+ assert_equal SUCCESS_SEND_MESSAGE, response["mensaje_transaccion"]
36
+ end
37
+
38
+ def test_multiple_message_send
39
+ text_veloper = TextVeloper::ApiSelector.api
40
+ text_veloper.config_tokens_account TOKEN_TEST, SUB_TOKEN_TEST
41
+ response = text_veloper.send_message(TEXT_MESSAGE, PHONE_NUMBERS)
42
+ response = JSON.parse(response)
43
+ assert_equal SUCCESS_TV_MESSAGE, response["transaccion"]
44
+ assert_equal SUCCESS_SEND_MESSAGE, response["mensaje_transaccion"]
45
+ end
46
+
47
+ def test_points_query
48
+ text_veloper = TextVeloper::ApiSelector.api
49
+ text_veloper.config_tokens_account TOKEN_TEST, SUB_TOKEN_TEST
50
+ response = JSON.parse(text_veloper.points_query)
51
+ assert_equal SUCCESS_TV_MESSAGE, response["transaccion"]
52
+ end
53
+
54
+ def test_messages_records
55
+ text_veloper = TextVeloper::ApiSelector.api
56
+ text_veloper.config_tokens_account TOKEN_TEST, SUB_TOKEN_TEST
57
+ response = JSON.parse(text_veloper.messages_records)
58
+ assert_equal SUCCESS_TV_MESSAGE, response["transaccion"]
59
+ end
60
+
61
+ def test_account_points_query
62
+ account_manager = TextVeloper::ApiSelector.account_manager
63
+ account_manager.config_token_account TOKEN_TEST
64
+ response = JSON.parse(account_manager.balance)
65
+ assert_equal SUCCESS_TV_MESSAGE, response["transaccion"]
66
+ end
67
+
68
+ def test_api_sub_account
69
+ account_manager = TextVeloper::ApiSelector.account_manager
70
+ account_manager.config_token_account TOKEN_TEST
71
+ response = JSON.parse(account_manager.purchase_history)
72
+ assert_equal SUCCESS_TV_MESSAGE, response["transaccion"]
73
+ end
74
+
75
+ def test_official_usage
76
+ account_manager = TextVeloper::ApiSelector.account_manager
77
+ account_manager.config_token_account TOKEN_TEST
78
+ sub_account = account_manager.sub_account_api SUB_TOKEN_TEST
79
+ response = sub_account.send_message TEXT_MESSAGE, PHONE_NUMBERS.first
80
+ response = JSON.parse(response)
81
+ assert_equal SUCCESS_TV_MESSAGE, response["transaccion"]
82
+ assert_equal SUCCESS_SEND_MESSAGE, response["mensaje_transaccion"]
83
+ response = sub_account.send_message TEXT_MESSAGE, PHONE_NUMBERS
84
+ response = JSON.parse(response)
85
+ assert_equal SUCCESS_TV_MESSAGE, response["transaccion"]
86
+ assert_equal SUCCESS_SEND_MESSAGE, response["mensaje_transaccion"]
87
+ response = JSON.parse(sub_account.points_query)
88
+ assert_equal SUCCESS_TV_MESSAGE, response["transaccion"]
89
+ response = JSON.parse(sub_account.messages_records)
90
+ assert_equal SUCCESS_TV_MESSAGE, response["transaccion"]
91
+ response = JSON.parse(account_manager.balance)
92
+ assert_equal SUCCESS_TV_MESSAGE, response["transaccion"]
93
+ response = JSON.parse(account_manager.purchase_history)
94
+ assert_equal SUCCESS_TV_MESSAGE, response["transaccion"]
95
+ end
96
+
97
+ end
@@ -0,0 +1,6 @@
1
+ require "test/unit"
2
+ require "json"
3
+
4
+ this_dir = File.join(File.dirname(__FILE__), "..")
5
+ $LOAD_PATH.unshift File.expand_path(this_dir)
6
+ require "text_veloper"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'text_veloper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "text_veloper"
8
+ spec.version = TextVeloper::VERSION
9
+ spec.authors = ["Gerardo Barcia Palacios"]
10
+ spec.email = ["gerardobarciap@gmail.com"]
11
+ spec.description = %q{Wrapper for Textveloper API.}
12
+ spec.summary = %q{Wrapper for Textveloper API for sending and manage SMS in Venezuela.}
13
+ spec.homepage = "https://github.com/gbarcia/rbtextveloper"
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
+ spec.add_development_dependency 'rails', '~> 3.0.9'
24
+
25
+ spec.add_runtime_dependency "rest-client"
26
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: text_veloper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gerardo Barcia Palacios
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.9
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.9
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Wrapper for Textveloper API.
70
+ email:
71
+ - gerardobarciap@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/generators/text_veloper/initialize/USAGE
82
+ - lib/generators/text_veloper/initialize/initializer_generator.rb
83
+ - lib/generators/text_veloper/initialize/templates/text_veloper.rb
84
+ - lib/text_veloper.rb
85
+ - lib/text_veloper/util.rb
86
+ - lib/text_veloper/version.rb
87
+ - test/test_application.rb
88
+ - test/test_helper.rb
89
+ - text_veloper.gemspec
90
+ homepage: https://github.com/gbarcia/rbtextveloper
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.3
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Wrapper for Textveloper API for sending and manage SMS in Venezuela.
114
+ test_files:
115
+ - test/test_application.rb
116
+ - test/test_helper.rb