├── .dockerignore ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── coverage.yml │ ├── docs.yml │ ├── publish.yml │ └── test.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── Dockerfile ├── Gemfile ├── Guardfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── bin ├── console └── setup ├── docker-compose.yml ├── docs ├── OpConnect.html ├── OpConnect │ ├── APIRequest.html │ ├── APIRequest │ │ ├── Actor.html │ │ └── Resource.html │ ├── BadRequest.html │ ├── Client.html │ ├── Client │ │ ├── Files.html │ │ ├── Items.html │ │ └── Vaults.html │ ├── ClientError.html │ ├── Configurable.html │ ├── Connection.html │ ├── Default.html │ ├── Error.html │ ├── Forbidden.html │ ├── InternalServerError.html │ ├── Item.html │ ├── Item │ │ ├── Field.html │ │ ├── File.html │ │ ├── GeneratorRecipe.html │ │ ├── Section.html │ │ └── URL.html │ ├── NotFound.html │ ├── Object.html │ ├── PayloadTooLarge.html │ ├── Response.html │ ├── Response │ │ └── RaiseError.html │ ├── ServerError.html │ ├── ServerHealth.html │ ├── ServerHealth │ │ └── Dependency.html │ ├── ServiceUnavailable.html │ ├── Unauthorized.html │ └── Vault.html ├── _config.yml ├── _index.html ├── class_list.html ├── css │ ├── common.css │ ├── full_list.css │ └── style.css ├── file.README.html ├── file_list.html ├── frames.html ├── index.html ├── js │ ├── app.js │ ├── full_list.js │ └── jquery.js ├── method_list.html └── top-level-namespace.html ├── lib ├── op_connect.rb └── op_connect │ ├── api_request.rb │ ├── api_request │ ├── actor.rb │ └── resource.rb │ ├── client.rb │ ├── client │ ├── files.rb │ ├── items.rb │ └── vaults.rb │ ├── configurable.rb │ ├── connection.rb │ ├── default.rb │ ├── error.rb │ ├── item.rb │ ├── item │ ├── field.rb │ ├── file.rb │ ├── generator_recipe.rb │ ├── section.rb │ └── url.rb │ ├── object.rb │ ├── response.rb │ ├── response │ └── raise_error.rb │ ├── server_health.rb │ ├── server_health │ └── dependency.rb │ ├── vault.rb │ └── version.rb ├── op_connect.gemspec └── test ├── fixtures ├── activity.json ├── errors │ ├── 400.json │ ├── 401.json │ ├── 403.json │ ├── 404.json │ └── 413.json ├── files │ ├── get.json │ ├── list.json │ └── testfile.txt ├── health.json ├── items │ ├── create.json │ ├── get.json │ ├── list.json │ ├── replace.json │ └── update.json ├── metrics.txt └── vaults │ ├── get.json │ └── list.json ├── op_connect ├── client │ ├── files_test.rb │ ├── items_test.rb │ └── vaults_test.rb ├── client_test.rb └── object_test.rb ├── op_connect_test.rb └── test_helper.rb /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/bin 15 | **/charts 16 | **/docker-compose* 17 | **/compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | README.md 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: partydrone 7 | 8 | --- 9 | 10 | ## Describe the bug 11 | A clear and concise description of what the bug is. 12 | 13 | ## To Reproduce 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | ## Expected behavior 21 | A clear and concise description of what you expected to happen. 22 | 23 | ## Screenshots 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | ## Environment 27 | - Gem version: 28 | - Ruby version: 29 | 30 | ## Additional context 31 | Add any other context about the problem here. 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: partydrone 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | name: Report Test Coverage 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | 7 | jobs: 8 | coverage: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@master 13 | 14 | - name: Set up Ruby 15 | uses: ruby/setup-ruby@v1 16 | with: 17 | ruby-version: '3.0' 18 | bundler: default 19 | bundler-cache: true 20 | 21 | - uses: paambaati/codeclimate-action@v2.7.5 22 | env: 23 | CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} 24 | with: 25 | coverageCommand: bundle exec rake test 26 | coverageLocations: | 27 | ${{ github.workspace }}/test/coverage/lcov/*.lcov:lcov 28 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Generate Documentation 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | 7 | jobs: 8 | docs: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Set up Ruby 14 | uses: ruby/setup-ruby@v1 15 | with: 16 | ruby-version: 3.1 17 | bundler: default 18 | bundler-cache: true 19 | 20 | - name: Install YARD 21 | run: gem install yard 22 | 23 | - name: Generate documentation 24 | run: yard --protected --output-dir ./docs lib/**/*.rb 25 | 26 | - name: Configure git 27 | run: | 28 | git config user.name "GitHub Actions Bot" 29 | git config user.email "<>" 30 | 31 | - name: Commit new files 32 | run: | 33 | # Stage files, then commit and push 34 | git add . 35 | git commit -m "Update documentation" 36 | git push origin main 37 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | build: 8 | name: Build + Publish 9 | runs-on: ubuntu-latest 10 | permissions: 11 | contents: read 12 | packages: write 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Set up Ruby 3.0 17 | uses: ruby/setup-ruby@v1 18 | with: 19 | ruby-version: 3.0 20 | 21 | - name: Publish to GitHub 22 | run: | 23 | mkdir -p $HOME/.gem 24 | touch $HOME/.gem/credentials 25 | chmod 0600 $HOME/.gem/credentials 26 | printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials 27 | gem build *.gemspec 28 | gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem 29 | env: 30 | GEM_HOST_API_KEY: 'Bearer ${{secrets.GITHUB_TOKEN}}' 31 | OWNER: ${{ github.repository_owner }} 32 | 33 | - name: Publish to RubyGems 34 | run: | 35 | mkdir -p $HOME/.gem 36 | touch $HOME/.gem/credentials 37 | chmod 0600 $HOME/.gem/credentials 38 | printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials 39 | gem build *.gemspec 40 | gem push *.gem 41 | env: 42 | GEM_HOST_API_KEY: '${{secrets.RUBYGEMS_AUTH_TOKEN}}' 43 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | strategy: 13 | matrix: 14 | ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1'] 15 | 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Set up Ruby 19 | uses: ruby/setup-ruby@v1 20 | with: 21 | ruby-version: ${{ matrix.ruby-version }} 22 | bundler: default 23 | bundler-cache: true 24 | - name: Check coding standards 25 | run: bundle exec standardrb 26 | - name: Run tests 27 | run: bundle exec rake 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /test/coverage/ 9 | /tmp/ 10 | /vendor/ 11 | Gemfile.lock 12 | 1password-credentials.json 13 | docker-compose.*.yml 14 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 8 | 9 | ## Our Standards 10 | 11 | Examples of behavior that contributes to a positive environment for our community include: 12 | 13 | * Demonstrating empathy and kindness toward other people 14 | * Being respectful of differing opinions, viewpoints, and experiences 15 | * Giving and gracefully accepting constructive feedback 16 | * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 17 | * Focusing on what is best not just for us as individuals, but for the overall community 18 | 19 | Examples of unacceptable behavior include: 20 | 21 | * The use of sexualized language or imagery, and sexual attention or 22 | advances of any kind 23 | * Trolling, insulting or derogatory comments, and personal or political attacks 24 | * Public or private harassment 25 | * Publishing others' private information, such as a physical or email 26 | address, without their explicit permission 27 | * Other conduct which could reasonably be considered inappropriate in a 28 | professional setting 29 | 30 | ## Enforcement Responsibilities 31 | 32 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 33 | 34 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 35 | 36 | ## Scope 37 | 38 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 39 | 40 | ## Enforcement 41 | 42 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at partydrone@icloud.com. All complaints will be reviewed and investigated promptly and fairly. 43 | 44 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 45 | 46 | ## Enforcement Guidelines 47 | 48 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 49 | 50 | ### 1. Correction 51 | 52 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 53 | 54 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 55 | 56 | ### 2. Warning 57 | 58 | **Community Impact**: A violation through a single incident or series of actions. 59 | 60 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 61 | 62 | ### 3. Temporary Ban 63 | 64 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 65 | 66 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 67 | 68 | ### 4. Permanent Ban 69 | 70 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 71 | 72 | **Consequence**: A permanent ban from any sort of public interaction within the community. 73 | 74 | ## Attribution 75 | 76 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 77 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 78 | 79 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 80 | 81 | [homepage]: https://www.contributor-covenant.org 82 | 83 | For answers to common questions about this code of conduct, see the FAQ at 84 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 85 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | ARG RUBY_VERSION 2 | FROM ruby:${RUBY_VERSION} 3 | 4 | ENV GEM_HOME /usr/local/bundle 5 | ENV PATH ${GEM_HOME}/bin:${GEM_HOME}/gems/bin:${PATH} 6 | 7 | RUN gem install yard 8 | 9 | WORKDIR /opt/gem 10 | 11 | COPY lib/op_connect/version.rb ./lib/op_connect/version.rb 12 | COPY Gemfile* *.gemspec ./ 13 | 14 | RUN bundle check || bundle install -j $(nproc) 15 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | # Specify your gem's dependencies in op_connect.gemspec 6 | gemspec 7 | 8 | gem "rake", "~> 13.0" 9 | gem "minitest", "~> 5.0" 10 | gem "minitest-reporters" 11 | gem "guard" 12 | gem "guard-minitest" 13 | gem "pry" 14 | gem "standard" 15 | gem "simplecov", require: false 16 | gem "simplecov-lcov", require: false 17 | gem "simplecov-tailwindcss", require: false 18 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | ## Uncomment and set this to only include directories you want to watch 5 | # directories %w(app lib config test spec features) \ 6 | # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")} 7 | 8 | ## Note: if you are using the `directories` clause above and you are not 9 | ## watching the project directory ('.'), then you will want to move 10 | ## the Guardfile to a watched dir and symlink it back, e.g. 11 | # 12 | # $ mkdir config 13 | # $ mv Guardfile config/ 14 | # $ ln -s config/Guardfile . 15 | # 16 | # and, you'll have to watch "config/Guardfile" instead of "Guardfile" 17 | 18 | guard :minitest, all_on_start: false do 19 | # with Minitest::Unit 20 | watch(%r{^test/(.*)_test\.rb$}) 21 | watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" } 22 | watch(%r{^test/test_helper\.rb$}) { "test" } 23 | end 24 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Andrew Porter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 1Password Connect Ruby SDK 2 | 3 | ![example workflow](https://github.com/partydrone/connect-sdk-ruby/actions/workflows/test.yml/badge.svg) [![Maintainability](https://api.codeclimate.com/v1/badges/e5d93bbb1ec1b779aada/maintainability)](https://codeclimate.com/github/partydrone/connect-sdk-ruby/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/e5d93bbb1ec1b779aada/test_coverage)](https://codeclimate.com/github/partydrone/connect-sdk-ruby/test_coverage) [![Gem Version](https://badge.fury.io/rb/op_connect.svg)](https://badge.fury.io/rb/op_connect) 4 | 5 | op_connect_banner 6 | 7 | The 1Password Connect Ruby SDK provides access to the 1Password Connect API 8 | hosted on your infrastructure. The gem is intended to be used by your 9 | applications, pipelines, and other automations to simplify accessing items 10 | stored in your 1Password vaults. 11 | 12 | ## Installation 13 | 14 | Add this line to your application's Gemfile: 15 | 16 | ```ruby 17 | gem 'op_connect' 18 | ``` 19 | 20 | And then execute: 21 | 22 | ```sh 23 | bundle install 24 | ``` 25 | 26 | Or install it yourself as: 27 | 28 | ```sh 29 | gem install op_connect 30 | ``` 31 | 32 | ## Configuration and Defaults 33 | 34 | While `OpConnect::Client` accepts a range of options when creating a new client 35 | instance, OpConnect's configuration API allows you to set your configuration 36 | options at the module level. This is particularly handy if you're creating a 37 | number of client instances based on some shared defaults. Changing options 38 | affects new instances only and will not modify existing `OpConnect::Client` 39 | instances created with previous options. 40 | 41 | ### Configuring module defaults 42 | 43 | Every writable attribute in `OpConnect::Configurable` can be set one at a time: 44 | 45 | ```ruby 46 | OpConnect.api_endpoint = "http://localhost:8080/v1" 47 | OpConnect.access_token = "secret_access_token" 48 | ``` 49 | 50 | Or in a batch: 51 | 52 | ```ruby 53 | OpConnect.configure do |config| 54 | config.api_endpoint = "http://localhost:8080/v1" 55 | config.access_token = "secret_access_token" 56 | end 57 | ``` 58 | 59 | ### Using ENV variables 60 | 61 | Default configuration values are specified in `OpConnect::Default`. Many attributes look for a 62 | default value from ENV before returning OpConnect's default. 63 | 64 | | Variable | Description | Default | 65 | | ------------------------- | ----------------------------------------------------------------------------- | ----------------------------------------------- | 66 | | `OP_CONNECT_ACCESS_TOKEN` | The API token used to authenticate the client to a 1Password Connect API. | | 67 | | `OP_CONNECT_API_ENDPOINT` | The URL of the 1Password Connect API server. | | 68 | | `OP_CONNECT_USER_AGENT` | The user-agent string the client uses when making requests. This is optional. | 1Password Connect Ruby SDK {OpConnect::VERSION} | 69 | 70 | ## Usage 71 | 72 | ### Making requests 73 | 74 | API methods are available as client instance methods. 75 | 76 | ```ruby 77 | # Provide an access token 78 | client = OpConnect::Client.new(access_token: "secret_access_token") 79 | 80 | # Fetch a list of vaults 81 | client.vaults 82 | ``` 83 | 84 | ### Using query parameters 85 | 86 | You can pass query parameters to some GET-based requests. 87 | 88 | ```ruby 89 | client.vaults filter: "title eq 'Secrets Automation'" 90 | ``` 91 | 92 | > 👀 For more information, see the [API documentation][api_docs]. 93 | 94 | ### Consuming resources 95 | 96 | Most methods return an object which provides convenient dot notation for fields 97 | returned in the API response. 98 | 99 | #### List vaults 100 | 101 | ```ruby 102 | vaults = client.vaults 103 | # => [# "alynbizzypgx62nti6zxajloei" 106 | ``` 107 | 108 | #### Get vault details 109 | 110 | ```ruby 111 | vault = client.vault(id: "alynbizzypgx62nti6zxajloei") 112 | # => # [# 👀 See the [API documentation](https://support.1password.com/connect-api-reference/#add-an-item) 128 | > for an example. 129 | 130 | ```ruby 131 | attributes = { 132 | vault: { 133 | id: vault.id 134 | }, 135 | title: "Secrets Automation Item", 136 | category: "LOGIN", 137 | fields: [ 138 | { 139 | value: "wendy", 140 | purpose: "USERNAME" 141 | }, 142 | { 143 | purpose: "PASSWORD", 144 | generate: true, 145 | recipe: { 146 | length: 55, 147 | characterSets: ["LETTERS", "DIGITS"] 148 | } 149 | } 150 | ] 151 | # … 152 | } 153 | 154 | item = client.create_item(vault_id: vault.id, body: attributes) 155 | # => # # "AWS IAM Account" 165 | item.favorite? 166 | # => false 167 | ``` 168 | 169 | #### Replace an item 170 | 171 | ```ruby 172 | attributes = { 173 | vault: { 174 | id: vault.id 175 | }, 176 | title: "Secrets Automation Item", 177 | category: "LOGIN", 178 | fields: [ 179 | { 180 | value: "jonathan", 181 | purpose: "USERNAME" 182 | }, 183 | { 184 | purpose: "PASSWORD", 185 | generate: true, 186 | recipe: { 187 | length: 55, 188 | characterSets: ["LETTERS", "DIGITS"] 189 | } 190 | } 191 | ] 192 | # … 193 | } 194 | 195 | item = client.replace_item(vault_id: vault.id, id: item.id, body: attributes) 196 | # => # 👀 See the [API documentation](https://support.1password.com/connect-api-reference/#add-an-item) 200 | > for an explanation and list of fields and object structure. 201 | 202 | #### Change item details 203 | 204 | Use the [JSON Patch](https://tools.ietf.org/html/rfc6902) document standard to 205 | compile a series of operations to make more targeted changes to an item. 206 | 207 | > 👀 See the [API documentation](https://support.1password.com/connect-api-reference/#change-item-details) 208 | > for more information. 209 | 210 | ```ruby 211 | attributes = [ 212 | {op: "replace", path: "/title", value: "New Secrets Automation Item"}, 213 | {op: "replace", path: "/fields/username", value: "tinkerbell"} 214 | ] 215 | 216 | item = client.update_item(vault_id: vault.id, id: item.id, body: attributes) 217 | # => # true 225 | ``` 226 | 227 | #### List files 228 | 229 | ```ruby 230 | files = client.files(vault_id: vault.id, item_id: item.id) 231 | # => [# # "The future belongs to the curious.\n" 246 | ``` 247 | 248 | #### List API activity 249 | 250 | Retrieve a list of API requests made to the server. 251 | 252 | ```ruby 253 | client.activity 254 | # => [# true 264 | ``` 265 | 266 | #### Get server health info 267 | 268 | Query the state of the server and its service dependencies. 269 | 270 | ```ruby 271 | client.health 272 | # => # "# HELP go_gc_duration_seconds A summary of the pause duration of … 282 | ``` 283 | 284 | ## Development 285 | 286 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. 287 | 288 | 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). 289 | 290 | ### Running a local 1Password Connect API server 291 | 292 | This project includes a docker-compose.yml file that will download and run an 293 | API and Sync server for you to test with locally. You will need to: 294 | 295 | - [ ] Install Docker, Docker for Mac, or Docker for Windows. 296 | - [ ] Place your 1password-credentials.json file in the root of this project. 297 | 298 | > 👀 See [Get started with a 1Password Secrets Automation workflow][secrets_automation_workflow] 299 | > for more information. 300 | 301 | ### Resources 302 | 303 | Some links that are definitely worth checking out: 304 | 305 | - [1Password Secrets Automation](https://1password.com/secrets/) 306 | - [Get started with a 1Password Secrets Automation workflow][secrets_automation_workflow] 307 | - [1Password Connect API reference][api_docs] 308 | 309 | ## Contributing 310 | 311 | Bug reports and pull requests are welcome on GitHub at . 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/partydrone/connect/blob/main/CODE_OF_CONDUCT.md). 312 | 313 | ## License 314 | 315 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). 316 | 317 | ## Code of Conduct 318 | 319 | Everyone interacting in the Connect project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/partydrone/connect/blob/main/CODE_OF_CONDUCT.md). 320 | 321 | [api_docs]: https://support.1password.com/connect-api-reference '1Password Connect API reference' 322 | [secrets_automation_workflow]: https://support.1password.com/secrets-automation/ 'Get started with a 1Password Secrets Automation workflow' 323 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_tasks" 4 | require "rake/testtask" 5 | 6 | Rake::TestTask.new(:test) do |t| 7 | t.libs << "test" 8 | t.libs << "lib" 9 | t.test_files = FileList["test/**/*_test.rb"] 10 | end 11 | 12 | task default: :test 13 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require "bundler/setup" 5 | require "op_connect" 6 | 7 | # You can add fixtures and/or initialization code here to make experimenting 8 | # with your gem easier. You can also use a different console, if you like. 9 | 10 | # (If you use this, don't forget to add pry to your Gemfile!) 11 | require "pry" 12 | Pry.start 13 | 14 | client ||= OpConnect.client 15 | 16 | require "irb" 17 | IRB.start(__FILE__) 18 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | ruby: 5 | build: 6 | args: 7 | RUBY_VERSION: 3.1.1 8 | context: . 9 | depends_on: 10 | - op-connect-api 11 | - op-connect-sync 12 | environment: 13 | - OP_CONNECT_API_ENDPOINT=http://op-connect-api:8080/v1 14 | volumes: 15 | - .:/opt/gem 16 | - bundle:/usr/local/bundle 17 | 18 | op-connect-api: 19 | image: 1password/connect-api:latest 20 | ports: 21 | - 8080:8080 22 | volumes: 23 | - ./1password-credentials.json:/home/opuser/.op/1password-credentials.json 24 | - op-connect-data:/home/opuser/.op/data 25 | op-connect-sync: 26 | image: 1password/connect-sync:latest 27 | ports: 28 | - 8081:8080 29 | volumes: 30 | - ./1password-credentials.json:/home/opuser/.op/1password-credentials.json 31 | - op-connect-data:/home/opuser/.op/data 32 | 33 | volumes: 34 | bundle: null 35 | op-connect-data: null 36 | -------------------------------------------------------------------------------- /docs/OpConnect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Module: OpConnect 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Module: OpConnect 63 | 64 | 65 | 66 |

