bot_delive 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
+ SHA256:
3
+ metadata.gz: e05b5f13355e2a00bd8ee4afde390b79817ae4d2ce4bbe571e62cc49cc8b854c
4
+ data.tar.gz: 21c53e560ad2ca8846a1dc6d6b4d9bdd8ec67b5815180fd56ae2295077bad85c
5
+ SHA512:
6
+ metadata.gz: c7f5f9d4be06d9331eca32e952d9625405f65e6f281c2866ea12f826ed2d27c56ce0319f7b6debdbe04d757ab2f44582e3970b62b527f316915415a5d1369b28
7
+ data.tar.gz: 1df6cecfac4fa81f139d868b0413ba9a7090fc9b8aa9a1d0822bafa74c9bdf3963da75de5065ff6980b0d3b9d374975fbb8a5265dbd633eab38d805297736e73
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.5
7
+ before_install: gem install bundler -v 1.16.6
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bot_delive.gemspec
6
+ gemspec
7
+ gem 'rest-client'
8
+ gem 'activesupport'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Farhad
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,73 @@
1
+ # BotDelive
2
+
3
+ **BotDelive** is a Push Notification and 2-factor authentication API service that works over the chat bots (Telegram and Messenger).
4
+
5
+ -------------
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bot_delive'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bot_delive
22
+
23
+ ## Usage
24
+ Let's require the gem first. Don't forget to define "app_id" and "secret_key"
25
+
26
+ ```ruby
27
+ require 'bot_delive'
28
+
29
+ BotDelive.configure do |config|
30
+ config.app_id = 'test_id'
31
+ config.secret_key = 'test_secret'
32
+ end
33
+ ```
34
+ **Verify the "Access Code":**
35
+
36
+ ```ruby
37
+ @response = BotDelive.verify(access_code: 'ByffboUAX')
38
+ if @response.success?
39
+ @response.payload.user_id
40
+ end
41
+ ```
42
+
43
+ **Send 2-factor authentication request (long polling):**
44
+
45
+ ```ruby
46
+ @response = BotDelive.auth(user_id: 'user-id')
47
+ if @response.success?
48
+ @response.payload.respond
49
+ end
50
+ ```
51
+
52
+ **Send Push Notification request:**
53
+
54
+ ```ruby
55
+ @response = BotDelive.push(
56
+ user_id: 'UjplD0x56P4E-Y_XsZRFM3TPivpSLWB-rqy5Y0Xv',
57
+ message: 'test message from ruby test'
58
+ )
59
+
60
+ if @response.success?
61
+ puts "push notification sent successfully"
62
+ end
63
+ ```
64
+
65
+ Documentation
66
+ -------------
67
+
68
+ Complete documentation available at: [https://botdelive.com/docs](https://botdelive.com/docs)
69
+
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bot_delive"
5
+
6
+ require "irb"
7
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bot_delive/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bot_delive"
8
+ spec.version = BotDelive::VERSION
9
+ spec.authors = ["Farhad"]
10
+ spec.email = ["farhad9801@gmail.com"]
11
+
12
+ spec.summary = %q{ A Ruby gem of BotDelive API }
13
+ spec.description = %q{BotDelive is a Push Notification and 2-factor authentication API service that works over the chat bots (Telegram and Messenger).}
14
+ spec.homepage = "https://github.com/0x2C6/botdelive-ruby"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
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_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+
30
+ spec.add_runtime_dependency "activesupport"
31
+ end
data/lib/bot_delive.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'bot_delive/version'
2
+ require 'bot_delive/configuration'
3
+ require 'bot_delive/request'
4
+ require 'bot_delive/error'
5
+ require 'active_support/core_ext/string/inflections'
6
+
7
+ module BotDelive
8
+ extend Configuration
9
+
10
+ [:verify, :auth, :push].each do |method_name|
11
+ define_singleton_method method_name do |options = {}|
12
+ raise BotDelive::Error::NullCredentialsError.new('app_id or secret_key is not defined') unless self.config
13
+ options[:app_id] = self.config.app_id
14
+ options[:secret_key] = self.config.secret_key
15
+ BotDelive::Request.send(method_name, options)
16
+ end
17
+ end
18
+ end
19
+
20
+ class Hash
21
+ def success?
22
+ return self["success"]
23
+ end
24
+
25
+ def method_missing(m, *args, &block)
26
+ return self["#{m}".camelize(:lower)]
27
+ end
28
+ end
@@ -0,0 +1,8 @@
1
+ class BotDelive::Base
2
+ attr_accessor :app_id, :secret_key
3
+
4
+ def initialize(values = {})
5
+ @app_id = values[:app_id]
6
+ @secret_key = values[:secret_key]
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ require 'bot_delive/base'
2
+
3
+ module BotDelive::Configuration
4
+ def configure
5
+ @config = BotDelive::Base.new
6
+ yield @config if block_given?
7
+ end
8
+
9
+ def config
10
+ @config if @config
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module BotDelive::Error
2
+ class NullCredentialsError < StandardError; end
3
+ end
@@ -0,0 +1,25 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+
4
+ module BotDelive::Request
5
+ BASE_API_URL = "https://botdelive.com/api"
6
+ VERIFY_URL = "#{BASE_API_URL}/verifyAC"
7
+ AUTH_URL = "#{BASE_API_URL}/sendAuth"
8
+ PUSH_URL = "#{BASE_API_URL}/sendPush"
9
+
10
+ class << self
11
+ [:verify, :auth, :push].each do |method_name|
12
+ define_method method_name do |options|
13
+ properties = Hash.new
14
+ properties["appId"] = options[:app_id]
15
+ properties["secretKey"] = options[:secret_key]
16
+ properties["accessCode"] = options[:access_code]
17
+ properties["userId"] = options[:user_id]
18
+ properties["message"] = options[:message]
19
+ response = RestClient.get Object.const_get("BotDelive::Request::#{method_name.upcase}_URL"),
20
+ {params: properties}
21
+ return JSON.parse(response)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module BotDelive
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bot_delive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Farhad
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-24 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
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: BotDelive is a Push Notification and 2-factor authentication API service
70
+ that works over the chat bots (Telegram and Messenger).
71
+ email:
72
+ - farhad9801@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - bot_delive.gemspec
87
+ - lib/bot_delive.rb
88
+ - lib/bot_delive/base.rb
89
+ - lib/bot_delive/configuration.rb
90
+ - lib/bot_delive/error.rb
91
+ - lib/bot_delive/request.rb
92
+ - lib/bot_delive/version.rb
93
+ homepage: https://github.com/0x2C6/botdelive-ruby
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.7.8
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A Ruby gem of BotDelive API
117
+ test_files: []