Skip to content

Update endpoint to patch.io #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.5.0] - 2021-03-01

### Changed

- Changed base URL from https://api.usepatch.com to https://api.patch.io

## [1.4.0] - 2021-02-15

### Added
Expand All @@ -20,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Adds support for creating carbon emission estimates for flights, shipping, and vehicles. See the [docs](https://docs.usepatch.com/#/?id=estimates) for more information.
- Adds support for creating carbon emission estimates for flights, shipping, and vehicles. See the [docs](https://docs.patch.io/#/?id=estimates) for more information.

## [1.2.5] - 2020-01-08

Expand Down
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
# Patch Ruby SDK

![Test](https://github.com/patch-technology/patch-ruby/workflows/Test/badge.svg)
[![Gem Version](https://badge.fury.io/rb/patch_ruby.svg)](https://badge.fury.io/rb/patch_ruby)
[![Discord](https://img.shields.io/discord/733029448558837792)](https://discord.gg/AU8543D)

The official Ruby gem for the [Patch API](https://www.usepatch.com)
The official Ruby gem for the [Patch API](https://www.patch.io)

## Documentation
For a complete API reference, check out [Patch's API Reference.](https://docs.usepatch.com/)

For a complete API reference, check out [Patch's API Reference.](https://docs.patch.io/)

## Installation

Add the gem to your Gemfile:

```ruby
gem 'patch_ruby'
```

Then run:

```shell
bundle
```

Or install it directly with

```shell
gem install patch_ruby
```

### Requirements

- Ruby 1.9+

## Usage

### Configuration

After installing the gem, you'll have to configure it with your API key which is available from the API key page in the Patch dashboard:

```ruby
require 'patch_ruby'

Expand All @@ -43,6 +50,7 @@ end
```

### Orders

In Patch, orders represent a purchase of carbon offsets or negative emissions by mass. Place orders directly if you know the amount of carbon dioxide you would like to sequester. If you do not know how much to purchase, use an estimate.

In Patch, orders represent a purchase of carbon offsets or negative emissions by mass.
Expand All @@ -51,9 +59,10 @@ If you do not know how much to purchase, use an estimate.
You can also create an order with a maximum desired price, and we'll allocate enough mass to
fulfill the order for you.

[API Reference](https://docs.usepatch.com/#/?id=orders)
[API Reference](https://docs.patch.io/#/?id=orders)

#### Examples

```ruby
# Create an order - you can create an order
# providing either mass_g or total_price_cents_usd, but not both
Expand Down Expand Up @@ -92,11 +101,13 @@ Patch::Order.retrieve_orders(page: page)
```

### Estimates

Estimates allow API users to get a quote for the cost of compensating a certain amount of CO2. When creating an estimate, an order in the `draft` state will also be created, reserving the allocation of a project for 5 minutes. If you don't place your draft order within those 5 minutes, the order will automatically be cancelled.

[API Reference](https://docs.usepatch.com/#/?id=estimates)
[API Reference](https://docs.patch.io/#/?id=estimates)

#### Examples

```ruby
# Create a mass estimate
mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
Expand Down Expand Up @@ -142,6 +153,7 @@ Patch::Estimate.retrieve_estimates(page: page)
```

### Projects

Projects are the ways Patch takes CO2 out of the air. They can represent reforestation, enhanced weathering, direct air carbon capture, etc. When you place an order via Patch, it is allocated to a project.

When fetching Projects, you can add filters to the query to narrow the result. Currently supported filters are:
Expand All @@ -150,9 +162,10 @@ When fetching Projects, you can add filters to the query to narrow the result. C
- `type`
- `minimum_available_mass`

[API Reference](https://docs.usepatch.com/#/?id=projects)
[API Reference](https://docs.patch.io/#/?id=projects)

#### Examples

```ruby
# Retrieve a project
project_id = 'pro_test_1234' # Pass in the project's ID
Expand All @@ -176,11 +189,13 @@ Patch::Project.retrieve_projects(minimum_available_mass: minimum_available_mass)
```

### Preferences
Preferences are how you route your orders in Patch. If you don't have a preference, Patch will allocate your order to the least expensive option. If you do have a preference, all of your orders will be sent to that project. You can set your preferences via API, or through the [Patch Dashboard](https://dashboard.usepatch.com/projects).

[API Reference](https://docs.usepatch.com/#/?id=preferences)
Preferences are how you route your orders in Patch. If you don't have a preference, Patch will allocate your order to the least expensive option. If you do have a preference, all of your orders will be sent to that project. You can set your preferences via API, or through the [Patch Dashboard](https://dashboard.patch.io/projects).

[API Reference](https://docs.patch.io/#/?id=preferences)

#### Examples

```ruby
# Create a preference
project_id = 'pro_test_1234' # Pass in the project_id for your preference
Expand All @@ -202,26 +217,31 @@ Patch::Preference.retrieve_preferences(page: page)
## Development

To build the gem locally, run:

```
$ gem build patch_ruby.gemspec
```

This will create a .gem file. To install the local gem:

```
$ gem install patch_ruby-1.x.x.gem
```

Install dependencies:

```
$ bundle install
```

Set up required environment variables:

```
$ export SANDBOX_API_KEY=<SANDBOX API KEY>
```

Run tests:

```
$ bundle exec rspec
```
4 changes: 2 additions & 2 deletions lib/patch_ruby/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Configuration

def initialize
@scheme = 'https'
@host = 'api.usepatch.com'
@host = 'api.patch.io'
@base_path = ''
@api_key = {}
@api_key_prefix = {}
Expand Down Expand Up @@ -212,7 +212,7 @@ def server_settings
variables: {
defaultHost: {
description: "No description provided",
default_value: "api.usepatch.com",
default_value: "api.patch.io",
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/patch_ruby/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
=end

module Patch
VERSION = '1.4.0'
VERSION = '1.5.0'
end
2 changes: 1 addition & 1 deletion patch_ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.authors = ["Patch Technology"]
s.email = ["developers@usepatch.com"]
s.homepage = "https://www.usepatch.com"
s.homepage = "https://www.patch.io"
s.summary = "Ruby wrapper for the Patch API"
s.description = "Ruby wrapper for the Patch API"
s.license = 'MIT'
Expand Down
6 changes: 3 additions & 3 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
before(:each) do
# uncomment below to setup host and base_path
# require 'URI'
# uri = URI.parse("https://api.usepatch.com")
# uri = URI.parse("https://api.patch.io")
# Patch.configure do |c|
# c.host = uri.host
# c.base_path = uri.path
Expand All @@ -28,14 +28,14 @@
describe '#base_url' do
it 'should have the default value' do
# uncomment below to test default value of the base path
# expect(config.base_url).to eq("https://api.usepatch.com")
# expect(config.base_url).to eq("https://api.patch.io")
end

it 'should remove trailing slashes' do
[nil, '', '/', '//'].each do |base_path|
config.base_path = base_path
# uncomment below to test trailing slashes
# expect(config.base_url).to eq("https://api.usepatch.com")
# expect(config.base_url).to eq("https://api.patch.io")
end
end
end
Expand Down