Skip to content
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
hyperline (0.1.0)
hyperline (0.2.0)
faraday (~> 2.0)
faraday-retry (~> 2.0)

Expand Down
2 changes: 2 additions & 0 deletions lib/hyperline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
require_relative 'hyperline/resources/plans'
require_relative 'hyperline/resources/custom_properties'
require_relative 'hyperline/resources/price_configurations'
require_relative 'hyperline/resources/aggregators'
require_relative 'hyperline/resources/price_books'
require_relative 'hyperline/client'

module Hyperline
Expand Down
8 changes: 8 additions & 0 deletions lib/hyperline/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,13 @@ def price_configurations
def custom_properties
@custom_properties ||= Resources::CustomProperties.new(@connection)
end

def aggregators
@aggregators ||= Resources::Aggregators.new(@connection)
end

def price_books
@price_books ||= Resources::PriceBooks.new(@connection)
end
end
end
13 changes: 13 additions & 0 deletions lib/hyperline/resources/aggregators.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Hyperline
module Resources
class Aggregators < BaseResource
private

def base_path
'/v1/aggregators'
end
end
end
end
23 changes: 23 additions & 0 deletions lib/hyperline/resources/price_books.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Hyperline
module Resources
class PriceBooks < BaseResource
# Attaches products to the price book, copying their default price
# configurations into it.
def add_products(id, product_ids:)
request(:post, "#{resource_path(id)}/products", product_ids: product_ids)
end

def remove_product(id, product_id)
request(:delete, "#{resource_path(id)}/products/#{product_id}")
end

private

def base_path
'/v1/price-books'
end
end
end
end
2 changes: 1 addition & 1 deletion lib/hyperline/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Hyperline
VERSION = '0.1.0'
VERSION = '0.2.0'
end
68 changes: 68 additions & 0 deletions spec/hyperline/resources/aggregators_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Hyperline::Resources::Aggregators do
let(:client) { build_client }
let(:aggregators) { client.aggregators }

describe '#list' do
it 'returns a collection of aggregators' do
stub_api(
:get,
'/v1/aggregators',
body: {
meta: { total: 1, taken: 1, skipped: 0 },
data: [{ id: 'agg_001', name: 'seats', operation: 'count' }]
}
)

result = aggregators.list

expect(result).to be_a(Hyperline::Collection)
expect(result.data.length).to eq(1)
expect(result.data.first['name']).to eq('seats')
end
end

describe '#create' do
it 'creates an aggregator' do
stub =
stub_request(:post, 'https://api.hyperline.co/v1/aggregators').with(
body: {
name: 'seats',
entity: 'seats',
operation: 'count',
type: 'metered',
unit_name: 'seat'
}.to_json
).to_return(
status: 201,
headers: { 'Content-Type' => 'application/json' },
body: { id: 'agg_001', name: 'seats' }.to_json
)

result =
aggregators.create(
name: 'seats',
entity: 'seats',
operation: 'count',
type: 'metered',
unit_name: 'seat'
)

expect(stub).to have_been_requested
expect(result['id']).to eq('agg_001')
end
end

describe '#get' do
it 'returns an aggregator' do
stub_api(:get, '/v1/aggregators/agg_001', body: { id: 'agg_001', name: 'seats' })

result = aggregators.get('agg_001')

expect(result['id']).to eq('agg_001')
end
end
end
71 changes: 71 additions & 0 deletions spec/hyperline/resources/price_books_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Hyperline::Resources::PriceBooks do
let(:client) { build_client }
let(:price_books) { client.price_books }

describe '#list' do
it 'returns a collection of price books' do
stub_api(
:get,
'/v1/price-books',
body: {
meta: { total: 1, taken: 1, skipped: 0 },
data: [{ id: 'pb_001', name: 'F25 ES' }]
}
)

result = price_books.list

expect(result).to be_a(Hyperline::Collection)
expect(result.data.first['name']).to eq('F25 ES')
end
end

describe '#create' do
it 'creates a price book' do
stub =
stub_request(:post, 'https://api.hyperline.co/v1/price-books').with(
body: { name: 'F25 ES', description: 'Spanish F25 catalog' }.to_json
).to_return(
status: 201,
headers: { 'Content-Type' => 'application/json' },
body: { id: 'pb_001', name: 'F25 ES' }.to_json
)

result = price_books.create(name: 'F25 ES', description: 'Spanish F25 catalog')

expect(stub).to have_been_requested
expect(result['id']).to eq('pb_001')
end
end

describe '#add_products' do
it 'attaches products to the price book' do
stub =
stub_request(:post, 'https://api.hyperline.co/v1/price-books/pb_001/products').with(
body: { product_ids: %w[itm_001 itm_002] }.to_json
).to_return(status: 204, headers: { 'Content-Type' => 'application/json' }, body: '')

price_books.add_products('pb_001', product_ids: %w[itm_001 itm_002])

expect(stub).to have_been_requested
end
end

describe '#remove_product' do
it 'removes a product from the price book' do
stub =
stub_request(
:delete,
'https://api.hyperline.co/v1/price-books/pb_001/products/itm_001'
).to_return(status: 204, headers: { 'Content-Type' => 'application/json' }, body: '')

price_books.remove_product('pb_001', 'itm_001')

expect(stub).to have_been_requested
end
end
end