diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index c84b2ee..0000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,88 +0,0 @@ -# This is a sample .codeclimate.yml configured for Engine analysis on Code -# Climate Platform. For an overview of the Code Climate Platform, see here: -# http://docs.codeclimate.com/article/300-the-codeclimate-platform - -# Under the engines key, you can configure which engines will analyze your repo. -# Each key is an engine name. For each value, you need to specify enabled: true -# to enable the engine as well as any other engines-specific configuration. - -# For more details, see here: -# http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform - -# For a list of all available engines, see here: -# http://docs.codeclimate.com/article/296-engines-available-engines - -#engines: -# to turn on an engine, add it here and set enabled to `true` -# to turn off an engine, set enabled to `false` or remove it -# rubocop: -# enabled: true -# golint: -# enabled: true -# gofmt: -# enabled: true -# eslint: -# enabled: true -# csslint: -# enabled: true - -# Engines can analyze files and report issues on them, but you can separately -# decide which files will receive ratings based on those issues. This is -# specified by path patterns under the ratings key. - -# For more details see here: -# http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform - -# ratings: -# paths: -# - app/** -# - lib/** -# - "**.rb" -# - "**.go" - -# You can globally exclude files from being analyzed by any engine using the -# exclude_paths key. - -#All maintainability checks are enabled by default with the following configurations. -#checks, -# argument-count: -# config: -# threshold: 4 -# complex-logic: -# config: -# threshold: 4 -# file-lines: -# config: -# threshold: 250 -# method-complexity: -# config: -# threshold: 5 -# method-count: -# config: -# threshold: 20 -# method-lines: -# config: -# threshold: 25 -# nested-control-flow: -# config: -# threshold: 4 -# return-statements: -# config: -# threshold: 4 -# similar-code: -# config: -# threshold: # language-specific defaults. an override will affect all languages. -# identical-code: -# config: -# threshold: # language-specific defaults. an override will affect all languages. - -engines: - sonar-java: - enabled: true - channel: beta - -exclude_paths: -- "scripts/" -- ".github/" -- "gradle/" -- "**/test/" \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE deleted file mode 100644 index 5588c7f..0000000 --- a/.github/ISSUE_TEMPLATE +++ /dev/null @@ -1,17 +0,0 @@ -#### Issue Summary - -A summary of the issue and the environment in which it occurs. If suitable, include the steps required to reproduce the bug. Please feel free to include screenshots, screencasts, code examples. - - -#### Steps to Reproduce - -1. This is the first step -2. This is the second step -3. Further steps, etc. - -Any other information you want to share that is relevant to the issue being reported. Especially, why do you consider this to be a bug? What do you expect to happen instead? - -#### Technical details: - -* java-http-client Version: master (latest commit: [commit number]) -* Java Version: X.X diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE deleted file mode 100644 index 7ad590b..0000000 --- a/.github/PULL_REQUEST_TEMPLATE +++ /dev/null @@ -1,24 +0,0 @@ - -# Fixes # - -### Checklist -- [ ] I have made a material change to the repo (functionality, testing, spelling, grammar) -- [ ] I have read the [Contribution Guide] and my PR follows them. -- [ ] I updated my branch with the master branch. -- [ ] I have added tests that prove my fix is effective or that my feature works -- [ ] I have added necessary documentation about the functionality in the appropriate .md file -- [ ] I have added in line documentation to the code I modified - -### Short description of what this PR does: -- -- - -If you have questions, please send an email to [Sendgrid](mailto:dx@sendgrid.com), or file a Github Issue in this repository. diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml new file mode 100644 index 0000000..2f5232b --- /dev/null +++ b/.github/workflows/pr-lint.yml @@ -0,0 +1,15 @@ +name: Lint PR +on: + pull_request_target: + types: [ opened, edited, synchronize, reopened ] + +jobs: + validate: + name: Validate title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v4 + with: + types: chore docs fix feat test misc + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml new file mode 100644 index 0000000..9abc8c2 --- /dev/null +++ b/.github/workflows/test-and-deploy.yml @@ -0,0 +1,93 @@ +name: Test and Deploy +on: + push: + branches: [ '*' ] + tags: [ '*' ] + pull_request: + branches: [ main ] + schedule: + # Run automatically at 8AM PST Monday-Friday + - cron: '0 15 * * 1-5' + workflow_dispatch: + +jobs: + test: + name: Test + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + matrix: + java: [ 8, 11, 17 ] + steps: + - uses: actions/checkout@v2 + + - name: Set up Java + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: ${{ matrix.java }} + cache: 'maven' + + - run: mvn install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V + - name: Run Unit Tests + run: mvn test -B + + deploy: + name: Deploy + if: success() && github.ref_type == 'tag' + needs: [ test ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Sonatype Maven + uses: actions/setup-java@v2 + with: + java-version: 8 + distribution: temurin + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: GPG_PASSPHRASE + + - name: Install Dependencies + run: make install + + - name: Create GitHub Release + uses: sendgrid/dx-automator/actions/release@main + with: + assets: java-http-client.jar + footer: '**[Maven](https://mvnrepository.com/artifact/com.sendgrid/java-http-client/${version})**' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish to Maven + env: + MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + run: mvn clean deploy -DskipTests=true -B -U -Prelease + + - name: Submit metric to Datadog + uses: sendgrid/dx-automator/actions/datadog-release-metric@main + env: + DD_API_KEY: ${{ secrets.DATADOG_API_KEY }} + + notify-on-failure: + name: Slack notify on failure + if: failure() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref_type == 'tag') + needs: [ test, deploy ] + runs-on: ubuntu-latest + steps: + - uses: rtCamp/action-slack-notify@v2 + env: + SLACK_COLOR: failure + SLACK_ICON_EMOJI: ':github:' + SLACK_MESSAGE: ${{ format('Test *{0}*, Deploy *{1}*, {2}/{3}/actions/runs/{4}', needs.test.result, needs.deploy.result, github.server_url, github.repository, github.run_id) }} + SLACK_TITLE: Action Failure - ${{ github.repository }} + SLACK_USERNAME: GitHub Actions + SLACK_MSG_AUTHOR: twilio-dx + SLACK_FOOTER: Posted automatically using GitHub Actions + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + MSG_MINIMAL: true diff --git a/.github/workflows/update-dependencies.yml b/.github/workflows/update-dependencies.yml new file mode 100644 index 0000000..35ec8ed --- /dev/null +++ b/.github/workflows/update-dependencies.yml @@ -0,0 +1,60 @@ +name: Update dependencies +on: + schedule: + # Run automatically at 7AM PST Tuesday + - cron: '0 14 * * 2' + workflow_dispatch: + +jobs: + update-dependencies-and-test: + name: Update Dependencies & Test + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + max-parallel: 1 + matrix: + java: [ 8, 11, 17 ] + + steps: + - name: Checkout java-http-client + uses: actions/checkout@v2 + + - name: Set up Java + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: ${{ matrix.java }} + cache: 'maven' + + - name: Updating semver dependencies + run: make update-deps + + - run: mvn install -Dgpg.skip -Dmaven.javadoc.skip=true -B -V + + - name: Add & Commit + if: matrix.java == '17' + uses: EndBug/add-and-commit@v8.0.2 + env: + GITHUB_TOKEN: ${{ secrets.SG_JAVA_GITHUB_TOKEN }} + with: + add: 'pom.xml' + default_author: 'github_actions' + message: 'chore: update java-http-client dependencies' + + notify-on-failure: + name: Slack notify on failure + if: failure() + needs: [ update-dependencies-and-test ] + runs-on: ubuntu-latest + steps: + - uses: rtCamp/action-slack-notify@v2 + env: + SLACK_COLOR: failure + SLACK_ICON_EMOJI: ':github:' + SLACK_MESSAGE: ${{ format('Update dependencies *{0}*, {1}/{2}/actions/runs/{3}', needs.update-dependencies-and-test.result, github.server_url, github.repository, github.run_id) }} + SLACK_TITLE: Action Failure - ${{ github.repository }} + SLACK_USERNAME: GitHub Actions + SLACK_MSG_AUTHOR: twilio-dx + SLACK_FOOTER: Posted automatically using GitHub Actions + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + MSG_MINIMAL: true diff --git a/.gitignore b/.gitignore index b5c5801..4268a51 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ repo/ # Environment files .env/*.* + +java-http-client.jar diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c00bd23..0000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: java -jdk: -- oraclejdk8 -- openjdk8 -before_script: -- chmod a+x gradlew -script: -- ./gradlew build check -after_script: -- "./scripts/s3upload.sh" -after_success: - - bash <(curl -s https://codecov.io/bash) -t $CODECOV_KEY -env: - global: - - S3_POLICY: ewogICJleHBpcmF0aW9uIjogIjIxMDAtMDEtMDFUMTI6MDA6MDAuMDAwWiIsCiAgImNvbmRpdGlvbnMiOiBbCiAgICB7ImFjbCI6ICJwdWJsaWMtcmVhZCIgfSwKICAgIHsiYnVja2V0IjogInNlbmRncmlkLW9wZW4tc291cmNlIiB9LAogICAgWyJzdGFydHMtd2l0aCIsICIka2V5IiwgInNlbmRncmlkLWphdmEvIl0sCiAgICBbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMjA0OCwgMjY4NDM1NDU2XSwKICAgIFsiZXEiLCAiJENvbnRlbnQtVHlwZSIsICJhcHBsaWNhdGlvbi96aXAiXQogIF0KfQo= - - secure: Iki1btwhG1nlyjnEMu90Oh/hoatFpPiiKkqpj7siLnlLp2xbBQ2003jRsn30I3Vujes2ugvzdlHqBJ9lDwRvfGrKXcLlRvYuDQ24N2YKquEiKHUxs+iMOzTQj6Sf64KL5O0aSZd1l5rjWgsQ0qqjHW9u3l5bUjqxzrhAI2Js37U= - - secure: Khi6a4z1lfZmDEDV738MOiWznRcTv5ILZUM+igEw2txX7PGX+B5909WridpAijTGiurJ6eda7jvsUgci8DTPQCXB18LD6N870hnPcSQkuI6zDAhKTx+w/ZsfPLWh28sP2CVzbqGdxaitZDKxRWaVmKnBZpyi8XI9UKjmyK2sjwE= - - secure: wKXAjjBgCLM4h++nP1xDQQtYU10JbwwynY0XB920SoQjI2Uu82cMPtkEXFWTpzyIS2hE5B3qvu75VHNdLqDUtek3e3lBg5k3SpYgGin20dg3SDEJrvA4vlvcApdQ132pMEWdDOVwzbXhm9+JTjALYbc3fX+VAQX1u5daPyeDGC4= -notifications: - hipchat: - rooms: - secure: j/23RY7nDWHMrpIcZiiwH3ORsWnmkZrMWKfv761RnJviYBQJy1cDEmvsyZy5w2AlE1w+CLNm+G7SI35N2eKZqtked+pWcx3nBN+bVmt7uRXmj16Oc5x2ztX6QWs3xFtUfGiA8t17q/LGRZlw9SiNI+SbP2wBHDJl66+KZWTppjbcmz/Rdax2OKj843Zx92bqsdAOjsdfwFm3B4isHQjE6hoS9u0MtIQ4KpkX4xOTJSF/r0RpIYWI37E41dDmdjLWIsYnj01P9dI+IQLN5OIfsaVQGWLVV9YkHjsEzOspJHBz8Mf40ADY76Exm/V+phRS2Q4tmAsAPXQ9lchS3uooat9z3RlfSxfIhVbjxTDLN7E/PMXCYAMKRU2FUqDYQoX3qSZBT9717Agz84T15S7l4g009bzzTgoHVpJjHVhNCRR1hWfaWFj7oRi8s0BDhQCclZ0ug+s//29LQWViSOvK7/prhJJwqDOD+GciVE4VDe1NFj7vhDTuIoWYU87D8zuZadLMz2jz1w67Oa1jJ1Ok64iFTqBS9AKQAfPKeQq9dZQ4SKMlS1Zyr8Y013ebp8CG01I8TZYQiBdbyhzYkAVSaz4x+Qh3n6WPJLJA0FUuQFcn3p1UQS/I16U2253F7w5t+7wU2DMj8k8k7ZN373FZc1ZWngX5ljR6nMoJNR73opg= - template: - - '%{repository} - Build %{build_number} on branch %{branch} by %{author}: %{message} - View on GitHub' - format: html - notify: true diff --git a/CHANGELOG.md b/CHANGELOG.md index bfd40b5..e4a94c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,130 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [4.2.0] - 2017-10-30 +[2022-05-18] Version 4.5.1 +-------------------------- +**Library - Docs** +- [PR #144](https://github.com/sendgrid/java-http-client/pull/144): Update to align with SendGrid Support. Thanks to [@garethpaul](https://github.com/garethpaul)! + +**Library - Fix** +- [PR #143](https://github.com/sendgrid/java-http-client/pull/143): override default gh token. Thanks to [@beebzz](https://github.com/beebzz)! + + +[2022-03-09] Version 4.5.0 +-------------------------- +**Library - Chore** +- [PR #142](https://github.com/sendgrid/java-http-client/pull/142): push Datadog Release Metric upon deploy success. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Library - Feature** +- [PR #141](https://github.com/sendgrid/java-http-client/pull/141): add GH action to update dependencies. Thanks to [@JenniferMah](https://github.com/JenniferMah)! + + +[2022-02-09] Version 4.4.0 +-------------------------- +**Library - Chore** +- [PR #139](https://github.com/sendgrid/java-http-client/pull/139): upgrade supported language versions. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #138](https://github.com/sendgrid/java-http-client/pull/138): add gh release to workflow. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)! +- [PR #137](https://github.com/sendgrid/java-http-client/pull/137): merge test and deploy workflows. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)! + +**Library - Feature** +- [PR #134](https://github.com/sendgrid/java-http-client/pull/134): Support multiple duplicate queryparams. Thanks to [@mjjs](https://github.com/mjjs)! + + +[2022-01-12] Version 4.3.9 +-------------------------- +**Library - Chore** +- [PR #136](https://github.com/sendgrid/java-http-client/pull/136): update license year. Thanks to [@JenniferMah](https://github.com/JenniferMah)! + + +[2021-12-01] Version 4.3.8 +-------------------------- +**Library - Chore** +- [PR #135](https://github.com/sendgrid/java-http-client/pull/135): fix pom for release. Thanks to [@eshanholtz](https://github.com/eshanholtz)! +- [PR #133](https://github.com/sendgrid/java-http-client/pull/133): migrate to github actions. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + + +[2021-05-19] Version 4.3.7 +-------------------------- +**Library - Chore** +- [PR #131](https://github.com/sendgrid/java-http-client/pull/131): Bump org.apache.httpcomponents.httpclient from 4.5.12 to 4.5.13. Thanks to [@akunzai](https://github.com/akunzai)! + + +[2020-08-19] Version 4.3.6 +-------------------------- +**Library - Chore** +- [PR #128](https://github.com/sendgrid/java-http-client/pull/128): update GitHub branch references to use HEAD. Thanks to [@thinkingserious](https://github.com/thinkingserious)! + +**Library - Docs** +- [PR #97](https://github.com/sendgrid/java-http-client/pull/97): Correcting *.md files using Grammarly. Thanks to [@pushkyn](https://github.com/pushkyn)! +- [PR #101](https://github.com/sendgrid/java-http-client/pull/101): Add first timers file. Thanks to [@Varpie](https://github.com/Varpie)! + + +[2020-08-05] Version 4.3.5 +-------------------------- +**Library - Docs** +- [PR #86](https://github.com/sendgrid/java-http-client/pull/86): Moved usage and enviorment variables to USAGE.md. Thanks to [@rareinator](https://github.com/rareinator)! + + +[2020-07-22] Version 4.3.4 +-------------------------- +**Library - Fix** +- [PR #109](https://github.com/sendgrid/java-http-client/pull/109): correct the LICENSE.md link in pom.xml. Thanks to [@crweiner](https://github.com/crweiner)! + +**Library - Docs** +- [PR #108](https://github.com/sendgrid/java-http-client/pull/108): Create a Use Cases Directory. Thanks to [@ajloria](https://github.com/ajloria)! + + +[2020-03-04] Version 4.3.3 +-------------------------- +**Library - Chore** +- [PR #127](https://github.com/sendgrid/java-http-client/pull/127): fix JDK Travis failures. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + + +[2020-02-19] Version 4.3.2 +-------------------------- +**Library - Chore** +- [PR #111](https://github.com/sendgrid/java-http-client/pull/111): Update the Client file documentation. Thanks to [@vinifarias](https://github.com/vinifarias)! + + +[2020-02-05] Version 4.3.1 +-------------------------- +**Library - Docs** +- [PR #126](https://github.com/sendgrid/java-http-client/pull/126): baseline all the templated markdown docs. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + + +[2020-02-01] Version 4.3.0 +-------------------------- +**Library - Feature** +- [PR #25](https://github.com/sendgrid/java-http-client/pull/25): do not close or manage lifecycle of http-client passed in. Thanks to [@maxxedev](https://github.com/maxxedev)! +- [PR #34](https://github.com/sendgrid/java-http-client/pull/34): Add close method to Client. Thanks to [@tsuyoshizawa](https://github.com/tsuyoshizawa)! +- [PR #67](https://github.com/sendgrid/java-http-client/pull/67): Adding Docker support. Thanks to [@mithunsasidharan](https://github.com/mithunsasidharan)! + +**Library - Fix** +- [PR #26](https://github.com/sendgrid/java-http-client/pull/26): use .equals to compare strings. Thanks to [@maxxedev](https://github.com/maxxedev)! +- [PR #36](https://github.com/sendgrid/java-http-client/pull/36): No longer throwing IOExceptions on non 2xx response codes. Thanks to [@andy-trimble](https://github.com/andy-trimble)! +- [PR #77](https://github.com/sendgrid/java-http-client/pull/77): Closes #72 Update Example.java. Thanks to [@AbdulDroid](https://github.com/AbdulDroid)! + +**Library - Chore** +- [PR #54](https://github.com/sendgrid/java-http-client/pull/54): Added example file, updated .gitignore and README. Thanks to [@dhsrocha](https://github.com/dhsrocha)! +- [PR #58](https://github.com/sendgrid/java-http-client/pull/58): added .codeclimate,yml for codeclimate run. Thanks to [@skshelar](https://github.com/skshelar)! +- [PR #73](https://github.com/sendgrid/java-http-client/pull/73): Fixes #71. Thanks to [@huytranrjc](https://github.com/huytranrjc)! +- [PR #76](https://github.com/sendgrid/java-http-client/pull/76): Update travis - add codecov. Thanks to [@pushkyn](https://github.com/pushkyn)! +- [PR #92](https://github.com/sendgrid/java-http-client/pull/92): update LICENSE - bump year. Thanks to [@pushkyn](https://github.com/pushkyn)! +- [PR #115](https://github.com/sendgrid/java-http-client/pull/115): add [openjdk11] to Travis build. Thanks to [@sullis](https://github.com/sullis)! +- [PR #117](https://github.com/sendgrid/java-http-client/pull/117): Update transitive dependencies. Thanks to [@kebeda](https://github.com/kebeda)! +- [PR #123](https://github.com/sendgrid/java-http-client/pull/123): prep the repo for automated releases. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Library - Docs** +- [PR #59](https://github.com/sendgrid/java-http-client/pull/59): Typos in CONTRIBUTING.md. Thanks to [@rkaranam](https://github.com/rkaranam)! +- [PR #113](https://github.com/sendgrid/java-http-client/pull/113): Add our Developer Experience Engineer career opportunity to the READM…. Thanks to [@mptap](https://github.com/mptap)! + +**Library - Test** +- [PR #66](https://github.com/sendgrid/java-http-client/pull/66): Test to check year in license file. Thanks to [@pushkyn](https://github.com/pushkyn)! +- [PR #93](https://github.com/sendgrid/java-http-client/pull/93): removed tests that were testing for files that didnt exist, bumped gradle version to 4.10.2. Thanks to [@Strum355](https://github.com/Strum355)! + + +[2017-10-30] Version 4.2.0 +--------------------------- ### Added - [Pull #22](https://github.com/sendgrid/java-http-client/pull/22): Allow setting both `apache http client` and `test` parameters - BIG thanks to [Maxim Novak](https://github.com/maximn) for the pull request! @@ -22,14 +145,14 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### BREAKING Change - [Pull #14](https://github.com/sendgrid/java-http-client/pull/14): Make response have private variables - Fixed [Issue #12](https://github.com/sendgrid/java-http-client/issues/12): The public Response variables should be private -- The breaking change is that variables that were public are now private and accessable only via getters and setters +- The breaking change is that variables that were public are now private and accessible only via getters and setters - BIG thanks to [Diego Camargo](https://github.com/belfazt) for the pull request! ## [3.0.0] - 2016-10-06 ### BREAKING Change - [Pull #15](https://github.com/sendgrid/java-http-client/pull/15): Update the request object with sensible defaults and access methods - Fixes [Issue #13](https://github.com/sendgrid/java-http-client/issues/13): Update the Request object with sensible defaults and access methods -- The breaking change is that variables that were public are now private and accessable only via getters and setters +- The breaking change is that variables that were public are now private and accessible only via getters and setters - BIG thanks to [Diego Camargo](https://github.com/belfazt) for the pull request! ## [2.3.4] - 2016-08-09 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index e3ce656..2f0727e 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,41 +1,73 @@ -# SendGrid Community Code of Conduct +# Contributor Covenant Code of Conduct -The SendGrid open source community is made up of members from around the globe with a diverse set of skills, personalities, and experiences. It is through these differences that our community experiences successes and continued growth. When you're working with members of the community, we encourage you to follow these guidelines, which help steer our interactions and strive to maintain a positive, successful and growing community. +## Our Pledge -### Be Open -Members of the community are open to collaboration, whether it's on pull requests, code reviews, approvals, issues or otherwise. We're receptive to constructive comments and criticism, as the experiences and skill sets of all members contribute to the whole of our efforts. We're accepting of all who wish to take part in our activities, fostering an environment where anyone can participate, and everyone can make a difference. +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, 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. -### Be Considerate -Members of the community are considerate of their peers, which include other contributors and users of SendGrid. We're thoughtful when addressing the efforts of others, keeping in mind that often the labor was completed with the intent of the good of the community. We're attentive in our communications, whether in person or online, and we're tactful when approaching differing views. +## Our Standards -### Be Respectful -Members of the community are respectful. We're respectful of others, their positions, their skills, their commitments and their efforts. We're respectful of the volunteer efforts that permeate the SendGrid community. We're respectful of the processes outlined in the community, and we work within them. When we disagree, we are courteous in raising our issues. Overall, we're good to each other. We contribute to this community not because we have to, but because we want to. If we remember that, these guidelines will come naturally. +Examples of behavior that contributes to creating a positive environment +include: -## Additional Guidance +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members -### Disclose Potential Conflicts of Interest -Community discussions often involve interested parties. We expect participants to be aware when they are conflicted due to employment or other projects they are involved in and disclose those interests to other project members. When in doubt, over-disclose. Perceived conflicts of interest are important to address so that the community’s decisions are credible even when unpopular, difficult or favorable to the interests of one group over another. +Examples of unacceptable behavior by participants include: -### Interpretation -This Code is not exhaustive or complete. It is not a rulebook; it serves to distill our common understanding of a collaborative, shared environment and goals. We expect it to be followed in spirit as much as in the letter. When in doubt, try to abide by [SendGrid’s cultural values](https://sendgrid.com/blog/employee-engagement-the-4h-way) defined by our “4H’s”: Happy, Hungry, Humble and Honest. +- The use of sexualized language or imagery and unwelcome sexual attention or + advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic + address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting -### Enforcement -Most members of the SendGrid community always comply with this Code, not because of the existence of this Code, but because they have long experience participating in open source communities where the conduct described above is normal and expected. However, failure to observe this Code may be grounds for suspension, reporting the user for abuse or changing permissions for outside contributors. +## Our Responsibilities -## If you have concerns about someone’s conduct -**Initiate Direct Contact** - It is always appropriate to email a community member (if contact information is available), mention that you think their behavior was out of line, and (if necessary) point them to this Code. +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. -**Discuss Publicly** - Discussing publicly is always acceptable. Note, though, that approaching the person directly may be better, as it tends to make them less defensive, and it respects the time of other community members, so you probably want to try direct contact first. +Project maintainers 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, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. -**Contact the Moderators** - You can reach the SendGrid moderators by emailing dx@sendgrid.com. +## Scope -## Submission to SendGrid Repositories -Finally, just a reminder, changes to the SendGrid repositories will only be accepted upon completion of the [SendGrid Contributor Agreement](https://cla.sendgrid.com). +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at open-source@twilio.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. ## Attribution -SendGrid thanks the following, on which it draws for content and inspiration: +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html -* [Python Community Code of Conduct](https://www.python.org/psf/codeofconduct/) -* [Open Source Initiative General Code of Conduct](https://opensource.org/codeofconduct) -* [Apache Code of Conduct](https://www.apache.org/foundation/policies/conduct.html) \ No newline at end of file +[homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bd3c598..ff28f44 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,57 +1,11 @@ -Hello! Thank you for choosing to help contribute to one of the SendGrid open source projects. There are many ways you can contribute and help is always welcome. We simply ask that you follow the following contribution policies. +Hello! Thank you for choosing to help contribute to one of the SendGrid open source projects. There are many ways you can contribute and help is always welcome. We simply ask that you follow the following contribution policies. -- [CLAs and CCLAs](#cla) -- [Roadmap & Milestones](#roadmap) -- [Feature Request](#feature-request) -- [Submit a Bug Report](#submit-a-bug-report) - [Improvements to the Codebase](#improvements-to-the-codebase) - [Understanding the Code Base](#understanding-the-codebase) - [Testing](#testing) - [Style Guidelines & Naming Conventions](#style-guidelines-and-naming-conventions) - [Creating a Pull Request](#creating-a-pull-request) - - -We use [Milestones](https://github.com/sendgrid/java-http-client/milestones) to help define current roadmaps, please feel free to grab an issue from the current milestone. Please indicate that you have begun work on it to avoid collisions. Once a PR is made, community review, comments, suggestions and additional PRs are welcomed and encouraged. - - -## CLAs and CCLAs - -Before you get started, SendGrid requires that a SendGrid Contributor License Agreement (CLA) be filled out by every contributor to a SendGrid open source project. - -Our goal with the CLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way the CLA encourages broad participation by our open source community and helps us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution. - -SendGrid does not merge a pull request made against a SendGrid open source project until that pull request is associated with a signed CLA. Copies of the CLA are available [here](https://gist.github.com/SendGridDX/98b42c0a5d500058357b80278fde3be8#file-sendgrid_cla). - -When you create a Pull Request, after a few seconds, a comment will appear with a link to the CLA. Click the link and fill out the brief form and then click the "I agree" button and you are all set. You will not be asked to re-sign the CLA unless we make a change. - -There are a few ways to contribute, which we'll enumerate below: - - -## Feature Request - -If you'd like to make a feature request, please read this section. - -The GitHub issue tracker is the preferred channel for library feature requests, but please respect the following restrictions: - -- Please **search for existing issues** in order to ensure we don't have duplicate bugs/feature requests. -- Please be respectful and considerate of others when commenting on issues - - -## Submit a Bug Report - -Note: DO NOT include your credentials in ANY code examples, descriptions, or media you make public. - -A software bug is a demonstrable issue in the code base. In order for us to diagnose the issue and respond as quickly as possible, please add as much detail as possible into your bug report. - -Before you decide to create a new issue, please try the following: - -1. Check the Github issues tab if the identified issue has already been reported, if so, please add a +1 to the existing post. -2. Update to the latest version of this code and check if issue has already been fixed -3. Copy and fill in the Bug Report Template we have provided below - -### Please use our Bug Report Template - -In order to make the process easier, we've included a [sample bug report template](https://github.com/sendgrid/java-http-client/blob/master/.github/ISSUE_TEMPLATE) (borrowed from [Ghost](https://github.com/TryGhost/Ghost/)). The template uses [GitHub flavored markdown](https://help.github.com/articles/github-flavored-markdown/) for formatting. +- [Code Reviews](#code-reviews) ## Improvements to the Codebase @@ -64,8 +18,8 @@ We welcome direct contributions to the java-http-client code base. Thank you! ##### Prerequisites ##### -- Java version Oracle JDK 8 or OpenJDK 7 -- Please see [build.gradle](https://github.com/sendgrid/java-http-client/blob/master/build.gradle) +- Java 8 or 11 +- Please see [pom.xml](pom.xml) ##### Initial setup: ##### @@ -76,7 +30,7 @@ cd java-http-client ##### Execute: ##### -See the [examples folder](https://github.com/sendgrid/java-http-client/tree/master/examples) to get started quickly. +See the [examples folder](examples) to get started quickly. You will need to setup the following environment to use the SendGrid example: @@ -120,9 +74,9 @@ Provides a standard interface to an API's response. All PRs require passing tests before the PR will be reviewed. -All test files are in [`java-http-client/src/test/java/com/sendgrid`](https://github.com/sendgrid/java-http-client/tree/master/src/test/java/com/sendgrid). +All test files are in [`java-http-client/src/test/java/com/sendgrid`](src/test/java/com/sendgrid). -For the purposes of contributing to this repo, please update the [`ClientTest.java`](https://github.com/sendgrid/java-http-client/blob/master/src/test/java/com/sendgrid/ClientTest.java) file with unit tests as you modify the code. +For the purposes of contributing to this repo, please update the [`ClientTest.java`](src/test/java/com/sendgrid/ClientTest.java) file with unit tests as you modify the code. Run the tests: @@ -172,7 +126,7 @@ Please run your code through: 4. Commit your changes in logical chunks. Please adhere to these [git commit message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) - or your code is unlikely be merged into the main project. Use Git's + or your code is unlikely to be merged into the main project. Use Git's [interactive rebase](https://help.github.com/articles/interactive-rebase) feature to tidy up your commits before making them public. @@ -183,7 +137,7 @@ Please run your code through: 5. Locally merge (or rebase) the upstream development branch into your topic branch: ```bash - git pull [--rebase] upstream master + git pull [--rebase] upstream main ``` 6. Push your topic branch up to your fork: @@ -193,6 +147,7 @@ Please run your code through: ``` 7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/) - with a clear title and description against the `master` branch. All tests must be passing before we will review the PR. + with a clear title and description against the `main` branch. All tests must be passing before we will review the PR. -If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo. +## Code Reviews +If you can, please look at open PRs and review them. Give feedback and help us merge these PRs much faster! If you don't know how, GitHub has some great [information on how to review a Pull Request](https://help.github.com/articles/about-pull-request-reviews/). diff --git a/FIRST_TIMERS.md b/FIRST_TIMERS.md new file mode 100644 index 0000000..ab29f04 --- /dev/null +++ b/FIRST_TIMERS.md @@ -0,0 +1,53 @@ +# How To Contribute to Twilio SendGrid Repositories via GitHub +Contributing to the Twilio SendGrid repositories is easy! All you need to do is find an open issue (see the bottom of this page for a list of repositories containing open issues), fix it and submit a pull request. Once you have submitted your pull request, the team can easily review it before it is merged into the repository. + +To make a pull request, follow these steps: + +1. Log into GitHub. If you do not already have a GitHub account, you will have to create one in order to submit a change. Click the Sign up link in the upper right-hand corner to create an account. Enter your username, password, and email address. If you are an employee of Twilio SendGrid, please use your full name with your GitHub account and enter Twilio SendGrid as your company so we can easily identify you. + + + +2. __[Fork](https://help.github.com/fork-a-repo/)__ the [java-http-client](https://github.com/sendgrid/java-http-client) repository: + + + +3. __Clone__ your fork via the following commands: + +```bash +# Clone your fork of the repo into the current directory +git clone https://github.com/your_username/java-http-client +# Navigate to the newly cloned directory +cd java-http-client +# Assign the original repo to a remote called "upstream" +git remote add upstream https://github.com/sendgrid/java-http-client +``` + +> Don't forget to replace *your_username* in the URL by your real GitHub username. + +4. __Create a new topic branch__ (off the main project development branch) to contain your feature, change, or fix: + +```bash +git checkout -b +``` + +5. __Commit your changes__ in logical chunks. + +Please adhere to these [git commit message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) or your code is unlikely be merged into the main project. Use Git's [interactive rebase](https://help.github.com/articles/interactive-rebase) feature to tidy up your commits before making them public. Probably you will also have to create tests (if needed) or create or update the example code that demonstrates the functionality of this change to the code. + +6. __Locally merge (or rebase)__ the upstream development branch into your topic branch: + +```bash +git pull [--rebase] upstream main +``` + +7. __Push__ your topic branch up to your fork: + +```bash +git push origin +``` + +8. __[Open a Pull Request](https://help.github.com/articles/creating-a-pull-request/#changing-the-branch-range-and-destination-repository/)__ with a clear title and description against the `main` branch. All tests must be passing before we will review the PR. + +## Important notice + +Before creating a pull request, make sure that you respect the repository's constraints regarding contributions. You can find them in the [CONTRIBUTING.md](CONTRIBUTING.md) file. diff --git a/LICENSE.md b/LICENSE similarity index 59% rename from LICENSE.md rename to LICENSE index 4e9ed16..3154774 100644 --- a/LICENSE.md +++ b/LICENSE @@ -1,13 +1,13 @@ -The MIT License (MIT) +MIT License -Copyright (c) 2016-2018 SendGrid, Inc. +Copyright (C) 2023, Twilio SendGrid, Inc. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..851986a --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.PHONY: install package test update-deps test-integration clean + +VERSION := $(shell mvn help:evaluate -Dexpression=project.version --batch-mode | grep -e '^[^\[]') +install: + @java -version || (echo "Java is not installed, please install Java >= 7"; exit 1); + mvn clean install -DskipTests=true -Dgpg.skip -B + cp target/java-http-client-$(VERSION).jar java-http-client.jar + +package: + mvn package -DskipTests=true -Dgpg.skip -B + cp target/java-http-client-$(VERSION).jar java-http-client.jar + +test: + mvn test + +update-deps: + mvn versions:use-latest-releases versions:commit -DallowMajorUpdates=false + +clean: + mvn clean diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..bc85492 --- /dev/null +++ b/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,31 @@ + + +# Fixes # + +A short description of what this PR does. + +### Checklist +- [x] I acknowledge that all my contributions will be made under the project's license +- [ ] I have made a material change to the repo (functionality, testing, spelling, grammar) +- [ ] I have read the [Contribution Guidelines](https://github.com/sendgrid/java-http-client/blob/main/CONTRIBUTING.md) and my PR follows them +- [ ] I have titled the PR appropriately +- [ ] I have updated my branch with the main branch +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] I have added the necessary documentation about the functionality in the appropriate .md file +- [ ] I have added inline documentation to the code I modified + +If you have questions, please file a [support ticket](https://support.sendgrid.com), or create a GitHub Issue in this repository. diff --git a/README.md b/README.md index 43a297c..0f646b8 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) +![SendGrid Logo](twilio_sendgrid_logo.png) -[![Build Status](https://travis-ci.org/sendgrid/java-http-client.svg?branch=master)](https://travis-ci.org/sendgrid/java-http-client) +[![Test and Deploy](https://github.com/sendgrid/java-http-client/actions/workflows/test-and-deploy.yml/badge.svg)](https://github.com/sendgrid/java-http-client/actions/workflows/test-and-deploy.yml) [![Maven Central](https://img.shields.io/maven-central/v/com.sendgrid/java-http-client.svg)](http://mvnrepository.com/artifact/com.sendgrid/java-http-client) -[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.md) +[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid) [![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/java-http-client.svg)](https://github.com/sendgrid/java-http-client/graphs/contributors) @@ -15,24 +15,23 @@ If you are looking for the SendGrid API client library, please see [this repo](h * [Announcements](#announcements) * [Installation](#installation) * [Quick Start](#quick-start) -* [Usage](#usage) -* [Roadmap](#roadmap) +* [Usage](./USAGE.md) * [How to Contribute](#contribute) * [About](#about) +* [Support](#support) * [License](#license) # Announcements -**NEW:** If you're a software engineer who is passionate about #DeveloperExperience and/or #OpenSource, [this is an incredible opportunity to join our #DX team](https://sendgrid.com/careers/role/1421152/?gh_jid=1421152) as a Developer Experience Engineer and work with [@thinkingserious](https://github.com/thinkingserious) and [@aroach](https://github.com/aroach)! Tell your friends :) -All updates to this project is documented in our [CHANGELOG](https://github.com/sendgrid/java-http-client/blob/master/CHANGELOG.md). +All updates to this project are documented in our [CHANGELOG](CHANGELOG.md). # Installation ## Prerequisites -- Java version Oracle JDK 8 or OpenJDK 7 +- Java 8, 11, or 17 ## Install via Maven w/ Gradle @@ -40,7 +39,7 @@ All updates to this project is documented in our [CHANGELOG](https://github.com/ ... dependencies { ... - compile 'com.sendgrid:java-http-client:4.2.0' + compile 'com.sendgrid:java-http-client:4.5.1' } repositories { @@ -55,19 +54,15 @@ repositories { com.sendgrid java-http-client - 4.2.0 + 4.5.1 ``` `mvn install` -## Install via Fat Jar - -[sendgrid-java-latest.jar](http://dx.sendgrid.com/downloads/java-http-client/java-http-client-latest.jar) - ## Dependencies -- Please see the [build.gradle file](https://github.com/sendgrid/java-http-client/blob/master/build.gradle) +- Please see the [pom.xml file](pom.xml) # Quick Start @@ -101,6 +96,8 @@ try { request.addHeader("Authorization", "Bearer YOUR_API_KEY"); request.addQueryParam("limit", "100"); request.addQueryParam("offset", "0"); +// Will be parsed to categories=cake&categories=pie&categories=baking +request.addQueryParam("categories", "cake&pie&baking"); request.setBody("{\"name\": \"My Request Body\"}"); request.setMethod(Method.POST); String param = "param"; @@ -116,60 +113,29 @@ try { } ``` - -# Usage - -- [Example Code](https://github.com/sendgrid/java-http-client/tree/master/examples) -- [Library Usage Documentation](USAGE.md) - - -The example uses SendGrid, you can get your free account [here](https://sendgrid.com/free?source=java-http-client). - -First, update your environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys). - -```bash -echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env -echo "sendgrid.env" >> .gitignore -source ./sendgrid.env -``` - -```bash -mvn package -cd examples -javac -classpath {path_to}/sendgrid-java-http-client-4.0.0-jar.jar:. Example.java && java -classpath {path_to}/sendgrid-java-http-client-4.0.0-jar.jar:. Example -``` - -## Environment Variables - -You can do the following to create a .env file: - -```cp .env_example .env``` - -Then, just add your API Key into your .env file. - - -# Roadmap - -If you are interested in the future direction of this project, please take a look at our [milestones](https://github.com/sendgrid/java-http-client/milestones). We would love to hear your feedback. - # How to Contribute -We encourage contribution to our projects please see our [CONTRIBUTING](https://github.com/sendgrid/java-http-client/blob/master/CONTRIBUTING.md) guide for details. +We encourage contribution to our projects please see our [CONTRIBUTING](CONTRIBUTING.md) guide for details. Quick links: -- [Feature Request](https://github.com/sendgrid/java-http-client/blob/master/CONTRIBUTING.md#feature-request) -- [Bug Reports](https://github.com/sendgrid/java-http-client/blob/master/CONTRIBUTING.md#submit-a-bug-report) -- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/java-http-client/blob/master/CONTRIBUTING.md#cla) -- [Improvements to the Codebase](https://github.com/sendgrid/java-http-client/blob/master/CONTRIBUTING.md#improvements-to-the-codebase) +- [Feature Request](CONTRIBUTING.md#feature-request) +- [Bug Reports](CONTRIBUTING.md#submit-a-bug-report) +- [Improvements to the Codebase](CONTRIBUTING.md#improvements-to-the-codebase) +- [Review Pull Requests](CONTRIBUTING.md#Code-Reviews) # About -java-http-client is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com). +java-http-client is maintained and funded by Twilio SendGrid, Inc. The names and logos for java-http-client are trademarks of Twilio SendGrid, Inc. + + +# Support + +If you need help using SendGrid, please check the [Twilio SendGrid Support Help Center](https://support.sendgrid.com). -java-http-client is maintained and funded by SendGrid, Inc. The names and logos for java-http-client are trademarks of SendGrid, Inc. +If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo! # License -[The MIT License (MIT)](LICENSE.txt) +[The MIT License (MIT)](LICENSE) diff --git a/USAGE.md b/USAGE.md index 40c3f83..4a01093 100644 --- a/USAGE.md +++ b/USAGE.md @@ -1,6 +1,6 @@ # Usage -- [Example Code](https://github.com/sendgrid/java-http-client/tree/master/examples) +- [Example Code](examples) The example uses SendGrid, you can get your free account [here](https://sendgrid.com/free?source=java-http-client). @@ -16,4 +16,12 @@ source ./sendgrid.env mvn package cd examples javac -classpath {path_to}/sendgrid-java-http-client-4.0.0-jar.jar:. Example.java && java -classpath {path_to}/sendgrid-java-http-client-4.0.0-jar.jar:. Example -``` \ No newline at end of file +``` + +## Environment Variables + +You can do the following to create a .env file: + +```cp .env_example .env``` + +Then, just add your API Key into your .env file. \ No newline at end of file diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 3a4d715..0000000 --- a/build.gradle +++ /dev/null @@ -1,155 +0,0 @@ -/** - * Commands: - * - gradle build - * - gradle test - * - gradle assemble - * - gradle uploadArchives - * - * To execute the 'uploadArchives' task, the following properties must be specified - * in an external 'gradle.properties' file: - * - sonatypeUsername - * - sonatypePassword - */ - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'signing' -apply plugin: 'com.github.johnrengelman.shadow' - -group = 'com.sendgrid' -version = '4.2.0' -ext.packaging = 'jar' - -allprojects { - apply plugin: 'java' - sourceCompatibility = 1.7 - targetCompatibility = 1.7 -} - -if (!hasProperty("sonatypeUsername")) { - ext.sonatypeUsername = null - ext.sonatypePassword = null -} - -buildscript { - dependencies { - classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4' - } - repositories { - jcenter() - } -} - -dependencies { - compile 'org.apache.httpcomponents:httpcore:4.4.4' - compile 'org.apache.httpcomponents:httpclient:4.5.2' - testCompile 'org.mockito:mockito-core:1.10.19' - testCompile group: 'junit', name: 'junit-dep', version: '4.10' - -} - -repositories { - mavenCentral() -} - -allprojects { - gradle.projectsEvaluated { - tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" - } - } -} - -// adds 'with-dependencies' to the shadowJar name -shadowJar { - classifier 'jar' - baseName "sendgrid-java-http-client" - version version -} -jar { - manifest { - attributes("Implementation-Title": "http", "Implementation-Version": version) - } -} - -// copy shadowJar to base project directory so they will be in git (and on github for download) -build << { - copy { - println "Copying ${shadowJar.archiveName} to $projectDir/repo/com/sendgrid/$version" - from("$buildDir/libs/${shadowJar.archiveName}") - into("$projectDir/repo/com/sendgrid/$version") - } - copy { - println "Copying ${shadowJar.archiveName} to $projectDir/repo/com/sendgrid" - from("$buildDir/libs/${shadowJar.archiveName}") - into("$projectDir/repo/com/sendgrid") - } - tasks.renameSendGridVersionJarToSendGridJar.execute() -} - -task renameSendGridVersionJarToSendGridJar { - doLast { - file("$projectDir/repo/com/sendgrid/${shadowJar.archiveName}").renameTo(file("$projectDir/repo/com/sendgrid/http-jar.jar")) - } -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from 'build/docs/javadoc' -} - -task sourcesJar(type: Jar) { - from sourceSets.main.allSource - classifier = 'sources' -} - -signing { - required { gradle.taskGraph.hasTask("uploadArchives") } - sign configurations.archives -} - -uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { - authentication(userName: sonatypeUsername, password: sonatypePassword) - } - - pom.project { - name 'http' - packaging 'jar' - description 'A simple HTTP client' - url 'https://github.com/sendgrid/java-http-client' - - scm { - url 'scm:git@github.com:sendgrid/java-http-client.git' - connection 'scm:git@github.com:sendgrid/java-http-client.git' - developerConnection 'scm:git@github.com:sendgrid/java-http-client.git' - } - - licenses { - license { - name 'MIT License' - url 'http://opensource.org/licenses/MIT' - distribution 'repo' - } - } - - developers { - developer { - id 'thinkingserious' - name 'Elmer Thomas' - } - } - } - } - } -} - -artifacts { - archives shadowJar - archives jar - archives javadocJar - archives sourcesJar -} diff --git a/docker/Dockerfile b/docker/Dockerfile index 79a5b0b..5e2749f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,13 +1,13 @@ FROM store/oracle/serverjre:8 -ENV OAI_SPEC_URL="https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json" +ENV OAI_SPEC_URL="https://raw.githubusercontent.com/sendgrid/sendgrid-oai/HEAD/oai_stoplight.json" RUN yum install -y git WORKDIR /root # install Prism -ADD https://raw.githubusercontent.com/stoplightio/prism/master/install.sh install.sh +ADD https://raw.githubusercontent.com/stoplightio/prism/HEAD/install.sh install.sh RUN chmod +x ./install.sh && sync && \ ./install.sh && \ rm ./install.sh diff --git a/docker/README.md b/docker/README.md index 6a7e0cb..fabe4c0 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,5 +1,5 @@ # Supported tags and respective `Dockerfile` links - - `v1.0.0`, `latest` [(Dockerfile)](https://github.com/sendgrid/java-http-client/blob/master/docker/Dockerfile) + - `v1.0.0`, `latest` [(Dockerfile)](Dockerfile) # Quick reference Due to Oracle's JDK license, you must build this Docker image using the official Oracle image located in the Docker Store. You will need a Docker store account. Once you have an account, you must accept the Oracle license [here](https://store.docker.com/images/oracle-serverjre-8). On the command line, type `docker login` and provide your credentials. You may then build the image using this command `docker build -t sendgrid/java-http-client -f Dockerfile .` @@ -11,7 +11,7 @@ Due to Oracle's JDK license, you must build this Docker image using the official https://github.com/sendgrid/java-http-client/issues - **Where to get more info:** - [USAGE.md](https://github.com/sendgrid/java-http-client/blob/master/docker/USAGE.md) + [USAGE.md](USAGE.md) - **Maintained by:** [SendGrid Inc.](https://sendgrid.com) @@ -26,12 +26,6 @@ Due to Oracle's JDK license, you must build this Docker image using the official $ docker run -it -v /path/to/cool-java-http-client:/mnt/java-http-client sendgrid/java-http-client ``` -For more detailed information, see [USAGE.md](https://github.com/sendgrid/java-http-client/blob/master/docker/USAGE.md). +For more detailed information, see [USAGE.md](USAGE.md). -# About - -java-http-client is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com). - -java-http-client is maintained and funded by SendGrid, Inc. The names and logos for java-http-client are trademarks of SendGrid, Inc. - -![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) \ No newline at end of file +![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) diff --git a/docker/USAGE.md b/docker/USAGE.md index 7b4245e..9fbfb81 100644 --- a/docker/USAGE.md +++ b/docker/USAGE.md @@ -25,11 +25,4 @@ You can mount repositories in the `/mnt/java-http-client` and `/mnt/java-http-cl # Testing Testing is easy! Run the container, `cd sendgrid`, and run `./gradlew test`. - -# About - -java-http-client is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com). - -java-http-client is maintained and funded by SendGrid, Inc. The names and logos for java-http-client are trademarks of SendGrid, Inc. - -![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) \ No newline at end of file +![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 0087cd3..0000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 7177a30..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Mon May 26 17:38:02 PDT 2014 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip \ No newline at end of file diff --git a/gradlew b/gradlew deleted file mode 100755 index e659319..0000000 --- a/gradlew +++ /dev/null @@ -1,162 +0,0 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" \ No newline at end of file diff --git a/pom.xml b/pom.xml index 92ad782..efcc8d7 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,5 @@ - + + 4.0.0 org.sonatype.oss @@ -7,16 +7,16 @@ 7 com.sendgrid - http + java-http-client jar A simple HTTP client HTTP REST client, simplified for Java - 4.2.0 + 4.5.1 https://github.com/sendgrid/java-http-client The MIT License (MIT) - https://github.com/sendgrid/java-http-client/blob/master/LICENSE + https://github.com/sendgrid/java-http-client/blob/HEAD/LICENSE repo @@ -24,8 +24,81 @@ https://github.com/sendgrid/java-http-client scm:git:git@github.com:sendgrid/java-http-client.git scm:git:git@github.com:sendgrid/java-http-client.git - HEAD + 4.5.1 + + + release + + + release + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.8 + true + + ossrh + https://oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.4 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + ${gpg.keyname} + ${gpg.passphrase} + + --pinentry-mode + loopback + + + + + + + + + 1.8 1.8 @@ -34,7 +107,7 @@ junit junit-dep - 4.10 + 4.11 test @@ -46,12 +119,12 @@ org.apache.httpcomponents httpcore - 4.4.4 + 4.4.15 org.apache.httpcomponents httpclient - 4.5.2 + 4.5.13 @@ -59,22 +132,88 @@ org.jacoco jacoco-maven-plugin - 0.7.7.201606060606 + 0.8.5 - - - prepare-agent - - - - report - test - - report - - + + + prepare-agent + + + + report + test + + report + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-release-plugin + 2.4.2 + + + org.apache.maven.scm + maven-scm-provider-gitexe + 1.8.1 + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.1.1 + + + jar-with-dependencies + + + + + make-assembly + package + + single + + - + \ No newline at end of file diff --git a/scripts/generate_upload_policy.php b/scripts/generate_upload_policy.php deleted file mode 100644 index 18fdf82..0000000 --- a/scripts/generate_upload_policy.php +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env php -$blocksize) - $key=pack('H*', $hashfunc($key)); - $key=str_pad($key,$blocksize,chr(0x00)); - $ipad=str_repeat(chr(0x36),$blocksize); - $opad=str_repeat(chr(0x5c),$blocksize); - $hmac = pack( - 'H*',$hashfunc( - ($key^$opad).pack( - 'H*',$hashfunc( - ($key^$ipad).$data - ) - ) - ) - ); - return bin2hex($hmac); -} - -/* - * Used to encode a field for Amazon Auth - * (taken from the Amazon S3 PHP example library) - */ -function hex2b64($str) -{ - $raw = ''; - for ($i=0; $i < strlen($str); $i+=2) - { - $raw .= chr(hexdec(substr($str, $i, 2))); - } - return base64_encode($raw); -} - -if (count($argv) != 3) { - echo "Usage: " . $argv[0] . " \n"; - exit(1); -} - -$policy = file_get_contents($argv[1]); -$secret = $argv[2]; - -/* - * Base64 encode the Policy Document and then - * create HMAC SHA-1 signature of the base64 encoded policy - * using the secret key. Finally, encode it for Amazon Authentication. - */ -$base64_policy = base64_encode($policy); -$signature = hex2b64(hmacsha1($secret, $base64_policy)); -echo "S3_POLICY=\"" . $base64_policy . "\"\nS3_SIGNATURE=\"" . $signature . "\"\n" -?> diff --git a/scripts/s3policy.json b/scripts/s3policy.json deleted file mode 100644 index 487f00c..0000000 --- a/scripts/s3policy.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "expiration": "2100-01-01T12:00:00.000Z", - "conditions": [ - {"acl": "public-read" }, - {"bucket": "sendgrid-open-source" }, - ["starts-with", "$key", "http/"], - ["content-length-range", 2048, 268435456], - ["eq", "$Content-Type", "application/zip"] - ] -} \ No newline at end of file diff --git a/scripts/s3upload.sh b/scripts/s3upload.sh deleted file mode 100644 index b9bd916..0000000 --- a/scripts/s3upload.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# From: -# http://raamdev.com/2008/using-curl-to-upload-files-via-post-to-amazon-s3/ - -GIT_VERSION=`git rev-parse --short HEAD` - -curl -X POST \ - -F "key=http/versions/http-$GIT_VERSION.jar" \ - -F "acl=public-read" \ - -F "AWSAccessKeyId=$S3_ACCESS_KEY" \ - -F "Policy=$S3_POLICY" \ - -F "Signature=$S3_SIGNATURE" \ - -F "Content-Type=application/zip" \ - -F "file=@./repo/com/sendgrid/http-jar.jar" \ - https://s3.amazonaws.com/$S3_BUCKET - -if [ "$TRAVIS_BRANCH" = "master" ] -then - curl -X POST \ - -F "key=http/http.jar" \ - -F "acl=public-read" \ - -F "AWSAccessKeyId=$S3_ACCESS_KEY" \ - -F "Policy=$S3_POLICY" \ - -F "Signature=$S3_SIGNATURE" \ - -F "Content-Type=application/zip" \ - -F "file=@./repo/com/sendgrid/http-jar.jar" \ - https://s3.amazonaws.com/$S3_BUCKET -fi - -exit 0 \ No newline at end of file diff --git a/src/main/java/com/sendgrid/Client.java b/src/main/java/com/sendgrid/Client.java index ea8e0b2..d0865fd 100644 --- a/src/main/java/com/sendgrid/Client.java +++ b/src/main/java/com/sendgrid/Client.java @@ -9,10 +9,11 @@ import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; +import java.util.Arrays; +import java.util.List; import org.apache.http.Header; import org.apache.http.HttpMessage; -import org.apache.http.annotation.NotThreadSafe; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.ResponseHandler; import org.apache.http.client.methods.CloseableHttpResponse; @@ -27,8 +28,10 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -// Hack to get DELETE to accept a request body -@NotThreadSafe + +/** + * Hack to get DELETE to accept a request body. + */ class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { public static final String METHOD_NAME = "DELETE"; @@ -43,6 +46,7 @@ public HttpDeleteWithBody(final String uri) { } } + /** * Class Client allows for quick and easy access any REST or REST-like API. */ @@ -52,6 +56,7 @@ public class Client implements Closeable { private Boolean test; private boolean createdHttpClient; + /** * Constructor for using the default CloseableHttpClient. */ @@ -61,6 +66,7 @@ public Client() { this.createdHttpClient = true; } + /** * Constructor for passing in an httpClient, typically for mocking. Passed-in httpClient will not be closed * by this Client. @@ -72,8 +78,9 @@ public Client(CloseableHttpClient httpClient) { this(httpClient, false); } + /** - * Constructor for passing in a test parameter to allow for http calls + * Constructor for passing in a test parameter to allow for http calls. * * @param test * is a Bool @@ -82,8 +89,9 @@ public Client(Boolean test) { this(HttpClients.createDefault(), test); } + /** - * Constructor for passing in a an httpClient and test parameter to allow for http calls + * Constructor for passing in an httpClient and test parameter to allow for http calls. * * @param httpClient * an Apache CloseableHttpClient @@ -106,6 +114,8 @@ public Client(CloseableHttpClient httpClient, Boolean test) { * (e.g. "/your/endpoint/path") * @param queryParams * map of key, values representing the query parameters + * @throws URISyntaxException + * in of a URI syntax error */ public URI buildUri(String baseUri, String endpoint, Map queryParams) throws URISyntaxException { URIBuilder builder = new URIBuilder(); @@ -121,8 +131,19 @@ public URI buildUri(String baseUri, String endpoint, Map queryPa builder.setPath(endpoint); if (queryParams != null) { + String multiValueDelimiter = "&"; + for (Map.Entry entry : queryParams.entrySet()) { - builder.setParameter(entry.getKey(), entry.getValue()); + String value = entry.getValue(); + + if (value.indexOf(multiValueDelimiter) != -1) { + List values = Arrays.asList(value.split(multiValueDelimiter)); + for (String val : values) { + builder.addParameter(entry.getKey(), val); + } + } else { + builder.setParameter(entry.getKey(), entry.getValue()); + } } } @@ -135,11 +156,15 @@ public URI buildUri(String baseUri, String endpoint, Map queryPa return uri; } + /** * Prepare a Response object from an API call via Apache's HTTP client. * * @param response * from a call to a CloseableHttpClient + * @throws IOException + * in case of a network error + * @return the response object */ public Response getResponse(CloseableHttpResponse response) throws IOException { ResponseHandler handler = new SendGridResponseHandler(); @@ -156,9 +181,18 @@ public Response getResponse(CloseableHttpResponse response) throws IOException { return new Response(statusCode, responseBody, responseHeaders); } + /** * Make a GET request and provide the status code, response body and * response headers. + * + * @param request + * the request object + * @throws URISyntaxException + * in case of a URI syntax error + * @throws IOException + * in case of a network error + * @return the response object */ public Response get(Request request) throws URISyntaxException, IOException { URI uri = null; @@ -179,9 +213,18 @@ public Response get(Request request) throws URISyntaxException, IOException { return executeApiCall(httpGet); } + /** * Make a POST request and provide the status code, response body and * response headers. + * + * @param request + * the request object + * @throws URISyntaxException + * in case of a URI syntax error + * @throws IOException + * in case of a network error + * @return the response object */ public Response post(Request request) throws URISyntaxException, IOException { URI uri = null; @@ -206,9 +249,18 @@ public Response post(Request request) throws URISyntaxException, IOException { return executeApiCall(httpPost); } + /** * Make a PATCH request and provide the status code, response body and * response headers. + * + * @param request + * the request object + * @throws URISyntaxException + * in case of a URI syntax error + * @throws IOException + * in case of a network error + * @return the response object */ public Response patch(Request request) throws URISyntaxException, IOException { URI uri = null; @@ -233,9 +285,18 @@ public Response patch(Request request) throws URISyntaxException, IOException { return executeApiCall(httpPatch); } + /** * Make a PUT request and provide the status code, response body and * response headers. + * + * @param request + * the request object + * @throws URISyntaxException + * in case of a URI syntax error + * @throws IOException + * in case of a network error + * @return the response object */ public Response put(Request request) throws URISyntaxException, IOException { URI uri = null; @@ -260,8 +321,17 @@ public Response put(Request request) throws URISyntaxException, IOException { return executeApiCall(httpPut); } + /** * Make a DELETE request and provide the status code and response headers. + * + * @param request + * the request object + * @throws URISyntaxException + * in case of a URI syntax error + * @throws IOException + * in case of a network error + * @return the response object */ public Response delete(Request request) throws URISyntaxException, IOException { URI uri = null; @@ -292,6 +362,16 @@ private void writeContentTypeIfNeeded(Request request, HttpMessage httpMessage) } } + + /** + * Makes a call to the client API. + * + * @param httpPost + * the request method object + * @throws IOException + * in case of a network error + * @return the response object + */ private Response executeApiCall(HttpRequestBase httpPost) throws IOException { try { CloseableHttpResponse serverResponse = httpClient.execute(httpPost); @@ -305,8 +385,15 @@ private Response executeApiCall(HttpRequestBase httpPost) throws IOException { } } + /** * A thin wrapper around the HTTP methods. + * + * @param request + * the request object + * @throws IOException + * in case of a network error + * @return the response object */ public Response api(Request request) throws IOException { try { @@ -336,11 +423,25 @@ public Response api(Request request) throws IOException { } } + + /** + * Closes the http client. + * + * @throws IOException + * in case of a network error + */ @Override public void close() throws IOException { this.httpClient.close(); } + + /** + * Closes and finalizes the http client. + * + * @throws Throwable + * in case of an error + */ @Override public void finalize() throws Throwable { try { diff --git a/src/test/java/com/sendgrid/ClientTest.java b/src/test/java/com/sendgrid/ClientTest.java index 9367379..0425199 100644 --- a/src/test/java/com/sendgrid/ClientTest.java +++ b/src/test/java/com/sendgrid/ClientTest.java @@ -33,8 +33,10 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; +import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -62,6 +64,7 @@ public void testbuildUri() { Map queryParams = new HashMap(); queryParams.put("test1", "1"); queryParams.put("test2", "2"); + queryParams.put("test3", "3&4&5"); try { uri = client.buildUri(baseUri, endpoint, queryParams); } catch (URISyntaxException ex) { @@ -70,10 +73,23 @@ public void testbuildUri() { Assert.assertTrue(errors.toString(), false); } - String url = uri.toString(); - System.out.println(url); - Assert.assertTrue(url.equals("https://api.test.com/endpoint?test2=2&test1=1") || - url.equals("https://api.test.com/endpoint?test1=1&test2=2")); + URL url = null; + try { + url = uri.toURL(); + } catch (MalformedURLException ex) { + StringWriter errors = new StringWriter(); + ex.printStackTrace(new PrintWriter(errors)); + Assert.assertTrue(errors.toString(), false); + } + + Assert.assertTrue(url.getProtocol().equals("https")); + Assert.assertTrue(url.getHost().equals("api.test.com")); + Assert.assertTrue(url.getPath().equals("/endpoint")); + Assert.assertTrue(this.queryParamHasCorrectValue(url, "test1", "1")); + Assert.assertTrue(this.queryParamHasCorrectValue(url, "test2", "2")); + Assert.assertTrue(this.queryParamHasCorrectValue(url, "test3", "3")); + Assert.assertTrue(this.queryParamHasCorrectValue(url, "test3", "4")); + Assert.assertTrue(this.queryParamHasCorrectValue(url, "test3", "5")); } @Test @@ -174,4 +190,8 @@ public void testPut() { public void testDelete() { testMethod(Method.DELETE, 204); } + + private boolean queryParamHasCorrectValue(URL url, String key, String value) { + return url.getQuery().indexOf(key + "=" + value) != -1; + } } diff --git a/src/test/java/com/sendgrid/LicenseTest.java b/src/test/java/com/sendgrid/LicenseTest.java index 057060b..04e4849 100644 --- a/src/test/java/com/sendgrid/LicenseTest.java +++ b/src/test/java/com/sendgrid/LicenseTest.java @@ -13,7 +13,7 @@ public class LicenseTest { @Test public void testLicenseShouldHaveCorrectYear() throws IOException { String copyrightText = null; - try (BufferedReader br = new BufferedReader(new FileReader("./LICENSE.md"))) { + try (BufferedReader br = new BufferedReader(new FileReader("./LICENSE"))) { for (String line; (line = br.readLine()) != null; ) { if (line.startsWith("Copyright")) { copyrightText = line; @@ -21,7 +21,7 @@ public void testLicenseShouldHaveCorrectYear() throws IOException { } } } - String expectedCopyright = String.format("Copyright (c) 2016-%d SendGrid, Inc.", Calendar.getInstance().get(Calendar.YEAR)); + String expectedCopyright = String.format("Copyright (C) %d, Twilio SendGrid, Inc. ", Calendar.getInstance().get(Calendar.YEAR)); Assert.assertEquals("License has incorrect year", copyrightText, expectedCopyright); } } diff --git a/src/test/java/com/sendgrid/TestRequiredFilesExist.java b/src/test/java/com/sendgrid/TestRequiredFilesExist.java index a6421a9..02e3d35 100644 --- a/src/test/java/com/sendgrid/TestRequiredFilesExist.java +++ b/src/test/java/com/sendgrid/TestRequiredFilesExist.java @@ -12,7 +12,7 @@ public class TestRequiredFilesExist { new File("./docker/Docker").exists(); assertTrue(dockerExists); } - + /* // ./docker-compose.yml or ./docker/docker-compose.yml @Test public void checkDockerComposeExists() { boolean dockerComposeExists = new File("./docker-compose.yml").exists() || @@ -23,21 +23,12 @@ public class TestRequiredFilesExist { @Test public void checkEnvSampleExists() { assertTrue(new File("./.env_sample").exists()); } */ - + // ./.gitignore @Test public void checkGitIgnoreExists() { assertTrue(new File("./.gitignore").exists()); } - // ./.travis.yml - @Test public void checkTravisExists() { - assertTrue(new File("./.travis.yml").exists()); - } - - // ./.codeclimate.yml - @Test public void checkCodeClimateExists() { - assertTrue(new File("./.codeclimate.yml").exists()); - } // ./CHANGELOG.md @Test public void checkChangelogExists() { @@ -54,19 +45,14 @@ public class TestRequiredFilesExist { assertTrue(new File("./CONTRIBUTING.md").exists()); } - // ./.github/ISSUE_TEMPLATE - @Test public void checkIssuesTemplateExists() { - assertTrue(new File("./.github/ISSUE_TEMPLATE").exists()); - } - - // ./LICENSE.md + // ./LICENSE @Test public void checkLicenseExists() { - assertTrue(new File("./LICENSE.md").exists()); + assertTrue(new File("./LICENSE").exists()); } - // ./.github/PULL_REQUEST_TEMPLATE + // ./PULL_REQUEST_TEMPLATE.md @Test public void checkPullRequestExists() { - assertTrue(new File("./.github/PULL_REQUEST_TEMPLATE").exists()); + assertTrue(new File("./PULL_REQUEST_TEMPLATE.md").exists()); } // ./README.md diff --git a/static/img/github-fork.png b/static/img/github-fork.png new file mode 100644 index 0000000..6503be3 Binary files /dev/null and b/static/img/github-fork.png differ diff --git a/static/img/github-sign-up.png b/static/img/github-sign-up.png new file mode 100644 index 0000000..491392b Binary files /dev/null and b/static/img/github-sign-up.png differ diff --git a/twilio_sendgrid_logo.png b/twilio_sendgrid_logo.png new file mode 100644 index 0000000..a4c2223 Binary files /dev/null and b/twilio_sendgrid_logo.png differ diff --git a/use_cases/README.md b/use_cases/README.md new file mode 100644 index 0000000..657a022 --- /dev/null +++ b/use_cases/README.md @@ -0,0 +1,5 @@ +This documentation provides examples for specific SendGrid v3 API use cases. Please [open an issue](https://github.com/sendgrid/java-http-client/issues) or make a pull request for any email use cases you would like us to document here. Thank you! + +# Email Use Cases + +# Non-mail Use Cases