67 |
68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 |
80 |
Defined in:
81 |
lib/op_connect/api_request.rb,
82 | lib/op_connect/client.rb,
lib/op_connect/configurable.rb,
lib/op_connect/connection.rb,
lib/op_connect/default.rb,
lib/op_connect/error.rb,
lib/op_connect/item.rb,
lib/op_connect/object.rb,
lib/op_connect/response.rb,
lib/op_connect/server_health.rb,
lib/op_connect/vault.rb,
lib/op_connect/version.rb
83 |
84 |
85 | 86 |
87 | 88 |

Defined Under Namespace

89 |

90 | 91 | 92 | Modules: Configurable, Connection, Default, Response 93 | 94 | 95 | 96 | Classes: APIRequest, BadRequest, Client, ClientError, Error, Forbidden, InternalServerError, Item, NotFound, Object, PayloadTooLarge, ServerError, ServerHealth, ServiceUnavailable, Unauthorized, Vault 97 | 98 | 99 |

100 | 101 | 102 |

103 | Constant Summary 104 | collapse 105 |

106 | 107 |
108 | 109 |
VERSION = 110 | 111 |
112 |
"0.1.3"
113 | 114 |
115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 |
126 | 127 | 132 | 133 |
134 | 135 | -------------------------------------------------------------------------------- /docs/OpConnect/BadRequest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Exception: OpConnect::BadRequest 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Exception: OpConnect::BadRequest 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | ClientError 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 |
86 | show all 87 | 88 |
89 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
102 |
Defined in:
103 |
lib/op_connect/error.rb
104 |
105 | 106 |
107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 |

Method Summary

129 | 130 |

Methods inherited from Error

131 |

from_response, #initialize

132 | 133 |
134 |

Constructor Details

135 | 136 |

This class inherits a constructor from OpConnect::Error

137 | 138 |
139 | 140 | 141 |
142 | 143 | 148 | 149 |
150 | 151 | -------------------------------------------------------------------------------- /docs/OpConnect/Client/Vaults.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Module: OpConnect::Client::Vaults 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Module: OpConnect::Client::Vaults 63 | 64 | 65 | 66 |

67 |
68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 |
78 |
Included in:
79 |
OpConnect::Client
80 |
81 | 82 | 83 | 84 |
85 |
Defined in:
86 |
lib/op_connect/client/vaults.rb
87 |
88 | 89 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 |

100 | Instance Method Summary 101 | collapse 102 |

103 | 104 |
    105 | 106 |
  • 107 | 108 | 109 | #get_vault(id:) ⇒ Object 110 | 111 | 112 | 113 | (also: #vault) 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 |
    126 | 127 |
  • 128 | 129 | 130 |
  • 131 | 132 | 133 | #list_vaults(**params) ⇒ Object 134 | 135 | 136 | 137 | (also: #vaults) 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 |
    150 | 151 |
  • 152 | 153 | 154 |
155 | 156 | 157 | 158 | 159 |
160 |

Instance Method Details

161 | 162 | 163 |
164 |

165 | 166 | #get_vault(id:) ⇒ Object 167 | 168 | 169 | 170 | Also known as: 171 | vault 172 | 173 | 174 | 175 | 176 |

177 | 178 | 186 | 193 | 194 |
179 |
180 | 
181 | 
182 | 9
183 | 10
184 | 11
185 |
187 |
# File 'lib/op_connect/client/vaults.rb', line 9
188 | 
189 | def get_vault(id:)
190 |   Vault.new get("vaults/#{id}").body
191 | end
192 |
195 |
196 | 197 |
198 |

199 | 200 | #list_vaults(**params) ⇒ Object 201 | 202 | 203 | 204 | Also known as: 205 | vaults 206 | 207 | 208 | 209 | 210 |

211 | 212 | 220 | 227 | 228 |
213 |
214 | 
215 | 
216 | 4
217 | 5
218 | 6
219 |
221 |
# File 'lib/op_connect/client/vaults.rb', line 4
222 | 
223 | def list_vaults(**params)
224 |   get("vaults", params: params).body.map { |vault| Vault.new(vault) }
225 | end
226 |
229 |
230 | 231 |
232 | 233 |
234 | 235 | 240 | 241 |
242 | 243 | -------------------------------------------------------------------------------- /docs/OpConnect/ClientError.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Exception: OpConnect::ClientError 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Exception: OpConnect::ClientError 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | Error 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 | show all 85 | 86 |
87 |
88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 |
100 |
Defined in:
101 |
lib/op_connect/error.rb
102 |
103 | 104 |
105 | 106 |
107 |

Direct Known Subclasses

108 |

BadRequest, Forbidden, NotFound, PayloadTooLarge, Unauthorized

109 |
110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 |

Method Summary

125 | 126 |

Methods inherited from Error

127 |

from_response, #initialize

128 | 129 |
130 |

Constructor Details

131 | 132 |

This class inherits a constructor from OpConnect::Error

133 | 134 |
135 | 136 | 137 |
138 | 139 | 144 | 145 |
146 | 147 | -------------------------------------------------------------------------------- /docs/OpConnect/Forbidden.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Exception: OpConnect::Forbidden 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Exception: OpConnect::Forbidden 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | ClientError 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 |
86 | show all 87 | 88 |
89 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
102 |
Defined in:
103 |
lib/op_connect/error.rb
104 |
105 | 106 |
107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 |

Method Summary

129 | 130 |

Methods inherited from Error

131 |

from_response, #initialize

132 | 133 |
134 |

Constructor Details

135 | 136 |

This class inherits a constructor from OpConnect::Error

137 | 138 |
139 | 140 | 141 |
142 | 143 | 148 | 149 |
150 | 151 | -------------------------------------------------------------------------------- /docs/OpConnect/InternalServerError.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Exception: OpConnect::InternalServerError 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Exception: OpConnect::InternalServerError 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | ServerError 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 |
86 | show all 87 | 88 |
89 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
102 |
Defined in:
103 |
lib/op_connect/error.rb
104 |
105 | 106 |
107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 |

Method Summary

129 | 130 |

Methods inherited from Error

131 |

from_response, #initialize

132 | 133 |
134 |

Constructor Details

135 | 136 |

This class inherits a constructor from OpConnect::Error

137 | 138 |
139 | 140 | 141 |
142 | 143 | 148 | 149 |
150 | 151 | -------------------------------------------------------------------------------- /docs/OpConnect/Item/GeneratorRecipe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Class: OpConnect::Item::GeneratorRecipe 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Class: OpConnect::Item::GeneratorRecipe 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | Object 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 |
80 | show all 81 | 82 |
83 |
84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 |
96 |
Defined in:
97 |
lib/op_connect/item/generator_recipe.rb
98 |
99 | 100 |
101 | 102 | 103 | 104 | 105 | 106 |

Instance Attribute Summary collapse

107 |
    108 | 109 |
  • 110 | 111 | 112 | #character_sets ⇒ Object 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | readonly 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 |
    132 |

    Returns the value of attribute character_sets.

    133 |
    134 | 135 |
  • 136 | 137 | 138 |
  • 139 | 140 | 141 | #length ⇒ Object 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | readonly 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 |
    161 |

    Returns the value of attribute length.

    162 |
    163 | 164 |
  • 165 | 166 | 167 |
168 | 169 | 170 | 171 | 172 | 173 |

174 | Instance Method Summary 175 | collapse 176 |

177 | 178 |
    179 | 180 |
  • 181 | 182 | 183 | #initialize(options = {}) ⇒ GeneratorRecipe 184 | 185 | 186 | 187 | 188 | 189 | 190 | constructor 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 |
    200 |

    A new instance of GeneratorRecipe.

    201 |
    202 | 203 |
  • 204 | 205 | 206 |
207 | 208 | 209 |
210 |

Constructor Details

211 | 212 |
213 |

214 | 215 | #initialize(options = {}) ⇒ GeneratorRecipe 216 | 217 | 218 | 219 | 220 | 221 |

222 |
223 | 224 |

Returns a new instance of GeneratorRecipe.

225 | 226 | 227 |
228 |
229 |
230 | 231 | 232 |
233 | 234 | 243 | 251 | 252 |
235 |
236 | 
237 | 
238 | 6
239 | 7
240 | 8
241 | 9
242 |
244 |
# File 'lib/op_connect/item/generator_recipe.rb', line 6
245 | 
246 | def initialize(options = {})
247 |   @length = options["length"] if options & ["length"]
248 |   @character_sets = options["characterSets"] if options & ["characterSets"]
249 | end
250 |
253 |
254 | 255 |
256 | 257 |
258 |

Instance Attribute Details

259 | 260 | 261 | 262 |
263 |

264 | 265 | #character_setsObject (readonly) 266 | 267 | 268 | 269 | 270 | 271 |

272 |
273 | 274 |

Returns the value of attribute character_sets.

275 | 276 | 277 |
278 |
279 |
280 | 281 | 282 |
283 | 284 | 292 | 299 | 300 |
285 |
286 | 
287 | 
288 | 4
289 | 5
290 | 6
291 |
293 |
# File 'lib/op_connect/item/generator_recipe.rb', line 4
294 | 
295 | def character_sets
296 |   @character_sets
297 | end
298 |
301 |
302 | 303 | 304 | 305 |
306 |

307 | 308 | #lengthObject (readonly) 309 | 310 | 311 | 312 | 313 | 314 |

315 |
316 | 317 |

Returns the value of attribute length.

318 | 319 | 320 |
321 |
322 |
323 | 324 | 325 |
326 | 327 | 335 | 342 | 343 |
328 |
329 | 
330 | 
331 | 4
332 | 5
333 | 6
334 |
336 |
# File 'lib/op_connect/item/generator_recipe.rb', line 4
337 | 
338 | def length
339 |   @length
340 | end
341 |
344 |
345 | 346 |
347 | 348 | 349 |
350 | 351 | 356 | 357 |
358 | 359 | -------------------------------------------------------------------------------- /docs/OpConnect/Item/Section.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Class: OpConnect::Item::Section 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Class: OpConnect::Item::Section 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | Object 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 |
80 | show all 81 | 82 |
83 |
84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 |
96 |
Defined in:
97 |
lib/op_connect/item/section.rb
98 |
99 | 100 |
101 | 102 | 103 | 104 | 105 | 106 |

Instance Attribute Summary collapse

107 |
    108 | 109 |
  • 110 | 111 | 112 | #id ⇒ Object 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | readonly 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 |
    132 |

    Returns the value of attribute id.

    133 |
    134 | 135 |
  • 136 | 137 | 138 |
  • 139 | 140 | 141 | #label ⇒ Object 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | readonly 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 |
    161 |

    Returns the value of attribute label.

    162 |
    163 | 164 |
  • 165 | 166 | 167 |
168 | 169 | 170 | 171 | 172 | 173 |

174 | Instance Method Summary 175 | collapse 176 |

177 | 178 |
    179 | 180 |
  • 181 | 182 | 183 | #initialize(options = {}) ⇒ Section 184 | 185 | 186 | 187 | 188 | 189 | 190 | constructor 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 |
    200 |

    A new instance of Section.

    201 |
    202 | 203 |
  • 204 | 205 | 206 |
207 | 208 | 209 |
210 |

Constructor Details

211 | 212 |
213 |

214 | 215 | #initialize(options = {}) ⇒ Section 216 | 217 | 218 | 219 | 220 | 221 |

222 |
223 | 224 |

Returns a new instance of Section.

225 | 226 | 227 |
228 |
229 |
230 | 231 | 232 |
233 | 234 | 243 | 251 | 252 |
235 |
236 | 
237 | 
238 | 6
239 | 7
240 | 8
241 | 9
242 |
244 |
# File 'lib/op_connect/item/section.rb', line 6
245 | 
246 | def initialize(options = {})
247 |   @id = options["id"]
248 |   @label = options["label"]
249 | end
250 |
253 |
254 | 255 |
256 | 257 |
258 |

Instance Attribute Details

259 | 260 | 261 | 262 |
263 |

264 | 265 | #idObject (readonly) 266 | 267 | 268 | 269 | 270 | 271 |

272 |
273 | 274 |

Returns the value of attribute id.

275 | 276 | 277 |
278 |
279 |
280 | 281 | 282 |
283 | 284 | 292 | 299 | 300 |
285 |
286 | 
287 | 
288 | 4
289 | 5
290 | 6
291 |
293 |
# File 'lib/op_connect/item/section.rb', line 4
294 | 
295 | def id
296 |   @id
297 | end
298 |
301 |
302 | 303 | 304 | 305 |
306 |

307 | 308 | #labelObject (readonly) 309 | 310 | 311 | 312 | 313 | 314 |

315 |
316 | 317 |

Returns the value of attribute label.

318 | 319 | 320 |
321 |
322 |
323 | 324 | 325 |
326 | 327 | 335 | 342 | 343 |
328 |
329 | 
330 | 
331 | 4
332 | 5
333 | 6
334 |
336 |
# File 'lib/op_connect/item/section.rb', line 4
337 | 
338 | def label
339 |   @label
340 | end
341 |
344 |
345 | 346 |
347 | 348 | 349 |
350 | 351 | 356 | 357 |
358 | 359 | -------------------------------------------------------------------------------- /docs/OpConnect/Item/URL.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Class: OpConnect::Item::URL 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Class: OpConnect::Item::URL 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | Object 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 |
80 | show all 81 | 82 |
83 |
84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 |
96 |
Defined in:
97 |
lib/op_connect/item/url.rb
98 |
99 | 100 |
101 | 102 | 103 | 104 | 105 | 106 |

