brasilfone_api 0.1.0

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: 41578249c76b016bda6604ba940bd67b558a2d03
4
+ data.tar.gz: 39f1cf13406692058a9f91cee1dff5c17f1f4703
5
+ SHA512:
6
+ metadata.gz: 51c7dc953fa3ce45fca14b456a8d20c628707dbe3ee872f308a6b7036aef4a4daf4068921948996ed42db3639c3ac33727f530930a0cf1e707bfb0d1a83f321c
7
+ data.tar.gz: e0c4cdf4fe1b6e9016fb757cd78ab284694804cebfa1ff7d7844ee64e5122f89f256e5ea4a40afa310f6b57dccea5ed92aea32735d0edbad6ae8d1a806752ab4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in brasilfone_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Victor Fonseca
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,55 @@
1
+ # BrasilfoneAPI
2
+
3
+ This gem provides a simple ruby API to communicate with Brasilfone's web API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'brasilfone_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install brasilfone_api
20
+
21
+
22
+ ## Configuring
23
+
24
+ Add your authorized credentials to BrasilfoneAPI:
25
+
26
+ ```ruby
27
+ BrasilfoneAPI.configure do |config|
28
+ config.username = 'martianbuddy'
29
+ config.password = '0508'
30
+ end
31
+ ```
32
+
33
+ Remember that you need to enable the credentials from Brasilfone's dashboard
34
+
35
+ ## Usage
36
+
37
+ Those are the methods that can be called from the module:
38
+
39
+ ```ruby
40
+ BrasilfoneAPI.send_sms('phone_number', 'message text')
41
+ BrasilfoneAPI.sms_status('sms_id')
42
+ BrasilfoneAPI.balance
43
+ BrasilfoneAPI.sms_status_by_date_range('start date', 'end date') #yyyy-mm-dd hh:mm:ss
44
+ BrasilfoneAPI.reply_status_for_sms('sms_id')
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/redealumni/brasilfone_api.
50
+
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
55
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "brasilfone_api"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'brasilfone_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "brasilfone_api"
8
+ spec.version = BrasilfoneAPI::VERSION
9
+ spec.authors = ["Victor Fonseca"]
10
+ spec.email = ["victorcel19@gmail.com"]
11
+
12
+ spec.summary = %q{Used to interface with Brasilfone's web API}
13
+ spec.description = %q{Used to interface with Brasilfone's web API}
14
+ spec.homepage = "https://github.com/redealumni/brasilfone_api"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "xmlhasher", "~> 1.0.2"
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.11"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "pry", "~> 0.10.3"
36
+ spec.add_development_dependency "webmock", "~> 1.24.1"
37
+ end
@@ -0,0 +1,21 @@
1
+ module BrasilfoneAPI
2
+ class Configuration
3
+ attr_accessor :username, :password
4
+
5
+ def self.configure
6
+ @config ||= Configuration.new
7
+ yield(@config) if block_given?
8
+ @config
9
+ end
10
+
11
+ def self.config
12
+ @config || configure
13
+ end
14
+
15
+ def self.reset
16
+ @config || configure
17
+ config.username = nil
18
+ config.password = nil
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,65 @@
1
+ module BrasilfoneAPI
2
+ module HttpAPIHandler
3
+ module ServiceURI
4
+ require 'uri'
5
+
6
+ class << self
7
+ def uri_for_service(service, parameters)
8
+ builder = URIBuilder.new(service, parameters)
9
+ builder.build
10
+ end
11
+ end
12
+
13
+ class URIBuilder
14
+ require 'brasilfone_api/http_api_handler/uri_constants'
15
+
16
+ def initialize(service, parameters)
17
+ @service = service
18
+ @parameters = parameters
19
+ end
20
+
21
+ def build
22
+ service_exists = URIConstants::SERVICES_NAMES.key?(@service)
23
+ raise 'Invalid Service' unless service_exists
24
+ @parameters.each do |param, _value|
25
+ param_exists = URIConstants::PARAMETERS_NAMES.key?(param)
26
+ raise 'Invalid Paramenters' unless param_exists
27
+ end
28
+
29
+ uri = URI(URIConstants::BRASILFONE_BASE_URI)
30
+ uri.query = uri_parameters
31
+ uri
32
+ end
33
+
34
+ private
35
+
36
+ def uri_parameters
37
+ parameters = {}
38
+ parameters.merge!(service_parameter)
39
+ parameters.merge!(credential_parameters)
40
+ parameters.merge!(other_parameters)
41
+ URI.encode_www_form(parameters)
42
+ end
43
+
44
+ def service_parameter
45
+ { service: URIConstants::SERVICES_NAMES[@service] }
46
+ end
47
+
48
+ def credential_parameters
49
+ username = BrasilfoneAPI.config.username
50
+ password = BrasilfoneAPI.config.password
51
+ { username: username, password: password }
52
+ end
53
+
54
+ def other_parameters
55
+ other_params = {}
56
+ @parameters.each do |param, value|
57
+ param_name = URIConstants::PARAMETERS_NAMES[param]
58
+ other_params[param_name] = value
59
+ end
60
+ other_params
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,23 @@
1
+ module BrasilfoneAPI
2
+ module HttpAPIHandler
3
+ module URIConstants
4
+ BRASILFONE_BASE_URI = 'http://api.brasilfone.com.br/'.freeze
5
+
6
+ SERVICES_NAMES = {
7
+ SEND_SMS: 'SendSMS'.freeze,
8
+ GET_SMS_STATUS: 'GetStatus'.freeze,
9
+ GET_BALANCE: 'GetBalance'.freeze,
10
+ GET_STATUS_BY_DATE: 'GetStatusByDate'.freeze,
11
+ GET_REPLY_STATUS: 'GetStatusResposta'.freeze
12
+ }.freeze
13
+
14
+ PARAMETERS_NAMES = {
15
+ destination: 'to'.freeze,
16
+ id: 'id'.freeze,
17
+ start_date: 'date_start'.freeze,
18
+ end_date: 'date_end'.freeze,
19
+ text: 'text'.freeze
20
+ }.freeze
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ require 'net/http'
2
+ require 'net/http'
3
+ require 'brasilfone_api/http_api_handler/service_uri'
4
+ require 'uri'
5
+ require 'xmlhasher'
6
+
7
+ module BrasilfoneAPI
8
+ module HttpAPIHandler
9
+ class << self
10
+ def send_request_for_service(service, parameters = {})
11
+ uri = BrasilfoneAPI::HttpAPIHandler::ServiceURI.uri_for_service(
12
+ service,
13
+ parameters
14
+ )
15
+
16
+ request = Net::HTTP::Get.new(uri)
17
+ response = Net::HTTP.start(uri.host, uri.port) do |http|
18
+ http.request(request)
19
+ end
20
+ XmlHasher.parse(response.body)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module BrasilfoneAPI
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'brasilfone_api/version'
2
+ require 'brasilfone_api/configuration'
3
+ require 'brasilfone_api/http_api_handler'
4
+
5
+ module BrasilfoneAPI
6
+ class << self
7
+ def configure(&block)
8
+ BrasilfoneAPI::Configuration.configure(&block)
9
+ end
10
+
11
+ def config
12
+ BrasilfoneAPI::Configuration.config
13
+ end
14
+
15
+ def send_sms(destination, text)
16
+ HttpAPIHandler.send_request_for_service(
17
+ :SEND_SMS,
18
+ destination: destination,
19
+ text: text
20
+ )
21
+ end
22
+
23
+ def sms_status(sms_id)
24
+ HttpAPIHandler.send_request_for_service(
25
+ :GET_SMS_STATUS,
26
+ id: sms_id
27
+ )
28
+ end
29
+
30
+ def balance
31
+ HttpAPIHandler.send_request_for_service(:GET_BALANCE)
32
+ end
33
+
34
+ def sms_status_by_date_range(start_date, end_date)
35
+ HttpAPIHandler.send_request_for_service(
36
+ :GET_STATUS_BY_DATE,
37
+ start_date: start_date,
38
+ end_date: end_date
39
+ )
40
+ end
41
+
42
+ def reply_status_for_sms(sms_id)
43
+ HttpAPIHandler.send_request_for_service(
44
+ :GET_SMS_STATUS,
45
+ id: sms_id
46
+ )
47
+ end
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brasilfone_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Victor Fonseca
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xmlhasher
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.24.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.24.1
97
+ description: Used to interface with Brasilfone's web API
98
+ email:
99
+ - victorcel19@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - brasilfone_api.gemspec
114
+ - lib/brasilfone_api.rb
115
+ - lib/brasilfone_api/configuration.rb
116
+ - lib/brasilfone_api/http_api_handler.rb
117
+ - lib/brasilfone_api/http_api_handler/service_uri.rb
118
+ - lib/brasilfone_api/http_api_handler/uri_constants.rb
119
+ - lib/brasilfone_api/version.rb
120
+ homepage: https://github.com/redealumni/brasilfone_api
121
+ licenses:
122
+ - MIT
123
+ metadata:
124
+ allowed_push_host: https://rubygems.org
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.5.1
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Used to interface with Brasilfone's web API
145
+ test_files: []