class BusinessCentral::Subscription

Constants

API_OBJECT
SUPPORTED_METHODS

Attributes

client[R]
endpoint[R]
resource[R]

Public Class Methods

new(client, resource, endpoint) click to toggle source
# File lib/business_central/subscription.rb, line 17
def initialize(client, resource, endpoint)
  @client = client.nil? ? BusinessCentral::Client.new() : client
  @resource = resource
  @endpoint = endpoint
end

Public Instance Methods

build_request_object() click to toggle source
# File lib/business_central/subscription.rb, line 60
def build_request_object
end
create() click to toggle source
# File lib/business_central/subscription.rb, line 31
def create
  request = Net::HTTP::Post.new(URI(request_url))
  request.content_type = "application/json"
  request.basic_auth(@client.api_username, @client.api_password)
  request.body = JSON.generate(post_data)
  request

  response = perform_request(request)

  JSON.parse(response.body)
end
get() click to toggle source
# File lib/business_central/subscription.rb, line 23
def get
  request = Net::HTTP::Get.new(URI(request_url))
  request.content_type = "application/json"
  request.basic_auth(@client.api_username, @client.api_password)
  response = perform_request(request)
  JSON.parse(response.body)
end
perform_request(request) click to toggle source
# File lib/business_central/subscription.rb, line 43
def perform_request(request)
  Net::HTTP.start(request.uri.hostname, request.uri.port, use_ssl: true) do |http|
    http.request(request)
  end
end
post_data() click to toggle source
# File lib/business_central/subscription.rb, line 53
def post_data
  {
    "notificationUrl": @endpoint,
    "resource": @resource
  }
end
request_url() click to toggle source
# File lib/business_central/subscription.rb, line 49
def request_url
  "#{@client.api_host}#{@client.api_version}#{@client.api_path}/subscriptions"
end