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 README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Beyond API Ruby Client
# Beyond Api Ruby Client

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/beyond_api`. To experiment with that code, run `bin/console` for an interactive prompt.

Expand Down
4 changes: 2 additions & 2 deletions beyond_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ require "beyond_api/version"

Gem::Specification.new do |spec|
spec.name = "beyond_api"
spec.version = BeyondAPI::VERSION
spec.version = BeyondApi::VERSION
spec.authors = ["Unai Abrisketa", "German San Emeterio", "Kathia Salazar"]

spec.summary = %q{Ruby client to access the Beyond API}
spec.summary = %q{Ruby client to access the Beyond Api}
# spec.description = %q{Write a longer description or delete this line.}
spec.homepage = "https://github.com/ePages-de/beyond_api"

Expand Down
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require "dotenv/load"
require "beyond_api"

unless ENV["CLIENT_ID"].nil? and ENV["CLIENT_SECRET"].nil?
BeyondAPI.setup do |config|
BeyondApi.setup do |config|
config.client_id = ENV["CLIENT_ID"]
config.client_secret = ENV["CLIENT_SECRET"]
config.remove_response_links = true
Expand Down
6 changes: 3 additions & 3 deletions endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

✅ = Checked

🌞 = On the Ruby API
🌞 = On the Ruby Api

## 1. Change Log

Expand Down Expand Up @@ -1165,7 +1165,7 @@ session.products.disable_purchasability(product_id)

## 17. Custom Product Attributes

The `attributes` resource is used to manage additional user-defined attributes which have a product attribute definition as key, and a string or number as value. These are the basic attribute types supported by the API.
The `attributes` resource is used to manage additional user-defined attributes which have a product attribute definition as key, and a string or number as value. These are the basic attribute types supported by the Api.

| Type | Description |
|---|---|
Expand Down Expand Up @@ -1939,7 +1939,7 @@ session.newsletter_target.delete

## 27. Webhooks

This resource is used to manage webhook subscriptions. ePages can send webhook notifications to your application any time an event happens that you’ve subscribed to. Subscriptions are useful for events that are not triggered by a direct API request. The following event types are supported:
This resource is used to manage webhook subscriptions. ePages can send webhook notifications to your application any time an event happens that you’ve subscribed to. Subscriptions are useful for events that are not triggered by a direct Api request. The following event types are supported:

| Event Type Name | Description | Required Scope |
|---|---|---|
Expand Down
2 changes: 1 addition & 1 deletion lib/beyond_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require "beyond_api/ext"
require "beyond_api/utils"

module BeyondAPI
module BeyondApi
class Error < StandardError; end

class << self
Expand Down
14 changes: 7 additions & 7 deletions lib/beyond_api/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

require 'faraday'

module BeyondAPI
module BeyondApi
class Connection
def self.default
Faraday.new(ssl: { verify: true }) do |faraday|
faraday.options[:open_timeout] = BeyondAPI.configuration.open_timeout.to_i
faraday.options[:timeout] = BeyondAPI.configuration.timeout.to_i
faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
faraday.headers['Accept'] = 'application/json'
faraday.headers['Content-Type'] = 'application/json'
faraday.request(:multipart)
Expand All @@ -18,12 +18,12 @@ def self.default

def self.token
Faraday.new(ssl: { verify: true }) do |faraday|
faraday.options[:open_timeout] = BeyondAPI.configuration.open_timeout.to_i
faraday.options[:timeout] = BeyondAPI.configuration.timeout.to_i
faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
faraday.headers['Accept'] = 'application/json'
faraday.adapter(:net_http)
faraday.basic_auth(BeyondAPI.configuration.client_id,
BeyondAPI.configuration.client_secret)
faraday.basic_auth(BeyondApi.configuration.client_id,
BeyondApi.configuration.client_secret)
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/beyond_api/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

require "json"

module BeyondAPI
module BeyondApi
class Request
class << self
[:get, :delete].each do |method|
define_method(method) do |session, path, params = {}|
response = BeyondAPI::Connection.default.send(method) do |request|
response = BeyondApi::Connection.default.send(method) do |request|
request.url(session.api_url + path)
request.headers['Authorization'] = "Bearer #{ session.access_token }"
request.params = params.to_h.camelize_keys
Expand All @@ -19,7 +19,7 @@ class << self

[:post, :put, :patch].each do |method|
define_method(method) do |session, path, body = {}, params = {}|
response = BeyondAPI::Connection.default.send(method) do |request|
response = BeyondApi::Connection.default.send(method) do |request|
request.url(session.api_url + path)
request.headers['Authorization'] = "Bearer #{ session.access_token }"
request.params = params.to_h.camelize_keys
Expand All @@ -32,7 +32,7 @@ class << self
end

def self.upload(session, path, file_binary, content_type, params)
response = BeyondAPI::Connection.default.post do |request|
response = BeyondApi::Connection.default.post do |request|
request.url(session.api_url + path)
request.headers['Authorization'] = "Bearer #{ session.access_token }"
request.headers['Content-Type'] = content_type
Expand All @@ -44,7 +44,7 @@ def self.upload(session, path, file_binary, content_type, params)
end

def self.token(url, params)
response = BeyondAPI::Connection.token.post do |request|
response = BeyondApi::Connection.token.post do |request|
request.url(url)
request.params = params
end
Expand Down
4 changes: 2 additions & 2 deletions lib/beyond_api/resources/base.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# frozen_string_literal: true

module BeyondAPI
module BeyondApi
class Base
class InvalidSessionError < StandardError; end

attr_reader :session

def initialize(session)
@session = session
raise InvalidSessionError.new("Invalid session") unless session.is_a? BeyondAPI::Session
raise InvalidSessionError.new("Invalid session") unless session.is_a? BeyondApi::Session
if session.api_url.nil? || session.access_token.nil? || session.refresh_token.nil?
raise InvalidSessionError.new("Session api_url, access_token and refresh_token cannot be nil")
end
Expand Down
46 changes: 23 additions & 23 deletions lib/beyond_api/resources/carts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

require "beyond_api/utils"

module BeyondAPI
module BeyondApi
class Carts < Base
include BeyondAPI::Utils
include BeyondApi::Utils

#
# A +POST+ request is used to add a line item to the cart. Currently only product line items are supported.
Expand All @@ -27,7 +27,7 @@ class Carts < Base
# @cart = session.carts.add_line_item("6d529573-b39e-4cd4-99fe-856432ea97f3", body)
#
def add_line_item(cart_id, body)
response, status = BeyondAPI::Request.post(@session, "/carts/#{cart_id}/line-items", body)
response, status = BeyondApi::Request.post(@session, "/carts/#{cart_id}/line-items", body)

handle_response(response, status)
end
Expand All @@ -44,7 +44,7 @@ def add_line_item(cart_id, body)
# @cart = session.carts.create
#
def create(body)
response, status = BeyondAPI::Request.post(@session, "/carts", body)
response, status = BeyondApi::Request.post(@session, "/carts", body)

handle_response(response, status)
end
Expand Down Expand Up @@ -73,7 +73,7 @@ def create(body)
# @payment = session.carts.create_payment("158bdcee-178a-4b5f-88ff-1953f5ea8e09/", body)
#
def create_payment(cart_id, body)
response, status = BeyondAPI::Request.post(@session, "/carts/#{cart_id}/create-payment", body)
response, status = BeyondApi::Request.post(@session, "/carts/#{cart_id}/create-payment", body)

handle_response(response, status)
end
Expand Down Expand Up @@ -114,7 +114,7 @@ def create_payment(cart_id, body)
# @payment = session.carts.create_payment_and_order("f6c6615b-a9f6-420e-be1d-46339ddc5fda", body)
#
def create_payment_and_order(cart_id, body)
response, status = BeyondAPI::Request.post(@session, "/carts/#{cart_id}/create-payment-and-order", body)
response, status = BeyondApi::Request.post(@session, "/carts/#{cart_id}/create-payment-and-order", body)

handle_response(response, status)
end
Expand Down Expand Up @@ -149,7 +149,7 @@ def create_payment_and_order(cart_id, body)
# @order = session.carts.create_order("986247da-b78f-422c-a273-917804896974", body)
#
def create_order(cart_id, body)
response, status = BeyondAPI::Request.post(@session, "/carts/#{cart_id}/order", body)
response, status = BeyondApi::Request.post(@session, "/carts/#{cart_id}/order", body)

handle_response(response, status)
end
Expand All @@ -167,7 +167,7 @@ def create_order(cart_id, body)
# session.carts.delete("1a58f22f-481a-4993-9947-62c1c2857f87")
#
def delete(cart_id)
response, status = BeyondAPI::Request.delete(@session, "/carts/#{cart_id}")
response, status = BeyondApi::Request.delete(@session, "/carts/#{cart_id}")

handle_response(response, status, respond_with_true: true)
end
Expand All @@ -186,7 +186,7 @@ def delete(cart_id)
# @cart = session.carts.delete_line_item("3fb55475-f6d2-471a-90ac-ccee7896b9f7", "51c86195-d2b9-4073-9a14-7ddd5a76b6a7")
#
def delete_line_item(cart_id, line_item_id)
response, status = BeyondAPI::Request.delete(@session, "/carts/#{cart_id}/line-items/#{line_item_id}")
response, status = BeyondApi::Request.delete(@session, "/carts/#{cart_id}/line-items/#{line_item_id}")

handle_response(response, status, respond_with_true: true)
end
Expand All @@ -205,7 +205,7 @@ def delete_line_item(cart_id, line_item_id)
# session.carts.delete_line_item("2fa7dc36-8305-4628-b961-f2c3f7dda47d")
#
def delete_shipping_address(cart_id)
response, status = BeyondAPI::Request.delete(@session, "/carts/#{cart_id}/shipping-address")
response, status = BeyondApi::Request.delete(@session, "/carts/#{cart_id}/shipping-address")

handle_response(response, status, respond_with_true: true)
end
Expand All @@ -225,7 +225,7 @@ def delete_shipping_address(cart_id)
# @cart = session.carts.find("26857145-aeab-4210-9191-3906573a14ae")
#
def find(cart_id)
response, status = BeyondAPI::Request.get(@session, "/carts/#{cart_id}")
response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}")

handle_response(response, status)
end
Expand All @@ -244,7 +244,7 @@ def find(cart_id)
# @payment_method = session.carts.payment_method("26857145-aeab-4210-9191-3906573a14ae")
#
def payment_method(cart_id)
response, status = BeyondAPI::Request.get(@session, "/carts/#{cart_id}/payment-methods/current")
response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}/payment-methods/current")

handle_response(response, status)
end
Expand All @@ -266,7 +266,7 @@ def payment_method(cart_id)
# @payment_methods = session.carts.payment_methods("45f9009d-4d2f-43b1-9cd2-ea29ff0d46d6")
#
def payment_methods(cart_id)
response, status = BeyondAPI::Request.get(@session, "/carts/#{cart_id}/payment-methods")
response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}/payment-methods")

handle_response(response, status)
end
Expand All @@ -293,7 +293,7 @@ def payment_methods(cart_id)
# @cart = session.carts.replace_line_item("f73629e5-fecf-4474-9b04-6b2fcd4663c4", "2c9c0f38-0b9e-4fa7-bcbe-960098ff63aa", body)
#
def replace_line_item(cart_id, line_item_id, body)
response, status = BeyondAPI::Request.put(@session, "/carts/#{cart_id}/line-items/#{line_item_id}", body)
response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/line-items/#{line_item_id}", body)

handle_response(response, status)
end
Expand All @@ -315,7 +315,7 @@ def replace_line_item(cart_id, line_item_id, body)
# @cart = session.carts.replace_line_item("c1436110-e283-49b3-a748-0321efec6d35", body)
#
def replace_line_items(cart_id, body)
response, status = BeyondAPI::Request.put(@session, "/carts/#{cart_id}/line-items", body)
response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/line-items", body)

handle_response(response, status)
end
Expand Down Expand Up @@ -364,7 +364,7 @@ def replace_line_items(cart_id, body)
# @cart = session.carts.set_billing_address("01da6aa7-8aa2-4383-a496-6611a14afbc9", body)
#
def set_billing_address(cart_id, body)
response, status = BeyondAPI::Request.put(@session, "/carts/#{cart_id}/billing-address", body)
response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/billing-address", body)

handle_response(response, status)
end
Expand All @@ -386,7 +386,7 @@ def set_billing_address(cart_id, body)
# @cart = session.carts.set_payment_method("750c8a68-ef58-4955-b05f-29e35fa19687", "6498f339-7fe6-43d4-8e2a-6da68d7cdfe3")
#
def set_payment_method(cart_id, payment_method_id)
response, status = BeyondAPI::Request.put(@session, "/carts/#{cart_id}/payment-methods/current",
response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/payment-methods/current",
"#{@session.api_url}/payment-methods/#{payment_method_id}")

handle_response(response, status)
Expand All @@ -407,7 +407,7 @@ def set_payment_method(cart_id, payment_method_id)
# @cart = session.carts.set_payment_method_to_default("d1efcb74-ab96-43c5-b404-9c1f927dc3d2")
#
def set_payment_method_to_default(cart_id)
response, status = BeyondAPI::Request.put(@session, "/carts/#{cart_id}/payment-methods/default")
response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/payment-methods/default")

handle_response(response, status)
end
Expand Down Expand Up @@ -456,7 +456,7 @@ def set_payment_method_to_default(cart_id)
# @cart = session.carts.set_shipping_address("01da6aa7-8aa2-4383-a496-6611a14afbc9", body)
#
def set_shipping_address(cart_id, body)
response, status = BeyondAPI::Request.put(@session, "/carts/#{cart_id}/shipping-address", body)
response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/shipping-address", body)

handle_response(response, status)
end
Expand All @@ -479,7 +479,7 @@ def set_shipping_address(cart_id, body)
# @cart = session.carts.set_shipping_method("a4e7922a-f895-4a7d-8cb1-6ecf74d7ceba", "59e26c99-ef1d-4ee8-a79f-d078cd6dfe24", "f3d3ce8d-eeab-44b6-81bb-67a4f1d7a57f")
#
def set_shipping_method(cart_id, shipping_zone_id, shipping_method_id)
response, status = BeyondAPI::Request.put(@session, "/carts/#{cart_id}/shipping-methods/current",
response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/shipping-methods/current",
"#{session.api_url}/shipping-zones/#{shipping_zone_id}/shipping-methods/#{shipping_method_id}")

handle_response(response, status)
Expand All @@ -501,7 +501,7 @@ def set_shipping_method(cart_id, shipping_zone_id, shipping_method_id)
# @cart = session.carts.set_shipping_method_to_default("a4e7922a-f895-4a7d-8cb1-6ecf74d7ceba")
#
def set_shipping_method_to_default(cart_id)
response, status = BeyondAPI::Request.put(@session, "/carts/#{cart_id}/shipping-methods/current",
response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/shipping-methods/current",
"#{session.api_url}/shipping-zones/#{shipping_zone_id}/shipping-methods/#{shipping_method_id}")

handle_response(response, status)
Expand All @@ -522,7 +522,7 @@ def set_shipping_method_to_default(cart_id)
# @shipping_method = session.carts.shipping_method("9093a339-66fd-4cc1-9dcf-d23003c38b41")
#
def shipping_method(cart_id)
response, status = BeyondAPI::Request.get(@session, "/carts/#{cart_id}")
response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}")
handle_response(response, status)
end

Expand All @@ -540,7 +540,7 @@ def shipping_method(cart_id)
# @cart = session.carts.shipping_methods("05a547a0-80dc-4a8c-b9b6-aa028b6ef7d8")
#
def shipping_methods(cart_id)
response, status = BeyondAPI::Request.get(@session, "/carts/#{cart_id}")
response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}")
handle_response(response, status)
end
end
Expand Down
Loading