ruby-vibe 0.0.1

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: 38ac243997c9534289e2c30281046b2e210c9e2190c10e5144378f84d33c917e
4
+ data.tar.gz: 7b5f99b1d24ef41dd60ed6b8bd07591449789fc6945d73df58d284eeb042933f
5
+ SHA512:
6
+ metadata.gz: bd56e369f03b2c0b591cdc0096c3f66c53c95feab97ef111bfcee2213ea840de40c638734df857c8d589853e1642689c73b7d8de44cd50047c073a01a1de4bf3
7
+ data.tar.gz: b65e12ff689faad07beab6ada1934f638d769913db8325cc551625d1a35ec33a9d0e38d225652b29625550b9ec46ad436dfce517a44880b6840a22444fc9138f
data/lib/ruby_vibe.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'ruby_vibe/client'
2
+ require 'ruby_vibe/calls'
3
+ require 'ruby_vibe/version'
4
+ require 'ruby_vibe/configuration'
5
+ require 'ruby_vibe/urls'
6
+
7
+ class RubyVibe
8
+
9
+ attr_accessor :client
10
+
11
+ include Calls
12
+
13
+ def initialize(auth_token: nil)
14
+ @client = Client.new(auth_token: auth_token)
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ require 'ruby_vibe/calls/info'
2
+ require 'ruby_vibe/calls/messaging'
3
+
4
+ class RubyVibe
5
+ module Calls
6
+ include Info
7
+ include Messaging
8
+ end
9
+ end
@@ -0,0 +1,37 @@
1
+ class RubyVibe
2
+ module Calls
3
+ module Info
4
+
5
+ def get_account_data
6
+ client.action(RubyVibe::URLS::GET_ACCOUNT_INFO)
7
+ end
8
+
9
+ def set_webhook(url, events: [], send_name: true, send_photo: true)
10
+ payload = {
11
+ url: url,
12
+ event_types: events,
13
+ send_name: send_name,
14
+ send_photo: send_photo
15
+ }
16
+
17
+ client.action(RubyVibe::URLS::SET_WEBHOOK, payload: payload)
18
+ end
19
+
20
+ def get_user_details(user_id)
21
+ payload = {
22
+ id: user_id
23
+ }
24
+
25
+ client.action(RubyVibe::URLS::GET_USER_DETAILS, payload: payload)
26
+ end
27
+
28
+ def get_online(ids=[])
29
+ payload = {
30
+ ids: ids
31
+ }
32
+
33
+ client.action(RubyVibe::URLS::GET_ONLINE, payload: payload)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,40 @@
1
+ class RubyVibe
2
+ module Calls
3
+ module Messaging
4
+
5
+ def send_message(receiver:, text:, sender_name: nil, sender_avatar: nil, tracking_data: nil, type: 'text', keyboard: nil)
6
+ payload = {
7
+ receiver:receiver,
8
+ sender:{
9
+ name:sender_name || RubyVibe.config.sender_name,
10
+ avatar:sender_avatar || RubyVibe.config.sender_avatar
11
+ },
12
+ tracking_data:tracking_data,
13
+ type:type,
14
+ text:text
15
+ }.compact
16
+
17
+ payload.merge!({ keyboard: keyboard }) unless keyboard.nil?
18
+
19
+ client.action(RubyVibe::URLS::MESSAGE, payload: payload)
20
+ end
21
+
22
+ def broadcast_message(broadcast_list:[], text:, sender_name: nil, sender_avatar: nil, type: 'text', rich_media: nil, keyboard: nil)
23
+ payload = {
24
+ sender:{
25
+ name: sender_name || RubyVibe.config.sender_name,
26
+ avatar: sender_avatar || RubyVibe.config.sender_avatar
27
+ },
28
+ type: type,
29
+ text: text,
30
+ broadcast_list: broadcast_list,
31
+ }
32
+
33
+ payload.merge!({ rich_media: rich_media }) unless rich_media.nil?
34
+ payload.merge!({ keyboard: keyboard }) unless keyboard.nil?
35
+
36
+ client.action(RubyVibe::URLS::BROADCAST_MESSAGE, payload: payload)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,51 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'byebug'
4
+
5
+ class RubyVibe
6
+ class Client
7
+
8
+ attr_accessor :token
9
+
10
+ def initialize(auth_token:)
11
+ RubyVibe.configure
12
+
13
+ @token = auth_token
14
+ end
15
+
16
+ def action(url, payload: {}, http_method: :post)
17
+ headers = {
18
+ 'User-Agent': "RubyVibe client v#{RubyVibe::VERSION})",
19
+ 'X-Viber-Auth-Token': token || RubyVibe.config.auth_token
20
+ }
21
+
22
+ response = ::RestClient::Request.execute(
23
+ method: http_method,
24
+ url: url,
25
+ payload: payload.to_json,
26
+ headers: headers,
27
+ timeout: 5,
28
+ verify_ssl: ::OpenSSL::SSL::VERIFY_NONE
29
+ )
30
+
31
+ return_response(response)
32
+ end
33
+
34
+ private
35
+
36
+ def return_response(response)
37
+ success = true
38
+ error_message = nil
39
+ hash = JSON.parse(response.body)
40
+
41
+ unless hash.dig('status').to_i == 0
42
+ success = false
43
+ error_message = hash.dig('status_message')
44
+ end
45
+
46
+
47
+ Struct.new(:success?, :hash, :error_message).new(success, hash, error_message)
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ class RubyVibe
2
+ class << self
3
+ # Accessor for global configuration.
4
+ attr_accessor :config
5
+ end
6
+
7
+ def self.configure
8
+ self.config ||= Configuration.new
9
+ yield(config) if block_given?
10
+ end
11
+
12
+ class Configuration
13
+ attr_accessor :auth_token, :sender_name, :sender_avatar
14
+
15
+ def initialize
16
+ @auth_token = nil
17
+ @sender_name = nil
18
+ @sender_avatar = 'http://avatar.example.com'
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ class RubyVibe
2
+ module URLS
3
+ API = 'https://chatapi.viber.com/pa'.freeze
4
+ SET_WEBHOOK = "#{API}/set_webhook".freeze
5
+ MESSAGE = "#{API}/send_message".freeze
6
+ GET_ACCOUNT_INFO = "#{API}/get_account_info".freeze
7
+ GET_USER_DETAILS = "#{API}/get_user_details".freeze
8
+ BROADCAST_MESSAGE = "#{API}/broadcast_message".freeze
9
+ GET_ONLINE = "#{API}/get_online".freeze
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ class RubyVibe
2
+ VERSION='0.0.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-vibe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adem Dinarevic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-07-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: 2.1.4
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.4
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
+ description: Ruby client for Viber API
56
+ email:
57
+ - ademdinarevic@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/ruby_vibe.rb
63
+ - lib/ruby_vibe/calls.rb
64
+ - lib/ruby_vibe/calls/info.rb
65
+ - lib/ruby_vibe/calls/messaging.rb
66
+ - lib/ruby_vibe/client.rb
67
+ - lib/ruby_vibe/configuration.rb
68
+ - lib/ruby_vibe/urls.rb
69
+ - lib/ruby_vibe/version.rb
70
+ homepage: https://github.com/ademdc/ruby-vibe
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.0.9
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Ruby client for Viber API
93
+ test_files: []