{"id":17495431,"url":"https://github.com/ekohe/ruby-office365","last_synced_at":"2025-04-22T23:22:08.783Z","repository":{"id":61707508,"uuid":"554181037","full_name":"ekohe/ruby-office365","owner":"ekohe","description":"A simple ruby library to interact with Microsoft Graph and Office 365 API.","archived":false,"fork":false,"pushed_at":"2024-12-11T10:59:24.000Z","size":85,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-17T22:47:59.159Z","etag":null,"topics":["access-token","api","azure","calendars","contacts","events","graph-api","mailboxes","microsoft","oauth2","office365","refresh-token","rest","ruby","token"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ekohe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-19T11:39:28.000Z","updated_at":"2025-02-27T11:35:19.000Z","dependencies_parsed_at":"2024-08-14T17:35:44.950Z","dependency_job_id":null,"html_url":"https://github.com/ekohe/ruby-office365","commit_stats":{"total_commits":38,"total_committers":4,"mean_commits":9.5,"dds":0.3421052631578947,"last_synced_commit":"b94bbab9af049b38fe3c57bceed8a91730a43224"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekohe%2Fruby-office365","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekohe%2Fruby-office365/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekohe%2Fruby-office365/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekohe%2Fruby-office365/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ekohe","download_url":"https://codeload.github.com/ekohe/ruby-office365/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250338505,"owners_count":21414199,"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":["access-token","api","azure","calendars","contacts","events","graph-api","mailboxes","microsoft","oauth2","office365","refresh-token","rest","ruby","token"],"created_at":"2024-10-19T14:06:05.031Z","updated_at":"2025-04-22T23:22:08.743Z","avatar_url":"https://github.com/ekohe.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Office 365 (2024) \u003cimg src=\"https://i.ibb.co/g3mpswn/microsoft-office-365-logo-2016-100727915-large.webp\" align=\"right\" width=\"250\" height=\"150\"\u003e\n\nA simple ruby library to interact with Microsoft Graph **[Explorer](https://developer.microsoft.com/en-us/graph/graph-explorer)** and Office 365 API\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n    $ bundle add ruby-office365\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n    $ gem install ruby-office365\n\n## Features\n\n- Supports user's mailboxes, calendars, contacts, events\n- Supports refresh token\n\n## Configuration\n\nYou can pass configuration options as a block to `Office365::REST::Client.new`.\n\n- tenant_id: optional, only required for refresh_token\n- client_id: optional, only required for refresh_token\n- client_secret: optional, only required for refresh_token\n- access_token: required for fetch mailbox, calendars, contacts data\n- refresh_token: optional, only required for refresh_token\n- debug: optional, default false, output the request information\n\n### Used to get data from MS Graph API\n\n```ruby\nclient = Office365::REST::Client.new do |config|\n  config.access_token = \"YOUR_ACCESS_TOKEN\"\n  config.debug = \"true/false\" # Optional, default to false, output the information in the request\nend\n```\n\n### For refresh token\n\n```ruby\nclient = Office365::REST::Client.new do |config|\n  config.tenant_id = \"YOUR_ORG_TENANT_ID\"\n  config.client_id = \"YOUR_APP_CLIENT_ID\"\n  config.client_secret = \"YOUR_APP_CLIENT_SECRET\"\n  config.refresh_token = \"YOUR_REFRESH_TOKEN\"\n  config.debug = \"true/false\" # Optional, default to false, output the information in the request\nend\n```\n\n## Usage\n\nAfter configuring a `client`, you can do the following things.\n\n**Response structure**\n\n    - results: wrap all data into results\n    - next_link: get the new link for the next page of data\n\n**A simple way to convert an office365 object to JSON**\n\n    - as_json: convert office365 object to JSON format\n\n**Get my profile by access token**\n\n```ruby\nirb(main):004:0\u003e response = client.me\nirb(main):010:0\u003e response.display_name\n=\u003e \"Hello World\"\nirb(main):004:0\u003e response.as_json\n=\u003e {\n    :odata_context=\u003e\"https://graph.microsoft.com/v1.0/$metadata#users/$entity\",\n    :display_name=\u003e\"Hello World\",\n    :surname=\u003e\"Hello\",\n    :given_name=\u003e\"World\",\n    :id=\u003e\"d7e954e0b50095ad\",\n    :user_principal_name=\u003e\"hello.world@mail.com\",\n    :business_phones=\u003e[],\n    :job_title=\u003enil,\n    :mail=\u003enil,\n    :mobile_phone=\u003enil,\n    :office_location=\u003enil,\n    :preferred_language=\u003enil\n}\n```\n\n**Get my calendars by access token**\n\n```ruby\nirb(main):005:0\u003e client.calendars\nirb(main):005:0\u003e client.calendars[:results]\nirb(main):005:0\u003e client.calendars[:next_link]\n```\n\n**Get my events by access token**\n\n```ruby\nirb(main):005:0\u003e client.events\nirb(main):005:0\u003e client.events[:results]\nirb(main):005:0\u003e client.events[:next_link]\n```\n\n**Get my events for the next week**\n\n```ruby\nirb(main):005:0\u003e client.events({ startdatetime: \"2024-11-14T00:00:00.000Z\", enddatetime: \"2024-11-21T00:00:00.000Z\" })\nirb(main):005:0\u003e client.events[:results]\nirb(main):005:0\u003e client.events[:next_link]\n```\n\n**Get my event by id**\n\n```ruby\nirb(main):005:0\u003e client.event('identifier')\nirb(main):005:0\u003e client.event('identifier')[:results]\n```\n\nResults will return an array even if it is a single result.\n\n**Get my mails by access token**\n\n```ruby\nirb(main):005:0\u003e client.messages\nirb(main):005:0\u003e client.messages[:results]\nirb(main):005:0\u003e client.messages({ filter: \"createdDateTime lt 2022-01-01\" })\nirb(main):005:0\u003e client.messages({ filter: \"createdDateTime lt 2022-01-01\", next_link: 'https://....' })\n```\n\n**Get my contacts by access token**\n\n```ruby\nirb(main):018:0\u003e response = client.contacts\nirb(main):020:0\u003e client.contacts[:results][0].display_name\n=\u003e \"Encore S.\"\nirb(main):018:0\u003e response[:results][0].as_json\n=\u003e {\n    :odata_etag=\u003e\"W/\\\"EQAAABYAAACbUc86NQthQ7+Mvj19ecwVAABjabQj\\\"\",\n    :id=\u003e\"AQMkADAwATM3ZmYAZS00ZTU5LWY3NwBjLTAwAi0wMAoARgAAA4QFHqPHk4JJj7ZVaRPCKk4HAJtRzzo1C2FDv4y_PX15zBUAAAIBDgAAAJtRzzo1C2FDv4y_PX15zBUAAABja1I_AAAA\",\n    :created_date_time=\u003e\"2022-10-24T02:48:56Z\",\n    :last_modified_date_time=\u003e\"2022-10-24T02:48:57Z\",\n    :change_key=\u003e\"EQAAABYAAACbUc86NQthQ7+Mvj19ecwVAABjabQj\",\n    :categories=\u003e[],\n    :parent_folder_id=\u003e\"AQMkADAwATM3ZmYAZS00ZTU5LWY3NwBjLTAwAi0wMAoALgAAA4QFHqPHk4JJj7ZVaRPCKk4BAJtRzzo1C2FDv4y_PX15zBUAAAIBDgAAAA==\",\n    :birthday=\u003enil,\n    :file_as=\u003e\"\",\n    :display_name=\u003e\"Name S.\",\n    :given_name=\u003e\"Name\",\n    :initials=\u003enil,\n    :middle_name=\u003enil,\n    :nick_name=\u003enil,\n    :surname=\u003e\"S.\",\n    :title=\u003enil,\n    :yomi_given_name=\u003enil,\n    :yomi_surname=\u003enil,\n    :yomi_company_name=\u003e\"\",\n    :generation=\u003enil,\n    :im_addresses=\u003e[],\n    :job_title=\u003e\"\",\n    :company_name=\u003enil,\n    :department=\u003e\"\",\n    :office_location=\u003e\"\",\n    :profession=\u003enil,\n    :business_home_page=\u003e\"\",\n    :assistant_name=\u003e\"\",\n    :manager=\u003e\"\",\n    :home_phones=\u003e[],\n    :mobile_phone=\u003e\"\",\n    :business_phones=\u003e[],\n    :spouse_name=\u003e\"\",\n    :personal_notes=\u003e\"\",\n    :children=\u003e[],\n    :email_addresses=\u003e[{\"name\"=\u003e\"name@google.com\", \"address\"=\u003e\"name@google.com\"}],\n    :home_address=\u003e{},\n    :business_address=\u003e{},\n    :other_address=\u003e{}\n}\n```\n\n**Refresh access token by refresh token**\n\n```ruby\nirb(main):005:0\u003e response = client.refresh_token!\nirb(main):005:0\u003e response.scope\n=\u003e \"openid User.Read profile email\"\nirb(main):005:0\u003e response.access_token\n=\u003e \"eyJ0eXAiOiJKV1QiLCJub25jZSI6ImFDYUladFJ6M3RSc3dFaktxUHdGbF9kVlFmbjJabG85Mjlkb2xaeFBhZm8iLCJhbGciOiJSUzI1NiIsIng1dCI6IjJaUXBKM1VwYmpBWVhZR2FYRUpsOGxWMFRPSSIsImtpZCI6IjJaUXBKM1VwYmpBWVhZR2FYRUpsOGxWMFRPSSJ9...\"\nirb(main):005:0\u003e response.refresh_token\n=\u003e \"0.ARgA7EiQdLv1qECnFqPfrznKsT9ERYaGfG9Ki5WzQtEllj8YAJk.AgABAAEAAAD--DLA3VO7QrddgJg7WevrAgDs_wQA9P-Q1ODlBsrdZi-5s2mfLtEsavBgiEhGcz1KEf26fMrGFU3LM_og5l6wjSAtQ83XHLuje0_KYGol26_LGV_uH0F1MwCFR1N3ctwg4_....\"\n```\n\n**Create Subscription: it will create a webhook for Office365**\n\n```ruby\nargs = {\n  changeType: \"updated,deleted\",\n  notificationUrl: \"https://hello-world.com/office365/notifications\",\n  lifecycleNotificationUrl: \"https://hello-world.com/office365/lifecycle_notifications\",\n  resource: \"/me/{type}\",\n  expirationDateTime: \"2024-08-07T12:00:00.0000000Z\",\n  clientState: \"SecretClientState\"\n}\n\nirb(main):005:0\u003e subscription = client.create_subscription(args)\n```\n\nwill return the subscription object `Office365::Models::Subscription`\n\n**Renew Subscription**\n\n```ruby\nargs = {\n  identifier: \"subscription-identifier\",\n  expirationDateTime: \"2024-08-08T12:00:00.0000000Z\"\n}\n\nirb(main):005:0\u003e subscription = client.renew_subscription(args)\n```\n\nwill return the subscription object `Office365::Models::Subscription`\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Copyright\n\nCopyright (c) 2022 Encore Shao. See LICENSE for details.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ekohe/ruby-office365.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekohe%2Fruby-office365","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fekohe%2Fruby-office365","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekohe%2Fruby-office365/lists"}