zenvia 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: d477e08cafc18b358e582f3788a8a59302df4eb3
4
+ data.tar.gz: 56619eb2c81847d605e00cdccb94b1bcdd13ce6e
5
+ SHA512:
6
+ metadata.gz: 045e56f661d29a816c75b8cbd9c56eac3793964646197daba33c2f4c13c6112811f8ab29af309c3e3a1f339fe5da6972df71e2a545f6930d9a5d81613d2b74dd
7
+ data.tar.gz: d9aabb44dcd305f1a151fca33f19cba0dd4870786ec93ed4d5047b642e03fa46673180693e65cf74cd31c2ec543d15bb6ccee7c12ac95e4a644fdc15e51ed369
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
15
+ *.sw[nop]
16
+ .azk
17
+ bin
18
+ .env
data/Azkfile.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Documentation: http://docs.azk.io/Azkfile.js
3
+ */
4
+
5
+ // Adds the systems that shape your system
6
+ systems({
7
+ zenvia: {
8
+ depends : [],
9
+ image : "dynaum/ruby-bundler-node",
10
+ provision : [ "bundle install --binstubs --path /azk/bundler", ],
11
+ workdir : "/azk/#{manifest.dir}",
12
+ command : "bundle exec rackup config.ru --port $HTTP_PORT",
13
+ envs : { RUBY_ENV: "dev", },
14
+ mounts : {
15
+ '/azk/#{manifest.dir}' : path("."),
16
+ "/azk/bundler" : persistent("bundler-#{system.name}")
17
+ },
18
+ },
19
+ });
20
+
21
+
22
+
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rspec' , '~> 2.14.1'
7
+ gem 'webmock' , '~> 1.18.0'
8
+ gem 'vcr' , '~> 2.8.0'
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
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,59 @@
1
+ # Zenvia
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'zenvia'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install zenvia
20
+
21
+ ## Usage
22
+
23
+ ### Sending a message
24
+
25
+ ```ruby
26
+ sms = Zenvia::Sms.new 'number', 'message'
27
+ sms.send
28
+ ```
29
+
30
+ ## Config
31
+
32
+ ```ruby
33
+ Zenvia.configure do |config|
34
+ config.account = ENV["ZENVIA_ACCOUNT"]
35
+ config.code = ENV["ZENVIA_CODE"]
36
+ end
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it ( https://github.com/parafuzo/zenvia/fork )
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create a new Pull Request
46
+
47
+ ## Azk
48
+
49
+ ### Install azk
50
+
51
+ ### Bundle Install
52
+ ```shell
53
+ azk shell -c "bundle install --binstubs --path /azk/bundler"
54
+ ```
55
+
56
+ ### Test
57
+ ```shell
58
+ azk shell -c "bundle exec rspec"
59
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,11 @@
1
+ module Zenvia
2
+ class Config
3
+ include Singleton
4
+
5
+ attr_accessor :account, :code, :timeout
6
+
7
+ def timeout
8
+ @timeout || 10
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module Zenvia
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,44 @@
1
+ module Zenvia
2
+ class Request
3
+ BASE_URL = "http://www.zenvia360.com.br"
4
+ POST_PATH = "/GatewayIntegration/msgSms.do"
5
+
6
+ attr_reader :params, :response
7
+
8
+ def initialize
9
+ session.base_url = BASE_URL
10
+ session.timeout = Zenvia.config.timeout
11
+ end
12
+
13
+ def post(params)
14
+ @params = params
15
+ @response = session.post POST_PATH, parse_params
16
+
17
+ parse_response
18
+ end
19
+
20
+ private
21
+
22
+ def parse_response
23
+ code, message = response.body.split " - "
24
+ raise Error, message if code != "000"
25
+
26
+ {code: code, message: message}
27
+ end
28
+
29
+ def parse_params
30
+ {
31
+ account: Zenvia.config.account,
32
+ code: Zenvia.config.code,
33
+ dispatch: params[:dispatch],
34
+ to: params[:to],
35
+ msg: params[:message],
36
+ id: params[:id]
37
+ }
38
+ end
39
+
40
+ def session
41
+ @session ||= Patron::Session.new
42
+ end
43
+ end
44
+ end
data/lib/zenvia/sms.rb ADDED
@@ -0,0 +1,32 @@
1
+ module Zenvia
2
+ class Sms
3
+ attr_accessor :to, :message, :dispatch, :message_id
4
+
5
+ def initialize(to, message)
6
+ @to, @message = to, message
7
+ end
8
+
9
+ def send
10
+ request.post post_params
11
+ end
12
+
13
+ def dispatch
14
+ @dispatch || :send
15
+ end
16
+
17
+ private
18
+
19
+ def post_params
20
+ {
21
+ to: to,
22
+ message: message,
23
+ dispatch: dispatch,
24
+ id: message_id
25
+ }.delete_if { |k,v| v.nil? }
26
+ end
27
+
28
+ def request
29
+ @request ||= Request.new
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Zenvia
2
+ VERSION = "0.0.1"
3
+ end
data/lib/zenvia.rb ADDED
@@ -0,0 +1,19 @@
1
+ $:.unshift File.expand_path('../lib', __dir__)
2
+
3
+ require 'patron'
4
+
5
+ module Zenvia
6
+ def self.config
7
+ Config.instance
8
+ end
9
+
10
+ def self.configure(&block)
11
+ block.call(self.config)
12
+ end
13
+
14
+ autoload :Config , 'zenvia/config'
15
+ autoload :Error , 'zenvia/error'
16
+ autoload :Request , 'zenvia/request'
17
+ autoload :Sms , 'zenvia/sms'
18
+ autoload :Version , 'zenvia/version'
19
+ end
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://www.zenvia360.com.br/GatewayIntegration/msgSms.do
6
+ body:
7
+ encoding: ASCII-8BIT
8
+ string: account=parafuzo&code=58FfZ912P9&dispatch=send&to=5511971889422&msg=Message%20sent%20by%20parafuzo.com&id=42
9
+ headers:
10
+ Content-Type:
11
+ - application/x-www-form-urlencoded
12
+ Expect:
13
+ - ''
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Server:
20
+ - Apache-Coyote/1.1
21
+ X-Powered-By:
22
+ - 'Servlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)/JBossWeb-2.0'
23
+ Set-Cookie:
24
+ - JSESSIONID=2898F8FE1673042C97DCD45CF92F6E60.node42; Path=/
25
+ Content-Type:
26
+ - text/plain;charset=ISO-8859-1
27
+ Content-Length:
28
+ - '18'
29
+ Date:
30
+ - Mon, 10 Nov 2014 18:56:38 GMT
31
+ body:
32
+ encoding: ASCII-8BIT
33
+ string: 000 - Message Sent
34
+ http_version:
35
+ recorded_at: Fri, 07 Nov 2014 03:50:46 GMT
36
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://www.zenvia360.com.br/GatewayIntegration/msgSms.do
6
+ body:
7
+ encoding: ASCII-8BIT
8
+ string: account=parafuzo&code=58FfZ912P9&dispatch=send&to=5511971889422&msg=&id=42
9
+ headers:
10
+ Content-Type:
11
+ - application/x-www-form-urlencoded
12
+ Expect:
13
+ - ''
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Server:
20
+ - Apache-Coyote/1.1
21
+ X-Powered-By:
22
+ - 'Servlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)/JBossWeb-2.0'
23
+ Set-Cookie:
24
+ - JSESSIONID=834435163BCA2AC65D1CBB032A1A9790.node42; Path=/
25
+ Content-Type:
26
+ - text/plain;charset=ISO-8859-1
27
+ Content-Length:
28
+ - '27'
29
+ Date:
30
+ - Mon, 10 Nov 2014 18:56:38 GMT
31
+ body:
32
+ encoding: ASCII-8BIT
33
+ string: 010 - Empty message content
34
+ http_version:
35
+ recorded_at: Fri, 07 Nov 2014 03:50:47 GMT
36
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,22 @@
1
+ ENV["RACK_ENV"] = 'test'
2
+
3
+ require_relative '../lib/zenvia'
4
+
5
+ require 'vcr'
6
+
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = File.join(__dir__, "fixtures/vcr_cassettes")
9
+ c.hook_into :webmock
10
+ c.ignore_hosts '127.0.0.1'
11
+ end
12
+
13
+ RSpec.configure do |config|
14
+ config.color = true
15
+ config.tty = true
16
+ config.order = "random"
17
+ end
18
+
19
+ Zenvia.configure do |config|
20
+ config.account = ENV["ZENVIA_ACCOUNT"]
21
+ config.code = ENV["ZENVIA_CODE"]
22
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zenvia::Request do
4
+ describe "#post" do
5
+ let(:params) { {
6
+ to: '5511971889422',
7
+ message: "Message sent by parafuzo.com",
8
+ dispatch: :send,
9
+ id: "42"
10
+ } }
11
+
12
+ def do_post
13
+ subject.post params
14
+ end
15
+
16
+ it "should return a parsed response" do
17
+ VCR.use_cassette('zenvia_request') do
18
+ response = do_post
19
+
20
+ response[:code].should eq "000"
21
+ response[:message].should eq "Message Sent"
22
+ end
23
+ end
24
+
25
+ context "when an error occurs" do
26
+ let(:params) { {
27
+ to: '5511971889422',
28
+ dispatch: :send,
29
+ id: "42"
30
+ } }
31
+
32
+ it "should raise an exception" do
33
+ VCR.use_cassette('zenvia_request_error') do
34
+ expect { do_post }.to raise_error Zenvia::Error, 'Empty message content'
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zenvia::Sms do
4
+ describe "#send" do
5
+ let(:request_mock) { double post: true }
6
+
7
+ subject { described_class.new :number, :message }
8
+
9
+ before do
10
+ Zenvia::Request.stub(:new).and_return request_mock
11
+ end
12
+
13
+ it "should call request with correct params" do
14
+ request_mock.should_receive(:post).with({
15
+ to: :number, message: :message, dispatch: :send
16
+ })
17
+
18
+ subject.send
19
+ end
20
+
21
+ context "when there is a message id" do
22
+ it "should send id" do
23
+ request_mock.should_receive(:post).with({
24
+ to: :number, message: :message, dispatch: :send, id: 'message id'
25
+ })
26
+
27
+ subject.message_id = 'message id'
28
+ subject.send
29
+ end
30
+ end
31
+ end
32
+ end
data/zenvia.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zenvia/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "zenvia"
8
+ spec.version = Zenvia::VERSION
9
+ spec.authors = ["Parafuzo Core Team"]
10
+ spec.email = ["dev@parafuzo.com"]
11
+ spec.summary = %q{Zenvia Ruby Library}
12
+ spec.description = %q{Ruby version API to send sms with Zenvia}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.7"
22
+ spec.add_development_dependency "rake" , "~> 10.0"
23
+ spec.add_development_dependency "patron" , "~> 0.4.18"
24
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zenvia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Parafuzo Core Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-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
+ - !ruby/object:Gem::Dependency
42
+ name: patron
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.18
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.18
55
+ description: Ruby version API to send sms with Zenvia
56
+ email:
57
+ - dev@parafuzo.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Azkfile.js
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/zenvia.rb
69
+ - lib/zenvia/config.rb
70
+ - lib/zenvia/error.rb
71
+ - lib/zenvia/request.rb
72
+ - lib/zenvia/sms.rb
73
+ - lib/zenvia/version.rb
74
+ - spec/fixtures/vcr_cassettes/zenvia_request.yml
75
+ - spec/fixtures/vcr_cassettes/zenvia_request_error.yml
76
+ - spec/spec_helper.rb
77
+ - spec/zenvia/request_spec.rb
78
+ - spec/zenvia/sms_spec.rb
79
+ - zenvia.gemspec
80
+ homepage: ''
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.2.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Zenvia Ruby Library
104
+ test_files:
105
+ - spec/fixtures/vcr_cassettes/zenvia_request.yml
106
+ - spec/fixtures/vcr_cassettes/zenvia_request_error.yml
107
+ - spec/spec_helper.rb
108
+ - spec/zenvia/request_spec.rb
109
+ - spec/zenvia/sms_spec.rb