Code Monkey home page Code Monkey logo

layer-ruby's Introduction

Layer Platform API

Build Status Gem Version

Ruby bindings for the Layer Platform API.

Installation

Add this line to your application's Gemfile:

gem 'layer-ruby', require: 'layer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install layer-ruby

Usage

Please refer to the Layer Platform API documentation for details about the required payloads and responses.

Configuration

To use interact with the Layer Platform API, you need your Layer APP ID as well as a Layer Platform API Token. The gem reads both values from the LAYER_APP_ID and LAYER_PLATFORM_TOKEN environment variables. Alternatively you can specify the values by configuring the Layer::Client like this:

Layer::Client.configure do |config|
  config.app_id = 'YOUR_APP_ID_HERE'
  config.token = 'YOUR_PLATFORM_TOKEN_HERE'
end

Creating Conversations

conversation = Layer::Conversation.create({ participants: ['1', '2'] })

Retrieving Conversations

To retrieve a existing conversation, just use Conversation.find passing it the conversation id:

conversation = Layer::Conversation.find('CONVERSATION_ID_HERE')

Updating Conversations

To update a conversation, just update the conversation's attributes and call save.

conversation = Layer::Conversation.find('CONVERSATION_ID_HERE')
conversation.participants << 3
conversation.metadata[:foo] = 'bar'
conversation.save

Sending Messages

In order to send messages, you first have to load (or create) a Conversation. Afterwards you can send a message to the conversation like this:

conversation = Layer::Conversation.find('CONVERSATION_ID_HERE')
conversation.messages.create({ sender: { name: 'Server' }, parts: [{ body: 'Hello!', mime_type: 'text/plain' }]})

Sending Announcements

You can send a announcements like this:

Layer::Announcement.create({ recipients: 'everyone', sender: { name: 'Server' }, parts: [{ body: 'Hello!', mime_type: 'text/plain' }]})

Managing block lists

Managing block lists is also possible:

user = Layer::User.find('user_id')
user.blocks.all # Returns a list of blocks
user.blocks.create({ user_id: 'other_user' }) # Adds the other user to the block list
user.blocks.delete('other_user') # Removes the other user from the block list
user.blocks.all.first.delete # Removes the first entry from the block list

Using the gem with multiple applications at once

It's possible to create a new instance of Layer::Client and passing both the app id and the token to the initializer:

client = Layer::Client.new('YOUR_APP_ID_HERE', 'YOUR_PLATFORM_TOKEN_HERE')

The client will not use any global configuration. You can pass the client as a second parameter to any operations (create, find) described above.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake rspec 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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/benedikt/layer-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Related Work

Check out the layer-identity_token gem to generate authentication tokens for the Layer SDK.

layer-ruby's People

Contributors

benedikt avatar we5 avatar curbsaleem avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.