viberroo 0.2.3 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fe4c409ad9d9ae8053ef0e40c5cc84c65c72336ced11df2840c056ff7742994
4
- data.tar.gz: eba48d877205587c10ca5f839efaf007f4486ca51f9ac80c47583ccd3087af37
3
+ metadata.gz: a661824a1b2c538825640dd7d42f65a8ffcf9179dc73867acd446e5f211d9958
4
+ data.tar.gz: 30f03980c6244cb6cf958b9a5bff4404deb61134163a80729c63c3c9a58754a1
5
5
  SHA512:
6
- metadata.gz: 11a9ddf29a2e0f66dd4c4d155c03e22535734c3ee5df4d70f16f806da7be0f1382f2b29df5502dd112638e3a4f14b7994ddda9fea17ffd5ccce8314384c21322
7
- data.tar.gz: 493428110e0fe5961fa02fbd3e9369b777c8ed013e447722a91701978a60691717ff7896c3f4300be1beb09db478053e07da7ac48b97b378fff8fffef346111e
6
+ metadata.gz: 2bd2f511ac9b539c6d4eb52c5bb6b2df6fc7757484af45c4594a6a5ca4ae5fd33268e3648a405b0f239ee052ad2824fc02d919e80d061dd6954f59ba40fcf222
7
+ data.tar.gz: 95cd4af8ca90022ddd501b42c3437848b1400a3a71d84793ec08e2df7c018ce3af4bbfa1ca2a26b4cd48485a4e2148ce63b9e9b811503ab55a01ce674a0dbe85
@@ -1,9 +1,8 @@
1
1
  require 'json'
2
- require 'faraday'
3
2
  require 'viberroo/configuration'
4
3
  require 'viberroo/message'
5
4
  require 'viberroo/input'
6
- require 'viberroo/callback'
5
+ require 'viberroo/response'
7
6
  require 'viberroo/bot'
8
7
  require 'logger'
9
8
 
@@ -1,8 +1,9 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
1
4
  module Viberroo
2
5
  class Bot
3
- def initialize(token: nil, response: nil, callback: nil)
4
- warn 'DEPRECATION WARNING: callback Viberroo::Bot.new `callback:` parameter will be renamed to `response:` in next minor release.' if callback
5
-
6
+ def initialize(token: nil, response: nil)
6
7
  Viberroo.configure
7
8
 
8
9
  @headers = {
@@ -10,7 +11,6 @@ module Viberroo
10
11
  'Content-Type': 'application/json'
11
12
  }
12
13
  @response = response
13
- @callback = callback
14
14
  end
15
15
 
16
16
  def set_webhook(url:, event_types: nil, send_name: nil, send_photo: nil)
@@ -18,75 +18,48 @@ module Viberroo
18
18
  send_name: send_name, send_photo: send_photo)
19
19
  end
20
20
 
21
- def set_webhook!(url:, event_types: nil, send_name: nil, send_photo: nil)
22
- parse set_webhook(url: url, event_types: event_types,
23
- send_name: send_name, send_photo: send_photo)
24
- end
25
-
26
21
  def remove_webhook
27
22
  request(URL::WEBHOOK, url: '')
28
23
  end
29
24
 
30
- def remove_webhook!
31
- parse remove_webhook
32
- end
33
-
34
25
  def send(message:, keyboard: {})
35
26
  request(URL::MESSAGE,
36
- { receiver: @response&.user_id || @callback&.user_id }.merge(message).merge(keyboard))
37
- end
38
-
39
- def send!(message:, keyboard: {})
40
- parse self.send(message: message, keyboard: keyboard)
27
+ { receiver: @response&.user_id }.merge(message).merge(keyboard))
41
28
  end
42
29
 
43
30
  def broadcast(message:, to:)
44
31
  request(URL::BROADCAST_MESSAGE, message.merge(broadcast_list: to))
45
32
  end
46
33
 
47
- def broadcast!(message:, to:)
48
- parse broadcast(message: message, to: to)
49
- end
50
-
51
34
  def get_account_info
52
35
  request(URL::GET_ACCOUNT_INFO)
53
36
  end
54
37
 
55
- def get_account_info!
56
- parse get_account_info
57
- end
58
-
59
38
  def get_user_details(id:)
60
39
  request(URL::GET_USER_DETAILS, id: id)
61
40
  end
62
41
 
63
- def get_user_details!(id:)
64
- parse get_user_details(id: id)
65
- end
66
-
67
42
  def get_online(ids:)
68
43
  request(URL::GET_ONLINE, ids: ids)
69
44
  end
70
45
 
71
- def get_online!(ids:)
72
- parse get_online(ids: ids)
73
- end
74
-
75
46
  private
76
47
 
77
48
  def request(url, params = {})
78
- response = Faraday.post(url, compact(params).to_json, @headers)
49
+ uri = URI(url)
50
+
51
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
52
+ request = Net::HTTP::Post.new(uri, @headers)
53
+ request.body = compact(params).to_json
54
+
55
+ http.request(request)
56
+ end
79
57
 
80
58
  Viberroo.config.logger&.info("##{caller_name} -- #{response.body}")
81
59
 
82
60
  Viberroo.config.parse_response_body ? JSON.parse(response.body) : response
83
61
  end
84
62
 
85
- def parse(request)
86
- warn 'DEPRECATION WARNING: Viberroo::Bot bang methods will be dropped on next minor release. Use Viberroo.config.parse_response_body.'
87
- JSON.parse(request.body)
88
- end
89
-
90
63
  def compact(params)
91
64
  params.delete_if { |_, v| v.nil? }
92
65
  end
@@ -1,7 +1,7 @@
1
1
  require 'recursive-open-struct'
2
2
 
3
3
  module Viberroo
4
- class Callback
4
+ class Response
5
5
  attr_reader :params
6
6
 
7
7
  def initialize(params)
@@ -1,3 +1,3 @@
1
1
  module Viberroo
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viberroo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Habchak
@@ -10,20 +10,6 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: faraday
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 1.0.0
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.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: recursive-open-struct
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -46,10 +32,10 @@ extra_rdoc_files: []
46
32
  files:
47
33
  - lib/viberroo.rb
48
34
  - lib/viberroo/bot.rb
49
- - lib/viberroo/callback.rb
50
35
  - lib/viberroo/configuration.rb
51
36
  - lib/viberroo/input.rb
52
37
  - lib/viberroo/message.rb
38
+ - lib/viberroo/response.rb
53
39
  - lib/viberroo/version.rb
54
40
  homepage: https://github.com/vikdotdev/viberroo
55
41
  licenses:
@@ -73,5 +59,5 @@ requirements: []
73
59
  rubygems_version: 3.0.3
74
60
  signing_key:
75
61
  specification_version: 4
76
- summary: Viber bot for Ruby.
62
+ summary: Viber bot for Ruby / Rails.
77
63
  test_files: []