Skip to content

Commit

Permalink
Merge pull request #19 from vikdotdev/v0.3.4-patch
Browse files Browse the repository at this point in the history
fix Bot#initialize, deprecate Bot#send
  • Loading branch information
vikdotdev authored Jul 3, 2022
2 parents 8bd69b9 + 3dc6ff2 commit 301ced4
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 31 deletions.
49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Changelog

This project partially adheres to [semver
2.0.0](http://semver.org/spec/v2.0.0.html) with the exception that breaking
changes can be introduced on MINOR level up until v1.0.0. It also follows the
recommendations of [keepachangelog.com](http://keepachangelog.com/).

## Unreleased

### Breaking Changes
- Rename config to configuration

### Added
- None

### Fixed
- None

### Changed
- None

### Removed
- None

### Security
- None

### Deprecated
- None

## v0.3.4
Start a changelog.

### Breaking Changes
- None

### Fixed
- Add empty default `Viberroo::Response` instance to `Viberroo::Bot` constructor to avoid setting redundant objects during webhook subscription phase e.g. `Viberro::Bot.new(response: Viberroo::Response.new({})).set_webhook` becomes `Viberro::Bot.new.set_webhook`.
- Fix Ruby version compatibility from `2.4` to correctly specified `2.3`.

### Deprecated
- Deprecate `Bot#send`. Will get replaced by `Bot#send_message` in next minor release.

### Added
- Add `Bot#send_message` that acts same as `Bot#send`.

### Removed
- Logger entry for every `Bot` request that had no configuration options.

2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
viberroo (0.3.2)
viberroo (0.3.4)
recursive-open-struct (~> 1.1.1)

GEM
Expand Down
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This Viber bot is a thin wrapper for Viber REST API, written in Ruby. It uses mo
Add this line to your application's Gemfile:

```ruby
gem 'viberroo', '~> 0.3.3'
gem 'viberroo', '~> 0.3.4'
```

And then execute:
Expand Down Expand Up @@ -176,22 +176,6 @@ release a new version, update the version number in `version.rb`, create a tag
for a new version, and then merge to master, GitHub actions will take care of running specs and pushing to [rubygems.org](https://rubygems.org).


## TODO
* change method signatures:
* set_webhook -> make false as default value for send_name and send_photo
* send -> keyboard to nil
* remove safe navigation to extend ruby version compatibility
* location_button -> change to simple lon:, lat: params
* picture_message -> change to url:, text: nil, thumbnail: nil
* video_message -> change to url:, size:, duration: nil, thumbnail: nil
* file_message -> change url:, size:, name:
* contact message -> change name:, phone:
* url_message -> change to single unnamed parameter
* sticker_message -> change to id:
* rich_media_message -> change to columns:, rows:, buttons:, alt: nil
* rename config to configuration


## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/vikdotdev/viberroo.

Expand Down
21 changes: 14 additions & 7 deletions lib/viberroo/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Bot
# @see Configuration
# @see https://developers.viber.com/docs/api/rest-bot-api/#authentication-token
#
def initialize(response:, token: nil)
def initialize(response: Response.new({}), token: nil)
Viberroo.configure

@headers = {
Expand Down Expand Up @@ -65,7 +65,7 @@ def initialize(response:, token: nil)
#
def set_webhook(url:, event_types: nil, send_name: nil, send_photo: nil)
request(URL::WEBHOOK, url: url, event_types: event_types,
send_name: send_name, send_photo: send_photo)
send_name: send_name, send_photo: send_photo)
end

##
Expand Down Expand Up @@ -140,9 +140,18 @@ def remove_webhook
# @see https://viber.github.io/docs/tools/keyboards/#buttons-parameters
# @see https://developers.viber.com/docs/api/rest-bot-api/#keyboards
#
def send_message(message, keyboard: {})
request(URL::MESSAGE, { receiver: @response.user_id }.merge(message, keyboard))
end

# @deprecated Use {#send_message} instead.
def send(message:, keyboard: {})
request(URL::MESSAGE,
{ receiver: @response&.user_id }.merge(message).merge(keyboard))
Viberroo.config.logger.info(<<~WARNING)
DEPRECATION WARNING: Bot#send method is going to be removed in the next
minor release. Use Bot#send_message instead.
WARNING

send_message(message, keyboard: keyboard)
end

##
Expand Down Expand Up @@ -204,7 +213,7 @@ def get_user_details(id:)
# @example
# response = @bot.get_online(ids: ViberSubscriber.sample(100).pluck(:viber_id))
#
# @param [Array] message **Required**. List of user ids.
# @param [Array] ids **Required**. List of user ids.
#
# @return [Net::HTTPResponse || Hash]
#
Expand All @@ -227,8 +236,6 @@ def request(url, params = {})
http.request(request)
end

Viberroo.config.logger&.info("##{caller_name} -- #{response.body}")

Viberroo.config.parse_response_body ? JSON.parse(response.body) : response
end

Expand Down
6 changes: 3 additions & 3 deletions lib/viberroo/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ class Configuration
# @return [String]
#
# @see Bot#set_webhook
attr_accessor :auth_token
attr_accessor :auth_token

##
# Specifies whether to parse response body of Bot requests.
#
# @return [true || false]
#
# @see Bot
attr_accessor :parse_response_body
attr_accessor :parse_response_body

def initialize
@auth_token = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/viberroo/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Viberroo
VERSION = '0.3.3'.freeze
VERSION = '0.3.4'.freeze
end
6 changes: 4 additions & 2 deletions spec/bot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
let(:bot) { Viberroo::Bot.new(token: token, response: response) }

describe 'setting a webhook' do
let(:bot) { Viberroo::Bot.new(token: token) }
let!(:body) do
{ url: 'http://my.host.com', event_types: %w[conversation_started] }
end
Expand All @@ -29,6 +30,7 @@
end

describe 'removing a webhook' do
let(:bot) { Viberroo::Bot.new(token: token) }
let!(:request) do
stub_request(:post, Viberroo::URL::WEBHOOK)
.with(headers: headers)
Expand Down Expand Up @@ -63,8 +65,8 @@

before { subject }

context 'with #send' do
subject { bot.send(message: message) }
context 'with #send_message' do
subject { bot.send_message(message) }

it 'makes a request with correct url, body and headers' do
expect(request).to have_been_made.once
Expand Down

0 comments on commit 301ced4

Please sign in to comment.