Sha256: be8c7f7d643318fef059b06fc57d3b5ae8c9edc6152afa14c46fc554b6c963ef

Contents?: true

Size: 616 Bytes

Versions: 1

Compression:

Stored size: 616 Bytes

Contents

require 'rest-client'

class DiscoApp::ApiClient

  SUBSCRIPTION_ENDPOINT = 'app_subscriptions.json'.freeze

  def initialize(shop, url)
    @shop = shop
    @url = url
  end

  def create_app_subscription
    return if @url.blank?

    url = @url + SUBSCRIPTION_ENDPOINT
    begin
      RestClient::Request.execute(
        method: :post,
        headers: { content_type: :json },
        url: url,
        payload: { shop: @shop, subscription: @shop.current_subscription }.to_json
      )
    rescue RestClient::BadRequest, RestClient::ResourceNotFound => e
      raise DiscoApiError, e.message
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
disco_app-0.17.0 app/clients/disco_app/api_client.rb