Sha256: 38b1bb8918e2a9b1064b1739fdd3e2dcd36c27c1a7e32f1bb601e6a53d8e3c3e

Contents?: true

Size: 1.7 KB

Versions: 9

Compression:

Stored size: 1.7 KB

Contents

module Paddle
  module Classic
    class Client
      BASE_URL = "https://vendors.paddle.com/api"
      SANDBOX_BASE_URL = "https://sandbox-vendors.paddle.com/api"

      attr_reader :vendor_id, :vendor_auth_code, :sandbox, :adapter

      def initialize(vendor_id:, vendor_auth_code:, sandbox: false, adapter: Faraday.default_adapter, stubs: nil)
        @vendor_id = vendor_id
        @vendor_auth_code = vendor_auth_code
        @sandbox = sandbox
        @adapter = adapter

        # Test stubs for requests
        @stubs = stubs
      end

      def plans
        PlansResource.new(self)
      end

      def coupons
        CouponsResource.new(self)
      end

      def products
        ProductsResource.new(self)
      end

      def licenses
        LicensesResource.new(self)
      end

      def pay_links
        PayLinksResource.new(self)
      end

      def transactions
        TransactionsResource.new(self)
      end

      def payments
        PaymentsResource.new(self)
      end

      def users
        UsersResource.new(self)
      end

      def webhooks
        WebhooksResource.new(self)
      end

      def modifiers
        ModifiersResource.new(self)
      end

      def charges
        ChargesResource.new(self)
      end

      def url
        if sandbox == true
          SANDBOX_BASE_URL
        else
          BASE_URL
        end
      end

      def connection
        @connection ||= Faraday.new(url) do |conn|
          conn.headers = {
            "User-Agent" => "paddle/v#{VERSION} (github.com/deanpcmad/paddle)"
          }

          conn.request :json

          conn.response :json, content_type: "application/json"

          conn.adapter adapter, @stubs
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
paddle-2.7.0 lib/paddle/classic/client.rb
paddle-2.6.0 lib/paddle/classic/client.rb
paddle-2.5.2 lib/paddle/classic/client.rb
paddle-2.5.1 lib/paddle/classic/client.rb
paddle-2.5.0 lib/paddle/classic/client.rb
paddle-2.4.1 lib/paddle/classic/client.rb
paddle-2.4.0 lib/paddle/classic/client.rb
paddle-2.3.0 lib/paddle/classic/client.rb
paddle-2.2.1 lib/paddle/classic/client.rb