whathor 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c62ee953137e715320ff127ce44a903a89f6188
4
+ data.tar.gz: 36ba8b5d6141ca0dcb54d55206b6cce15cdb0e20
5
+ SHA512:
6
+ metadata.gz: f9710f9ac0ece7e50a4f6d7a3d98c94ca63234f7acae8226d43718be9c56b14e2ca6db6b1ff178122f1bddd0f52b9540e6398b70933badbbbb3f5e007fcf02ac
7
+ data.tar.gz: 30af6f21786a7319cfd866dd4e9abef72fef2a9bfb2ca691f3c7e5ab5c64fbfc2293441167da194438873f0e342ce37ae5931c10250d8bcb1663f8b3a109860b
@@ -0,0 +1,22 @@
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
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in whathor.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Larry Morales Jordan
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.
@@ -0,0 +1,39 @@
1
+ # Whathor
2
+
3
+ Whathor allows you in an easy way to send Whatsapp messages directly from your ruby app by acting
4
+ as a wrapper for Whatools Rest API. To be able to use this gem you have to register and
5
+ get a token key from [https://wha.tools](https://wha.tools/).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'whathor'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install whathor
20
+
21
+ ## Usage
22
+
23
+ There are only three easy steps for this to work:
24
+
25
+ ```ruby
26
+
27
+ # 1. Before any message is sent for the first time, you have to subscribe against Whatools Rest API
28
+ # by passing the token.
29
+ Whathor.subscribe "MY_WHATOOLS_TOKEN"
30
+
31
+ # 2. Sends a message to another whatsapp user by specifying the phone number prefixed with country code
32
+ # and body of the message.
33
+ Whathor.message to: '573001231231231', body: "This is cool! :)" # 57 = country code, 3001231231231 = Phone number
34
+
35
+ # 3. When you are done sending messages. Unsubscribe from Whatools so that further notifications and
36
+ # messages are not lost.
37
+ Whathor.unsubscribe
38
+ ```
39
+ You can read more about Whatools API specification in [https://api.wha.tools/v0](https://api.wha.tools/v0/)
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ require "whathor/version"
2
+ require 'rest_client'
3
+
4
+ module Whathor
5
+
6
+ def self.subscribe(token)
7
+ @token = token
8
+ resp = RestClient.get 'https://api.wha.tools/v0/subscribe', {params: {key: @token}} # => "{\"success\": true}"
9
+ JSON.parse(resp, symbolize_names: true)[:success]
10
+ end
11
+
12
+ def self.unsubscribe
13
+ return false if @token.nil?
14
+ resp = RestClient.get 'https://api.wha.tools/v0/unsubscribe', {params: {key: @token}} # => "{\"success\": true}"
15
+ JSON.parse(resp, symbolize_names: true)[:success]
16
+ end
17
+
18
+ def self.message(to: '', body: '')
19
+ raise ArgumentError.new("number of receiver\'s message is empty") unless !to.empty?
20
+ raise ArgumentError.new("body of message is empty") unless !body.empty?
21
+ return false if @token.nil?
22
+ resp = RestClient.post 'https://api.wha.tools/v0/message', key: @token, to: to, body: body, ack: true # => "{\"result\": \"0123456789-0\", \"success\": true}"
23
+ JSON.parse(resp, symbolize_names: true)[:success]
24
+ end
25
+
26
+ end
@@ -0,0 +1,3 @@
1
+ module Whathor
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ TOKEN = "a-s-u-b-s-c-r-i-p-t-i-o-n-t-o-k-e-n"
4
+
5
+ RSpec.describe Whathor do
6
+
7
+ context "subscription with Whatools" do
8
+ it "subscribes an API Token with whatools" do
9
+ allow(RestClient).to receive_messages(get: "{\"success\":true}")
10
+ resp = Whathor.subscribe TOKEN
11
+ expect(resp).to be_truthy
12
+ end
13
+
14
+ it "returns false when API Token is bad" do
15
+ allow(RestClient).to receive_messages(get: "{\"success\":false}")
16
+ resp = Whathor.subscribe "BADWHATOOLSTOKEN"
17
+ expect(resp).to be_falsy
18
+ end
19
+
20
+ context "Given a subscription already exists" do
21
+ before do
22
+ allow(RestClient).to receive_messages(get: "{\"success\":true}")
23
+ Whathor.subscribe TOKEN
24
+ end
25
+ it "unsubscribes with whatools" do
26
+ resp = Whathor.unsubscribe
27
+ expect(resp).to be_truthy
28
+ end
29
+ end
30
+
31
+ it "returns false when no subscription was accomplished first" do
32
+ resp = Whathor.unsubscribe
33
+ expect(resp).to be_falsy
34
+ end
35
+ end
36
+
37
+ context "send messages" do
38
+ it "raises ArgumentError when :to param is empty" do
39
+ expect{
40
+ Whathor.message(to: '')
41
+ }.to raise_error(ArgumentError)
42
+ end
43
+
44
+ it "raises ArgumentError when :body param is empty" do
45
+ expect{
46
+ Whathor.message(to: '579876543210', body: '')
47
+ }.to raise_error(ArgumentError)
48
+ end
49
+
50
+ it "returns false if no subscription was previously performed" do
51
+ resp = Whathor.message(to: '579876543210', body: 'Hello :)')
52
+ expect(resp).to be_falsy
53
+ end
54
+
55
+ it "returns true when a message was successfully sent" do
56
+ allow(RestClient).to receive_messages(get: "{\"success\":true}", post: "{\"success\":true}")
57
+ Whathor.subscribe TOKEN
58
+ resp = Whathor.message(to: '001234567890', body: 'Hello :)')
59
+ expect(resp).to be_truthy
60
+ Whathor.unsubscribe
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,93 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ require 'whathor'
20
+
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # The settings below are suggested to provide a good initial experience
46
+ # with RSpec, but feel free to customize to your heart's content.
47
+ =begin
48
+ # These two settings work together to allow you to limit a spec run
49
+ # to individual examples or groups you care about by tagging them with
50
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
51
+ # get run.
52
+ config.filter_run :focus
53
+ config.run_all_when_everything_filtered = true
54
+
55
+ # Limits the available syntax to the non-monkey patched syntax that is
56
+ # recommended. For more details, see:
57
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
58
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
59
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
60
+ config.disable_monkey_patching!
61
+
62
+ # This setting enables warnings. It's recommended, but in some cases may
63
+ # be too noisy due to issues in dependencies.
64
+ config.warnings = true
65
+
66
+ # Many RSpec users commonly either run the entire suite or an individual
67
+ # file, and it's useful to allow more verbose output when running an
68
+ # individual spec file.
69
+ if config.files_to_run.one?
70
+ # Use the documentation formatter for detailed output,
71
+ # unless a formatter has already been configured
72
+ # (e.g. via a command-line flag).
73
+ config.default_formatter = 'doc'
74
+ end
75
+
76
+ # Print the 10 slowest examples and example groups at the
77
+ # end of the spec run, to help surface which specs are running
78
+ # particularly slow.
79
+ config.profile_examples = 10
80
+
81
+ # Run specs in random order to surface order dependencies. If you find an
82
+ # order dependency and want to debug it, you can fix the order by providing
83
+ # the seed, which is printed after each run.
84
+ # --seed 1234
85
+ config.order = :random
86
+
87
+ # Seed global randomization in this process using the `--seed` CLI option.
88
+ # Setting this allows you to use `--seed` to deterministically reproduce
89
+ # test failures related to randomization by passing the same `--seed` value
90
+ # as the one that triggered the failure.
91
+ Kernel.srand config.seed
92
+ =end
93
+ end
@@ -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 'whathor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "whathor"
8
+ spec.version = Whathor::VERSION
9
+ spec.authors = ["Larry Morales Jordan"]
10
+ spec.email = ["larrymoralesjordan@gmail.com"]
11
+ spec.summary = %q{Wraper gem for your app to be able to send whatsapp meesages.}
12
+ spec.description = %q{Wraper gem fro whatools API. It helps you to send whatsapp messages from your ruby app.}
13
+ spec.homepage = "https://github.com/larrymjordan/whathor"
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.6"
22
+ spec.add_development_dependency "rake", "~> 0"
23
+ spec.add_development_dependency "rspec", '~> 3'
24
+
25
+ spec.add_runtime_dependency "rest-client", "~> 1.8"
26
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whathor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Larry Morales Jordan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-09 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
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: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ description: Wraper gem fro whatools API. It helps you to send whatsapp messages from
70
+ your ruby app.
71
+ email:
72
+ - larrymoralesjordan@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/whathor.rb
84
+ - lib/whathor/version.rb
85
+ - spec/lib/whathor_spec.rb
86
+ - spec/spec_helper.rb
87
+ - whathor.gemspec
88
+ homepage: https://github.com/larrymjordan/whathor
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Wraper gem for your app to be able to send whatsapp meesages.
112
+ test_files:
113
+ - spec/lib/whathor_spec.rb
114
+ - spec/spec_helper.rb