Sha256: 74f6bfb467e750de0102f6f76f2829801fe0f2e29987bfc35f80b1597fe2cabf

Contents?: true

Size: 1.71 KB

Versions: 7

Compression:

Stored size: 1.71 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" => "paddlerb/v#{VERSION} (github.com/deanpcmad/paddlerb)"
          }

          conn.request :json

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
paddle-2.1.2 lib/paddle/classic/client.rb
paddle-2.1.1 lib/paddle/classic/client.rb
paddle-2.1.0 lib/paddle/classic/client.rb
paddle-2.0.0 lib/paddle/classic/client.rb
paddle-1.1.2 lib/paddle/classic/client.rb
paddle-1.1.1 lib/paddle/classic/client.rb
paddle-1.1.0 lib/paddle/classic/client.rb