viberroo 0.0.2 → 0.0.7

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: 2409b9e53d6abf7e9b7c8e8278c2612748b509d0dfc87835bd975d7c8d6cc45e
4
- data.tar.gz: 6864f673f4663907e2ee0bd63060290f6dc3ee8e84e1afceec6048543108dde0
3
+ metadata.gz: ffd5dd8c29342acd993ed001e8957b006e7e74e82ee7f64f887b9fe7dd4cb42c
4
+ data.tar.gz: f1febbae3bf056dd257c726f794f1124efc3f20ac41014dbddb95ade90408d54
5
5
  SHA512:
6
- metadata.gz: b061bfa854f9d63368dba3f3446927542c568ec24d241cde30b70d27873358d86bb381608d7b2ee1933d86599338852cea2bb72f826414e94ed5357f927f1e7c
7
- data.tar.gz: 45dd3f7274232324d2834a669265c68d46e812f1a7e919603e7db320f1284d3189ab35ee281c7f9548516b2f4412aed23d66d6f26fa42469e38465532ac8f77b
6
+ metadata.gz: 1e9ffcebd82b968bb287484553170dbce430b036c9580fedec698540ab63738bb1c5b187d46765c5f5e96ab1b39151efaffcdb4625050157c9d429f1085944ab
7
+ data.tar.gz: cc2ca4deb311c1cce8b294f4fdcb3be3c4e67b2ce3a7818ca2afb6b9847764d51a8c7df6c3b5c3c6915a31712f884cd44a5326488c8c1faeef2d03f2a3b757da
@@ -1,12 +1,11 @@
1
1
  require 'json'
2
2
  require 'faraday'
3
- require 'message'
4
- require 'bot'
5
- require 'input'
6
- require 'user'
7
- require 'bot'
3
+ require 'viberroo/message'
4
+ require 'viberroo/bot'
5
+ require 'viberroo/input'
6
+ require 'viberroo/response'
7
+ require 'viberroo/bot'
8
8
 
9
9
  module Viberroo
10
- API_URL = 'https://chatapi.viber.com/pa'
11
- VERSION = '0.0.2'
10
+ API_URL = 'https://chatapi.viber.com/pa'.freeze
12
11
  end
@@ -0,0 +1,16 @@
1
+ module Viberroo
2
+ class Bot
3
+ include Message
4
+
5
+ def initialize(token:, response: {})
6
+ @webhook_url = "#{API_URL}/set_webhook"
7
+ @message_url = "#{API_URL}/send_message"
8
+ @headers = { 'X-Viber-Auth-Token': token, 'Content-Type': 'application/json' }
9
+ @response = response
10
+ end
11
+
12
+ def set_webhook(params)
13
+ Faraday.post(@webhook_url, params.to_json, @headers)
14
+ end
15
+ end
16
+ end
@@ -15,6 +15,12 @@ module Viberroo
15
15
  }.merge(params)
16
16
  end
17
17
 
18
+ def self.share_phone(params = {})
19
+ { ActionType: 'share-phone',
20
+ min_api_version: 3
21
+ }.merge(params)
22
+ end
23
+
18
24
  def self.none(params = {})
19
25
  { ActionType: 'none' }.merge(params)
20
26
  end
