{"id":15397344,"url":"https://github.com/cakejelly/layer-api","last_synced_at":"2025-04-15T22:30:36.932Z","repository":{"id":35118854,"uuid":"39310742","full_name":"cakejelly/layer-api","owner":"cakejelly","description":"A ruby toolkit for Layer's Web API's (https://developer.layer.com/docs)","archived":false,"fork":false,"pushed_at":"2019-12-27T17:18:03.000Z","size":131,"stargazers_count":18,"open_issues_count":2,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T05:10:06.149Z","etag":null,"topics":["layer","messaging-layer","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cakejelly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-18T19:51:15.000Z","updated_at":"2020-06-19T00:17:48.000Z","dependencies_parsed_at":"2022-09-16T14:21:51.338Z","dependency_job_id":null,"html_url":"https://github.com/cakejelly/layer-api","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakejelly%2Flayer-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakejelly%2Flayer-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakejelly%2Flayer-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakejelly%2Flayer-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cakejelly","download_url":"https://codeload.github.com/cakejelly/layer-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249165831,"owners_count":21223330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["layer","messaging-layer","ruby"],"created_at":"2024-10-01T15:37:06.706Z","updated_at":"2025-04-15T22:30:36.589Z","avatar_url":"https://github.com/cakejelly.png","language":"Ruby","readme":"# [DEPRECATED] The layer messaging platform shut down on October 30th 2019 along with it's API\n# Layer Ruby Gem\n[![Build Status](https://travis-ci.org/cakejelly/layer-api.svg?branch=master)](https://travis-ci.org/cakejelly/layer-api) [![Gem Version](https://badge.fury.io/rb/layer-api.svg)](http://badge.fury.io/rb/layer-api)\n\nSimple wrapper for Layer's Web API's\n\nIf you want to learn more, check out the [official documentation](https://developer.layer.com/docs/platform).\n\n## Migrating from 0.3.x\nVersion 0.4 is not compatible with older versions. SEE [MIGRATING](MIGRATING.md) for details on how to migrate your code to the latest version.\n\n## Installation ##\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'layer-api'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install layer-api\n\n\n## Usage\n\n### Resources\nAll client methods return `Resource` objects or a collection of `Resource` objects. Every attribute from a resource can be accessed by calling attribute methods:\n\n```ruby\nconversation = platform.conversations.find(\"fb2f3a48-523d-4449-a57f-c6651fc6612c\")\n#\u003cLayer::Resources::Conversation @attributes={...}\u003e\n\n# Get the stripped uuid for any resource\nconversation.uuid\n# =\u003e \"fb2f3a48-523d-4449-a57f-c6651fc6612c\"\n\nconversation.url\n# =\u003e \"https://api.layer.com/apps/\u003cAPP_ID\u003e/conversations/fb2f3a48-523d-4449-a57f-c6651fc6612c\"\n\n# Retrieve all attributes\nconversation.attributes\n# =\u003e {\"id\" =\u003e \"fb2f3a48-523d-4449-a57f-c6651fc6612c\", \"url\" =\u003e \"https://api.layer.com/apps/\u003cAPP_ID\u003e/conversations/fb2f3a48-523d-4449-a57f-c6651fc6612c\", ...}\n```\n\n### [Platform](https://developer.layer.com/docs/platform)\nSee the [Platform API docs](https://developer.layer.com/docs/platform) for additional info.\n\n#### Authentication/setup\n\n```ruby\nplatform = Layer::Platform::Client.new(api_token: \"your_api_token\", app_id: \"your_app_id\")\n# =\u003e #\u003cLayer::Platform::Client @api_token=\"...\", @app_id=\"...\"\u003e\n```\nIf you have `ENV['LAYER_API_TOKEN']` and `ENV['LAYER_APP_ID']` environment variables setup, they will be used by default and don't need to be included:\n\n```ruby\nplatform = Layer::Platform::Client.new\n# =\u003e #\u003cLayer::Platform::Client @api_token=\"...\", @app_id=\"...\"\u003e\n```\n\n#### Retrieving Conversations ####\n\n```ruby\nuser = platform.users.find(\"user_id\")\nconvs = user.conversations.list\n# =\u003e [#\u003cLayer::Resources::Conversation\u003e, #\u003cLayer::Resources::Conversation\u003e, ...]\n\n```\n\n#### Retrieving A Single Conversation ####\n\n```ruby\n# For a user\nuser = platform.users.find(\"user_id\")\nconv = user.conversations.find(\"conversation_id\")\n# =\u003e #\u003cLayer::Resources::Conversation @attributes={...}\u003e\n\n# or alternatively\nconv = platform.conversations.find(\"conversation_id\")\n# =\u003e #\u003cLayer::Resources::Conversation @attributes={...}\u003e\n```\n\n#### Creating Conversations ####\n\n```ruby\nconversation = {\n  participants: [\n    \"1234\",\n    \"5678\"\n  ],\n  distinct: false,\n  metadata: {\n    background_color: \"#3c3c3c\"\n  }\n}\n\nplatform.conversations.create(conversation)\n# =\u003e #\u003cLayer::Resources::Conversation @attributes={...}\u003e\n```\n\n#### Editing Conversations ####\n\n```ruby\nconv = platform.conversations.find(\"conversation_id\")\n\noperations = [\n  { operation: \"add\", property: \"participants\", value: \"user1\" },\n  { operation: \"add\", property: \"participants\", value: \"user2\" }\n]\n\nconv.update(operations)\n# =\u003e true\n```\n#### Deleting Conversations ####\n\n```ruby\nconv = platform.conversations.find(\"conversation_id\")\nconv.destroy\n# =\u003e true\n\n```\n\n#### Initiating a Rich Content Upload\n\n```ruby\nconv = platform.conversations.find(\"conversation_id\")\ncontent = conv.content.create(mime_type: \"image/png\", file: File.open(\"image.png\"))\n# =\u003e #\u003cLayer::Resources::RichContent @attributes={...}\u003e\n\ncontent.upload_url\n# =\u003e \"https://www.googleapis.com/upload/storage/path/to/content\"\n```\n\n#### Refreshing the download URL for a Content Object\n\n```ruby\ncontent = conv.content.find(\"content_id\")\n# =\u003e #\u003cLayer::Resources::RichContent @attributes={...}\u003e\n\ncontent.download_url\n# =\u003e \"http://google-testbucket.storage.googleapis.com/some/download/path\"\n\ncontent.refresh_url\n# =\u003e \"https://api.layer.com/apps/\u003cAPP_ID\u003e/conversations/\u003cCONVERSATION_ID\u003e/content/\u003cCONTENT_ID\u003e\"\n```\n\n#### Sending Messages ####\n\n```ruby\nmessage = {\n  sender: {\n    name: \"t-bone\"\n  },\n  parts: [\n    {\n        body: \"Hello, World!\",\n        mime_type: \"text/plain\"\n    },\n    {\n        body: \"YW55IGNhcm5hbCBwbGVhc3VyZQ==\",\n        mime_type: \"image/jpeg\",\n        encoding: \"base64\"\n    }\n  ],\n  notification: {\n    text: \"This is the alert text to include with the Push Notification.\",\n    sound: \"chime.aiff\"\n  }\n}\n\nconv = platform.conversations.find(\"conversation_id\")\nconv.messages.create(message)\n# =\u003e #\u003cLayer::Resources::Message @attributes={...}\u003e\n```\n\n#### Retrieving Messages ####\n\n```ruby\n# From a specific user's perspective\nconv = platform.users.find(\"user_id\").conversations.find(\"conversation_id\")\nconv.messages.list\n# =\u003e [#\u003cLayer::Resources::Message\u003e, #\u003cLayer::Resources::Message\u003e, ...]\n\n# From the system's perspective\nconv = platform.conversations.find(\"conversation_id\")\nconv.messages.list\n# =\u003e [#\u003cLayer::Resources::Message\u003e, #\u003cLayer::Resources::Message\u003e, ...]\n```\n\n#### Retrieving A Single Message ####\n\n```ruby\n# From a specific user's perspective\nuser = platform.users.find(\"user_id\")\nmessages = user.messages.find(\"message_id\")\n# =\u003e #\u003cLayer::Resources::Message @attributes={...}\u003e\n\n# From the systems perspective\nconv = platform.conversations.find(\"conversation_id\")\nmessages = conv.messages.find(\"message_id\")\n# =\u003e #\u003cLayer::Resources::Message @attributes={...}\u003e\n```\n\n#### Deleting A Message\n\n```ruby\nconv = platform.conversations.find(\"conversation_id\")\nconv.messages.find(\"message_id\").destroy\n# =\u003e true\n```\n\n#### Sending Announcements ####\n\n```ruby\nannouncement = {\n  recipients: [ \"1234\", \"5678\" ],\n  sender: {\n    name: \"The System\"\n  },\n  parts: [\n    {\n        body: \"Hello, World!\",\n        mime_type: \"text/plain\"\n    }\n  ],\n  notification: {\n    text: \"This is the alert text to include with the Push Notification.\",\n    sound: \"chime.aiff\"\n  }\n}\n\nplatform.announcements.create(announcement)\n# =\u003e #\u003cLayer::Resources::Announcement @attributes={...}\u003e\n```\n\n#### Modifying A Users Block List ####\n\n```ruby\nuser = platform.users.find(\"user_id\")\n\noperations = [\n    { operation: \"add\", property: \"blocks\", value: \"blockMe1\" },\n    { operation: \"add\", property: \"blocks\", value: \"blockMe2\" },\n    { operation: \"remove\", property: \"blocks\", value: \"unblockMe\" }\n]\n\nuser.update(operations)\n# =\u003e true\n```\n\n#### Retrieving A Users Block List\n\n```ruby\nuser = platform.users.find(\"user_id\")\n\nblocks = user.blocks.list\n# =\u003e [#\u003cLayer::Resources::Block\u003e, [#\u003cLayer::Resources::Block\u003e, ...]\n```\n\n#### Blocking Users\n\n```ruby\n# using params\nowner = platform.users.find(\"owner\")\nowner.blocks.create(user_id: \"blocked\")\n# =\u003e #\u003cLayer::Resources::Block @attributes={...}\u003e\n\n# passing a User object\nowner = platform.users.find(\"owner\")\nblocked = platform.users.find(\"blocked\")\n\nowner.blocks.create(blocked)\n# =\u003e #\u003cLayer::Resources::Block @attributes={...}\u003e\n```\n\n#### Unblocking Users\n\n```ruby\n\n# using the blocked users id\nowner = platform.users.find(\"owner\")\nowner.blocks.find(\"blocked_user\").destroy\n# =\u003e true\n\n# using a User object\nowner = platform.users.find(\"owner\")\nblocked = platform.users.find(\"blocked\")\n\nowner.blocks.find(blocked).destroy\n# =\u003e true\n```\n\n#### Creating a User Identity\n\n```ruby\nidentity = {\n  display_name: \"Frodo the Dodo\",\n  avatar_url: \"http://sillylordoftheringspictures.com/frodo-riding-a-dodo.png\",\n  first_name: \"Frodo\",\n  last_name: \"Baggins\",\n  phone_number: \"13791379137\",\n  email_address: \"frodo@sillylordoftheringspictures.com\",\n  metadata: {\n    level: \"35\",\n    race: \"Dodo\"\n  }\n}\n\nuser = platform.users.find(\"user_id\")\nuser.create_identity(identity)\n# =\u003e true\n\n```\n\n#### Retrieving a User's Identity\n\n```ruby\nuser = platform.users.find(\"user_id\")\nuser.identity\n# =\u003e {\"first_name\"=\u003e\"Frodo\", \"phone_number\"=\u003e\"13791379137\", \"email_address\"=\u003e\"frodo@sillylordoftheringspictures.com\", \"display_name\"=\u003e\"Frodo the Dodo\", \"user_id\"=\u003e\"jake\", \"last_name\"=\u003e\"Baggins\", \"metadata\"=\u003e{\"race\"=\u003e\"Dodo\", \"level\"=\u003e\"35\"}, \"avatar_url\"=\u003e\"http://sillylordoftheringspictures.com/frodo-riding-a-dodo.png\"}\n```\n\n#### Updating an Identity\n\n```ruby\noperations = [\n  { operation: \"set\", property: \"last_name\", value: \"Dodo\" },\n  { operation: \"set\", property: \"phone_number\", value: \"\" },\n  { operation: \"set\", property: \"metadata.level\", value: \"2\" }\n]\n\nuser.update_identity(operations)\n# =\u003e true\n```\n\n#### Replacing an identity\n\n```ruby\nidentity = {\n  display_name: \"Frodo the Dodo\",\n  avatar_url: \"http://sillylordoftheringspictures.com/frodo-riding-a-dodo.png\",\n  first_name: \"Frodo\",\n  last_name: \"Baggins\",\n  phone_number: \"13791379137\",\n  email_address: \"frodo@sillylordoftheringspictures.com\",\n  metadata: {\n    level: \"35\",\n    race: \"Dodo\"\n  }\n}\n\nuser.replace_identity(identity)\n# =\u003e true\n\n```\n\n#### Deleting a User's Identity\n\n```ruby\nuser = platform.users.find(\"user_id\")\nuser.destroy_identity\n# =\u003e true\n```\n\n#### Setting a Users Badge\n\n```ruby\nuser = platform.users.find(\"user_id\")\nuser.set_badge(10)\n# =\u003e true\n```\n\n#### Retrieving a Users Badge\n\n```ruby\nuser = platform.users.find(\"user_id\")\nuser.badge\n# =\u003e { \"external_unread_count\" =\u003e 13, \"unread_conversation_count\" =\u003e 10, \"unread_message_count\" =\u003e 50 }\n```\n\n\n#### Generating Identity Tokens ####\nSee: [the official authentication guide](https://developer.layer.com/docs/android/guides#authentication)\n\nMake sure the following environment variables are set:\n`ENV['LAYER_KEY_ID']`\n`ENV['LAYER_PROVIDER_ID']`\n`ENV['LAYER_PRIVATE_KEY']`\n\n```ruby\n# Returns a valid signed identity token. #\ntoken = platform.generate_identity_token(user_id: \"1234\", nonce: \"your_random_nonce\")\n# =\u003e #\u003cLayer::IdentityToken:0x007f89b4adb890\u003e\n\ntoken.to_s\n# =\u003e \"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsInR.cCI6IkpXVCIsImN0eSI6ImxheWVyLWVpdDt2PTEiLCJraWQiOiJhNz.5YTE0MC02YzY3LTExZTUtYjM0Mi1jZGJmNDAwZTE5NDgifQ\"\n```\n\n### [Webhooks](https://developer.layer.com/docs/webhooks)\nSee the [Webhooks API docs](https://developer.layer.com/docs/webhooks) for additional info.\n\n#### Authentication/setup\n\n```ruby\nclient = Layer::Webhooks::Client.new(api_token: \"your_api_token\", app_id: \"your_app_id\")\n# =\u003e #\u003cLayer::Webhooks::Client @api_token=\"...\", @app_id=\"...\"\u003e\n```\nIf you have `ENV['LAYER_API_TOKEN']` and `ENV['LAYER_APP_ID']` environment variables setup, they will be used by default and don't need to be included:\n```ruby\nclient = Layer::Webhooks::Client.new\n# =\u003e #\u003cLayer::Webhooks::Client @api_token=\"...\", @app_id=\"...\"\u003e\n```\n\n#### Registering Webhooks\n\n```ruby\nclient.webhooks.create(\n  version: \"1.0\",\n  target_url: \"https://mydomain.com/my-webhook-endpoint\",\n  events: [\"conversation.created\", \"message.sent\"],\n  secret: \"1697f925ec7b1697f925ec7b\",\n  config: {:key1=\u003e\"value1\", :key2=\u003e\"value2\"}\n)\n# =\u003e #\u003cLayer::Resources::Webhook @attributes={...}\u003e\n```\n\n#### Listing Webhooks\n\n```ruby\nclient.webhooks.list\n# =\u003e [#\u003cLayer::Resources::Webhook\u003e, #\u003cLayer::Resources::Webhook\u003e, ...]\n```\n\n#### Retrieving Webhooks\n\n```ruby\nclient.webhooks.find(\"webhook_id\")\n# =\u003e #\u003cLayer::Resources::Webhook @attributes={...}\u003e\n```\n\n#### Activating Webhooks\n\n```ruby\nwebhook = client.webhooks.find(\"webhook_id\")\nwebhook.activate\n```\n\n#### Deactivating Webhooks\n\n```ruby\nwebhook = client.webhooks.find(\"webhook_id\")\nwebhook.deactivate\n```\n\n#### Deleting Webhooks\n\n```ruby\nwebhook = client.webhooks.find(\"webhook_id\")\nwebhook.destroy\n```\n\n\n## Development ##\n\nAfter 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.\n\nTo 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).\n\n## Contributing ##\n\nBug reports and pull requests are welcome on GitHub at https://github.com/cakejelly/layer-api.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcakejelly%2Flayer-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcakejelly%2Flayer-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcakejelly%2Flayer-api/lists"}