Instance Attribute Summary collapse

107 |
    108 | 109 |
  • 110 | 111 | 112 | #is_primary ⇒ Object 113 | 114 | 115 | 116 | (also: #primary?) 117 | 118 | 119 | 120 | 121 | 122 | 123 | readonly 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 |
    134 |

    Returns the value of attribute is_primary.

    135 |
    136 | 137 |
  • 138 | 139 | 140 |
  • 141 | 142 | 143 | #url ⇒ Object 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | readonly 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 |
    163 |

    Returns the value of attribute url.

    164 |
    165 | 166 |
  • 167 | 168 | 169 |
170 | 171 | 172 | 173 | 174 | 175 |

176 | Instance Method Summary 177 | collapse 178 |

179 | 180 |
    181 | 182 |
  • 183 | 184 | 185 | #initialize(options = {}) ⇒ URL 186 | 187 | 188 | 189 | 190 | 191 | 192 | constructor 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 |
    202 |

    A new instance of URL.

    203 |
    204 | 205 |
  • 206 | 207 | 208 |
209 | 210 | 211 |
212 |

Constructor Details

213 | 214 |
215 |

216 | 217 | #initialize(options = {}) ⇒ URL 218 | 219 | 220 | 221 | 222 | 223 |

224 |
225 | 226 |

Returns a new instance of URL.

227 | 228 | 229 |
230 |
231 |
232 | 233 | 234 |
235 | 236 | 245 | 253 | 254 |
237 |
238 | 
239 | 
240 | 8
241 | 9
242 | 10
243 | 11
244 |
246 |
# File 'lib/op_connect/item/url.rb', line 8
247 | 
248 | def initialize(options = {})
249 |   @url = options["url"]
250 |   @is_primary = options["primary"] || false
251 | end
252 |
255 |
256 | 257 |
258 | 259 |
260 |

Instance Attribute Details

261 | 262 | 263 | 264 |
265 |

266 | 267 | #is_primaryObject (readonly) 268 | 269 | 270 | 271 | Also known as: 272 | primary? 273 | 274 | 275 | 276 | 277 |

278 |
279 | 280 |

Returns the value of attribute is_primary.

281 | 282 | 283 |
284 |
285 |
286 | 287 | 288 |
289 | 290 | 298 | 305 | 306 |
291 |
292 | 
293 | 
294 | 4
295 | 5
296 | 6
297 |
299 |
# File 'lib/op_connect/item/url.rb', line 4
300 | 
301 | def is_primary
302 |   @is_primary
303 | end
304 |
307 |
308 | 309 | 310 | 311 |
312 |

313 | 314 | #urlObject (readonly) 315 | 316 | 317 | 318 | 319 | 320 |

321 |
322 | 323 |

Returns the value of attribute url.

324 | 325 | 326 |
327 |
328 |
329 | 330 | 331 |
332 | 333 | 341 | 348 | 349 |
334 |
335 | 
336 | 
337 | 4
338 | 5
339 | 6
340 |
342 |
# File 'lib/op_connect/item/url.rb', line 4
343 | 
344 | def url
345 |   @url
346 | end
347 |
350 |
351 | 352 |
353 | 354 | 355 |
356 | 357 | 362 | 363 |
364 | 365 | -------------------------------------------------------------------------------- /docs/OpConnect/NotFound.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Exception: OpConnect::NotFound 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Exception: OpConnect::NotFound 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | ClientError 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 |
86 | show all 87 | 88 |
89 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
102 |
Defined in:
103 |
lib/op_connect/error.rb
104 |
105 | 106 |
107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 |

Method Summary

129 | 130 |

Methods inherited from Error

131 |

from_response, #initialize

132 | 133 |
134 |

Constructor Details

135 | 136 |

This class inherits a constructor from OpConnect::Error

137 | 138 |
139 | 140 | 141 |
142 | 143 | 148 | 149 |
150 | 151 | -------------------------------------------------------------------------------- /docs/OpConnect/Object.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Class: OpConnect::Object 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Class: OpConnect::Object 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | SimpleDelegator 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 | 80 | 81 |
82 | show all 83 | 84 |
85 |
86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 |
98 |
Defined in:
99 |
lib/op_connect/object.rb
100 |
101 | 102 |
103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 |

113 | Instance Method Summary 114 | collapse 115 |

116 | 117 |
    118 | 119 |
  • 120 | 121 | 122 | #initialize(attributes) ⇒ Object 123 | 124 | 125 | 126 | 127 | 128 | 129 | constructor 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 |
    139 |

    A new instance of Object.

    140 |
    141 | 142 |
  • 143 | 144 | 145 |
146 | 147 | 148 | 149 |
150 |

Constructor Details

151 | 152 |
153 |

154 | 155 | #initialize(attributes) ⇒ Object 156 | 157 | 158 | 159 | 160 | 161 |

162 |
163 | 164 |

Returns a new instance of Object.

165 | 166 | 167 |
168 |
169 |
170 | 171 | 172 |
173 | 174 | 182 | 189 | 190 |
175 |
176 | 
177 | 
178 | 5
179 | 6
180 | 7
181 |
183 |
# File 'lib/op_connect/object.rb', line 5
184 | 
185 | def initialize(attributes)
186 |   super to_ostruct(attributes)
187 | end
188 |
191 |
192 | 193 |
194 | 195 | 196 |
197 | 198 | 203 | 204 |
205 | 206 | -------------------------------------------------------------------------------- /docs/OpConnect/PayloadTooLarge.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Exception: OpConnect::PayloadTooLarge 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Exception: OpConnect::PayloadTooLarge 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | ClientError 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 |
86 | show all 87 | 88 |
89 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
102 |
Defined in:
103 |
lib/op_connect/error.rb
104 |
105 | 106 |
107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 |

Method Summary

129 | 130 |

Methods inherited from Error

131 |

from_response, #initialize

132 | 133 |
134 |

Constructor Details

135 | 136 |

This class inherits a constructor from OpConnect::Error

137 | 138 |
139 | 140 | 141 |
142 | 143 | 148 | 149 |
150 | 151 | -------------------------------------------------------------------------------- /docs/OpConnect/Response.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Module: OpConnect::Response 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Module: OpConnect::Response 63 | 64 | 65 | 66 |

67 |
68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 |
80 |
Defined in:
81 |
lib/op_connect/response.rb
82 |
83 | 84 |
85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 |
96 | 97 | 102 | 103 |
104 | 105 | -------------------------------------------------------------------------------- /docs/OpConnect/Response/RaiseError.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Class: OpConnect::Response::RaiseError 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Class: OpConnect::Response::RaiseError 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | Faraday::Middleware 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 | 80 | 81 |
82 | show all 83 | 84 |
85 |
86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 |
98 |
Defined in:
99 |
lib/op_connect/response/raise_error.rb
100 |
101 | 102 |
103 | 104 |

Overview

105 |
106 | 107 |

This class raises an OpConnect-flavored exception based on HTTP status codes returned by the API.

108 | 109 | 110 |
111 |
112 |
113 | 114 | 115 |
116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 |

124 | Instance Method Summary 125 | collapse 126 |

127 | 128 |
    129 | 130 |
  • 131 | 132 | 133 | #on_complete(response) ⇒ Object 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
    148 | 149 |
  • 150 | 151 | 152 |
153 | 154 | 155 | 156 | 157 | 158 |
159 |

Instance Method Details

160 | 161 | 162 |
163 |

164 | 165 | #on_complete(response) ⇒ Object 166 | 167 | 168 | 169 | 170 | 171 |

172 | 173 | 183 | 192 | 193 |
174 |
175 | 
176 | 
177 | 9
178 | 10
179 | 11
180 | 12
181 | 13
182 |
184 |
# File 'lib/op_connect/response/raise_error.rb', line 9
185 | 
186 | def on_complete(response)
187 |   if (error = OpConnect::Error.from_response(response))
188 |     raise error
189 |   end
190 | end
191 |
194 |
195 | 196 |
197 | 198 |
199 | 200 | 205 | 206 |
207 | 208 | -------------------------------------------------------------------------------- /docs/OpConnect/ServerError.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Exception: OpConnect::ServerError 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Exception: OpConnect::ServerError 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | Error 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 | show all 85 | 86 |
87 |
88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 |
100 |
Defined in:
101 |
lib/op_connect/error.rb
102 |
103 | 104 |
105 | 106 |
107 |

Direct Known Subclasses

108 |

InternalServerError, ServiceUnavailable

109 |
110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 |

Method Summary

125 | 126 |

Methods inherited from Error

127 |

from_response, #initialize

128 | 129 |
130 |

Constructor Details

131 | 132 |

This class inherits a constructor from OpConnect::Error

133 | 134 |
135 | 136 | 137 |
138 | 139 | 144 | 145 |
146 | 147 | -------------------------------------------------------------------------------- /docs/OpConnect/ServiceUnavailable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Exception: OpConnect::ServiceUnavailable 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Exception: OpConnect::ServiceUnavailable 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | ServerError 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 |
86 | show all 87 | 88 |
89 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
102 |
Defined in:
103 |
lib/op_connect/error.rb
104 |
105 | 106 |
107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 |

Method Summary

129 | 130 |

Methods inherited from Error

131 |

from_response, #initialize

132 | 133 |
134 |

Constructor Details

135 | 136 |

This class inherits a constructor from OpConnect::Error

137 | 138 |
139 | 140 | 141 |
142 | 143 | 148 | 149 |
150 | 151 | -------------------------------------------------------------------------------- /docs/OpConnect/Unauthorized.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Exception: OpConnect::Unauthorized 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
36 | 61 | 62 |

Exception: OpConnect::Unauthorized 63 | 64 | 65 | 66 |

67 |
68 | 69 |
70 |
Inherits:
71 |
72 | ClientError 73 | 74 |
    75 |
  • Object
  • 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 |
86 | show all 87 | 88 |
89 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
102 |
Defined in:
103 |
lib/op_connect/error.rb
104 |
105 | 106 |
107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 |

Method Summary

129 | 130 |

Methods inherited from Error

131 |

from_response, #initialize

132 | 133 |
134 |

Constructor Details

135 | 136 |

This class inherits a constructor from OpConnect::Error

137 | 138 |
139 | 140 | 141 |
142 | 143 | 148 | 149 |
150 | 151 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /docs/class_list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Class List 19 | 20 | 21 | 22 |
23 |
24 |

Class List

25 |
26 | 27 | 28 | Classes 29 | 30 | 31 | 32 | Methods 33 | 34 | 35 | 36 | Files 37 | 38 | 39 |
40 | 41 | 42 |
43 | 44 | 49 |
50 | 51 | 52 | -------------------------------------------------------------------------------- /docs/css/common.css: -------------------------------------------------------------------------------- 1 | /* Override this file with custom rules */ -------------------------------------------------------------------------------- /docs/css/full_list.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; 4 | font-size: 13px; 5 | height: 101%; 6 | overflow-x: hidden; 7 | background: #fafafa; 8 | } 9 | 10 | h1 { padding: 12px 10px; padding-bottom: 0; margin: 0; font-size: 1.4em; } 11 | .clear { clear: both; } 12 | .fixed_header { position: fixed; background: #fff; width: 100%; padding-bottom: 10px; margin-top: 0; top: 0; z-index: 9999; height: 70px; } 13 | #search { position: absolute; right: 5px; top: 9px; padding-left: 24px; } 14 | #content.insearch #search, #content.insearch #noresults { background: url(data:image/gif;base64,R0lGODlhEAAQAPYAAP///wAAAPr6+pKSkoiIiO7u7sjIyNjY2J6engAAAI6OjsbGxjIyMlJSUuzs7KamppSUlPLy8oKCghwcHLKysqSkpJqamvT09Pj4+KioqM7OzkRERAwMDGBgYN7e3ujo6Ly8vCoqKjY2NkZGRtTU1MTExDw8PE5OTj4+PkhISNDQ0MrKylpaWrS0tOrq6nBwcKysrLi4uLq6ul5eXlxcXGJiYoaGhuDg4H5+fvz8/KKiohgYGCwsLFZWVgQEBFBQUMzMzDg4OFhYWBoaGvDw8NbW1pycnOLi4ubm5kBAQKqqqiQkJCAgIK6urnJyckpKSjQ0NGpqatLS0sDAwCYmJnx8fEJCQlRUVAoKCggICLCwsOTk5ExMTPb29ra2tmZmZmhoaNzc3KCgoBISEiIiIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCAAAACwAAAAAEAAQAAAHaIAAgoMgIiYlg4kACxIaACEJCSiKggYMCRselwkpghGJBJEcFgsjJyoAGBmfggcNEx0flBiKDhQFlIoCCA+5lAORFb4AJIihCRbDxQAFChAXw9HSqb60iREZ1omqrIPdJCTe0SWI09GBACH5BAkIAAAALAAAAAAQABAAAAdrgACCgwc0NTeDiYozCQkvOTo9GTmDKy8aFy+NOBA7CTswgywJDTIuEjYFIY0JNYMtKTEFiRU8Pjwygy4ws4owPyCKwsMAJSTEgiQlgsbIAMrO0dKDGMTViREZ14kYGRGK38nHguHEJcvTyIEAIfkECQgAAAAsAAAAABAAEAAAB2iAAIKDAggPg4iJAAMJCRUAJRIqiRGCBI0WQEEJJkWDERkYAAUKEBc4Po1GiKKJHkJDNEeKig4URLS0ICImJZAkuQAhjSi/wQyNKcGDCyMnk8u5rYrTgqDVghgZlYjcACTA1sslvtHRgQAh+QQJCAAAACwAAAAAEAAQAAAHZ4AAgoOEhYaCJSWHgxGDJCQARAtOUoQRGRiFD0kJUYWZhUhKT1OLhR8wBaaFBzQ1NwAlkIszCQkvsbOHL7Y4q4IuEjaqq0ZQD5+GEEsJTDCMmIUhtgk1lo6QFUwJVDKLiYJNUd6/hoEAIfkECQgAAAAsAAAAABAAEAAAB2iAAIKDhIWGgiUlh4MRgyQkjIURGRiGGBmNhJWHm4uen4ICCA+IkIsDCQkVACWmhwSpFqAABQoQF6ALTkWFnYMrVlhWvIKTlSAiJiVVPqlGhJkhqShHV1lCW4cMqSkAR1ofiwsjJyqGgQAh+QQJCAAAACwAAAAAEAAQAAAHZ4AAgoOEhYaCJSWHgxGDJCSMhREZGIYYGY2ElYebi56fhyWQniSKAKKfpaCLFlAPhl0gXYNGEwkhGYREUywag1wJwSkHNDU3D0kJYIMZQwk8MjPBLx9eXwuETVEyAC/BOKsuEjYFhoEAIfkECQgAAAAsAAAAABAAEAAAB2eAAIKDhIWGgiUlh4MRgyQkjIURGRiGGBmNhJWHm4ueICImip6CIQkJKJ4kigynKaqKCyMnKqSEK05StgAGQRxPYZaENqccFgIID4KXmQBhXFkzDgOnFYLNgltaSAAEpxa7BQoQF4aBACH5BAkIAAAALAAAAAAQABAAAAdogACCg4SFggJiPUqCJSWGgkZjCUwZACQkgxGEXAmdT4UYGZqCGWQ+IjKGGIUwPzGPhAc0NTewhDOdL7Ykji+dOLuOLhI2BbaFETICx4MlQitdqoUsCQ2vhKGjglNfU0SWmILaj43M5oEAOwAAAAAAAAAAAA==) no-repeat center left; } 15 | #full_list { padding: 0; list-style: none; margin-left: 0; margin-top: 80px; font-size: 1.1em; } 16 | #full_list ul { padding: 0; } 17 | #full_list li { padding: 0; margin: 0; list-style: none; } 18 | #full_list li .item { padding: 5px 5px 5px 12px; } 19 | #noresults { padding: 7px 12px; background: #fff; } 20 | #content.insearch #noresults { margin-left: 7px; } 21 | li.collapsed ul { display: none; } 22 | li a.toggle { cursor: default; position: relative; left: -5px; top: 4px; text-indent: -999px; width: 10px; height: 9px; margin-left: -10px; display: block; float: left; background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAK8AAACvABQqw0mAAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTM5jWRgMAAAAVdEVYdENyZWF0aW9uIFRpbWUAMy8xNC8wOeNZPpQAAAE2SURBVDiNrZTBccIwEEXfelIAHUA6CZ24BGaWO+FuzZAK4k6gg5QAdGAq+Bxs2Yqx7BzyL7Llp/VfzZeQhCTc/ezuGzKKnKSzpCxXJM8fwNXda3df5RZETlIt6YUzSQDs93sl8w3wBZxCCE10GM1OcWbWjB2mWgEH4Mfdyxm3PSepBHibgQE2wLe7r4HjEidpnXMYdQPKEMJcsZ4zs2POYQOcaPfwMVOo58zsAdMt18BuoVDPxUJRacELbXv3hUIX2vYmOUvi8C8ydz/ThjXrqKqqLbDIAdsCKBd+Wo7GWa7o9qzOQHVVVXeAbs+yHHCH4aTsaCOQqunmUy1yBUAXkdMIfMlgF5EXLo2OpV/c/Up7jG4hhHcYLgWzAZXUc2b2ixsfvc/RmNNfOXD3Q/oeL9axJE1yT9IOoUu6MGUkAAAAAElFTkSuQmCC) no-repeat bottom left; } 23 | li.collapsed a.toggle { opacity: 0.5; cursor: default; background-position: top left; } 24 | li { color: #888; cursor: pointer; } 25 | li.deprecated { text-decoration: line-through; font-style: italic; } 26 | li.odd { background: #f0f0f0; } 27 | li.even { background: #fafafa; } 28 | .item:hover { background: #ddd; } 29 | li small:before { content: "("; } 30 | li small:after { content: ")"; } 31 | li small.search_info { display: none; } 32 | a, a:visited { text-decoration: none; color: #05a; } 33 | li.clicked > .item { background: #05a; color: #ccc; } 34 | li.clicked > .item a, li.clicked > .item a:visited { color: #eee; } 35 | li.clicked > .item a.toggle { opacity: 0.5; background-position: bottom right; } 36 | li.collapsed.clicked a.toggle { background-position: top right; } 37 | #search input { border: 1px solid #bbb; border-radius: 3px; } 38 | #full_list_nav { margin-left: 10px; font-size: 0.9em; display: block; color: #aaa; } 39 | #full_list_nav a, #nav a:visited { color: #358; } 40 | #full_list_nav a:hover { background: transparent; color: #5af; } 41 | #full_list_nav span:after { content: ' | '; } 42 | #full_list_nav span:last-child:after { content: ''; } 43 | 44 | #content h1 { margin-top: 0; } 45 | li { white-space: nowrap; cursor: normal; } 46 | li small { display: block; font-size: 0.8em; } 47 | li small:before { content: ""; } 48 | li small:after { content: ""; } 49 | li small.search_info { display: none; } 50 | #search { width: 170px; position: static; margin: 3px; margin-left: 10px; font-size: 0.9em; color: #888; padding-left: 0; padding-right: 24px; } 51 | #content.insearch #search { background-position: center right; } 52 | #search input { width: 110px; } 53 | 54 | #full_list.insearch ul { display: block; } 55 | #full_list.insearch .item { display: none; } 56 | #full_list.insearch .found { display: block; padding-left: 11px !important; } 57 | #full_list.insearch li a.toggle { display: none; } 58 | #full_list.insearch li small.search_info { display: block; } 59 | -------------------------------------------------------------------------------- /docs/file_list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | File List 19 | 20 | 21 | 22 |
23 |
24 |

