# Qismo Ruby A Ruby API wrapper for Qiscus Multichannel API ## Installation Add this line to your application's Gemfile: ```ruby gem "qismo" ``` And then execute: ```bash bundle install ``` ## Usage **Example for single app id** ```ruby # config/initializers/qismo.rb # Initialization Qismo.init do |config| config.app_id = ENV["QISCUS_APP_ID"] config.secret_key = ENV["QISCUS_SECRET_KEY"] config.base_url = ENV["QISCUS_MULTICHANNEL_BASE_URL"] end # Get all rooms that have been waiting for a week rooms = Room.where(status: "waiting") .where("created_at >= :a_week", a_week: 1.week.ago) # Resolve the rooms rooms.each(Qismo::Room.resolve(&:id)) ``` **Example for multi app id** ```ruby # Get all rooms that have been waiting for a week rooms = Room.includes(:qiscus_app) .where(status: "waiting") .where("created_at >= :a_week", a_week: 1.week.ago) # Resolve the rooms rooms.each do |room| Qismo.new(app_id: room.qiscus_app.app_id, secret_key: room.qiscus_app.secret_key) Qismo::Room.resolve(room.id) end ``` **Nested operations** If you prefer to use nested operations, you can also use this package like below ```ruby client = Qismo.new(app_id: room.qiscus_app.app_id, secret_key: room.qiscus_app.secret_key) client.room.resolve(id) ``` **Requesting to unhandled API** Qiscus Multichannel is on fast development mode and at some condition, you might find this library is not handle the new API. If that happen, you can use the operations like below: ```ruby Qismo.client.call("post", "/api/v2/api_endpoint", json: {}, params: {}) ``` **Error handling** ```ruby begin room = Qismo::Room.resolve(123456) # Not Found rescue Qismo::HTTPError => e e.message # return error message e.http_code # return response code e.http_headers # return response headers in hash e.http_body # return response body in hash or string e.http_raw_body # return raw response body in string end ``` ## Experience This gem leverage YARD to improve text editor autocompletion Install YARD ```shell gem install yard ``` Change to project directory and expose gem YARD documentation ```shell yard gems ``` For VSCode users, you can use Solargraph gem to improve the autocompletion ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/qismo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/qismo/blob/master/CODE_OF_CONDUCT.md). ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). ## Code of Conduct Everyone interacting in the Qismo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/qismo/blob/master/CODE_OF_CONDUCT.md).