@@ -0,0 +1,65 @@
1
+ module Viberroo
2
+ module Message
3
+ # TODO: add list of params that is mandatory for particular message type,
4
+ # throw exceptions and log errors if not found
5
+
6
+ # required params = text
7
+ def send_message(params = {})
8
+ dispatch({ type: :text }.merge(params))
9
+ end
10
+
11
+ def send_rich_media(params = {})
12
+ dispatch({ type: :rich_media, min_api_version: 2 }.merge(params))
13
+ end
14
+
15
+ # required params = location.lat, location.lon
16
+ def send_location(params = {})
17
+ dispatch({ type: :location, min_api_version: 3 }.merge(params))
18
+ end
19
+
20
+ # required params = text, media
21
+ def send_picture(params = {})
22
+ dispatch({ type: :picture }.merge(params))
23
+ end
24
+
25
+ # required params = text, media
26
+ def send_video(params = {})
27
+ dispatch({ type: :video }.merge(params))
28
+ end
29
+
30
+ # required params = media, size, file_name
31
+ def send_file(params = {})
32
+ dispatch({ type: :file }.merge(params))
33
+ end
34
+
35
+ # required params = contact, contact.name, contact.phone_number
36
+ def send_contact(params = {})
37
+ dispatch({ type: :contact }.merge(params))
38
+ end
39
+
40
+ # required params = media
41
+ def send_url(params = {})
42
+ dispatch({ type: :url }.merge(params))
43
+ end
44
+
45
+ # required params = sticker_id
46
+ # https://viber.github.io/docs/tools/sticker-ids/
47
+ def send_sticker(params = {})
48
+ dispatch({ type: :sticker }.merge(params))
49
+ end
50
+
51
+ private
52
+
53
+ def dispatch(params)
54
+ Faraday.post(
55
+ @message_url,
56
+ normalize({ receiver: @response.user_id }.merge(params)),
57
+ @headers
58
+ )
59
+ end
60
+
61
+ def normalize(params)
62
+ params.delete_if { |_, v| v.nil? }.to_json
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,26 @@
1
+ require 'recursive-open-struct'
2
+
3
+ module Viberroo
4
+ class Response
5
+ class << self
6
+ def init(params)
7
+ @@os = RecursiveOpenStruct.new params.to_h
8
+ @@os.user_id = user_id
9
+ @@os
10
+ end
11
+
12
+ private
13
+
14
+ def user_id
15
+ case @@os.event
16
+ when 'conversation_started', 'subscribed'
17
+ @@os.user.id
18
+ when 'unsubscribed', 'delivered', 'seen', 'failed'
19
+ @@os.user_id
20
+ when 'message'
21
+ @@os.sender.id
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Viberroo
2
+ VERSION = '0.0.7'.freeze
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.0.2
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Habchak
@@ -44,11 +44,12 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
- - lib/bot.rb
48
- - lib/input.rb
49
- - lib/message.rb
50
- - lib/user.rb
51
47
  - lib/viberroo.rb
48
+ - lib/viberroo/bot.rb
49
+ - lib/viberroo/input.rb
50
+ - lib/viberroo/message.rb
51
+ - lib/viberroo/response.rb
52
+ - lib/viberroo/version.rb
52
53
  homepage: https://github.com/vikdotdev/viberroo
53
54
  licenses:
54
55
  - MIT
@@ -71,5 +72,5 @@ requirements: []
71
72
  rubygems_version: 3.1.2
72
73
  signing_key:
73
74
  specification_version: 4
74
- summary: Thin Viber REST API wrapper for ruby.
75
+ summary: Thin Viber REST API wrapper for Ruby.
75
76
  test_files: []
data/lib/bot.rb DELETED
@@ -1,16 +0,0 @@
1
- module Viberroo
2
- class Bot
3
- include Message
4
-
5
- def initialize(token:, user: {})
6
- @webhook_url = "#{API_URL}/set_webhook"
7
- @message_url = "#{API_URL}/send_message"
8
- @header = { 'X-Viber-Auth-Token': token }
9
- @user = user
10
- end
11
-
12
- def set_webhook(params)
13
- Faraday.post(@webhook_url, params.to_json, @header)
14
- end
15
- end
16
- end
@@ -1,37 +0,0 @@
1
- module Viberroo
2
- module Message
3
- def send_message(params = {})
4
- dispatch({
5
- type: :text
6
- }.merge(params))
7
- end
8
-
9
- def send_rich_media(params = {})
10
- dispatch({
11
- type: :rich_media,
12
- min_api_version: 2
13
- }.merge(params))
14
- end
15
-
16
- def send_location(params = {})
17
- dispatch({
18
- type: :location,
19
- min_api_version: 3
20
- }.merge(params))
21
- end
22
-
23
- private
24
-
25
- def dispatch(params)
26
- Faraday.post(
27
- @message_url,
28
- normalize({ receiver: @user.id }.merge(params)),
29
- @header
30
- )
31
- end
32
-
33
- def normalize(params)
34
- params.delete_if { |_, v| v.nil? }.to_json
35
- end
36
- end
37
- end
@@ -1,9 +0,0 @@
1
- require 'recursive-open-struct'
2
-
3
- module Viberroo
4
- class Response
5
- def self.init(params)
6
- RecursiveOpenStruct.new params
7
- end
8
- end
9
- end