File List

25 |
26 | 27 | 28 | Classes 29 | 30 | 31 | 32 | Methods 33 | 34 | 35 | 36 | Files 37 | 38 | 39 |
40 | 41 | 42 |
43 | 44 |
    45 | 46 | 47 |
  • 48 | 49 |
  • 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | -------------------------------------------------------------------------------- /docs/frames.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Documentation by YARD 0.9.27 6 | 7 | 13 | 17 | 18 | -------------------------------------------------------------------------------- /docs/js/app.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | var localStorage = {}, sessionStorage = {}; 4 | try { localStorage = window.localStorage; } catch (e) { } 5 | try { sessionStorage = window.sessionStorage; } catch (e) { } 6 | 7 | function createSourceLinks() { 8 | $('.method_details_list .source_code'). 9 | before("[View source]"); 10 | $('.toggleSource').toggle(function() { 11 | $(this).parent().nextAll('.source_code').slideDown(100); 12 | $(this).text("Hide source"); 13 | }, 14 | function() { 15 | $(this).parent().nextAll('.source_code').slideUp(100); 16 | $(this).text("View source"); 17 | }); 18 | } 19 | 20 | function createDefineLinks() { 21 | var tHeight = 0; 22 | $('.defines').after(" more..."); 23 | $('.toggleDefines').toggle(function() { 24 | tHeight = $(this).parent().prev().height(); 25 | $(this).prev().css('display', 'inline'); 26 | $(this).parent().prev().height($(this).parent().height()); 27 | $(this).text("(less)"); 28 | }, 29 | function() { 30 | $(this).prev().hide(); 31 | $(this).parent().prev().height(tHeight); 32 | $(this).text("more..."); 33 | }); 34 | } 35 | 36 | function createFullTreeLinks() { 37 | var tHeight = 0; 38 | $('.inheritanceTree').toggle(function() { 39 | tHeight = $(this).parent().prev().height(); 40 | $(this).parent().toggleClass('showAll'); 41 | $(this).text("(hide)"); 42 | $(this).parent().prev().height($(this).parent().height()); 43 | }, 44 | function() { 45 | $(this).parent().toggleClass('showAll'); 46 | $(this).parent().prev().height(tHeight); 47 | $(this).text("show all"); 48 | }); 49 | } 50 | 51 | function searchFrameButtons() { 52 | $('.full_list_link').click(function() { 53 | toggleSearchFrame(this, $(this).attr('href')); 54 | return false; 55 | }); 56 | window.addEventListener('message', function(e) { 57 | if (e.data === 'navEscape') { 58 | $('#nav').slideUp(100); 59 | $('#search a').removeClass('active inactive'); 60 | $(window).focus(); 61 | } 62 | }); 63 | 64 | $(window).resize(function() { 65 | if ($('#search:visible').length === 0) { 66 | $('#nav').removeAttr('style'); 67 | $('#search a').removeClass('active inactive'); 68 | $(window).focus(); 69 | } 70 | }); 71 | } 72 | 73 | function toggleSearchFrame(id, link) { 74 | var frame = $('#nav'); 75 | $('#search a').removeClass('active').addClass('inactive'); 76 | if (frame.attr('src') === link && frame.css('display') !== "none") { 77 | frame.slideUp(100); 78 | $('#search a').removeClass('active inactive'); 79 | } 80 | else { 81 | $(id).addClass('active').removeClass('inactive'); 82 | if (frame.attr('src') !== link) frame.attr('src', link); 83 | frame.slideDown(100); 84 | } 85 | } 86 | 87 | function linkSummaries() { 88 | $('.summary_signature').click(function() { 89 | document.location = $(this).find('a').attr('href'); 90 | }); 91 | } 92 | 93 | function summaryToggle() { 94 | $('.summary_toggle').click(function(e) { 95 | e.preventDefault(); 96 | localStorage.summaryCollapsed = $(this).text(); 97 | $('.summary_toggle').each(function() { 98 | $(this).text($(this).text() == "collapse" ? "expand" : "collapse"); 99 | var next = $(this).parent().parent().nextAll('ul.summary').first(); 100 | if (next.hasClass('compact')) { 101 | next.toggle(); 102 | next.nextAll('ul.summary').first().toggle(); 103 | } 104 | else if (next.hasClass('summary')) { 105 | var list = $('
    '); 106 | list.html(next.html()); 107 | list.find('.summary_desc, .note').remove(); 108 | list.find('a').each(function() { 109 | $(this).html($(this).find('strong').html()); 110 | $(this).parent().html($(this)[0].outerHTML); 111 | }); 112 | next.before(list); 113 | next.toggle(); 114 | } 115 | }); 116 | return false; 117 | }); 118 | if (localStorage.summaryCollapsed == "collapse") { 119 | $('.summary_toggle').first().click(); 120 | } else { localStorage.summaryCollapsed = "expand"; } 121 | } 122 | 123 | function constantSummaryToggle() { 124 | $('.constants_summary_toggle').click(function(e) { 125 | e.preventDefault(); 126 | localStorage.summaryCollapsed = $(this).text(); 127 | $('.constants_summary_toggle').each(function() { 128 | $(this).text($(this).text() == "collapse" ? "expand" : "collapse"); 129 | var next = $(this).parent().parent().nextAll('dl.constants').first(); 130 | if (next.hasClass('compact')) { 131 | next.toggle(); 132 | next.nextAll('dl.constants').first().toggle(); 133 | } 134 | else if (next.hasClass('constants')) { 135 | var list = $('
    '); 136 | list.html(next.html()); 137 | list.find('dt').each(function() { 138 | $(this).addClass('summary_signature'); 139 | $(this).text( $(this).text().split('=')[0]); 140 | if ($(this).has(".deprecated").length) { 141 | $(this).addClass('deprecated'); 142 | }; 143 | }); 144 | // Add the value of the constant as "Tooltip" to the summary object 145 | list.find('pre.code').each(function() { 146 | console.log($(this).parent()); 147 | var dt_element = $(this).parent().prev(); 148 | var tooltip = $(this).text(); 149 | if (dt_element.hasClass("deprecated")) { 150 | tooltip = 'Deprecated. ' + tooltip; 151 | }; 152 | dt_element.attr('title', tooltip); 153 | }); 154 | list.find('.docstring, .tags, dd').remove(); 155 | next.before(list); 156 | next.toggle(); 157 | } 158 | }); 159 | return false; 160 | }); 161 | if (localStorage.summaryCollapsed == "collapse") { 162 | $('.constants_summary_toggle').first().click(); 163 | } else { localStorage.summaryCollapsed = "expand"; } 164 | } 165 | 166 | function generateTOC() { 167 | if ($('#filecontents').length === 0) return; 168 | var _toc = $('
      '); 169 | var show = false; 170 | var toc = _toc; 171 | var counter = 0; 172 | var tags = ['h2', 'h3', 'h4', 'h5', 'h6']; 173 | var i; 174 | var curli; 175 | if ($('#filecontents h1').length > 1) tags.unshift('h1'); 176 | for (i = 0; i < tags.length; i++) { tags[i] = '#filecontents ' + tags[i]; } 177 | var lastTag = parseInt(tags[0][1], 10); 178 | $(tags.join(', ')).each(function() { 179 | if ($(this).parents('.method_details .docstring').length != 0) return; 180 | if (this.id == "filecontents") return; 181 | show = true; 182 | var thisTag = parseInt(this.tagName[1], 10); 183 | if (this.id.length === 0) { 184 | var proposedId = $(this).attr('toc-id'); 185 | if (typeof(proposedId) != "undefined") this.id = proposedId; 186 | else { 187 | var proposedId = $(this).text().replace(/[^a-z0-9-]/ig, '_'); 188 | if ($('#' + proposedId).length > 0) { proposedId += counter; counter++; } 189 | this.id = proposedId; 190 | } 191 | } 192 | if (thisTag > lastTag) { 193 | for (i = 0; i < thisTag - lastTag; i++) { 194 | if ( typeof(curli) == "undefined" ) { 195 | curli = $('
    1. '); 196 | toc.append(curli); 197 | } 198 | toc = $('
        '); 199 | curli.append(toc); 200 | curli = undefined; 201 | } 202 | } 203 | if (thisTag < lastTag) { 204 | for (i = 0; i < lastTag - thisTag; i++) { 205 | toc = toc.parent(); 206 | toc = toc.parent(); 207 | } 208 | } 209 | var title = $(this).attr('toc-title'); 210 | if (typeof(title) == "undefined") title = $(this).text(); 211 | curli =$('
      1. ' + title + '
      2. '); 212 | toc.append(curli); 213 | lastTag = thisTag; 214 | }); 215 | if (!show) return; 216 | html = ''; 217 | $('#content').prepend(html); 218 | $('#toc').append(_toc); 219 | $('#toc .hide_toc').toggle(function() { 220 | $('#toc .top').slideUp('fast'); 221 | $('#toc').toggleClass('hidden'); 222 | $('#toc .title small').toggle(); 223 | }, function() { 224 | $('#toc .top').slideDown('fast'); 225 | $('#toc').toggleClass('hidden'); 226 | $('#toc .title small').toggle(); 227 | }); 228 | } 229 | 230 | function navResizeFn(e) { 231 | if (e.which !== 1) { 232 | navResizeFnStop(); 233 | return; 234 | } 235 | 236 | sessionStorage.navWidth = e.pageX.toString(); 237 | $('.nav_wrap').css('width', e.pageX); 238 | $('.nav_wrap').css('-ms-flex', 'inherit'); 239 | } 240 | 241 | function navResizeFnStop() { 242 | $(window).unbind('mousemove', navResizeFn); 243 | window.removeEventListener('message', navMessageFn, false); 244 | } 245 | 246 | function navMessageFn(e) { 247 | if (e.data.action === 'mousemove') navResizeFn(e.data.event); 248 | if (e.data.action === 'mouseup') navResizeFnStop(); 249 | } 250 | 251 | function navResizer() { 252 | $('#resizer').mousedown(function(e) { 253 | e.preventDefault(); 254 | $(window).mousemove(navResizeFn); 255 | window.addEventListener('message', navMessageFn, false); 256 | }); 257 | $(window).mouseup(navResizeFnStop); 258 | 259 | if (sessionStorage.navWidth) { 260 | navResizeFn({which: 1, pageX: parseInt(sessionStorage.navWidth, 10)}); 261 | } 262 | } 263 | 264 | function navExpander() { 265 | var done = false, timer = setTimeout(postMessage, 500); 266 | function postMessage() { 267 | if (done) return; 268 | clearTimeout(timer); 269 | var opts = { action: 'expand', path: pathId }; 270 | document.getElementById('nav').contentWindow.postMessage(opts, '*'); 271 | done = true; 272 | } 273 | 274 | window.addEventListener('message', function(event) { 275 | if (event.data === 'navReady') postMessage(); 276 | return false; 277 | }, false); 278 | } 279 | 280 | function mainFocus() { 281 | var hash = window.location.hash; 282 | if (hash !== '' && $(hash)[0]) { 283 | $(hash)[0].scrollIntoView(); 284 | } 285 | 286 | setTimeout(function() { $('#main').focus(); }, 10); 287 | } 288 | 289 | function navigationChange() { 290 | // This works around the broken anchor navigation with the YARD template. 291 | window.onpopstate = function() { 292 | var hash = window.location.hash; 293 | if (hash !== '' && $(hash)[0]) { 294 | $(hash)[0].scrollIntoView(); 295 | } 296 | }; 297 | } 298 | 299 | $(document).ready(function() { 300 | navResizer(); 301 | navExpander(); 302 | createSourceLinks(); 303 | createDefineLinks(); 304 | createFullTreeLinks(); 305 | searchFrameButtons(); 306 | linkSummaries(); 307 | summaryToggle(); 308 | constantSummaryToggle(); 309 | generateTOC(); 310 | mainFocus(); 311 | navigationChange(); 312 | }); 313 | 314 | })(); 315 | -------------------------------------------------------------------------------- /docs/js/full_list.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | var $clicked = $(null); 4 | var searchTimeout = null; 5 | var searchCache = []; 6 | var caseSensitiveMatch = false; 7 | var ignoreKeyCodeMin = 8; 8 | var ignoreKeyCodeMax = 46; 9 | var commandKey = 91; 10 | 11 | RegExp.escape = function(text) { 12 | return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); 13 | } 14 | 15 | function escapeShortcut() { 16 | $(document).keydown(function(evt) { 17 | if (evt.which == 27) { 18 | window.parent.postMessage('navEscape', '*'); 19 | } 20 | }); 21 | } 22 | 23 | function navResizer() { 24 | $(window).mousemove(function(e) { 25 | window.parent.postMessage({ 26 | action: 'mousemove', event: {pageX: e.pageX, which: e.which} 27 | }, '*'); 28 | }).mouseup(function(e) { 29 | window.parent.postMessage({action: 'mouseup'}, '*'); 30 | }); 31 | window.parent.postMessage("navReady", "*"); 32 | } 33 | 34 | function clearSearchTimeout() { 35 | clearTimeout(searchTimeout); 36 | searchTimeout = null; 37 | } 38 | 39 | function enableLinks() { 40 | // load the target page in the parent window 41 | $('#full_list li').on('click', function(evt) { 42 | $('#full_list li').removeClass('clicked'); 43 | $clicked = $(this); 44 | $clicked.addClass('clicked'); 45 | evt.stopPropagation(); 46 | 47 | if (evt.target.tagName === 'A') return true; 48 | 49 | var elem = $clicked.find('> .item .object_link a')[0]; 50 | var e = evt.originalEvent; 51 | var newEvent = new MouseEvent(evt.originalEvent.type); 52 | newEvent.initMouseEvent(e.type, e.canBubble, e.cancelable, e.view, e.detail, e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget); 53 | elem.dispatchEvent(newEvent); 54 | evt.preventDefault(); 55 | return false; 56 | }); 57 | } 58 | 59 | function enableToggles() { 60 | // show/hide nested classes on toggle click 61 | $('#full_list a.toggle').on('click', function(evt) { 62 | evt.stopPropagation(); 63 | evt.preventDefault(); 64 | $(this).parent().parent().toggleClass('collapsed'); 65 | highlight(); 66 | }); 67 | } 68 | 69 | function populateSearchCache() { 70 | $('#full_list li .item').each(function() { 71 | var $node = $(this); 72 | var $link = $node.find('.object_link a'); 73 | if ($link.length > 0) { 74 | searchCache.push({ 75 | node: $node, 76 | link: $link, 77 | name: $link.text(), 78 | fullName: $link.attr('title').split(' ')[0] 79 | }); 80 | } 81 | }); 82 | } 83 | 84 | function enableSearch() { 85 | $('#search input').keyup(function(event) { 86 | if (ignoredKeyPress(event)) return; 87 | if (this.value === "") { 88 | clearSearch(); 89 | } else { 90 | performSearch(this.value); 91 | } 92 | }); 93 | 94 | $('#full_list').after(""); 95 | } 96 | 97 | function ignoredKeyPress(event) { 98 | if ( 99 | (event.keyCode > ignoreKeyCodeMin && event.keyCode < ignoreKeyCodeMax) || 100 | (event.keyCode == commandKey) 101 | ) { 102 | return true; 103 | } else { 104 | return false; 105 | } 106 | } 107 | 108 | function clearSearch() { 109 | clearSearchTimeout(); 110 | $('#full_list .found').removeClass('found').each(function() { 111 | var $link = $(this).find('.object_link a'); 112 | $link.text($link.text()); 113 | }); 114 | $('#full_list, #content').removeClass('insearch'); 115 | $clicked.parents().removeClass('collapsed'); 116 | highlight(); 117 | } 118 | 119 | function performSearch(searchString) { 120 | clearSearchTimeout(); 121 | $('#full_list, #content').addClass('insearch'); 122 | $('#noresults').text('').hide(); 123 | partialSearch(searchString, 0); 124 | } 125 | 126 | function partialSearch(searchString, offset) { 127 | var lastRowClass = ''; 128 | var i = null; 129 | for (i = offset; i < Math.min(offset + 50, searchCache.length); i++) { 130 | var item = searchCache[i]; 131 | var searchName = (searchString.indexOf('::') != -1 ? item.fullName : item.name); 132 | var matchString = buildMatchString(searchString); 133 | var matchRegexp = new RegExp(matchString, caseSensitiveMatch ? "" : "i"); 134 | if (searchName.match(matchRegexp) == null) { 135 | item.node.removeClass('found'); 136 | item.link.text(item.link.text()); 137 | } 138 | else { 139 | item.node.addClass('found'); 140 | item.node.removeClass(lastRowClass).addClass(lastRowClass == 'r1' ? 'r2' : 'r1'); 141 | lastRowClass = item.node.hasClass('r1') ? 'r1' : 'r2'; 142 | item.link.html(item.name.replace(matchRegexp, "$&")); 143 | } 144 | } 145 | if(i == searchCache.length) { 146 | searchDone(); 147 | } else { 148 | searchTimeout = setTimeout(function() { 149 | partialSearch(searchString, i); 150 | }, 0); 151 | } 152 | } 153 | 154 | function searchDone() { 155 | searchTimeout = null; 156 | highlight(); 157 | if ($('#full_list li:visible').size() === 0) { 158 | $('#noresults').text('No results were found.').hide().fadeIn(); 159 | } else { 160 | $('#noresults').text('').hide(); 161 | } 162 | $('#content').removeClass('insearch'); 163 | } 164 | 165 | function buildMatchString(searchString, event) { 166 | caseSensitiveMatch = searchString.match(/[A-Z]/) != null; 167 | var regexSearchString = RegExp.escape(searchString); 168 | if (caseSensitiveMatch) { 169 | regexSearchString += "|" + 170 | $.map(searchString.split(''), function(e) { return RegExp.escape(e); }). 171 | join('.+?'); 172 | } 173 | return regexSearchString; 174 | } 175 | 176 | function highlight() { 177 | $('#full_list li:visible').each(function(n) { 178 | $(this).removeClass('even odd').addClass(n % 2 == 0 ? 'odd' : 'even'); 179 | }); 180 | } 181 | 182 | /** 183 | * Expands the tree to the target element and its immediate 184 | * children. 185 | */ 186 | function expandTo(path) { 187 | var $target = $(document.getElementById('object_' + path)); 188 | $target.addClass('clicked'); 189 | $target.removeClass('collapsed'); 190 | $target.parentsUntil('#full_list', 'li').removeClass('collapsed'); 191 | if($target[0]) { 192 | window.scrollTo(window.scrollX, $target.offset().top - 250); 193 | highlight(); 194 | } 195 | } 196 | 197 | function windowEvents(event) { 198 | var msg = event.data; 199 | if (msg.action === "expand") { 200 | expandTo(msg.path); 201 | } 202 | return false; 203 | } 204 | 205 | window.addEventListener("message", windowEvents, false); 206 | 207 | $(document).ready(function() { 208 | escapeShortcut(); 209 | navResizer(); 210 | enableLinks(); 211 | enableToggles(); 212 | populateSearchCache(); 213 | enableSearch(); 214 | }); 215 | 216 | })(); 217 | -------------------------------------------------------------------------------- /docs/top-level-namespace.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Top Level Namespace 8 | 9 | — Documentation by YARD 0.9.27 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 |
        36 | 61 | 62 |

        Top Level Namespace 63 | 64 | 65 | 66 |

        67 |
        68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 |
        80 | 81 |

        Defined Under Namespace

        82 |

        83 | 84 | 85 | Modules: OpConnect 86 | 87 | 88 | 89 | 90 |

        91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 |
        101 | 102 | 107 | 108 |
        109 | 110 | -------------------------------------------------------------------------------- /lib/op_connect.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "faraday" 4 | require "faraday_middleware" 5 | 6 | # Ruby toolkit for the 1Password Connect REST API. 7 | # 8 | module OpConnect 9 | autoload :Client, "op_connect/client" 10 | autoload :Configurable, "op_connect/configurable" 11 | autoload :Connection, "op_connect/connection" 12 | autoload :Default, "op_connect/default" 13 | autoload :Object, "op_connect/object" 14 | autoload :Response, "op_connect/response" 15 | 16 | autoload :Error, "op_connect/error" 17 | autoload :ClientError, "op_connect/error" 18 | autoload :BadRequest, "op_connect/error" 19 | autoload :Forbidden, "op_connect/error" 20 | autoload :NotFound, "op_connect/error" 21 | autoload :PayloadTooLarge, "op_connect/error" 22 | autoload :Unauthorized, "op_connect/error" 23 | autoload :ServerError, "op_connect/error" 24 | autoload :InternalServerError, "op_connect/error" 25 | autoload :ServiceUnavailable, "op_connect/error" 26 | 27 | # Classes used to return a nicer object wrapping the response. 28 | autoload :APIRequest, "op_connect/api_request" 29 | autoload :Item, "op_connect/item" 30 | autoload :ServerHealth, "op_connect/server_health" 31 | autoload :Vault, "op_connect/vault" 32 | 33 | class << self 34 | include OpConnect::Configurable 35 | 36 | # API client based on configured options {Configurable} 37 | # 38 | # @return [OpConnect::Client] API wrapper 39 | # 40 | def client 41 | return @client if defined?(@client) && @client.same_options?(options) 42 | @client = OpConnect::Client.new(options) 43 | end 44 | end 45 | end 46 | 47 | OpConnect.setup 48 | -------------------------------------------------------------------------------- /lib/op_connect/api_request.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class APIRequest 3 | autoload :Actor, "op_connect/api_request/actor" 4 | autoload :Resource, "op_connect/api_request/resource" 5 | 6 | attr_reader :request_id, :timestamp, :action, :result, :actor, :resource 7 | 8 | def initialize(options = {}) 9 | @request_id = options["request_id"] 10 | @timestamp = options["timestamp"] 11 | @action = options["action"] 12 | @result = options["result"] 13 | @actor = Actor.new(options["actor"]) 14 | @resource = Resource.new(options["resource"]) 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/op_connect/api_request/actor.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class APIRequest 3 | class Actor 4 | attr_reader :id, :account, :jti, :user_agent, :ip 5 | 6 | def initialize(options = {}) 7 | @id = options["id"] 8 | @account = options["account"] 9 | @jti = options["jti"] 10 | @user_agent = options["user_agent"] 11 | @ip = options["ip"] 12 | end 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/op_connect/api_request/resource.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class APIRequest 3 | class Resource 4 | attr_reader :type, :vault, :item, :item_version 5 | 6 | def initialize(options = {}) 7 | @type = options["type"] 8 | @vault = Object.new(options["vault"]) 9 | @item = Object.new(options["item"]) 10 | @item_version = options["item_version"] 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/op_connect/client.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | # Client for the OpConnect API. 3 | # 4 | class Client 5 | autoload :Vaults, "op_connect/client/vaults" 6 | autoload :Items, "op_connect/client/items" 7 | autoload :Files, "op_connect/client/files" 8 | 9 | include OpConnect::Configurable 10 | include OpConnect::Connection 11 | include OpConnect::Client::Vaults 12 | include OpConnect::Client::Items 13 | include OpConnect::Client::Files 14 | 15 | def initialize(options = {}) 16 | OpConnect::Configurable.keys.each do |key| 17 | value = options.key?(key) ? options[key] : OpConnect.instance_variable_get(:"@#{key}") 18 | instance_variable_set(:"@#{key}", value) 19 | end 20 | end 21 | 22 | # Text representation of the client, masking tokens. 23 | # 24 | # @return [String] 25 | # 26 | def inspect 27 | inspected = super 28 | inspected.gsub!(@access_token, ("*" * 24).to_s) if @access_token 29 | inspected 30 | end 31 | 32 | # Retrieve a list of API requests that have been made. 33 | # 34 | # @param params [Hash] Optional parameters. 35 | # @option params [Integer] :limit How many API Events should be returned 36 | # in a single request. 37 | # @option params [Integer] :offset How far into the collection of API 38 | # Events should the response start. 39 | # 40 | # @return [Array] 41 | # 42 | def activity(**params) 43 | get("activity", params: params).body.map { |a| APIRequest.new(a) } 44 | end 45 | 46 | # Simple "ping" endpoint to check whether the server is active. 47 | # 48 | # @return [Boolean] Returns true if the server is active, false otherwise. 49 | # 50 | def heartbeat 51 | return true if get("/heartbeat").status == 200 52 | false 53 | rescue OpConnect::Error 54 | false 55 | end 56 | 57 | # Query the state of the server and its service dependencies. 58 | # 59 | # @return [ServerHealth] Returns a `ServerHealth` object. 60 | # 61 | def health 62 | ServerHealth.new get("/health").body 63 | end 64 | 65 | # Returns Prometheus metrics collected by the server. 66 | # 67 | # @return [String] Returns a plain text list of Prometheus metrics. 68 | # 69 | # @see https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format 70 | # Prometheus documentation 71 | # 72 | def metrics 73 | get("/metrics").body 74 | end 75 | end 76 | end 77 | -------------------------------------------------------------------------------- /lib/op_connect/client/files.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class Client 3 | module Files 4 | def list_files(vault_id:, item_id:, **params) 5 | get("vaults/#{vault_id}/items/#{item_id}/files", params: params).body.map { |file| Item::File.new(file) } 6 | end 7 | alias_method :files, :list_files 8 | 9 | def get_file(vault_id:, item_id:, id:, **params) 10 | Item::File.new get("vaults/#{vault_id}/items/#{item_id}/files/#{id}", params: params).body 11 | end 12 | alias_method :file, :get_file 13 | 14 | def get_file_content(vault_id:, item_id:, id:) 15 | get("vaults/#{vault_id}/items/#{item_id}/files/#{id}/content").body 16 | end 17 | alias_method :file_content, :get_file_content 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/op_connect/client/items.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class Client 3 | module Items 4 | # Get a list of items from a vault. 5 | # 6 | # @param vault_id [String] The vault UUID. 7 | # @param params [Hash] Query parameters. 8 | # @option params [String] :filter Optionally filter the item collection 9 | # based on item title using SCIM-sytle filters. 10 | # 11 | # @example 12 | # client.items(vault_id: vault.id, filter: 'title eq "foo"') 13 | # 14 | # @see https://ldapwiki.com/wiki/SCIM%20Filtering SCIM Filtering 15 | # 16 | # @return [] 17 | # 18 | def list_items(vault_id:, **params) 19 | get("vaults/#{vault_id}/items", params: params).body.map { |item| Item.new(item) } 20 | end 21 | alias_method :items, :list_items 22 | 23 | def get_item(vault_id:, id:) 24 | Item.new get("vaults/#{vault_id}/items/#{id}").body 25 | end 26 | alias_method :item, :get_item 27 | 28 | def create_item(vault_id:, **attributes) 29 | Item.new post("vaults/#{vault_id}/items", body: attributes).body 30 | end 31 | 32 | def replace_item(vault_id:, id:, **attributes) 33 | Item.new put("vaults/#{vault_id}/items/#{id}", body: attributes).body 34 | end 35 | 36 | def delete_item(vault_id:, id:) 37 | return true if delete("vaults/#{vault_id}/items/#{id}").status == 204 38 | false 39 | rescue OpConnect::Error 40 | false 41 | end 42 | 43 | def update_item(vault_id:, id:, **attributes) 44 | Item.new patch("vaults/#{vault_id}/items/#{id}", body: attributes, headers: {"Content-Type": "applicatoin/json-patch+json"}).body 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/op_connect/client/vaults.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class Client 3 | module Vaults 4 | def list_vaults(**params) 5 | get("vaults", params: params).body.map { |vault| Vault.new(vault) } 6 | end 7 | alias_method :vaults, :list_vaults 8 | 9 | def get_vault(id:) 10 | Vault.new get("vaults/#{id}").body 11 | end 12 | alias_method :vault, :get_vault 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/op_connect/configurable.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | module Configurable 3 | attr_accessor :access_token, :adapter, :stubs, :user_agent 4 | attr_writer :api_endpoint 5 | 6 | class << self 7 | def keys 8 | @keys ||= [ 9 | :access_token, 10 | :adapter, 11 | :api_endpoint, 12 | :stubs, 13 | :user_agent 14 | ] 15 | end 16 | end 17 | 18 | def configure 19 | yield self 20 | end 21 | 22 | def reset! 23 | OpConnect::Configurable.keys.each do |key| 24 | instance_variable_set(:"@#{key}", OpConnect::Default.options[key]) 25 | end 26 | 27 | self 28 | end 29 | alias_method :setup, :reset! 30 | 31 | def same_options?(opts) 32 | opts.hash == options.hash 33 | end 34 | 35 | def api_endpoint 36 | ::File.join(@api_endpoint, "") 37 | end 38 | 39 | private 40 | 41 | def options 42 | OpConnect::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }.to_h 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /lib/op_connect/connection.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | # Network layer for API clients. 3 | # 4 | module Connection 5 | # Make an HTTP GET request. 6 | # 7 | # @param url [String] The path, relative to {#api_endpoint}. 8 | # @param params [Hash] Query parameters for the request. 9 | # @param headers [Hash] Header params for the request. 10 | # 11 | # @return [Faraday::Response] 12 | # 13 | def get(url, params: {}, headers: {}) 14 | request :get, url, params, headers 15 | end 16 | 17 | # Make an HTTP POST request. 18 | # 19 | # @param url [String] The path, relative to {#api_endpoint}. 20 | # @param body [Hash] Body params for the request. 21 | # @param headers [Hash] Header params for the request. 22 | # 23 | # @return [Faraday::Response] 24 | # 25 | def post(url, body:, headers: {}) 26 | request :post, url, body, headers 27 | end 28 | 29 | # Make an HTTP PUT request. 30 | # 31 | # @param url [String] The path, relative to {#api_endpoint}. 32 | # @param body [Hash] Body params for the request. 33 | # @param headers [Hash] Header params for the request. 34 | # 35 | # @return [Faraday::Response] 36 | # 37 | def put(url, body:, headers: {}) 38 | request :put, url, body, headers 39 | end 40 | 41 | # Make an HTTP PATCH request. 42 | # 43 | # @param url [String] The path, relative to {#api_endpoint}. 44 | # @param body [Hash] Body params for the request. 45 | # @param headers [Hash] Header params for the request. 46 | # 47 | # @return [Faraday::Response] 48 | # 49 | def patch(url, body:, headers: {}) 50 | request :patch, url, body, headers 51 | end 52 | 53 | # Make an HTTP DELETE request. 54 | # 55 | # @param url [String] The path, relative to {#api_endpoint}. 56 | # @param params [Hash] Query params for the request. 57 | # @param headers [Hash] Header params for the request. 58 | # 59 | # @return [Faraday::Response] 60 | # 61 | def delete(url, params: {}, headers: {}) 62 | request :delete, url, params, headers 63 | end 64 | 65 | # Connection object for the 1Password Connect API. 66 | # 67 | # @return [Faraday::Client] 68 | # 69 | def connection 70 | @connection ||= Faraday.new(api_endpoint) do |http| 71 | http.headers[:user_agent] = user_agent 72 | 73 | http.request :authorization, :Bearer, access_token 74 | http.request :json 75 | 76 | http.use OpConnect::Response::RaiseError 77 | 78 | http.response :dates 79 | http.response :json, content_type: "application/json" 80 | 81 | http.adapter adapter, @stubs 82 | end 83 | end 84 | 85 | # Response for the last HTTP request. 86 | # 87 | # @return [Faraday::Response] 88 | # 89 | def last_response 90 | @last_response if defined? @last_response 91 | end 92 | 93 | private 94 | 95 | def request(method, path, data, headers = {}) 96 | @last_response = response = connection.send(method, path, data, headers) 97 | response 98 | rescue OpConnect::Error => error 99 | @last_response = nil 100 | raise error 101 | end 102 | end 103 | end 104 | -------------------------------------------------------------------------------- /lib/op_connect/default.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "op_connect/version" 4 | 5 | module OpConnect 6 | # Default configuration options for {Client} 7 | # 8 | module Default 9 | API_ENDPOINT = "http://localhost:8080/v1" 10 | USER_AGENT = "1Password Connect Ruby SDK #{OpConnect::VERSION}" 11 | 12 | class << self 13 | # Configuration options 14 | # 15 | # @return [Hash] 16 | # 17 | def options 18 | OpConnect::Configurable.keys.map { |key| [key, send(key)] }.to_h 19 | end 20 | 21 | # Default access token from ENV 22 | # 23 | # @return [String] 24 | # 25 | def access_token 26 | ENV["OP_CONNECT_ACCESS_TOKEN"] 27 | end 28 | 29 | # Default network adapter for Faraday (defaults to :net_http) 30 | # 31 | # @return [Symbol] 32 | # 33 | def adapter 34 | Faraday.default_adapter 35 | end 36 | 37 | # Default API endpoint from ENV or {API_ENDPOINT} 38 | # 39 | # @return [] 40 | # 41 | def api_endpoint 42 | ENV["OP_CONNECT_API_ENDPOINT"] || API_ENDPOINT 43 | end 44 | 45 | def stubs 46 | end 47 | 48 | # Default user agent from ENV or {USER_AGENT} 49 | # 50 | # @return [] 51 | # 52 | def user_agent 53 | ENV["OP_CONNECT_USER_AGENT"] || USER_AGENT 54 | end 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /lib/op_connect/error.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class Error < StandardError 3 | class << self 4 | def from_response(response) 5 | status = response.status 6 | 7 | if (klass = case status 8 | when 400 then OpConnect::BadRequest 9 | when 401 then OpConnect::Unauthorized 10 | when 403 then OpConnect::Forbidden 11 | when 404 then OpConnect::NotFound 12 | when 413 then OpConnect::PayloadTooLarge 13 | when 400..499 then OpConnect::ClientError 14 | when 500 then OpConnect::InternalServerError 15 | when 503 then OpConnect::ServiceUnavailable 16 | when 500..599 then OpConnect::ServerError 17 | end) 18 | klass.new(response) 19 | end 20 | end 21 | end 22 | 23 | def initialize(response = nil) 24 | @response = response 25 | super(build_error_message) 26 | end 27 | 28 | private 29 | 30 | def build_error_message 31 | return nil if @response.nil? 32 | 33 | message = "#{@response.method.to_s.upcase} " 34 | message << "#{@response.url}: " 35 | message << "#{@response.status} - " 36 | message << @response.body["message"].to_s if @response.body["message"] 37 | message << "\n\n#{@response.body}\n\n" 38 | 39 | message 40 | end 41 | end 42 | 43 | class ClientError < Error; end 44 | 45 | class BadRequest < ClientError; end 46 | 47 | class Unauthorized < ClientError; end 48 | 49 | class Forbidden < ClientError; end 50 | 51 | class NotFound < ClientError; end 52 | 53 | class PayloadTooLarge < ClientError; end 54 | 55 | class ServerError < Error; end 56 | 57 | class InternalServerError < ServerError; end 58 | 59 | class ServiceUnavailable < ServerError; end 60 | end 61 | -------------------------------------------------------------------------------- /lib/op_connect/item.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class Item 3 | autoload :Field, "op_connect/item/field" 4 | autoload :File, "op_connect/item/file" 5 | autoload :GeneratorRecipe, "op_connect/item/generator_recipe" 6 | autoload :Section, "op_connect/item/section" 7 | autoload :URL, "op_connect/item/url" 8 | 9 | attr_reader :id, :title, :vault, :category, :urls, :is_favorite, :tags, :version, :state, :sections, :fields, :files, :created_at, :updated_at, :last_edited_by 10 | 11 | alias_method :favorite?, :is_favorite 12 | 13 | def initialize(options = {}) 14 | @id = options["id"] 15 | @title = options["title"] 16 | @vault = Object.new(options["vault"]) 17 | @category = options["category"] 18 | @urls = options["urls"]&.collect! { |url| URL.new(url) } 19 | @is_favorite = options["favorite"] || false 20 | @tags = options["tags"] 21 | @version = options["version"] 22 | @state = options["state"] 23 | @sections = options["sections"]&.collect! { |section| Section.new(section) } || [] 24 | @fields = options["fields"]&.collect! { |field| Field.new(field) } || [] 25 | @files = options["files"]&.collect! { |file| File.new(file) } || [] 26 | @created_at = options["createdAt"] 27 | @updated_at = options["updatedAt"] 28 | @last_edited_by = options["lastEditedBy"] 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /lib/op_connect/item/field.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class Item 3 | class Field 4 | attr_reader :id, :purpose, :type, :value, :should_generate, :recipe, :section 5 | 6 | alias_method :generate?, :should_generate 7 | 8 | def initialize(options = {}) 9 | @id = options["id"] 10 | @purpose = options["purpose"] if options["purpose"] 11 | @type = options["type"] if options["type"] 12 | @value = options["value"] 13 | @should_generate = options["generate"] || false 14 | @recipe = GeneratorRecipe.new(options["recipe"]) 15 | @section = Object.new(options["section"]) 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/op_connect/item/file.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class Item 3 | class File 4 | attr_reader :id, :name, :size, :content_path, :content, :section 5 | 6 | def initialize(options = {}) 7 | @id = options["id"] 8 | @name = options["name"] 9 | @size = options["size"] 10 | @content_path = options["content_path"] 11 | @content = options["content"] 12 | @section = Object.new(options["section"]) 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/op_connect/item/generator_recipe.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class Item 3 | class GeneratorRecipe 4 | attr_reader :length, :character_sets 5 | 6 | def initialize(options = {}) 7 | @length = options["length"] if options & ["length"] 8 | @character_sets = options["characterSets"] if options & ["characterSets"] 9 | end 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/op_connect/item/section.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class Item 3 | class Section 4 | attr_reader :id, :label 5 | 6 | def initialize(options = {}) 7 | @id = options["id"] 8 | @label = options["label"] 9 | end 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/op_connect/item/url.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class Item 3 | class URL 4 | attr_reader :url, :is_primary 5 | 6 | alias_method :primary?, :is_primary 7 | 8 | def initialize(options = {}) 9 | @url = options["url"] 10 | @is_primary = options["primary"] || false 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/op_connect/object.rb: -------------------------------------------------------------------------------- 1 | require "ostruct" 2 | 3 | module OpConnect 4 | class Object < SimpleDelegator 5 | def initialize(attributes) 6 | super to_ostruct(attributes) 7 | end 8 | 9 | private 10 | 11 | def to_ostruct(obj) 12 | if obj.is_a?(Hash) 13 | OpenStruct.new(obj.map { |key, value| [key, to_ostruct(value)] }.to_h) 14 | elsif obj.is_a?(Array) 15 | obj.map { |o| to_ostruct(o) } 16 | else 17 | obj 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/op_connect/response.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | module Response 3 | autoload :RaiseError, "op_connect/response/raise_error" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/op_connect/response/raise_error.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | # Faraday response middleware 3 | # 4 | module Response 5 | # This class raises an OpConnect-flavored exception based on HTTP status 6 | # codes returned by the API. 7 | # 8 | class RaiseError < Faraday::Middleware 9 | def on_complete(response) 10 | if (error = OpConnect::Error.from_response(response)) 11 | raise error 12 | end 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/op_connect/server_health.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class ServerHealth 3 | autoload :Dependency, "op_connect/server_health/dependency" 4 | 5 | attr_reader :name, :version, :dependencies 6 | 7 | def initialize(options = {}) 8 | @name = options["name"] 9 | @version = options["version"] 10 | @dependencies = options["dependencies"]&.collect! { |dependency| Dependency.new(dependency) } || [] 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/op_connect/server_health/dependency.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class ServerHealth 3 | class Dependency 4 | attr_reader :service, :status, :message 5 | 6 | def initialize(options = {}) 7 | @service = options["service"] 8 | @status = options["status"] 9 | @message = options["message"] 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/op_connect/vault.rb: -------------------------------------------------------------------------------- 1 | module OpConnect 2 | class Vault 3 | attr_reader :id, :name, :attribute_version, :content_version, :items, :type, :created_at, :updated_at 4 | 5 | def initialize(options = {}) 6 | @id = options["id"] 7 | @name = options["name"] 8 | @attribute_version = options["attributeVersion"] 9 | @content_version = options["contentVersion"] 10 | @items = options["items"] 11 | @type = options["type"] 12 | @created_at = options["createdAt"] 13 | @updated_at = options["updatedAt"] 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/op_connect/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module OpConnect 4 | VERSION = "0.1.3" 5 | end 6 | -------------------------------------------------------------------------------- /op_connect.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative "lib/op_connect/version" 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = "op_connect" 7 | spec.version = OpConnect::VERSION 8 | spec.authors = ["Andrew Porter"] 9 | spec.email = ["partydrone@icloud.com"] 10 | 11 | spec.summary = "A Ruby SDK for the 1Password Connect API." 12 | spec.description = "A Ruby SDK for the 1Password Connect API." 13 | spec.homepage = "https://github.com/partydrone/connect-sdk-ruby" 14 | spec.license = "MIT" 15 | spec.required_ruby_version = ">= 2.5.0" 16 | 17 | # spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'" 18 | 19 | spec.metadata["homepage_uri"] = spec.homepage 20 | spec.metadata["source_code_uri"] = "https://github.com/partydrone/connect-sdk-ruby" 21 | spec.metadata["github_repo"] = "ssh://github.com/partydrone/connect-sdk-ruby" 22 | 23 | # Specify which files should be added to the gem when it is released. 24 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git. 25 | spec.files = Dir.chdir(File.expand_path(__dir__)) do 26 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } 27 | end 28 | spec.bindir = "exe" 29 | spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } 30 | spec.require_paths = ["lib"] 31 | 32 | spec.add_dependency "faraday", "~> 1.8" 33 | spec.add_dependency "faraday_middleware", "~> 1.2" 34 | end 35 | -------------------------------------------------------------------------------- /test/fixtures/activity.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "requestId": "d6bac025-2319-4e6e-8ecc-dd2429f9446a", 4 | "timestamp": "2021-10-31 07:48:57 UTC", 5 | "action": "READ", 6 | "result": "SUCCESS", 7 | "actor": { 8 | "id": "2L47D4X7AZBXZINPILVYXAKC6I", 9 | "account": "JXZGYLHD2ZHWTCHNEKZYWQQTAA", 10 | "jti": "rm4etwz4jqqqxskbqyaqxtlkmu", 11 | "userAgent": "1Password Connect Ruby Gem 0.1.0" 12 | }, 13 | "resource": { "type": "VAULT" } 14 | }, 15 | { 16 | "requestId": "3a0dca18-16c1-493a-bc51-0f887fd94030", 17 | "timestamp": "2021-10-30 22:54:51 UTC", 18 | "action": "READ", 19 | "result": "SUCCESS", 20 | "actor": { 21 | "id": "2L47D4X7AZBXZINPILVYXAKC6I", 22 | "account": "JXZGYLHD2ZHWTCHNEKZYWQQTAA", 23 | "jti": "rm4etwz4jqqqxskbqyaqxtlkmu", 24 | "userAgent": "1Password Connect Ruby Gem 0.1.0" 25 | }, 26 | "resource": { "type": "VAULT", "vault": { "id": "alynbizzypgx62nti6zxajloei" } } 27 | }, 28 | { 29 | "requestId": "881d95d6-30c6-42ea-b88c-1d1ef77def54", 30 | "timestamp": "2021-10-30 22:50:37 UTC", 31 | "action": "READ", 32 | "result": "SUCCESS", 33 | "actor": { 34 | "id": "2L47D4X7AZBXZINPILVYXAKC6I", 35 | "account": "JXZGYLHD2ZHWTCHNEKZYWQQTAA", 36 | "jti": "rm4etwz4jqqqxskbqyaqxtlkmu", 37 | "userAgent": "1Password Connect Ruby Gem 0.1.0" 38 | }, 39 | "resource": { "type": "VAULT" } 40 | }, 41 | { 42 | "requestId": "f8a60968-3a0d-4c4c-a6be-40e0ef203562", 43 | "timestamp": "2021-10-28 06:36:39 UTC", 44 | "action": "READ", 45 | "result": "SUCCESS", 46 | "actor": { 47 | "id": "2L47D4X7AZBXZINPILVYXAKC6I", 48 | "account": "JXZGYLHD2ZHWTCHNEKZYWQQTAA", 49 | "jti": "rm4etwz4jqqqxskbqyaqxtlkmu", 50 | "userAgent": "1Password Connect Ruby Gem 0.1.0" 51 | }, 52 | "resource": { "type": "VAULT" } 53 | }, 54 | { 55 | "requestId": "bb48ff09-d4a5-472c-86e9-3ddb31bd3851", 56 | "timestamp": "2021-10-28 06:34:07 UTC", 57 | "action": "READ", 58 | "result": "SUCCESS", 59 | "actor": { 60 | "id": "2L47D4X7AZBXZINPILVYXAKC6I", 61 | "account": "JXZGYLHD2ZHWTCHNEKZYWQQTAA", 62 | "jti": "rm4etwz4jqqqxskbqyaqxtlkmu", 63 | "userAgent": "1Password Connect Ruby Gem 0.1.0" 64 | }, 65 | "resource": { "type": "VAULT" } 66 | }, 67 | { 68 | "requestId": "492d922f-a1d0-4100-9526-2f1b9ba29670", 69 | "timestamp": "2021-10-28 06:21:16 UTC", 70 | "action": "READ", 71 | "result": "DENY", 72 | "actor": { 73 | "id": "2L47D4X7AZBXZINPILVYXAKC6I", 74 | "account": "JXZGYLHD2ZHWTCHNEKZYWQQTAA", 75 | "jti": "rm4etwz4jqqqxskbqyaqxtlkmu", 76 | "userAgent": "1Password Connect Ruby Gem 0.1.0" 77 | }, 78 | "resource": { "vault": { "id": "123abc" } } 79 | }, 80 | { 81 | "requestId": "e0ff35c5-6c56-4c17-84b0-c7018827283a", 82 | "timestamp": "2021-10-28 06:19:11 UTC", 83 | "action": "READ", 84 | "result": "SUCCESS", 85 | "actor": { 86 | "id": "2L47D4X7AZBXZINPILVYXAKC6I", 87 | "account": "JXZGYLHD2ZHWTCHNEKZYWQQTAA", 88 | "jti": "rm4etwz4jqqqxskbqyaqxtlkmu", 89 | "userAgent": "1Password Connect Ruby Gem 0.1.0" 90 | }, 91 | "resource": { "type": "VAULT" } 92 | }, 93 | { 94 | "requestId": "dc887ea9-3aa2-4ddb-bccb-b8cd5ccdce9c", 95 | "timestamp": "2021-10-28 06:17:33 UTC", 96 | "action": "READ", 97 | "result": "DENY", 98 | "actor": { 99 | "id": "2L47D4X7AZBXZINPILVYXAKC6I", 100 | "account": "JXZGYLHD2ZHWTCHNEKZYWQQTAA", 101 | "jti": "rm4etwz4jqqqxskbqyaqxtlkmu", 102 | "userAgent": "1Password Connect Ruby Gem 0.1.0" 103 | }, 104 | "resource": { "vault": { "id": "abc123" } } 105 | }, 106 | { 107 | "requestId": "23a63b99-2cf5-4225-be0b-1e79da30d556", 108 | "timestamp": "2021-10-28 06:13:22 UTC", 109 | "action": "READ", 110 | "result": "SUCCESS", 111 | "actor": { 112 | "id": "2L47D4X7AZBXZINPILVYXAKC6I", 113 | "account": "JXZGYLHD2ZHWTCHNEKZYWQQTAA", 114 | "jti": "rm4etwz4jqqqxskbqyaqxtlkmu", 115 | "userAgent": "1Password Connect Ruby Gem 0.1.0" 116 | }, 117 | "resource": { "type": "VAULT" } 118 | }, 119 | { 120 | "requestId": "f7e086b3-181d-4272-9dfb-fcec46bcb42e", 121 | "timestamp": "2021-10-28 06:08:48 UTC", 122 | "action": "READ", 123 | "result": "SUCCESS", 124 | "actor": { 125 | "id": "2L47D4X7AZBXZINPILVYXAKC6I", 126 | "account": "JXZGYLHD2ZHWTCHNEKZYWQQTAA", 127 | "jti": "rm4etwz4jqqqxskbqyaqxtlkmu", 128 | "userAgent": "1Password Connect Ruby Gem 0.1.0" 129 | }, 130 | "resource": { "type": "VAULT" } 131 | } 132 | ] 133 | -------------------------------------------------------------------------------- /test/fixtures/errors/400.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": 400, 3 | "message": "Unable to create item due to invalid input" 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/errors/401.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": 401, 3 | "message": "Invalid or missing token" 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/errors/403.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": 403, 3 | "message": "Unauthorized access" 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/errors/404.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": 404, 3 | "message": "Item not found" 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/errors/413.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": 413, 3 | "message": "File too large to display inline" 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/files/get.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "6r65pjq33banznomn7q22sj44e", 3 | "name": "testfile.txt", 4 | "size": 35, 5 | "content_path": "v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa/files/6r65pjq33banznomn7q22sj44e/content", 6 | "content": "VGhlIGZ1dHVyZSBiZWxvbmdzIHRvIHRoZSBjdXJpb3VzLgo=", 7 | "section": { 8 | "id": "95cdbc3b-7742-47ec-9056-44d6af82d562" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/fixtures/files/list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "6r65pjq33banznomn7q22sj44e", 4 | "name": "testfile.txt", 5 | "size": 35, 6 | "content_path": "v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa/files/6r65pjq33banznomn7q22sj44e/content", 7 | "content": "VGhlIGZ1dHVyZSBiZWxvbmdzIHRvIHRoZSBjdXJpb3VzLgo=", 8 | "section": { 9 | "id": "95cdbc3b-7742-47ec-9056-44d6af82d562" 10 | } 11 | } 12 | ] 13 | -------------------------------------------------------------------------------- /test/fixtures/files/testfile.txt: -------------------------------------------------------------------------------- 1 | The future belongs to the curious. 2 | -------------------------------------------------------------------------------- /test/fixtures/health.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1Password Connect API", 3 | "version": "1.2.1", 4 | "dependencies": [ 5 | { 6 | "service": "sync", 7 | "status": "TOKEN_NEEDED" 8 | }, 9 | { 10 | "service": "sqlite", 11 | "status": "ACTIVE", 12 | "message": "Connected to ~/1password.sqlite" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /test/fixtures/items/create.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "2fcbqwe9ndg175zg2dzwftvkpa", 3 | "title": "Secrets Automation Item", 4 | "tags": ["connect", "\ud83d\udc27"], 5 | "vault": { 6 | "id": "ftz4pm2xxwmwrsd7rjqn7grzfz" 7 | }, 8 | "category": "LOGIN", 9 | "sections": [ 10 | { 11 | "id": "95cdbc3b-7742-47ec-9056-44d6af82d562", 12 | "label": "Security Questions" 13 | } 14 | ], 15 | "fields": [ 16 | { 17 | "id": "username", 18 | "type": "STRING", 19 | "purpose": "USERNAME", 20 | "label": "username", 21 | "value": "wendy" 22 | }, 23 | { 24 | "id": "password", 25 | "type": "CONCEALED", 26 | "purpose": "PASSWORD", 27 | "label": "password", 28 | "value": "hLDegPkuMQqyQiyDZqRdWGoojiN5KYQtXuA0wBDe9z3Caj6FQGHpbGu", 29 | "entropy": 189.78359985351562 30 | }, 31 | { 32 | "id": "a6cvmeqakbxoflkgmor4haji7y", 33 | "type": "URL", 34 | "label": "Example", 35 | "value": "https://example.com" 36 | } 37 | ], 38 | "createdAt": "2021-04-10T17:20:05.98944527Z", 39 | "updatedAt": "2021-04-13T17:20:05.989445411Z" 40 | } 41 | -------------------------------------------------------------------------------- /test/fixtures/items/get.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "2fcbqwe9ndg175zg2dzwftvkpa", 3 | "title": "Secrets Automation Item", 4 | "tags": ["connect", "\ud83d\udc27"], 5 | "vault": { 6 | "id": "ftz4pm2xxwmwrsd7rjqn7grzfz" 7 | }, 8 | "category": "LOGIN", 9 | "sections": [ 10 | { 11 | "id": "95cdbc3b-7742-47ec-9056-44d6af82d562", 12 | "label": "Security Questions" 13 | } 14 | ], 15 | "fields": [ 16 | { 17 | "id": "username", 18 | "type": "STRING", 19 | "purpose": "USERNAME", 20 | "label": "username", 21 | "value": "wendy" 22 | }, 23 | { 24 | "id": "password", 25 | "type": "CONCEALED", 26 | "purpose": "PASSWORD", 27 | "label": "password", 28 | "value": "hLDegPkuMQqyQiyDZqRdWGoojiN5KYQtXuA0wBDe9z3Caj6FQGHpbGu", 29 | "entropy": 189.78359985351562 30 | }, 31 | { 32 | "id": "notesPlain", 33 | "type": "STRING", 34 | "purpose": "NOTES", 35 | "label": "notesPlain" 36 | }, 37 | { 38 | "id": "a6cvmeqakbxoflkgmor4haji7y", 39 | "type": "URL", 40 | "label": "Example", 41 | "value": "https://example.com" 42 | }, 43 | { 44 | "id": "boot3vsxwhuht6g7cmcx4m6rcm", 45 | "section": { 46 | "id": "95cdbc3b-7742-47ec-9056-44d6af82d562" 47 | }, 48 | "type": "CONCEALED", 49 | "label": "Recovery Key", 50 | "value": "s=^J@GhHP_isYP>LCq?vv8u7T:*wBP.c" 51 | }, 52 | { 53 | "id": "axwtgyjrvwfp5ij7mtkw2zvijy", 54 | "section": { 55 | "id": "95cdbc3b-7742-47ec-9056-44d6af82d562" 56 | }, 57 | "type": "STRING", 58 | "label": "Random Text", 59 | "value": "R)D~KZdV!8?51QoCibDUse7=n@wKR_}]" 60 | } 61 | ], 62 | "files": [ 63 | { 64 | "id": "6r65pjq33banznomn7q22sj44e", 65 | "name": "testfile.txt", 66 | "size": 35, 67 | "content_path": "v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa/files/6r65pjq33banznomn7q22sj44e/content" 68 | }, 69 | { 70 | "id": "oyez5gf6xjfptlhc3o4n6o6hvm", 71 | "name": "samplefile.png", 72 | "size": 296639, 73 | "content_path": "v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa/files/oyez5gf6xjfptlhc3o4n6o6hvm/content" 74 | } 75 | ], 76 | "createdAt": "2021-04-10T17:20:05.98944527Z", 77 | "updatedAt": "2021-04-13T17:20:05.989445411Z" 78 | } 79 | -------------------------------------------------------------------------------- /test/fixtures/items/list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "2fcbqwe9ndg175zg2dzwftvkpa", 4 | "title": "Secrets Automation Item", 5 | "tags": ["connect", "\ud83d\udc27"], 6 | "vault": { 7 | "id": "ftz4pm2xxwmwrsd7rjqn7grzfz" 8 | }, 9 | "category": "LOGIN", 10 | "sections": [ 11 | { 12 | "id": "95cdbc3b-7742-47ec-9056-44d6af82d562", 13 | "label": "Security Questions" 14 | } 15 | ], 16 | "fields": [ 17 | { 18 | "id": "username", 19 | "type": "STRING", 20 | "purpose": "USERNAME", 21 | "label": "username", 22 | "value": "wendy" 23 | }, 24 | { 25 | "id": "password", 26 | "type": "CONCEALED", 27 | "purpose": "PASSWORD", 28 | "label": "password", 29 | "value": "hLDegPkuMQqyQiyDZqRdWGoojiN5KYQtXuA0wBDe9z3Caj6FQGHpbGu", 30 | "entropy": 189.78359985351562 31 | }, 32 | { 33 | "id": "notesPlain", 34 | "type": "STRING", 35 | "purpose": "NOTES", 36 | "label": "notesPlain" 37 | }, 38 | { 39 | "id": "a6cvmeqakbxoflkgmor4haji7y", 40 | "type": "URL", 41 | "label": "Example", 42 | "value": "https://example.com" 43 | }, 44 | { 45 | "id": "boot3vsxwhuht6g7cmcx4m6rcm", 46 | "section": { 47 | "id": "95cdbc3b-7742-47ec-9056-44d6af82d562" 48 | }, 49 | "type": "CONCEALED", 50 | "label": "Recovery Key", 51 | "value": "s=^J@GhHP_isYP>LCq?vv8u7T:*wBP.c" 52 | }, 53 | { 54 | "id": "axwtgyjrvwfp5ij7mtkw2zvijy", 55 | "section": { 56 | "id": "95cdbc3b-7742-47ec-9056-44d6af82d562" 57 | }, 58 | "type": "STRING", 59 | "label": "Random Text", 60 | "value": "R)D~KZdV!8?51QoCibDUse7=n@wKR_}]" 61 | } 62 | ], 63 | "files": [ 64 | { 65 | "id": "6r65pjq33banznomn7q22sj44e", 66 | "name": "testfile.txt", 67 | "size": 35, 68 | "content_path": "v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa/files/6r65pjq33banznomn7q22sj44e/content" 69 | }, 70 | { 71 | "id": "oyez5gf6xjfptlhc3o4n6o6hvm", 72 | "name": "samplefile.png", 73 | "size": 296639, 74 | "content_path": "v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa/files/oyez5gf6xjfptlhc3o4n6o6hvm/content" 75 | } 76 | ], 77 | "createdAt": "2021-04-10T17:20:05.98944527Z", 78 | "updatedAt": "2021-04-13T17:20:05.989445411Z" 79 | } 80 | ] 81 | -------------------------------------------------------------------------------- /test/fixtures/items/replace.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "2fcbqwe9ndg175zg2dzwftvkpa", 3 | "title": "New Secrets Automation Item", 4 | "tags": ["connect", "\ud83d\udc27"], 5 | "vault": { 6 | "id": "ftz4pm2xxwmwrsd7rjqn7grzfz" 7 | }, 8 | "category": "LOGIN", 9 | "sections": [ 10 | { 11 | "id": "95cdbc3b-7742-47ec-9056-44d6af82d562", 12 | "label": "Security Questions" 13 | } 14 | ], 15 | "fields": [ 16 | { 17 | "id": "username", 18 | "type": "STRING", 19 | "purpose": "USERNAME", 20 | "label": "username", 21 | "value": "tinkerbell" 22 | }, 23 | { 24 | "id": "password", 25 | "type": "CONCEALED", 26 | "purpose": "PASSWORD", 27 | "label": "password", 28 | "value": "hLDegPkuMQqyQiyDZqRdWGoojiN5KYQtXuA0wBDe9z3Caj6FQGHpbGu", 29 | "entropy": 189.78359985351562 30 | }, 31 | { 32 | "id": "a6cvmeqakbxoflkgmor4haji7y", 33 | "type": "URL", 34 | "label": "Example", 35 | "value": "https://example.com" 36 | } 37 | ], 38 | "createdAt": "2021-04-10T17:20:05.98944527Z", 39 | "updatedAt": "2021-04-13T17:20:05.989445411Z" 40 | } 41 | -------------------------------------------------------------------------------- /test/fixtures/items/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "2fcbqwe9ndg175zg2dzwftvkpa", 3 | "title": "Updated Secrets Automation Item", 4 | "tags": ["connect", "\ud83d\udc27"], 5 | "vault": { 6 | "id": "ftz4pm2xxwmwrsd7rjqn7grzfz" 7 | }, 8 | "category": "LOGIN", 9 | "sections": [ 10 | { 11 | "id": "95cdbc3b-7742-47ec-9056-44d6af82d562", 12 | "label": "Security Questions" 13 | } 14 | ], 15 | "fields": [ 16 | { 17 | "id": "username", 18 | "type": "STRING", 19 | "purpose": "USERNAME", 20 | "label": "username", 21 | "value": "tinkerbell" 22 | }, 23 | { 24 | "id": "password", 25 | "type": "CONCEALED", 26 | "purpose": "PASSWORD", 27 | "label": "password", 28 | "value": "hLDegPkuMQqyQiyDZqRdWGoojiN5KYQtXuA0wBDe9z3Caj6FQGHpbGu", 29 | "entropy": 189.78359985351562 30 | }, 31 | { 32 | "id": "a6cvmeqakbxoflkgmor4haji7y", 33 | "type": "URL", 34 | "label": "Example", 35 | "value": "https://example.com" 36 | } 37 | ], 38 | "createdAt": "2021-04-10T17:20:05.98944527Z", 39 | "updatedAt": "2021-04-13T17:20:05.989445411Z" 40 | } 41 | -------------------------------------------------------------------------------- /test/fixtures/vaults/get.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "ytrfte14kw1uex5txaore1emkz", 3 | "name": "Demo", 4 | "attributeVersion": 1, 5 | "contentVersion": 72, 6 | "items": 7, 7 | "type": "USER_CREATED", 8 | "createdAt": "2021-04-10T17:34:26Z", 9 | "updatedAt": "2021-04-13T14:33:50Z" 10 | } 11 | -------------------------------------------------------------------------------- /test/fixtures/vaults/list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "ytrfte14kw1uex5txaore1emkz", 4 | "name": "Demo", 5 | "attributeVersion": 1, 6 | "contentVersion": 72, 7 | "items": 7, 8 | "type": "USER_CREATED", 9 | "createdAt": "2021-04-10T17:34:26Z", 10 | "updatedAt": "2021-04-13T14:33:50Z" 11 | } 12 | ] 13 | -------------------------------------------------------------------------------- /test/op_connect/client/files_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | describe OpConnect::Client::Files do 4 | let(:stubs) { Faraday::Adapter::Test::Stubs.new } 5 | let(:client) { OpConnect::Client.new(access_token: "fake", adapter: :test, stubs: stubs) } 6 | 7 | describe "list_files" do 8 | it "returns a list of files for an item" do 9 | stubs.get("/v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa/files") { [200, {"Content-Type": "application/json"}, fixture("files/list.json")] } 10 | 11 | _(client.files( 12 | vault_id: "ftz4pm2xxwmwrsd7rjqn7grzfz", 13 | item_id: "2fcbqwe9ndg175zg2dzwftvkpa" 14 | ).first).must_be_instance_of OpConnect::Item::File 15 | end 16 | end 17 | 18 | describe "get_file" do 19 | it "returns a file object" do 20 | stubs.get("/v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa/files/6r65pjq33banznomn7q22sj44e") { [200, {"Content-Type": "application/json"}, fixture("files/get.json")] } 21 | 22 | file = client.file( 23 | vault_id: "ftz4pm2xxwmwrsd7rjqn7grzfz", 24 | item_id: "2fcbqwe9ndg175zg2dzwftvkpa", 25 | id: "6r65pjq33banznomn7q22sj44e" 26 | ) 27 | 28 | _(file).must_be_instance_of OpConnect::Item::File 29 | _(file.id).must_equal "6r65pjq33banznomn7q22sj44e" 30 | _(file.name).must_equal "testfile.txt" 31 | end 32 | end 33 | 34 | describe "get_file_content" do 35 | it "returns the contents of a file" do 36 | stubs.get("/v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa/files/6r65pjq33banznomn7q22sj44e/content") { [200, {}, fixture("files/testfile.txt")] } 37 | 38 | content = client.file_content( 39 | vault_id: "ftz4pm2xxwmwrsd7rjqn7grzfz", 40 | item_id: "2fcbqwe9ndg175zg2dzwftvkpa", 41 | id: "6r65pjq33banznomn7q22sj44e" 42 | ) 43 | 44 | _(content).must_equal "The future belongs to the curious.\n" 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /test/op_connect/client/items_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | describe OpConnect::Client::Items do 4 | let(:stubs) { Faraday::Adapter::Test::Stubs.new } 5 | let(:client) { OpConnect::Client.new(access_token: "fake", adapter: :test, stubs: stubs) } 6 | 7 | describe "list_items" do 8 | it "returns a list of items for a vault" do 9 | stubs.get("/v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items") { [200, {"Content-Type": "application/json"}, fixture("items/list.json")] } 10 | 11 | _(client.items(vault_id: "ftz4pm2xxwmwrsd7rjqn7grzfz").first).must_be_instance_of OpConnect::Item 12 | end 13 | end 14 | 15 | describe "get_item" do 16 | it "returns an item for a vault" do 17 | stubs.get("/v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa") { [200, {"Content-Type": "application/json"}, fixture("items/get.json")] } 18 | 19 | item = client.item(vault_id: "ftz4pm2xxwmwrsd7rjqn7grzfz", id: "2fcbqwe9ndg175zg2dzwftvkpa") 20 | 21 | _(item).must_be_instance_of OpConnect::Item 22 | _(item.vault.id).must_equal "ftz4pm2xxwmwrsd7rjqn7grzfz" 23 | _(item.id).must_equal "2fcbqwe9ndg175zg2dzwftvkpa" 24 | end 25 | end 26 | 27 | describe "create_item" do 28 | it "creates a new item" do 29 | body = { 30 | vault: { 31 | id: "ftz4pm2xxwmwrsd7rjqn7grzfz" 32 | }, 33 | title: "Secrets Automation Item", 34 | category: "LOGIN", 35 | tags: [ 36 | "connect", 37 | "\\ud83d\\udc27" 38 | ], 39 | sections: [ 40 | { 41 | label: "Security Questions", 42 | id: "95cdbc3b-7742-47ec-9056-44d6af82d562" 43 | } 44 | ], 45 | fields: [ 46 | { 47 | value: "wendy", 48 | purpose: "USERNAME" 49 | }, 50 | { 51 | purpose: "PASSWORD", 52 | generate: true, 53 | recipe: { 54 | length: 55, 55 | characterSets: [ 56 | "LETTERS", 57 | "DIGITS" 58 | ] 59 | } 60 | }, 61 | { 62 | section: { 63 | id: "95cdbc3b-7742-47ec-9056-44d6af82d562" 64 | }, 65 | type: "CONCEALED", 66 | generate: true, 67 | label: "Recovery Key" 68 | }, 69 | { 70 | section: { 71 | id: "95cdbc3b-7742-47ec-9056-44d6af82d562" 72 | }, 73 | type: "STRING", 74 | generate: true, 75 | label: "Random Text" 76 | }, 77 | { 78 | type: "URL", 79 | label: "Example", 80 | value: "https://example.com" 81 | } 82 | ] 83 | } 84 | 85 | stubs.post("/v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items") { [200, {"Content-Type": "application/json"}, fixture("items/create.json")] } 86 | 87 | item = client.create_item(vault_id: "ftz4pm2xxwmwrsd7rjqn7grzfz", body: body) 88 | 89 | _(item).must_be_instance_of OpConnect::Item 90 | _(item.id).must_equal "2fcbqwe9ndg175zg2dzwftvkpa" 91 | end 92 | end 93 | 94 | describe "replace_item" do 95 | it "replaces an item with a new item" do 96 | body = { 97 | vault: { 98 | id: "ftz4pm2xxwmwrsd7rjqn7grzfz" 99 | }, 100 | title: "New Secrets Automation Item", 101 | category: "LOGIN", 102 | tags: [ 103 | "connect", 104 | "\\ud83d\\udc27" 105 | ], 106 | sections: [ 107 | { 108 | label: "Security Questions", 109 | id: "95cdbc3b-7742-47ec-9056-44d6af82d562" 110 | } 111 | ], 112 | fields: [ 113 | { 114 | value: "tinkerbell", 115 | purpose: "USERNAME" 116 | }, 117 | { 118 | purpose: "PASSWORD", 119 | generate: true, 120 | recipe: { 121 | length: 55, 122 | characterSets: [ 123 | "LETTERS", 124 | "DIGITS" 125 | ] 126 | } 127 | }, 128 | { 129 | section: { 130 | id: "95cdbc3b-7742-47ec-9056-44d6af82d562" 131 | }, 132 | type: "CONCEALED", 133 | generate: true, 134 | label: "Recovery Key" 135 | }, 136 | { 137 | section: { 138 | id: "95cdbc3b-7742-47ec-9056-44d6af82d562" 139 | }, 140 | type: "STRING", 141 | generate: true, 142 | label: "Random Text" 143 | }, 144 | { 145 | type: "URL", 146 | label: "Example", 147 | value: "https://example.com" 148 | } 149 | ] 150 | } 151 | 152 | stubs.put("/v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa") { [200, {"Content-Type": "application/json"}, fixture("items/replace.json")] } 153 | 154 | item = client.replace_item(vault_id: "ftz4pm2xxwmwrsd7rjqn7grzfz", id: "2fcbqwe9ndg175zg2dzwftvkpa", body: body) 155 | 156 | _(item).must_be_instance_of OpConnect::Item 157 | _(item.id).must_equal "2fcbqwe9ndg175zg2dzwftvkpa" 158 | end 159 | end 160 | 161 | describe "delete_item" do 162 | it "deletes an item" do 163 | stubs.delete("/v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa") { [204, {}, ""] } 164 | 165 | _(client.delete_item(vault_id: "ftz4pm2xxwmwrsd7rjqn7grzfz", id: "2fcbqwe9ndg175zg2dzwftvkpa")).must_equal true 166 | end 167 | 168 | it "returns false on error" do 169 | stubs.delete("/v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa") { [400, {}, ""] } 170 | 171 | _(client.delete_item(vault_id: "ftz4pm2xxwmwrsd7rjqn7grzfz", id: "2fcbqwe9ndg175zg2dzwftvkpa")).must_equal false 172 | end 173 | end 174 | 175 | describe "update_item" do 176 | it "updates an item" do 177 | attributes = [ 178 | {op: "replace", path: "/title", value: "New Secrets Automation Item"}, 179 | {op: "replace", path: "/fields/username", value: "tinkerbell"} 180 | ] 181 | 182 | stubs.patch("/v1/vaults/ftz4pm2xxwmwrsd7rjqn7grzfz/items/2fcbqwe9ndg175zg2dzwftvkpa") { [200, {"Content-Type": "application/json"}, fixture("items/update.json")] } 183 | 184 | item = client.update_item(vault_id: "ftz4pm2xxwmwrsd7rjqn7grzfz", id: "2fcbqwe9ndg175zg2dzwftvkpa", attributes: attributes) 185 | 186 | _(item).must_be_instance_of OpConnect::Item 187 | _(item.title).must_equal "Updated Secrets Automation Item" 188 | _(item.fields[0].value).must_equal "tinkerbell" 189 | end 190 | end 191 | end 192 | -------------------------------------------------------------------------------- /test/op_connect/client/vaults_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | describe OpConnect::Client::Vaults do 4 | let(:stubs) { Faraday::Adapter::Test::Stubs.new } 5 | let(:client) { OpConnect::Client.new(access_token: "fake", adapter: :test, stubs: stubs) } 6 | 7 | describe "list_vaults" do 8 | it "returns a list of vaults" do 9 | stubs.get("/v1/vaults") { [200, {"Content-Type": "application/json"}, fixture("vaults/list.json")] } 10 | 11 | _(client.vaults.first).must_be_instance_of OpConnect::Vault 12 | end 13 | end 14 | 15 | describe "get_vault" do 16 | it "returns a valut" do 17 | stubs.get("/v1/vaults/ytrfte14kw1uex5txaore1emkz") { [200, {"Content-Type": "application/json"}, fixture("vaults/get.json")] } 18 | 19 | vault = client.vault(id: "ytrfte14kw1uex5txaore1emkz") 20 | 21 | _(vault).must_be_instance_of OpConnect::Vault 22 | _(vault.id).must_equal "ytrfte14kw1uex5txaore1emkz" 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /test/op_connect/client_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | describe OpConnect::Client do 4 | subject { OpConnect::Client } 5 | 6 | before do 7 | OpConnect.reset! 8 | end 9 | 10 | after do 11 | OpConnect.reset! 12 | end 13 | 14 | describe "module configuration" do 15 | before do 16 | OpConnect.reset! 17 | OpConnect.configure do |config| 18 | OpConnect::Configurable.keys.each do |key| 19 | config.send("#{key}=", "Some #{key}") 20 | end 21 | end 22 | end 23 | 24 | after do 25 | OpConnect.reset! 26 | end 27 | 28 | it "inherits the module configuration" do 29 | client = subject.new 30 | 31 | OpConnect::Configurable.keys.each do |key| 32 | _(client.instance_variable_get(:"@#{key}")).must_equal "Some #{key}" 33 | end 34 | end 35 | 36 | describe "with class-level configuration" do 37 | before do 38 | @options = { 39 | access_token: "some-new-access_token", 40 | api_endpoint: "https://api.bogus.zzz/v1" 41 | } 42 | end 43 | 44 | it "overrides module configuration" do 45 | client = subject.new(@options) 46 | 47 | _(client.access_token).must_equal "some-new-access_token" 48 | _(client.api_endpoint).must_equal "https://api.bogus.zzz/v1/" 49 | end 50 | 51 | it "can set configuration after initialization" do 52 | client = subject.new 53 | client.configure do |config| 54 | @options.each do |key, value| 55 | config.send("#{key}=", value) 56 | end 57 | end 58 | 59 | _(client.access_token).must_equal "some-new-access_token" 60 | _(client.api_endpoint).must_equal "https://api.bogus.zzz/v1/" 61 | end 62 | 63 | it "masks tokens on inspect" do 64 | client = subject.new(access_token: "OPExnRuUZtQe6I9QtSNY5j5BrrnU") 65 | inspected = client.inspect 66 | _(inspected).wont_include "OPExnRuUZtQe6I9QtSNY5j5BrrnU" 67 | end 68 | end 69 | end 70 | 71 | describe ".last_response" do 72 | it "caches the last agent response" do 73 | OpConnect.reset! 74 | 75 | stub = Faraday::Adapter::Test::Stubs.new 76 | stub.get("/v1/heartbeat") { [200, {}, ""] } 77 | client = subject.new(access_token: "fake", adapter: :test, stubs: stub) 78 | 79 | _(client.last_response).must_be_nil 80 | 81 | client.get("heartbeat") 82 | 83 | _(client.last_response.status).must_equal 200 84 | end 85 | end 86 | 87 | describe ".get" do 88 | let(:stubs) { Faraday::Adapter::Test::Stubs.new } 89 | 90 | before do 91 | OpConnect.reset! 92 | end 93 | 94 | it "handles query params" do 95 | stubs.get("/heartbeat?foo=bar") do |env| 96 | _(env.url.query).must_equal "foo=bar" 97 | [200, {}, ""] 98 | end 99 | end 100 | 101 | it "handles headers" 102 | end 103 | 104 | describe "when making requests" do 105 | it "sets a deafult user agent" 106 | it "sets a custom user agent" 107 | end 108 | 109 | describe "utility methods" do 110 | let(:stubs) { Faraday::Adapter::Test::Stubs.new } 111 | let(:client) { subject.new(access_token: "fake", adapter: :test, stubs: stubs) } 112 | 113 | describe "activity" do 114 | it "returns a list of API requests" do 115 | stubs.get("/v1/activity") { [200, {"Content-Type": "application/json"}, fixture("activity.json")] } 116 | 117 | api_request = client.activity.first 118 | 119 | _(api_request).must_be_instance_of OpConnect::APIRequest 120 | _(api_request.action).must_equal "READ" 121 | end 122 | end 123 | 124 | describe "heartbeat" do 125 | it "returns true if the server is active" do 126 | stubs.get("/heartbeat") { [200, {"Content-Type": "text/plain"}, "."] } 127 | 128 | _(client.heartbeat).must_equal true 129 | end 130 | 131 | it "returns false if the servier is not active" do 132 | stubs.get("/heartbeat") { [500, {}, ""] } 133 | 134 | _(client.heartbeat).must_equal false 135 | end 136 | end 137 | 138 | describe "health" do 139 | it "returns the state of the server" do 140 | stubs.get("/health") { [200, {"Content-Type": "application/json"}, fixture("health.json")] } 141 | 142 | _(client.health).must_be_instance_of OpConnect::ServerHealth 143 | _(client.health.name).must_equal "1Password Connect API" 144 | end 145 | end 146 | 147 | describe "metrics" do 148 | it "returns metrics collected by the server" do 149 | stubs.get("/metrics") { [200, {"Content-Type": "text/plain"}, fixture("metrics.txt")] } 150 | 151 | _(client.metrics).must_match %r{go_goroutines 24} 152 | end 153 | end 154 | end 155 | 156 | describe "error handling" do 157 | let(:stubs) { Faraday::Adapter::Test::Stubs.new } 158 | let(:client) { subject.new(access_token: "fake", adapter: :test, stubs: stubs) } 159 | 160 | it "raises on 400" do 161 | stubs.get("/v1/whatever") { [400, {"Content-Type": "application/json"}, fixture("errors/400.json")] } 162 | 163 | _ { client.get("whatever") }.must_raise OpConnect::BadRequest 164 | end 165 | 166 | it "raises on 401" do 167 | stubs.get("/v1/who_are_you") { [401, {"Content-Type": "application/json"}, fixture("errors/401.json")] } 168 | 169 | _ { client.get("who_are_you") }.must_raise OpConnect::Unauthorized 170 | end 171 | 172 | it "raises on 403" do 173 | stubs.get("/v1/nope") { [403, {"Content-Type": "application/json"}, fixture("errors/403.json")] } 174 | 175 | _ { client.get("nope") }.must_raise OpConnect::Forbidden 176 | end 177 | 178 | it "raises on 404" do 179 | stubs.get("/v1/not_found") { [404, {"Content-Type": "application/json"}, fixture("errors/404.json")] } 180 | 181 | _ { client.get("not_found") }.must_raise OpConnect::NotFound 182 | end 183 | 184 | it "raises on 413" do 185 | stubs.get("/v1/too_big") { [413, {"Content-Type": "application/json"}, fixture("errors/413.json")] } 186 | 187 | _ { client.get("too_big") }.must_raise OpConnect::PayloadTooLarge 188 | end 189 | 190 | it "raises on 500" do 191 | stubs.get("/v1/server_error") { [500, {}, ""] } 192 | 193 | _ { client.get("server_error") }.must_raise OpConnect::InternalServerError 194 | end 195 | 196 | it "raises on 503" do 197 | stubs.get("/v1/service_unavailable") { [503, {}, ""] } 198 | 199 | _ { client.get("service_unavailable") }.must_raise OpConnect::ServiceUnavailable 200 | end 201 | end 202 | end 203 | -------------------------------------------------------------------------------- /test/op_connect/object_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | describe OpConnect::Object do 4 | subject { OpConnect::Object } 5 | 6 | it "creates an object from a hash" do 7 | _(subject.new(foo: "bar").foo).must_equal "bar" 8 | end 9 | 10 | it "handles nested hashes" do 11 | _(subject.new(foo: {bar: {baz: "foobar"}}).foo.bar.baz).must_equal "foobar" 12 | end 13 | 14 | it "handles numbers" do 15 | _(subject.new(foo: {bar: 1}).foo.bar).must_equal 1 16 | end 17 | 18 | it "handles arrays" do 19 | object = subject.new(foo: [{bar: :baz}]) 20 | 21 | _(object.foo.first).must_be_kind_of OpenStruct 22 | _(object.foo.first.bar).must_equal :baz 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /test/op_connect_test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "test_helper" 4 | 5 | describe OpConnect do 6 | subject { OpConnect } 7 | 8 | before do 9 | subject.setup 10 | end 11 | 12 | it "has a version number" do 13 | _(::OpConnect::VERSION).wont_be_nil 14 | end 15 | 16 | it "sets defaults" do 17 | OpConnect::Configurable.keys.each do |key| 18 | default = OpConnect::Default.send(key) 19 | actual = OpConnect.instance_variable_get(:"@#{key}") 20 | 21 | if default.nil? 22 | _(actual).must_be_nil 23 | else 24 | _(actual).must_equal default 25 | end 26 | end 27 | end 28 | 29 | describe ".client" do 30 | it "creates a OpConnect::Client" do 31 | _(subject.client).must_be_kind_of OpConnect::Client 32 | end 33 | 34 | it "caches the client when the same arguments are passed" do 35 | _(subject.client).must_equal subject.client 36 | end 37 | 38 | it "returns a fresh client when options are not the same" do 39 | client = subject.client 40 | subject.access_token = "some-random-token" 41 | client_two = subject.client 42 | client_three = subject.client 43 | 44 | _(client).wont_equal client_two 45 | _(client_two).must_equal client_three 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "simplecov" 4 | require "simplecov-lcov" 5 | require "simplecov-tailwindcss" 6 | 7 | SimpleCov.start do 8 | add_filter "/test/" 9 | coverage_dir "test/coverage" 10 | 11 | formatter SimpleCov::Formatter::MultiFormatter.new([ 12 | SimpleCov::Formatter::LcovFormatter, 13 | SimpleCov::Formatter::TailwindFormatter 14 | ]) 15 | 16 | add_group "Resources", "lib/op_connect/client/" 17 | add_group "Middleware", ["lib/op_connect/request/", "lib/op_connect/response/", "lib/op_connect/middleware/"] 18 | end 19 | 20 | $LOAD_PATH.unshift File.expand_path("../lib", __dir__) 21 | require "op_connect" 22 | require "minitest/autorun" 23 | require "minitest/reporters" 24 | require "faraday" 25 | require "json" 26 | 27 | Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(color: true) 28 | 29 | class Minitest::Test 30 | def fixture(filename) 31 | File.read("test/fixtures/#{filename}") 32 | end 33 | end 34 | --------------------------------------------------------------------------------